org.objectweb.asm.MethodAdapter Java Examples

The following examples show how to use org.objectweb.asm.MethodAdapter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MaybeContinuableClassVisitor.java    From tascalate-javaflow with Apache License 2.0 4 votes vote down vote up
@Override
public MethodVisitor visitMethod(int access, final String name, final String desc, String signature, String[] exceptions) {
    if (isAnnotation) {
        return null;
    }

    boolean isSynthetic = (access & Opcodes.ACC_SYNTHETIC) != 0;
    boolean isPackagePrivate = (access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) == 0;
    if (isSynthetic) {
        final boolean isAccessor = isPackagePrivate && name.startsWith("access$") && (access & Opcodes.ACC_STATIC) != 0;
        final boolean isBridge = (access & Opcodes.ACC_BRIDGE) != 0;
        if (isAccessor || isBridge) {
            return new MethodAdapter(NOP) {
                @Override
                public void visitMethodInsn(int opcode, String owner, String targetName, String targetDesc) {
                    if (selfclass.equals(owner)) {
                        if (isAccessor) {
                            actual2accessor.put(targetName + targetDesc, name + desc);
                        }
                        if (isBridge) {
                            bridge2specialization.put(name + desc, targetName + targetDesc);
                        }
                    }
                }
            };
        }
    }

    // If this method is desugared lambda body
    if ( isSynthetic && isPackagePrivate && name.startsWith("lambda$") ) {
        // RetroLambda desugars method body to package private
        desugaredLambdaBodies.add(name + desc);
        return null;
    }

    return new MethodAdapter(NOP) {

        private boolean methodContinuableAnnotationFound = false;

        @Override
        public AnnotationVisitor visitAnnotation(String description, boolean visible) {
            if (!methodContinuableAnnotationFound) {
                methodContinuableAnnotationFound = cciResolver.isContinuableAnnotation(description);
            }
            return null;
        }

        @Override 
        public void visitEnd() {
            if (methodContinuableAnnotationFound) {
                continuableMethods.add(name + desc);
            }
        }

    };
}