Example usage for org.objectweb.asm Opcodes ACC_SYNTHETIC

List of usage examples for org.objectweb.asm Opcodes ACC_SYNTHETIC

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes ACC_SYNTHETIC.

Prototype

int ACC_SYNTHETIC

To view the source code for org.objectweb.asm Opcodes ACC_SYNTHETIC.

Click Source Link

Usage

From source file:com.google.gwt.dev.javac.asm.CollectClassData.java

License:Apache License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    if ((access & Opcodes.ACC_SYNTHETIC) != 0) {
        // skip synthetic methods
        return null;
    }/*from   ww w  .  j a v  a2 s .c  o m*/
    CollectMethodData mv = new CollectMethodData(classType, access, name, desc, signature, exceptions);
    methods.add(mv);
    return mv;
}

From source file:com.google.gwt.dev.javac.CompilationUnitTypeOracleUpdater.java

License:Apache License

private boolean resolveMethod(TreeLogger logger, JRealClassType unresolvedType, CollectMethodData methodData,
        TypeParameterLookup typeParamLookup, TypeOracleBuildContext context) {
    Map<Class<? extends Annotation>, Annotation> declaredAnnotations = Maps.newHashMap();
    resolveAnnotations(logger, methodData.getAnnotations(), declaredAnnotations);
    String name = methodData.getName();

    if ("<clinit>".equals(name) || (methodData.getAccess() & Opcodes.ACC_SYNTHETIC) != 0) {
        // Ignore the following and leave them out of TypeOracle:
        // - static initializers
        // - synthetic methods
        return true;
    }//  ww  w  .j  av  a 2 s . c o m

    if (unresolvedType.isEnum() != null && "<init>".equals(name)) {
        // Leave enum constructors out of TypeOracle
        return true;
    }

    JAbstractMethod method;

    // Declare the type parameters. We will pass them into the constructors for
    // JConstructor/JMethod/JAnnotatedMethod. Then, we'll do a second pass to
    // resolve the bounds on each JTypeParameter object.
    JTypeParameter[] typeParams = collectTypeParams(methodData.getSignature());

    typeParamLookup.pushScope(typeParams);
    boolean hasReturnType = true;
    if ("<init>".equals(name)) {
        name = unresolvedType.getSimpleSourceName();
        method = newConstructor(unresolvedType, name, declaredAnnotations, typeParams);
        hasReturnType = false;
    } else {
        if (unresolvedType.isAnnotation() != null) {
            // TODO(jat): actually resolve the default annotation value.
            method = newAnnotationMethod(unresolvedType, name, declaredAnnotations, typeParams, null);
        } else {
            method = newMethod(unresolvedType, name, declaredAnnotations, typeParams);
        }
    }

    addModifierBits(method, mapBits(ASM_TO_SHARED_MODIFIERS, methodData.getAccess()));
    if (unresolvedType.isInterface() != null) {
        // Always add implicit modifiers on interface methods.
        addModifierBits(method, Shared.MOD_PUBLIC | Shared.MOD_ABSTRACT);
    }

    if ((methodData.getAccess() & Opcodes.ACC_VARARGS) != 0) {
        setVarArgs(method);
    }

    String signature = methodData.getSignature();
    if (signature != null) {
        // If we have a signature, use it for superclass and interfaces
        SignatureReader reader = new SignatureReader(signature);
        ResolveMethodSignature methodResolver = new ResolveMethodSignature(context.resolver, logger, method,
                typeParamLookup, hasReturnType, methodData, methodData.getArgTypes(), methodData.getArgNames(),
                methodData.hasActualArgNames(), context.allMethodArgs);
        reader.accept(methodResolver);
        if (!methodResolver.finish()) {
            logger.log(TreeLogger.ERROR, "Failed to resolve.");
            return false;
        }
    } else {
        if (hasReturnType) {
            Type returnType = Type.getReturnType(methodData.getDesc());
            JType returnJType = resolveType(returnType);
            if (returnJType == null) {
                logger.log(TreeLogger.ERROR, "Unable to resolve return type " + returnType.getInternalName());
                return false;
            }
            setReturnType(method, returnJType);
        }

        if (!resolveParameters(logger, method, methodData, context)) {
            // Already logged.
            return false;
        }
    }
    // The signature might not actually include the exceptions if they don't
    // include a type variable, so resolveThrows is always used (it does
    // nothing if there are already exceptions defined)
    if (!resolveThrows(logger, method, methodData)) {
        // Already logged.
        return false;
    }
    typeParamLookup.popScope();
    return true;
}

From source file:com.google.gwt.dev.javac.TypeOracleMediator.java

License:Open Source License

private boolean resolveMethod(TreeLogger logger, JRealClassType type, CollectMethodData methodData,
        TypeParameterLookup typeParamLookup) {
    Map<Class<? extends Annotation>, Annotation> declaredAnnotations = new HashMap<Class<? extends Annotation>, Annotation>();
    resolveAnnotations(logger, methodData.getAnnotations(), declaredAnnotations);
    String name = methodData.getName();

    if ("<clinit>".equals(name) || (methodData.getAccess() & Opcodes.ACC_SYNTHETIC) != 0) {
        // Ignore the following and leave them out of TypeOracle:
        // - static initializers
        // - synthetic methods
        return true;
    }//from  www .  j  a  v  a 2 s  . c o m

    if (type.isEnum() != null && "<init>".equals(name)) {
        // Leave enum constructors out of TypeOracle
        return true;
    }

    JAbstractMethod method;

    // Declare the type parameters. We will pass them into the constructors for
    // JConstructor/JMethod/JAnnotatedMethod. Then, we'll do a second pass to
    // resolve the bounds on each JTypeParameter object.
    JTypeParameter[] typeParams = collectTypeParams(methodData.getSignature());

    typeParamLookup.pushScope(typeParams);
    boolean hasReturnType = true;
    if ("<init>".equals(name)) {
        name = type.getSimpleSourceName();
        method = newConstructor(type, name, declaredAnnotations, typeParams);
        hasReturnType = false;
    } else {
        if (type.isAnnotation() != null) {
            // TODO(jat): actually resolve the default annotation value.
            method = newAnnotationMethod(type, name, declaredAnnotations, typeParams, null);
        } else {
            method = newMethod(type, name, declaredAnnotations, typeParams);
        }
    }

    addModifierBits(method, mapBits(ASM_TO_SHARED_MODIFIERS, methodData.getAccess()));
    if (type.isInterface() != null) {
        // Always add implicit modifiers on interface methods.
        addModifierBits(method, Shared.MOD_PUBLIC | Shared.MOD_ABSTRACT);
    }

    if ((methodData.getAccess() & Opcodes.ACC_VARARGS) != 0) {
        setVarArgs(method);
    }

    String signature = methodData.getSignature();
    if (signature != null) {
        // If we have a signature, use it for superclass and interfaces
        SignatureReader reader = new SignatureReader(signature);
        ResolveMethodSignature methodResolver = new ResolveMethodSignature(resolver, logger, method,
                typeParamLookup, hasReturnType, methodData, methodData.getArgTypes(), methodData.getArgNames(),
                methodData.hasActualArgNames(), allMethodArgs);
        // TraceSignatureVisitor trace = new TraceSignatureVisitor(
        // methodData.getAccess());
        // reader.accept(trace);
        // System.err.println("Method " + name + ": " + trace.getDeclaration());
        reader.accept(methodResolver);
        if (!methodResolver.finish()) {
            return false;
        }
    } else {
        if (hasReturnType) {
            Type returnType = Type.getReturnType(methodData.getDesc());
            JType returnJType = resolveType(returnType);
            if (returnJType == null) {
                return false;
            }
            setReturnType(method, returnJType);
        }

        if (!resolveParameters(logger, method, methodData)) {
            return false;
        }
    }
    // The signature might not actually include the exceptions if they don't
    // include a type variable, so resolveThrows is always used (it does
    // nothing if there are already exceptions defined)
    if (!resolveThrows(method, methodData)) {
        return false;
    }
    typeParamLookup.popScope();
    return true;
}

From source file:com.google.gwt.dev.shell.rewrite.RewriteSingleJsoImplDispatches.java

License:Apache License

/**
 * For regular Java objects that implement a SingleJsoImpl interface, write
 * instance trampoline dispatchers for mangled method names to the
 * implementing method./*from w w w .  j av a  2 s. c om*/
 */
private void writeTrampoline(String stubIntr) {
    /*
     * This is almost the same kind of trampoline as the ones generated in
     * WriteJsoImpl, however there are enough small differences between the
     * semantics of the dispatches that would make a common implementation far
     * more awkward than the duplication of code.
     */
    for (String mangledName : toImplement(stubIntr)) {
        for (Method method : jsoData.getDeclarations(mangledName)) {

            Method toCall = new Method(method.getName(), method.getDescriptor());

            // Must not be final
            MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, mangledName,
                    method.getDescriptor(), null, null);
            if (mv != null) {
                mv.visitCode();

                /*
                 * It just so happens that the stack and local variable sizes are the
                 * same, but they're kept distinct to aid in clarity should the
                 * dispatch logic change.
                 *
                 * These start at 1 because we need to load "this" onto the stack
                 */
                int var = 1;
                int size = 1;

                // load this
                mv.visitVarInsn(Opcodes.ALOAD, 0);

                // then the rest of the arguments
                for (Type t : toCall.getArgumentTypes()) {
                    size += t.getSize();
                    mv.visitVarInsn(t.getOpcode(Opcodes.ILOAD), var);
                    var += t.getSize();
                }

                // Make sure there's enough room for the return value
                size = Math.max(size, toCall.getReturnType().getSize());

                mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, currentTypeName, toCall.getName(),
                        toCall.getDescriptor(), false);
                mv.visitInsn(toCall.getReturnType().getOpcode(Opcodes.IRETURN));
                mv.visitMaxs(size, var);
                mv.visitEnd();
            }
        }
    }
}

From source file:com.google.gwt.dev.shell.rewrite.WriteJsoImpl.java

License:Apache License

/**
 * Records the original name and resets access opcodes.
 *//*from  ww  w.  j  a va 2 s. c om*/
@Override
public void visit(int version, int access, String name, String signature, String superName,
        String[] interfaces) {
    originalName = name;
    super.visit(version, Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC, name + '$', signature,
            superName, interfaces);
}

From source file:com.google.java.contract.core.agent.ContractFixingClassAdapter.java

License:Open Source License

/**
 * Visits the specified method fixing method calls.
 *///from  w  ww  .j a va2  s  . c om
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    MethodVisitor mv = cv.visitMethod(access | Opcodes.ACC_SYNTHETIC, name, desc, signature, exceptions);
    return new AccessMethodAdapter(mv);
}

From source file:com.google.java.contract.core.agent.LineNumberingClassAdapter.java

License:Open Source License

/**
 * Visits the specified method, adding line numbering.
 *//* w w  w. j a  va 2  s .co  m*/
@Override
public MethodVisitor visitMethod(int access, final String name, String desc, String signature,
        String[] exceptions) {
    MethodVisitor mv = cv.visitMethod(access | Opcodes.ACC_SYNTHETIC, name, desc, signature, exceptions);
    return new LineNumberingMethodAdapter(mv, access | Opcodes.ACC_SYNTHETIC, name, desc) {
        @Override
        protected void onMethodEnter() {
            this.lineNumbers = LineNumberingClassAdapter.this.lineNumbers;
            super.onMethodEnter();
        }
    };
}

From source file:com.googlecode.dex2jar.tools.JarAccessCmd.java

License:Apache License

static int str2acc(String s) {
    if (s == null) {
        return 0;
    }/*from w  ww . j  a va2s .c o  m*/
    int result = 0;
    s = s.toLowerCase();
    if (s.contains("public")) {
        result |= Opcodes.ACC_PUBLIC;
    }
    if (s.contains("private")) {
        result |= Opcodes.ACC_PRIVATE;
    }
    if (s.contains("protected")) {
        result |= Opcodes.ACC_PROTECTED;
    }
    if (s.contains("final")) {
        result |= Opcodes.ACC_FINAL;
    }
    if (s.contains("static")) {
        result |= Opcodes.ACC_STATIC;
    }
    if (s.contains("super")) {
        result |= Opcodes.ACC_SUPER;
    }
    if (s.contains("synchronized")) {
        result |= Opcodes.ACC_SYNCHRONIZED;
    }
    if (s.contains("volatile")) {
        result |= Opcodes.ACC_VOLATILE;
    }
    if (s.contains("bridge")) {
        result |= Opcodes.ACC_BRIDGE;
    }
    if (s.contains("transient")) {
        result |= Opcodes.ACC_TRANSIENT;
    }
    if (s.contains("varargs")) {
        result |= Opcodes.ACC_VARARGS;
    }
    if (s.contains("native")) {
        result |= Opcodes.ACC_NATIVE;
    }
    if (s.contains("strict")) {
        result |= Opcodes.ACC_STRICT;
    }
    if (s.contains("interface")) {
        result |= Opcodes.ACC_INTERFACE;
    }
    if (s.contains("abstract")) {
        result |= Opcodes.ACC_ABSTRACT;
    }
    if (s.contains("synthetic")) {
        result |= Opcodes.ACC_SYNTHETIC;
    }
    if (s.contains("annotation")) {
        result |= Opcodes.ACC_ANNOTATION;
    }
    if (s.contains("enum")) {
        result |= Opcodes.ACC_ENUM;
    }
    if (s.contains("deprecated")) {
        result |= Opcodes.ACC_DEPRECATED;
    }
    return result;
}

From source file:com.googlecode.gwt.test.internal.rewrite.RewriteSingleJsoImplDispatches.java

License:Apache License

/**
 * For regular Java objects that implement a SingleJsoImpl interface, write instance trampoline
 * dispatchers for mangled method names to the implementing method.
 *//*  ww w  .j av  a 2 s  .  c om*/
private void writeTrampoline(String stubIntr) {
    /*
     * This is almost the same kind of trampoline as the ones generated in WriteJsoImpl, however
     * there are enough small differences between the semantics of the dispatches that would make
     * a common implementation far more awkward than the duplication of code.
     */
    for (String mangledName : toImplement(stubIntr)) {
        for (Method method : jsoData.getDeclarations(mangledName)) {

            Method toCall = new Method(method.getName(), method.getDescriptor());

            // Must not be final
            MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, mangledName,
                    method.getDescriptor(), null, null);
            if (mv != null) {
                mv.visitCode();

                /*
                 * It just so happens that the stack and local variable sizes are the same, but
                 * they're kept distinct to aid in clarity should the dispatch logic change.
                 *
                 * These start at 1 because we need to load "this" onto the stack
                 */
                int var = 1;
                int size = 1;

                // load this
                mv.visitVarInsn(Opcodes.ALOAD, 0);

                // then the rest of the arguments
                for (Type t : toCall.getArgumentTypes()) {
                    size += t.getSize();
                    mv.visitVarInsn(t.getOpcode(Opcodes.ILOAD), var);
                    var += t.getSize();
                }

                // Make sure there's enough room for the return value
                size = Math.max(size, toCall.getReturnType().getSize());

                mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, currentTypeName, toCall.getName(),
                        toCall.getDescriptor());
                mv.visitInsn(toCall.getReturnType().getOpcode(Opcodes.IRETURN));
                mv.visitMaxs(size, var);
                mv.visitEnd();
            }
        }
    }
}

From source file:com.intellij.compiler.notNullVerification.ThrowOnNullMethodVisitor.java

License:Apache License

private boolean isSynthetic() {
    return (this.methodAccess & Opcodes.ACC_SYNTHETIC) != 0;
}