public void body(MethodVisitor mv) { getFieldFromThis("name", String.class); mv.visitInsn(ARETURN); // return the first object on the stack } });
@Override public AnnotationVisitor visitAnnotation(final String name, final String descriptor) { // Case of an element_value with an annotation_value field. // See https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.16.1. ++numElementValuePairs; if (useNamedValues) { annotation.putShort(symbolTable.addConstantUtf8(name)); } // Write tag and type_index, and reserve 2 bytes for num_element_value_pairs. annotation.put12('@', symbolTable.addConstantUtf8(descriptor)).putShort(0); return new AnnotationWriter(symbolTable, annotation, null); }
@Override public void visitEnum(final String name, final String descriptor, final String value) { // Case of an element_value with an enum_const_value field. // See https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html#jvms-4.7.16.1. ++numElementValuePairs; if (useNamedValues) { annotation.putShort(symbolTable.addConstantUtf8(name)); } annotation .put12('e', symbolTable.addConstantUtf8(descriptor)) .putShort(symbolTable.addConstantUtf8(value)); }
protected void invokeContainsKey( MethodVisitor mv, String fieldName ) { mv.visitLdcInsn( fieldName ); mv.visitVarInsn( ALOAD, 1 ); mv.visitMethodInsn( INVOKEVIRTUAL, Type.getInternalName( String.class ), "equals", "(" + Type.getDescriptor( Object.class ) + ")Z" ); Label l0 = new Label(); mv.visitJumpInsn( IFEQ, l0 ); mv.visitInsn( ICONST_1 ); mv.visitInsn( IRETURN ); mv.visitLabel( l0 ); }
@Override public AnnotationVisitor visitAnnotation(final String name, final String desc) { ++size; if (named) { bv.putShort(cw.newUTF8(name)); } // write tag and type, and reserve space for values count bv.put12('@', cw.newUTF8(desc)).putShort(0); return new AnnotationWriter(cw, true, bv, bv, bv.length - 2); }
@Override public void visitNestMember(final String nestMember) { if (nestMemberClasses == null) { nestMemberClasses = new ByteVector(); } ++numberOfNestMemberClasses; nestMemberClasses.putShort(symbolTable.addConstantClass(nestMember).index); }
@Override public void visitParameter(final String name, final int access) { if (parameters == null) { parameters = new ByteVector(); } ++parametersCount; parameters.putShort((name == null) ? 0 : symbolTable.addConstantUtf8(name)).putShort(access); }
@Override public AnnotationVisitor visitAnnotationDefault() { defaultValue = new ByteVector(); return new AnnotationWriter(symbolTable, /* useNamedValues = */ false, defaultValue, null); }
final MethodComparator comp = new MethodComparator(); boolean result = comp.equivalent( "evaluate", new ClassReader( getClassData( MethodCompareA.class ) ), "evaluate", new ClassReader( getClassData( MethodCompareB.class ) ) ); assertEquals( true, result ); new ClassReader( getClassData( MethodCompareA.class ) ), "evaluate2", new ClassReader( getClassData( MethodCompareA.class ) ) ); assertEquals( false, result ); new ClassReader( getClassData( MethodCompareB.class ) ), "evaluate2", new ClassReader( getClassData( MethodCompareA.class ) ) ); assertEquals( false, result ); new ClassReader( getClassData( MethodCompareB.class ) ), "evaluate", new ClassReader( getClassData( MethodCompareA.class ) ) ); assertEquals( true, result ); new ClassReader( getClassData( MethodCompareA.class ) ), "evaluate", new ClassReader( getClassData( MethodCompareA.class ) ) );
@Override public final void visitSource(final String file, final String debug) { if (file != null) { sourceFileIndex = symbolTable.addConstantUtf8(file); } if (debug != null) { debugExtension = new ByteVector().encodeUtf8(debug, 0, Integer.MAX_VALUE); } }
@Override public void visitRequire(final String module, final int access, final String version) { requires .putShort(symbolTable.addConstantModule(module).index) .putShort(access) .putShort(version == null ? 0 : symbolTable.addConstantUtf8(version)); requiresCount++; }
/** * Adds a new CONSTANT_String_info to the constant pool of this symbol table. * * @param index the constant pool index of the new Symbol. * @param value a string. */ private void addConstantUtf8(final int index, final String value) { add(new Entry(index, Symbol.CONSTANT_UTF8_TAG, value, hash(Symbol.CONSTANT_UTF8_TAG, value))); }
public AnnotationVisitor visitAnnotation( final String name, final String desc) { ++size; if (named) { bv.putShort(cw.newUTF8(name)); } // write tag and type, and reserve space for values count bv.put12('@', cw.newUTF8(desc)).putShort(0); return new AnnotationWriter(cw, true, bv, bv, bv.length - 2); }
public void body(MethodVisitor mv) { mv.visitVarInsn(ALOAD, 0);// read local variable 0 (initialized to this) and push it on the stack mv.visitLdcInsn(MY_NAME); // push the String MY_NAME on the stack putFieldInThis("name", String.class); mv.visitInsn(RETURN); } }).addMethod(ACC_PUBLIC, "toString", generator.methodDescr(String.class), new ClassGenerator.MethodBody() {
/** * Adds a new CONSTANT_Long_info or CONSTANT_Double_info to the constant pool of this symbol * table. * * @param index the constant pool index of the new Symbol. * @param tag one of {@link Symbol#CONSTANT_LONG_TAG} or {@link Symbol#CONSTANT_DOUBLE_TAG}. * @param value a long or double. */ private void addConstantLongOrDouble(final int index, final int tag, final long value) { add(new Entry(index, tag, value, hash(tag, value))); }
public AnnotationVisitor visitArray(final String name) { ++size; if (named) { bv.putShort(cw.newUTF8(name)); } // write tag, and reserve space for array size bv.put12('[', 0); return new AnnotationWriter(cw, false, bv, bv, bv.length - 2); }
public void body(MethodVisitor mv) { getFieldFromThis("name", String.class); mv.visitInsn(ARETURN); // return the first object on the stack } });
/** * Adds a new CONSTANT_NameAndType_info to the constant pool of this symbol table. * * @param index the constant pool index of the new Symbol. * @param name a field or method name. * @param descriptor a field or method descriptor. */ private void addConstantNameAndType(final int index, final String name, final String descriptor) { final int tag = Symbol.CONSTANT_NAME_AND_TYPE_TAG; add(new Entry(index, tag, name, descriptor, hash(tag, name, descriptor))); }
public void body(MethodVisitor mv) { putFieldInThisFromRegistry("name", String.class, 1); mv.visitInsn(RETURN); } }, String.class);
/** * Adds a new CONSTANT_Integer_info or CONSTANT_Float_info to the constant pool of this symbol * table. * * @param index the constant pool index of the new Symbol. * @param tag one of {@link Symbol#CONSTANT_INTEGER_TAG} or {@link Symbol#CONSTANT_FLOAT_TAG}. * @param value an int or float. */ private void addConstantIntegerOrFloat(final int index, final int tag, final int value) { add(new Entry(index, tag, value, hash(tag, value))); }