List of usage examples for org.objectweb.asm Type BYTE_TYPE
Type BYTE_TYPE
To view the source code for org.objectweb.asm Type BYTE_TYPE.
Click Source Link
From source file:boilerplate.processor.adapters.EqualsGenerators.java
License:Open Source License
private static final List<BytecodeGenerator> createGeneratorList() { BytecodeGenerator[] generators = { new Int32Generator(Type.BOOLEAN_TYPE), new Int32Generator(Type.CHAR_TYPE), new Int32Generator(Type.INT_TYPE), new Int32Generator(Type.SHORT_TYPE), new Int32Generator(Type.BYTE_TYPE), new LongGenerator(), new FloatGenerator(), new DoubleGenerator(), new ArraysGenerator(), new ObjectGenerator(), }; List<BytecodeGenerator> list = Arrays.asList(generators); return Collections.unmodifiableList(list); }
From source file:boilerplate.processor.adapters.ToStringMethodInsertion.java
License:Open Source License
private static List<BytecodeGenerator> createMethodList() { final Type objectType = Type.getType(Object.class); class ObjectMethodInsn extends ToStringMethodInsertion { ObjectMethodInsn() {/*from w w w. ja va2s .co m*/ super(objectType, "appendObject", "(Ljava/lang/StringBuilder;Ljava/lang/String;Ljava/lang/Object;)V"); } @Override public boolean matches(Type type) { return true; } } BytecodeGenerator[] arr = { new ToStringMethodInsertion(Type.BOOLEAN_TYPE, "appendBoolean", "(Ljava/lang/StringBuilder;Ljava/lang/String;Z)V"), new ToStringMethodInsertion(Type.BYTE_TYPE, "appendByte", "(Ljava/lang/StringBuilder;Ljava/lang/String;B)V"), new ToStringMethodInsertion(Type.CHAR_TYPE, "appendChar", "(Ljava/lang/StringBuilder;Ljava/lang/String;C)V"), new ToStringMethodInsertion(Type.DOUBLE_TYPE, "appendDouble", "(Ljava/lang/StringBuilder;Ljava/lang/String;D)V"), new ToStringMethodInsertion(Type.FLOAT_TYPE, "appendFloat", "(Ljava/lang/StringBuilder;Ljava/lang/String;F)V"), new ToStringMethodInsertion(Type.INT_TYPE, "appendInt", "(Ljava/lang/StringBuilder;Ljava/lang/String;I)V"), new ToStringMethodInsertion(Type.LONG_TYPE, "appendLong", "(Ljava/lang/StringBuilder;Ljava/lang/String;J)V"), new ToStringMethodInsertion(Type.SHORT_TYPE, "appendShort", "(Ljava/lang/StringBuilder;Ljava/lang/String;S)V"), // default new ObjectMethodInsn(), }; List<BytecodeGenerator> list = Arrays.asList(arr); return Collections.unmodifiableList(list); }
From source file:com.android.build.gradle.internal.incremental.ByteCodeUtils.java
License:Apache License
/** * Generates unboxing bytecode for the passed type. An {@link Object} is expected to be on the * stack when these bytecodes are inserted. * * ASM takes a short cut when dealing with short/byte types and convert them into int rather * than short/byte types. This is not an issue on the jvm nor Android's ART but it is an issue * on Dalvik.//w w w. j av a 2s. co m * * @param mv the {@link GeneratorAdapter} generating a method implementation. * @param type the expected un-boxed type. */ public static void unbox(GeneratorAdapter mv, Type type) { if (type.equals(Type.SHORT_TYPE)) { mv.checkCast(NUMBER_TYPE); mv.invokeVirtual(NUMBER_TYPE, SHORT_VALUE); } else if (type.equals(Type.BYTE_TYPE)) { mv.checkCast(NUMBER_TYPE); mv.invokeVirtual(NUMBER_TYPE, BYTE_VALUE); } else { mv.unbox(type); } }
From source file:com.android.build.gradle.internal.incremental.ByteCodeUtilsTest.java
License:Apache License
@Test public void testByteUnbox() { ByteCodeUtils.unbox(generator, Type.BYTE_TYPE); verify(generator, times(1)).checkCast(Type.getObjectType("java/lang/Number")); verify(generator, times(1)).invokeVirtual(Type.getObjectType("java/lang/Number"), Method.getMethod("byte byteValue()")); }
From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java
License:Apache License
/** * Returns the ASM {@link Type} object./* ww w . j a va 2 s. co m*/ * @param type the target type description * @return the corresponded {@link Type} object */ public static Type typeOf(TypeDescription type) { Arguments.requireNonNull(type); TypeDescription e = type.getErasure(); switch (e.getTypeKind()) { case BASIC: switch (((BasicTypeDescription) e).getBasicTypeKind()) { case BOOLEAN: return Type.BOOLEAN_TYPE; case BYTE: return Type.BYTE_TYPE; case CHAR: return Type.CHAR_TYPE; case DOUBLE: return Type.DOUBLE_TYPE; case FLOAT: return Type.FLOAT_TYPE; case INT: return Type.INT_TYPE; case LONG: return Type.LONG_TYPE; case SHORT: return Type.SHORT_TYPE; case VOID: return Type.VOID_TYPE; default: throw new AssertionError(type); } case ARRAY: return Type.getType('[' + typeOf(((ArrayTypeDescription) e).getComponentType()).getDescriptor()); case CLASS: return Type.getObjectType(((ClassDescription) e).getInternalName()); default: throw new AssertionError(type); } }
From source file:com.asakusafw.dag.compiler.codegen.KeyValueSerDeGenerator.java
License:Apache License
private static void putDeserializeBody(MethodVisitor v, List<PropertyReference> props, LocalVarRef input, LocalVarRef object) {/*from ww w . j a va 2 s . co m*/ if (props.isEmpty()) { input.load(v); v.visitMethodInsn(Opcodes.INVOKEINTERFACE, typeOf(DataInput.class).getInternalName(), "readByte", Type.getMethodDescriptor(Type.BYTE_TYPE), true); v.visitInsn(Opcodes.POP); } else { for (PropertyReference property : props) { object.load(v); getOption(v, property); input.load(v); v.visitMethodInsn(Opcodes.INVOKESTATIC, SERDE.getInternalName(), "deserialize", Type .getMethodDescriptor(Type.VOID_TYPE, typeOf(property.getType()), typeOf(DataInput.class)), false); } } }
From source file:com.facebook.buck.jvm.java.abi.DescriptorFactory.java
License:Apache License
public Type getType(TypeMirror typeMirror) { return Preconditions.checkNotNull(typeMirror.accept(new SimpleTypeVisitor8<Type, Void>() { @Override/*from w ww.java 2s. co m*/ protected Type defaultAction(TypeMirror t, Void aVoid) { throw new IllegalArgumentException(String.format("Unexpected type kind: %s", t.getKind())); } @Override public Type visitPrimitive(PrimitiveType type, Void aVoid) { switch (type.getKind()) { case BOOLEAN: return Type.BOOLEAN_TYPE; case BYTE: return Type.BYTE_TYPE; case CHAR: return Type.CHAR_TYPE; case SHORT: return Type.SHORT_TYPE; case INT: return Type.INT_TYPE; case LONG: return Type.LONG_TYPE; case FLOAT: return Type.FLOAT_TYPE; case DOUBLE: return Type.DOUBLE_TYPE; // $CASES-OMITTED$ default: throw new IllegalArgumentException(String.format("Unexpected type kind: %s", type.getKind())); } } @Override public Type visitNoType(NoType t, Void aVoid) { if (t.getKind() != TypeKind.VOID) { throw new IllegalArgumentException(String.format("Unexpected type kind: %s", t.getKind())); } return Type.VOID_TYPE; } @Override public Type visitArray(ArrayType t, Void aVoid) { return Type.getObjectType("[" + getDescriptor(t.getComponentType())); } @Override public Type visitDeclared(DeclaredType t, Void aVoid) { // The erasure of a parameterized type is just the unparameterized version (JLS8 4.6) TypeElement typeElement = (TypeElement) t.asElement(); if (typeElement.getQualifiedName().contentEquals("")) { // javac 7 uses a DeclaredType to model an intersection type if (typeElement.getKind() == ElementKind.INTERFACE) { return getType(typeElement.getInterfaces().get(0)); } return getType(typeElement.getSuperclass()); } return Type.getObjectType(getInternalName(typeElement)); } @Override public Type visitError(ErrorType t, Void aVoid) { // If there's an ErrorType, compilation is going to fail anyway, so it doesn't // matter what we return. return Type.getObjectType("java/lang/Object"); } @Override public Type visitTypeVariable(TypeVariable t, Void aVoid) { // The erasure of a type variable is the erasure of its leftmost bound (JLS8 4.6) // If there's only one bound, getUpperBound returns it directly; if there's more than // one it returns an IntersectionType return getType(t.getUpperBound()); } @Override public Type visitIntersection(IntersectionType t, Void aVoid) { // The erasure of a type variable is the erasure of its leftmost bound (JLS8 4.6) return getType(t.getBounds().get(0)); } }, null)); }
From source file:com.github.javalbert.reflection.ClassAccessFactory.java
License:Apache License
private void visitFieldAccessMethods() { List<AccessInfo> fieldAccessInfoList = Collections.unmodifiableList(Arrays.asList( // Primitive types ///*from w ww.j a va 2 s.c o m*/ AccessInfo.forPrimitive(MEMBER_TYPE_FIELD, Type.BOOLEAN_TYPE), AccessInfo.forPrimitive(MEMBER_TYPE_FIELD, Type.BYTE_TYPE), AccessInfo.forPrimitive(MEMBER_TYPE_FIELD, Type.CHAR_TYPE), AccessInfo.forPrimitive(MEMBER_TYPE_FIELD, Type.DOUBLE_TYPE), AccessInfo.forPrimitive(MEMBER_TYPE_FIELD, Type.FLOAT_TYPE), AccessInfo.forPrimitive(MEMBER_TYPE_FIELD, Type.INT_TYPE), AccessInfo.forPrimitive(MEMBER_TYPE_FIELD, Type.LONG_TYPE), AccessInfo.forPrimitive(MEMBER_TYPE_FIELD, Type.SHORT_TYPE), // Primitive wrapper types // AccessInfo.forPrimitiveWrapper(MEMBER_TYPE_FIELD, Boolean.class), AccessInfo.forPrimitiveWrapper(MEMBER_TYPE_FIELD, Byte.class), AccessInfo.forPrimitiveWrapper(MEMBER_TYPE_FIELD, Character.class), AccessInfo.forPrimitiveWrapper(MEMBER_TYPE_FIELD, Double.class), AccessInfo.forPrimitiveWrapper(MEMBER_TYPE_FIELD, Float.class), AccessInfo.forPrimitiveWrapper(MEMBER_TYPE_FIELD, Integer.class), AccessInfo.forPrimitiveWrapper(MEMBER_TYPE_FIELD, Long.class), AccessInfo.forPrimitiveWrapper(MEMBER_TYPE_FIELD, Short.class), // Common reference types // AccessInfo.forReferenceType(MEMBER_TYPE_FIELD, BigDecimal.class), AccessInfo.forReferenceType(MEMBER_TYPE_FIELD, Date.class), AccessInfo.forReferenceType(MEMBER_TYPE_FIELD, LocalDate.class), AccessInfo.forReferenceType(MEMBER_TYPE_FIELD, LocalDateTime.class), AccessInfo.forReferenceType(MEMBER_TYPE_FIELD, String.class))); for (int i = 0; i < fieldAccessInfoList.size(); i++) { AccessInfo fieldAccessInfo = fieldAccessInfoList.get(i); List<FieldInfo> fieldInfoList = typeToFieldsMap.get(fieldAccessInfo.className); visitAccessGetter(fieldInfoList, fieldAccessInfo); visitAccessGetterBridge(fieldAccessInfo); visitAccessSetter(fieldInfoList, fieldAccessInfo); visitAccessSetterBridge(fieldAccessInfo); } visitGeneralAccessGetter("getField", MEMBER_TYPE_FIELD, fieldInfoList); visitAccessGetterBridge("getField", "Ljava/lang/Object;", ARETURN); visitGeneralAccessSetter("setField", MEMBER_TYPE_FIELD, fieldInfoList); visitAccessSetterBridge("setField", ALOAD, "Ljava/lang/Object;"); }
From source file:com.github.javalbert.reflection.ClassAccessFactory.java
License:Apache License
private void visitPropertyAccessMethods() { List<AccessInfo> propertyAccessInfoList = Collections.unmodifiableList(Arrays.asList( // Primitive types ////from w w w .j a v a2 s . c o m AccessInfo.forPrimitive(MEMBER_TYPE_PROPERTY, Type.BOOLEAN_TYPE), AccessInfo.forPrimitive(MEMBER_TYPE_PROPERTY, Type.BYTE_TYPE), AccessInfo.forPrimitive(MEMBER_TYPE_PROPERTY, Type.CHAR_TYPE), AccessInfo.forPrimitive(MEMBER_TYPE_PROPERTY, Type.DOUBLE_TYPE), AccessInfo.forPrimitive(MEMBER_TYPE_PROPERTY, Type.FLOAT_TYPE), AccessInfo.forPrimitive(MEMBER_TYPE_PROPERTY, Type.INT_TYPE), AccessInfo.forPrimitive(MEMBER_TYPE_PROPERTY, Type.LONG_TYPE), AccessInfo.forPrimitive(MEMBER_TYPE_PROPERTY, Type.SHORT_TYPE), // Primitive wrapper types // AccessInfo.forPrimitiveWrapper(MEMBER_TYPE_PROPERTY, Boolean.class), AccessInfo.forPrimitiveWrapper(MEMBER_TYPE_PROPERTY, Byte.class), AccessInfo.forPrimitiveWrapper(MEMBER_TYPE_PROPERTY, Character.class), AccessInfo.forPrimitiveWrapper(MEMBER_TYPE_PROPERTY, Double.class), AccessInfo.forPrimitiveWrapper(MEMBER_TYPE_PROPERTY, Float.class), AccessInfo.forPrimitiveWrapper(MEMBER_TYPE_PROPERTY, Integer.class), AccessInfo.forPrimitiveWrapper(MEMBER_TYPE_PROPERTY, Long.class), AccessInfo.forPrimitiveWrapper(MEMBER_TYPE_PROPERTY, Short.class), // Common reference types // AccessInfo.forReferenceType(MEMBER_TYPE_PROPERTY, BigDecimal.class), AccessInfo.forReferenceType(MEMBER_TYPE_PROPERTY, Date.class), AccessInfo.forReferenceType(MEMBER_TYPE_PROPERTY, LocalDate.class), AccessInfo.forReferenceType(MEMBER_TYPE_PROPERTY, LocalDateTime.class), AccessInfo.forReferenceType(MEMBER_TYPE_PROPERTY, String.class))); for (int i = 0; i < propertyAccessInfoList.size(); i++) { AccessInfo propertyAccessInfo = propertyAccessInfoList.get(i); visitAccessGetter(typeToAccessorsMap.get(propertyAccessInfo.className), propertyAccessInfo); visitAccessGetterBridge(propertyAccessInfo); visitAccessSetter(typeToMutatorsMap.get(propertyAccessInfo.className), propertyAccessInfo); visitAccessSetterBridge(propertyAccessInfo); } visitGeneralAccessGetter("getProperty", MEMBER_TYPE_PROPERTY, accessorInfoList); visitAccessGetterBridge("getProperty", "Ljava/lang/Object;", ARETURN); visitGeneralAccessSetter("setProperty", MEMBER_TYPE_PROPERTY, mutatorInfoList); visitAccessSetterBridge("setProperty", ALOAD, "Ljava/lang/Object;"); }
From source file:com.googlecode.dex2jar.ir.Constant.java
License:Apache License
public static Constant nByte(byte i) { return new Constant(Type.BYTE_TYPE, i); }