@Override public int hashCode( final Object o ) { final FieldGen THIS = (FieldGen) o; return THIS.getSignature().hashCode() ^ THIS.getName().hashCode(); } };
@Override public boolean equals( final Object o1, final Object o2 ) { final FieldGen THIS = (FieldGen) o1; final FieldGen THAT = (FieldGen) o2; return THIS.getName().equals(THAT.getName()) && THIS.getSignature().equals(THAT.getSignature()); }
/** * Get field object after having set up all necessary values. */ public Field getField() { String signature = getSignature(); int name_index = cp.addUtf8(name); int signature_index = cp.addUtf8(signature); if(value != null) { checkType(type); int index = addConstant(); addAttribute(new ConstantValue(cp.addUtf8("ConstantValue"), 2, index, cp.getConstantPool())); } return new Field(access_flags, name_index, signature_index, getAttributes(), cp.getConstantPool()); }
/** * Get field object after having set up all necessary values. */ public Field getField() { final String signature = getSignature(); final int name_index = super.getConstantPool().addUtf8(super.getName()); final int signature_index = super.getConstantPool().addUtf8(signature); if (value != null) { checkType(super.getType()); final int index = addConstant(); addAttribute(new ConstantValue(super.getConstantPool().addUtf8("ConstantValue"), 2, index, super.getConstantPool().getConstantPool())); // sic } addAnnotationsAsAttribute(super.getConstantPool()); return new Field(super.getAccessFlags(), name_index, signature_index, getAttributes(), super.getConstantPool().getConstantPool()); // sic }
static void emitOneArgConstructor(ClassGen stubClass, FieldGen handlerField) { String stubClassName = stubClass.getClassName(); ConstantPoolGen cp = stubClass.getConstantPool(); InstructionList il = new InstructionList(); Type[] args = new Type[] { handlerField.getType() }; MethodGen mg = new MethodGen(Constants.ACC_PUBLIC, Type.VOID, args, null, "<init>", stubClassName, il, cp); InstructionFactory fac = new InstructionFactory(stubClass, cp); // call super-constructor il.append(InstructionFactory.createThis()); il.append(fac.createInvoke(stubClass.getSuperclassName(), "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL)); // push this again... il.append(InstructionFactory.createThis()); // push the handler il.append(InstructionFactory.createLoad(handlerField.getType(), 1)); // put handlerField il.append(new PUTFIELD(cp.addFieldref(stubClassName, handlerField .getName(), handlerField.getSignature()))); // return il.append(InstructionConstants.RETURN); // compute stack and locals... mg.setMaxStack(); mg.setMaxLocals(); stubClass.addMethod(mg.getMethod()); }
static void emitInitializerConstructor(ClassGen stubClass, FieldGen handlerField, FieldGen initializerField) { String stubClassName = stubClass.getClassName(); ConstantPoolGen cp = stubClass.getConstantPool(); InstructionList il = new InstructionList(); MethodGen mg = new MethodGen(Constants.ACC_PUBLIC, Type.VOID, Type.NO_ARGS, null, "<init>", stubClassName, il, cp); InstructionFactory fac = new InstructionFactory(stubClass, cp); // call super-constructor il.append(InstructionFactory.createThis()); il.append(fac.createInvoke(stubClass.getSuperclassName(), "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL)); // push "this" il.append(InstructionFactory.createThis()); // get static initializer il.append(fac.createGetStatic(stubClassName, initializerField.getName(), initializerField.getType())); emitInvoke(il, fac, getStubHandlerRef); // checkCast il.append(fac.createCast(Type.OBJECT, handlerField.getType())); // put handlerField il.append(new PUTFIELD(cp.addFieldref(stubClassName, handlerField .getName(), handlerField.getSignature()))); // return il.append(InstructionConstants.RETURN); // compute stack and locals... mg.setMaxStack(); mg.setMaxLocals(); stubClass.addMethod(mg.getMethod()); }