Example usage for org.objectweb.asm Type SHORT_TYPE

List of usage examples for org.objectweb.asm Type SHORT_TYPE

Introduction

In this page you can find the example usage for org.objectweb.asm Type SHORT_TYPE.

Prototype

Type SHORT_TYPE

To view the source code for org.objectweb.asm Type SHORT_TYPE.

Click Source Link

Document

The short type.

Usage

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() {//w w  w . j a  v a  2 s.c  o  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  a  v a 2  s  . com
 *
 * @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 testShortUnbox() {
    ByteCodeUtils.unbox(generator, Type.SHORT_TYPE);
    verify(generator, times(1)).checkCast(Type.getObjectType("java/lang/Number"));
    verify(generator, times(1)).invokeVirtual(Type.getObjectType("java/lang/Number"),
            Method.getMethod("short shortValue()"));
}

From source file:com.asakusafw.dag.compiler.codegen.AsmUtil.java

License:Apache License

/**
 * Returns the ASM {@link Type} object.//from   w w  w. ja  v  a  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.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//ww  w. j  av a 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   ww  w  . j ava 2 s  . c  om*/
            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 ww. j  a  v  a  2  s.com*/
            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 nShort(short i) {
    return new Constant(Type.SHORT_TYPE, i);
}

From source file:com.googlecode.dex2jar.ir.ts.TypeAnalyze.java

License:Apache License

private void e0expr(E0Expr op) {
    switch (op.vt) {
    case LOCAL://from  w w w. jav a2  s. c  o  m
        break;
    case NEW:
        NewExpr newExpr = (NewExpr) op;
        provideAs(newExpr, newExpr.type);
        break;
    case THIS_REF:
    case PARAMETER_REF:
    case EXCEPTION_REF:
        RefExpr refExpr = (RefExpr) op;
        Type refType = refExpr.type;
        if (refType == null && op.vt == VT.EXCEPTION_REF) {
            refType = Type.getType(Throwable.class);
        }
        provideAs(refExpr, refType);
        break;
    case CONSTANT:
        Constant cst = (Constant) op;
        // Type type = cst.type;
        Object value = cst.value;
        if (value instanceof String) {
            provideAs(cst, Type.getType(String.class));
        } else if (value instanceof Type) {
            provideAs(cst, Type.getType(Class.class));
        } else if (value instanceof Number) {
            if (value instanceof Integer || value instanceof Byte || value instanceof Short
                    || value instanceof Character) {
                int a = ((Number) value).intValue();
                if (a >= 0 && a <= 1) {
                    provideAs(cst, Type.BOOLEAN_TYPE);
                } else if (a >= Byte.MIN_VALUE && a <= Byte.MAX_VALUE) {
                    provideAs(cst, Type.BYTE_TYPE);
                } else if (a >= Short.MIN_VALUE && a <= Short.MAX_VALUE) {
                    provideAs(cst, Type.SHORT_TYPE);
                } else if (a >= Character.MIN_VALUE && a <= Character.MAX_VALUE) {
                    provideAs(cst, Type.CHAR_TYPE);
                } else {
                    provideAs(cst, Type.INT_TYPE);
                }
            } else if (value instanceof Long) {
                provideAs(cst, Type.LONG_TYPE);
            } else if (value instanceof Float) {
                provideAs(cst, Type.FLOAT_TYPE);
            } else if (value instanceof Double) {
                provideAs(cst, Type.DOUBLE_TYPE);
            }
        }
        break;
    }
}