public MethodVisitor visitMethod( final int access, final String name, final String desc, final String signature, final String[] exceptions) { return cv.visitMethod(access, name, desc, signature, exceptions); }
/** * Visits a method of the class. This method <i>must</i> return a new {@link MethodVisitor} * instance (or {@literal null}) each time it is called, i.e., it should not return a previously * returned visitor. * * @param access the method's access flags (see {@link Opcodes}). This parameter also indicates if * the method is synthetic and/or deprecated. * @param name the method's name. * @param descriptor the method's descriptor (see {@link Type}). * @param signature the method's signature. May be {@literal null} if the method parameters, * return type and exceptions do not use generic types. * @param exceptions the internal names of the method's exception classes (see {@link * Type#getInternalName()}). May be {@literal null}. * @return an object to visit the byte code of the method, or {@literal null} if this class * visitor is not interested in visiting the code of this method. */ public MethodVisitor visitMethod( final int access, final String name, final String descriptor, final String signature, final String[] exceptions) { if (cv != null) { return cv.visitMethod(access, name, descriptor, signature, exceptions); } return null; }
@Override public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) { MethodVisitor mv; if ("<clinit>".equals(name)) { int a = Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC; String n = prefix + counter++; mv = cv.visitMethod(a, n, desc, signature, exceptions); if (clinit == null) { clinit = cv.visitMethod(a, name, desc, null, null); } clinit.visitMethodInsn(Opcodes.INVOKESTATIC, this.name, n, desc, false); } else { mv = cv.visitMethod(access, name, desc, signature, exceptions); } return mv; }
/** * Makes the given class visitor visit this method. * * @param cv * a class visitor. */ public void accept(final ClassVisitor cv) { String[] exceptions = new String[this.exceptions.size()]; this.exceptions.toArray(exceptions); MethodVisitor mv = cv.visitMethod(access, name, desc, signature, exceptions); if (mv != null) { accept(mv); } }
@Override public final void end(final String element) { HashMap<?, ?> vals = (HashMap<?, ?>) pop(); int access = getAccess((String) vals.get("access")); String name = (String) vals.get("name"); String desc = (String) vals.get("desc"); String signature = (String) vals.get("signature"); ArrayList<?> excs = (ArrayList<?>) vals.get("exceptions"); String[] exceptions = excs.toArray(new String[excs.size()]); push(cv.visitMethod(access, name, desc, signature, exceptions)); } }
@Override public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) { Printer p = this.p.visitMethod(access, name, desc, signature, exceptions); MethodVisitor mv = cv == null ? null : cv.visitMethod(access, name, desc, signature, exceptions); return new TraceMethodVisitor(mv, p); }
/** * Creates a new {@link GeneratorAdapter}. <i>Subclasses must not use this * constructor</i>. Instead, they must use the * {@link #GeneratorAdapter(int, MethodVisitor, int, String, String)} * version. * * @param access * access flags of the adapted method. * @param method * the adapted method. * @param signature * the signature of the adapted method (may be <tt>null</tt>). * @param exceptions * the exceptions thrown by the adapted method (may be * <tt>null</tt>). * @param cv * the class visitor to which this adapter delegates calls. */ public GeneratorAdapter(final int access, final Method method, final String signature, final Type[] exceptions, final ClassVisitor cv) { this(access, method, cv .visitMethod(access, method.getName(), method.getDescriptor(), signature, getInternalNames(exceptions))); }
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { String newDesc = remapper.mapMethodDesc(desc); MethodVisitor mv = super.visitMethod(access, remapper.mapMethodName( className, name, desc), newDesc, remapper.mapSignature( signature, false), exceptions == null ? null : remapper.mapTypes(exceptions)); return mv == null ? null : createRemappingMethodAdapter(access, newDesc, mv); }
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { String newDesc = remapper.mapMethodDesc(desc); MethodVisitor mv = super.visitMethod(access, remapper.mapMethodName( className, name, desc), newDesc, remapper.mapSignature( signature, false), exceptions == null ? null : remapper.mapTypes(exceptions)); return mv == null ? null : createMethodRemapper(mv); }
protected void buildIsEmpty( ClassVisitor cw, String wrapperName, String coreName, ClassDefinition trait, ClassDefinition core, BitSet mask ) { boolean hasHardFields = core.getFieldsDefinitions().size() > 0; MethodVisitor mv = cw.visitMethod( ACC_PUBLIC, "isEmpty", "()Z", null, null ); mv.visitCode(); if ( ! hasHardFields ) { mv.visitVarInsn( ALOAD, 0 ); mv.visitMethodInsn( INVOKESPECIAL, Type.getInternalName( TripleBasedStruct.class ), "isEmpty", "()Z" ); } else { mv.visitInsn( ICONST_0 ); } mv.visitInsn( IRETURN ); // mv.visitMaxs( 1, 1 ); mv.visitMaxs( 0, 0 ); mv.visitEnd(); }
protected void buildSize( ClassVisitor cw, String wrapperName, String coreName, ClassDefinition trait, ClassDefinition core, BitSet mask ) { MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "size", "()I", null, null); mv.visitCode(); mv.visitVarInsn( ALOAD, 0 ); mv.visitMethodInsn( INVOKESPECIAL, Type.getInternalName( TripleBasedStruct.class ), "size", "()I" ); int n = core.getFieldsDefinitions().size(); for ( int j = 0; j < n; j++ ) { mv.visitInsn( ICONST_1 ); mv.visitInsn( IADD ); } mv.visitInsn(IRETURN); // mv.visitMaxs( core.getFieldsDefinitions().size() > 0 ? 2 : 1, // 1 ); mv.visitMaxs( 0, 0 ); mv.visitEnd(); }
protected void buildHardGetter( ClassVisitor cw, FieldDefinition field, String masterName, ClassDefinition proxy, ClassDefinition core, String getterName, boolean protect ) { Class fieldType = field.getType(); MethodVisitor mv = cw.visitMethod( protect ? ACC_PROTECTED : ACC_PUBLIC, getterName, "()" + Type.getDescriptor( fieldType ), null, null); mv.visitCode(); TraitFactory.invokeExtractor( mv, masterName, proxy, core, field ); if ( ! BuildUtils.isPrimitive( field.getTypeName() ) ) { mv.visitTypeInsn( CHECKCAST, Type.getInternalName( fieldType ) ); } mv.visitInsn( BuildUtils.returnType ( fieldType.getName() ) ); // mv.visitMaxs( 2, 1 ); mv.visitMaxs( 0, 0 ); mv.visitEnd(); }
private void buildIsEmpty( ClassVisitor cw, String wrapperName, String coreName, ClassDefinition trait, ClassDefinition core, BitSet mask ) { String internalWrapper = BuildUtils.getInternalType( wrapperName ); boolean hasHardFields = core.getFieldsDefinitions().size() > 0; MethodVisitor mv = cw.visitMethod( ACC_PUBLIC, "isEmpty", "()Z", null, null ); mv.visitCode(); if ( ! hasHardFields ) { mv.visitVarInsn( ALOAD, 0 ); mv.visitFieldInsn( GETFIELD, internalWrapper, "map", Type.getDescriptor( Map.class ) ); mv.visitMethodInsn( INVOKEINTERFACE, Type.getInternalName( Map.class ), "isEmpty", "()Z" ); } else { mv.visitInsn( ICONST_0 ); } mv.visitInsn( IRETURN ); // mv.visitMaxs( 1, 1 ); mv.visitMaxs( 0, 0 ); mv.visitEnd(); }
private void buildSize( ClassVisitor cw, String wrapperName, String coreName, ClassDefinition trait, ClassDefinition core, BitSet mask ) { String internalWrapper = BuildUtils.getInternalType( wrapperName ); MethodVisitor mv = cw.visitMethod( ACC_PUBLIC, "size", "()I", null, null ); mv.visitCode(); mv.visitVarInsn( ALOAD, 0 ); mv.visitFieldInsn( GETFIELD, internalWrapper, "map", Type.getDescriptor( Map.class ) ); mv.visitMethodInsn( INVOKEINTERFACE, Type.getInternalName( Map.class ), "size", "()I" ); int n = core.getFieldsDefinitions().size(); for ( int j = 0; j < n; j++ ) { mv.visitInsn( ICONST_1 ); mv.visitInsn( IADD ); } mv.visitInsn( IRETURN ); // mv.visitMaxs( core.getFieldsDefinitions().size() > 0 ? 2 : 1, 1 ); mv.visitMaxs( 0, 0 ); mv.visitEnd(); }
protected void buildGet( ClassVisitor cw, String wrapperName, String coreName, ClassDefinition trait, ClassDefinition core, BitSet mask ) { MethodVisitor mv = cw.visitMethod( ACC_PUBLIC, "get", "(" + Type.getDescriptor( Object.class ) + ")" + Type.getDescriptor( Object.class ), null, null ); mv.visitCode(); if ( core.getFieldsDefinitions().size() > 0 ) { for ( FieldDefinition field : core.getFieldsDefinitions() ) { invokeGet( mv, wrapperName, core, field.getName(), field ); } } mv.visitVarInsn( ALOAD, 0 ); mv.visitVarInsn( ALOAD, 1 ); mv.visitMethodInsn( INVOKESPECIAL, Type.getInternalName( TripleBasedStruct.class ), "get", "(" + Type.getDescriptor( Object.class ) + ")" + Type.getDescriptor( Object.class ) ); mv.visitInsn( ARETURN ); // mv.visitMaxs( 2, 2 ); mv.visitMaxs( 0, 0 ); mv.visitEnd(); }
private void buildGet( ClassVisitor cw, String wrapperName, String coreName, ClassDefinition trait, ClassDefinition core, BitSet mask ) { String internalWrapper = BuildUtils.getInternalType( wrapperName ); MethodVisitor mv = cw.visitMethod( ACC_PUBLIC, "get", "(" + Type.getDescriptor( Object.class ) + ")" + Type.getDescriptor( Object.class ), null, null ); mv.visitCode(); if ( core.getFieldsDefinitions().size() > 0) { for ( FieldDefinition field : core.getFieldsDefinitions() ) { invokeGet( mv, wrapperName, core, field.getName(), field ); } } mv.visitVarInsn( ALOAD, 0 ); mv.visitFieldInsn( GETFIELD, internalWrapper, "map", Type.getDescriptor( Map.class ) ); mv.visitVarInsn( ALOAD, 1 ); mv.visitMethodInsn( INVOKEINTERFACE, Type.getInternalName( Map.class ), "get", "(" + Type.getDescriptor( Object.class ) + ")" + Type.getDescriptor( Object.class ) ); mv.visitInsn( ARETURN ); // mv.visitMaxs( 2, 2 ); mv.visitMaxs( 0, 0 ); mv.visitEnd(); }
private void buildHardGetter( ClassVisitor cw, FieldDefinition field, String masterName, ClassDefinition proxy, ClassDefinition core, String getterName, boolean protect ) { String fieldName = field.getName(); Class fieldType = field.getType(); MethodVisitor mv = cw.visitMethod( protect ? ACC_PROTECTED : ACC_PUBLIC, getterName, "()" + Type.getDescriptor( field.getType() ), null, null); mv.visitCode(); TraitFactory.invokeExtractor( mv, masterName, proxy, core, field ); if ( ! BuildUtils.isPrimitive( field.getTypeName() ) ) { mv.visitTypeInsn( CHECKCAST, Type.getInternalName( fieldType ) ); } mv.visitInsn( BuildUtils.returnType ( field.getTypeName() ) ); // mv.visitMaxs( 2, 1 ); mv.visitMaxs( 0, 0 ); mv.visitEnd(); }
protected void buildPut( ClassVisitor cw, String wrapperName, String coreName, ClassDefinition trait, ClassDefinition core, BitSet mask ) { MethodVisitor mv = cw.visitMethod( ACC_PUBLIC, "put", "(" + Type.getDescriptor( String.class) + Type.getDescriptor( Object.class ) + ")" + Type.getDescriptor( Object.class ), null, null ); mv.visitCode(); if ( core.getFieldsDefinitions().size() > 0) { int j = 0; for ( FieldDefinition field : core.getFieldsDefinitions() ) { invokePut( mv, wrapperName, core, field.getName(), field ); } } mv.visitVarInsn( ALOAD, 0 ); mv.visitVarInsn( ALOAD, 1 ); mv.visitVarInsn( ALOAD, 2 ); mv.visitMethodInsn( INVOKESPECIAL, Type.getInternalName( TripleBasedStruct.class ), "put", "(" + Type.getDescriptor( String.class) + Type.getDescriptor( Object.class ) + ")" + Type.getDescriptor( Object.class ) ); mv.visitInsn( ARETURN ); // mv.visitMaxs( 4, 5 ); mv.visitMaxs( 0, 0 ); mv.visitEnd(); }
private void buildPut( ClassVisitor cw, String wrapperName, String coreName, ClassDefinition trait, ClassDefinition core, BitSet mask ) { String internalWrapper = BuildUtils.getInternalType( wrapperName ); MethodVisitor mv = cw.visitMethod( ACC_PUBLIC, "put", "(" + Type.getDescriptor( String.class ) + Type.getDescriptor( Object.class ) + ")" + Type.getDescriptor( Object.class ), null, null ); mv.visitCode(); if ( core.getFieldsDefinitions().size() > 0) { for ( FieldDefinition field : core.getFieldsDefinitions() ) { invokePut( mv, wrapperName, core, field.getName(), field ); } } mv.visitVarInsn( ALOAD, 0 ); mv.visitFieldInsn( GETFIELD, internalWrapper, "map", Type.getDescriptor( Map.class ) ); mv.visitVarInsn( ALOAD, 1 ); mv.visitVarInsn( ALOAD, 2 ); mv.visitMethodInsn( INVOKEINTERFACE, Type.getInternalName( Map.class ), "put", "(" + Type.getDescriptor( Object.class ) + Type.getDescriptor( Object.class ) + ")" + Type.getDescriptor( Object.class ) ); mv.visitInsn( ARETURN ); // mv.visitMaxs( 4, 5 ); mv.visitMaxs( 0, 0 ); mv.visitEnd(); }
private void buildKeyset( ClassVisitor cw, String wrapperName, String coreName, ClassDefinition trait, ClassDefinition core, BitSet mask ) { String internalWrapper = BuildUtils.getInternalType( wrapperName ); MethodVisitor mv = cw.visitMethod( ACC_PUBLIC, "keySet", "()" + Type.getDescriptor( Set.class ), "()Ljava/util/Set<Ljava/lang/String;>;", null ); mv.visitCode(); mv.visitTypeInsn( NEW, Type.getInternalName( HashSet.class ) ); mv.visitInsn( DUP ); mv.visitMethodInsn( INVOKESPECIAL, Type.getInternalName( HashSet.class ), "<init>", "()V" ); mv.visitVarInsn( ASTORE, 1 ); for ( FieldDefinition field : core.getFieldsDefinitions() ) { mv.visitVarInsn( ALOAD, 1 ); mv.visitLdcInsn( field.getName() ); mv.visitMethodInsn( INVOKEINTERFACE, Type.getInternalName( Set.class ), "add", "(" + Type.getDescriptor( Object.class ) + ")Z" ); mv.visitInsn( POP ); } mv.visitVarInsn( ALOAD, 1 ); mv.visitVarInsn( ALOAD, 0 ); mv.visitFieldInsn( GETFIELD, internalWrapper, "map", Type.getDescriptor( Map.class ) ); mv.visitMethodInsn( INVOKEINTERFACE, Type.getInternalName( Map.class ), "keySet", "()" + Type.getDescriptor( Set.class ) ); mv.visitMethodInsn( INVOKEINTERFACE, Type.getInternalName( Set.class ), "addAll", "(" + Type.getDescriptor( Collection.class ) + ")Z" ); mv.visitInsn( POP ); mv.visitVarInsn( ALOAD, 1 ); mv.visitInsn( ARETURN ); // mv.visitMaxs( 2, 2 ); mv.visitMaxs( 0, 0 ); mv.visitEnd(); }