Example usage for org.objectweb.asm Type BOOLEAN_TYPE

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

Introduction

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

Prototype

Type BOOLEAN_TYPE

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

Click Source Link

Document

The boolean 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 a2 s .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.asakusafw.dag.compiler.codegen.AsmUtil.java

License:Apache License

/**
 * Returns the ASM {@link Type} object.//from   w w  w .  j  av a  2s .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.AsmUtil.java

License:Apache License

/**
 * Invokes {@code ValueOption#isNull()}.
 * @param method the target method//from w  ww  .j av  a  2s .c  o  m
 * @param dataType the data type
 */
public static void getNullity(MethodVisitor method, TypeDescription dataType) {
    method.visitMethodInsn(Opcodes.INVOKEVIRTUAL, typeOf(dataType).getInternalName(), "isNull",
            Type.getMethodDescriptor(Type.BOOLEAN_TYPE), false);
}

From source file:com.datatorrent.stram.webapp.asm.ASMUtil.java

License:Apache License

/**
 * Get a list of getter methods from classnode asmNode
 * @param asmNode/*from  ww  w.j av  a 2  s  .  c  o  m*/
 * @return empty list if there is no getter method
 */
public static List<MethodNode> getPublicGetter(ClassNode asmNode) {
    List<MethodNode> result = new LinkedList<MethodNode>();
    @SuppressWarnings("unchecked")
    List<MethodNode> mList = asmNode.methods;
    for (MethodNode methodNode : mList) {

        if (
        //arg-list is 0 and return type is not void
        (Type.getArgumentTypes(methodNode.desc).length == 0
                && Type.getReturnType(methodNode.desc) != Type.VOID_TYPE) &&
        // and method name start with get or start with is if return type is boolean
                (methodNode.name.startsWith("get") || (methodNode.name.startsWith("is")
                        && Type.getReturnType(methodNode.desc) == Type.BOOLEAN_TYPE))
                &&
                // and must be public
                isPublic(methodNode.access))
            result.add(methodNode);
    }
    return result;
}

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/*www. ja v 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.gargoylesoftware.js.nashorn.internal.runtime.linker.JavaAdapterBytecodeGenerator.java

License:Open Source License

/**
 * Generates a method in the adapter class that adapts a method from the original class. The generated methods will
 * inspect the method handle field assigned to them. If it is null (the JS object doesn't provide an implementation
 * for the method) then it will either invoke its version in the supertype, or if it is abstract, throw an
 * {@link UnsupportedOperationException}. Otherwise, if the method handle field's value is not null, the handle is
 * invoked using invokeExact (signature polymorphic invocation as per JLS 15.12.3). Before the invocation, the
 * current Nashorn {@link Context} is checked, and if it is different than the global used to create the adapter
 * instance, the creating global is set to be the current global. In this case, the previously current global is
 * restored after the invocation. If invokeExact results in a Throwable that is not one of the method's declared
 * exceptions, and is not an unchecked throwable, then it is wrapped into a {@link RuntimeException} and the runtime
 * exception is thrown. The method handle retrieved from the field is guaranteed to exactly match the signature of
 * the method; this is guaranteed by the way constructors of the adapter class obtain them using
 * {@link #getHandle(Object, String, MethodType, boolean)}.
 * @param mi the method info describing the method to be generated.
 *//*from w w w  .j av  a 2  s  . c o  m*/
private void generateMethod(final MethodInfo mi) {
    final Method method = mi.method;
    final Class<?>[] exceptions = method.getExceptionTypes();
    final String[] exceptionNames = getExceptionNames(exceptions);
    final MethodType type = mi.type;
    final String methodDesc = type.toMethodDescriptorString();
    final String name = mi.getName();

    final Type asmType = Type.getMethodType(methodDesc);
    final Type[] asmArgTypes = asmType.getArgumentTypes();

    final InstructionAdapter mv = new InstructionAdapter(
            cw.visitMethod(getAccessModifiers(method), name, methodDesc, null, exceptionNames));
    mv.visitCode();

    final Label handleDefined = new Label();

    final Class<?> returnType = type.returnType();
    final Type asmReturnType = Type.getType(returnType);

    // See if we have overriding method handle defined
    if (classOverride) {
        mv.getstatic(generatedClassName, mi.methodHandleFieldName, METHOD_HANDLE_TYPE_DESCRIPTOR);
    } else {
        mv.visitVarInsn(ALOAD, 0);
        mv.getfield(generatedClassName, mi.methodHandleFieldName, METHOD_HANDLE_TYPE_DESCRIPTOR);
    }
    // stack: [handle]
    mv.visitInsn(DUP);
    mv.visitJumpInsn(IFNONNULL, handleDefined);

    // No handle is available, fall back to default behavior
    if (Modifier.isAbstract(method.getModifiers())) {
        // If the super method is abstract, throw an exception
        mv.anew(UNSUPPORTED_OPERATION_TYPE);
        mv.dup();
        mv.invokespecial(UNSUPPORTED_OPERATION_TYPE_NAME, INIT, VOID_NOARG_METHOD_DESCRIPTOR, false);
        mv.athrow();
    } else {
        mv.visitInsn(POP);
        // If the super method is not abstract, delegate to it.
        emitSuperCall(mv, method.getDeclaringClass(), name, methodDesc);
    }

    mv.visitLabel(handleDefined);
    // Load the creatingGlobal object
    if (classOverride) {
        // If class handle is defined, load the static defining global
        mv.getstatic(generatedClassName, GLOBAL_FIELD_NAME, GLOBAL_TYPE_DESCRIPTOR);
    } else {
        mv.visitVarInsn(ALOAD, 0);
        mv.getfield(generatedClassName, GLOBAL_FIELD_NAME, GLOBAL_TYPE_DESCRIPTOR);
    }
    // stack: [creatingGlobal, handle]
    final Label setupGlobal = new Label();
    mv.visitLabel(setupGlobal);

    // Determine the first index for a local variable
    int nextLocalVar = 1; // "this" is at 0
    for (final Type t : asmArgTypes) {
        nextLocalVar += t.getSize();
    }
    // Set our local variable indices
    final int currentGlobalVar = nextLocalVar++;
    final int globalsDifferVar = nextLocalVar++;

    mv.dup();
    // stack: [creatingGlobal, creatingGlobal, handle]

    // Emit code for switching to the creating global
    // Global currentGlobal = Context.getGlobal();
    invokeGetGlobal(mv);
    mv.dup();

    mv.visitVarInsn(ASTORE, currentGlobalVar);
    // stack: [currentGlobal, creatingGlobal, creatingGlobal, handle]
    // if(definingGlobal == currentGlobal) {
    final Label globalsDiffer = new Label();
    mv.ifacmpne(globalsDiffer);
    // stack: [creatingGlobal, handle]
    //     globalsDiffer = false
    mv.pop();
    // stack: [handle]
    mv.iconst(0); // false
    // stack: [false, handle]
    final Label invokeHandle = new Label();
    mv.goTo(invokeHandle);
    mv.visitLabel(globalsDiffer);
    // } else {
    //     Context.setGlobal(definingGlobal);
    // stack: [creatingGlobal, handle]
    invokeSetGlobal(mv);
    // stack: [handle]
    //     globalsDiffer = true
    mv.iconst(1);
    // stack: [true, handle]

    mv.visitLabel(invokeHandle);
    mv.visitVarInsn(ISTORE, globalsDifferVar);
    // stack: [handle]

    // Load all parameters back on stack for dynamic invocation. NOTE: since we're using a generic
    // Object(Object, Object, ...) type signature for the method, we must box all arguments here.
    int varOffset = 1;
    for (final Type t : asmArgTypes) {
        mv.load(varOffset, t);
        boxStackTop(mv, t);
        varOffset += t.getSize();
    }

    // Invoke the target method handle
    final Label tryBlockStart = new Label();
    mv.visitLabel(tryBlockStart);
    emitInvokeExact(mv, type.generic());
    convertReturnValue(mv, returnType, asmReturnType);
    final Label tryBlockEnd = new Label();
    mv.visitLabel(tryBlockEnd);
    emitFinally(mv, currentGlobalVar, globalsDifferVar);
    mv.areturn(asmReturnType);

    // If Throwable is not declared, we need an adapter from Throwable to RuntimeException
    final boolean throwableDeclared = isThrowableDeclared(exceptions);
    final Label throwableHandler;
    if (!throwableDeclared) {
        // Add "throw new RuntimeException(Throwable)" handler for Throwable
        throwableHandler = new Label();
        mv.visitLabel(throwableHandler);
        mv.anew(RUNTIME_EXCEPTION_TYPE);
        mv.dupX1();
        mv.swap();
        mv.invokespecial(RUNTIME_EXCEPTION_TYPE_NAME, INIT,
                Type.getMethodDescriptor(Type.VOID_TYPE, THROWABLE_TYPE), false);
        // Fall through to rethrow handler
    } else {
        throwableHandler = null;
    }
    final Label rethrowHandler = new Label();
    mv.visitLabel(rethrowHandler);
    // Rethrow handler for RuntimeException, Error, and all declared exception types
    emitFinally(mv, currentGlobalVar, globalsDifferVar);
    mv.athrow();
    final Label methodEnd = new Label();
    mv.visitLabel(methodEnd);

    mv.visitLocalVariable("currentGlobal", GLOBAL_TYPE_DESCRIPTOR, null, setupGlobal, methodEnd,
            currentGlobalVar);
    mv.visitLocalVariable("globalsDiffer", Type.BOOLEAN_TYPE.getDescriptor(), null, setupGlobal, methodEnd,
            globalsDifferVar);

    if (throwableDeclared) {
        mv.visitTryCatchBlock(tryBlockStart, tryBlockEnd, rethrowHandler, THROWABLE_TYPE_NAME);
        assert throwableHandler == null;
    } else {
        mv.visitTryCatchBlock(tryBlockStart, tryBlockEnd, rethrowHandler, RUNTIME_EXCEPTION_TYPE_NAME);
        mv.visitTryCatchBlock(tryBlockStart, tryBlockEnd, rethrowHandler, ERROR_TYPE_NAME);
        for (final String excName : exceptionNames) {
            mv.visitTryCatchBlock(tryBlockStart, tryBlockEnd, rethrowHandler, excName);
        }
        mv.visitTryCatchBlock(tryBlockStart, tryBlockEnd, throwableHandler, THROWABLE_TYPE_NAME);
    }
    endMethod(mv);
}

From source file:com.gargoylesoftware.js.nashorn.internal.tools.nasgen.MemberInfo.java

License:Open Source License

void verify() {
    switch (kind) {
    case CONSTRUCTOR: {
        final Type returnType = Type.getReturnType(javaDesc);
        if (!isJSObjectType(returnType)) {
            //commented for now, to processes classes from "src/test/java"
            //error("return value of a @Constructor method should be of Object type, found " + returnType);
        }//from   w w  w  .  jav a 2s  .c om
        final Type[] argTypes = Type.getArgumentTypes(javaDesc);
        if (argTypes.length < 2) {
            error("@Constructor methods should have at least 2 args");
        }
        if (!argTypes[0].equals(Type.BOOLEAN_TYPE)) {
            error("first argument of a @Constructor method should be of boolean type, found " + argTypes[0]);
        }
        if (!isJavaLangObject(argTypes[1])) {
            error("second argument of a @Constructor method should be of Object type, found " + argTypes[0]);
        }

        if (argTypes.length > 2) {
            for (int i = 2; i < argTypes.length - 1; i++) {
                if (!isJavaLangObject(argTypes[i])) {
                    error(i + "'th argument of a @Constructor method should be of Object type, found "
                            + argTypes[i]);
                }
            }

            final String lastArgTypeDesc = argTypes[argTypes.length - 1].getDescriptor();
            final boolean isVarArg = lastArgTypeDesc.equals(OBJECT_ARRAY_DESC);
            if (!lastArgTypeDesc.equals(OBJECT_DESC) && !isVarArg) {
                error("last argument of a @Constructor method is neither Object nor Object[] type: "
                        + lastArgTypeDesc);
            }

            if (isVarArg && argTypes.length > 3) {
                error("vararg of a @Constructor method has more than 3 arguments");
            }
        }
    }
        break;
    case FUNCTION: {
        final Type returnType = Type.getReturnType(javaDesc);
        if (!(isValidJSType(returnType) || Type.VOID_TYPE == returnType)) {
            error("return value of a @Function method should be a valid JS type, found " + returnType);
        }
        final Type[] argTypes = Type.getArgumentTypes(javaDesc);
        if (argTypes.length < 1) {
            error("@Function methods should have at least 1 arg");
        }
        if (!isJavaLangObject(argTypes[0])) {
            error("first argument of a @Function method should be of Object type, found " + argTypes[0]);
        }

        if (argTypes.length > 1) {
            for (int i = 1; i < argTypes.length - 1; i++) {
                if (!isJavaLangObject(argTypes[i])) {
                    error(i + "'th argument of a @Function method should be of Object type, found "
                            + argTypes[i]);
                }
            }

            final String lastArgTypeDesc = argTypes[argTypes.length - 1].getDescriptor();
            final boolean isVarArg = lastArgTypeDesc.equals(OBJECT_ARRAY_DESC);
            if (!lastArgTypeDesc.equals(OBJECT_DESC) && !isVarArg) {
                error("last argument of a @Function method is neither Object nor Object[] type: "
                        + lastArgTypeDesc);
            }

            if (isVarArg && argTypes.length > 2) {
                error("vararg @Function method has more than 2 arguments");
            }
        }
    }
        break;
    case SPECIALIZED_FUNCTION: {
        final Type returnType = Type.getReturnType(javaDesc);
        if (!(isValidJSType(returnType) || (isSpecializedConstructor() && Type.VOID_TYPE == returnType))) {
            error("return value of a @SpecializedFunction method should be a valid JS type, found "
                    + returnType);
        }
        final Type[] argTypes = Type.getArgumentTypes(javaDesc);
        for (int i = 0; i < argTypes.length; i++) {
            if (!isValidJSType(argTypes[i])) {
                error(i + "'th argument of a @SpecializedFunction method is not valid JS type, found "
                        + argTypes[i]);
            }
        }
    }
        break;
    case GETTER: {
        final Type[] argTypes = Type.getArgumentTypes(javaDesc);
        if (argTypes.length != 1) {
            error("@Getter methods should have one argument");
        }
        if (!isJavaLangObject(argTypes[0])) {
            error("first argument of a @Getter method should be of Object type, found: " + argTypes[0]);
        }

        if (Type.getReturnType(javaDesc).equals(Type.VOID_TYPE)) {
            error("return type of getter should not be void");
        }
    }
        break;
    case SETTER: {
        final Type[] argTypes = Type.getArgumentTypes(javaDesc);
        if (argTypes.length != 2) {
            error("@Setter methods should have two arguments");
        }
        if (!isJavaLangObject(argTypes[0])) {
            error("first argument of a @Setter method should be of Object type, found: " + argTypes[0]);
        }
        if (!Type.getReturnType(javaDesc).toString().equals("V")) {
            error("return type of of a @Setter method should be void, found: " + Type.getReturnType(javaDesc));
        }
    }
        break;
    case PROPERTY: {
        if (where == Where.CONSTRUCTOR) {
            if (isStatic()) {
                if (!isFinal()) {
                    error("static Where.CONSTRUCTOR @Property should be final");
                }

                if (!isJSPrimitiveType(Type.getType(javaDesc))) {
                    error("static Where.CONSTRUCTOR @Property should be a JS primitive");
                }
            }
        } else if (where == Where.PROTOTYPE) {
            if (isStatic()) {
                if (!isFinal()) {
                    error("static Where.PROTOTYPE @Property should be final");
                }

                if (!isJSPrimitiveType(Type.getType(javaDesc))) {
                    error("static Where.PROTOTYPE @Property should be a JS primitive");
                }
            }
        }
    }
        break;

    default:
        break;
    }
}

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  w  w.j av  a  2  s .  co 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
            ////  w  ww. j  a  va  2s. 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;");
}