FieldGen handlerFieldGen = new FieldGen(Constants.ACC_PRIVATE | Constants.ACC_FINAL, translate(handlerClass), Util .handlerFieldName(), cp); newStubClass.addField(handlerFieldGen.getField()); MethodRef method = methods[i]; dataFieldGens[i] = new FieldGen(Constants.ACC_PRIVATE | Constants.ACC_STATIC, typeOfDataFields, Util .methodFieldName(i), cp); newStubClass.addField(dataFieldGens[i].getField()); try { java.lang.reflect.Field f = proxyClass .getDeclaredField(dataFieldGens[i].getName());
final FieldGen fg = new FieldGen(f, clg.getConstantPool()); if (dbg) { System.err.println("Adding AnnotationEntry to the field"); fg.addAnnotationEntry(fruitBasedAnnotationEntry); if (dbg) { System.err.println("FieldGen (mutable field) is " + fg); clg.addField(fg.getField()); f = clg.getFields()[1]; // there are two fields in the class, removing
_cg.addField(field.getField());
/** * 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()); }
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()); }
@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()); }
/** * Instantiate from existing field. * * @param field Field object * @param cp constant pool (must contain the same entries as the field's constant pool) */ public FieldGen(final Field field, final ConstantPoolGen cp) { this(field.getAccessFlags(), Type.getType(field.getSignature()), field.getName(), cp); final Attribute[] attrs = field.getAttributes(); for (final Attribute attr : attrs) { if (attr instanceof ConstantValue) { setValue(((ConstantValue) attr).getConstantValueIndex()); } else if (attr instanceof Annotations) { final Annotations runtimeAnnotations = (Annotations)attr; final AnnotationEntry[] annotationEntries = runtimeAnnotations.getAnnotationEntries(); for (final AnnotationEntry element : annotationEntries) { addAnnotationEntry(new AnnotationEntryGen(element,cp,false)); } } else { addAttribute(attr); } } }
/** * Return string representation close to declaration format, * `public static final short MAX = 100', e.g.. * * @return String representation of field */ public final String toString() { String name, signature, access; // Short cuts to constant pool access = Utility.accessToString(access_flags); access = access.equals("")? "" : (access + " "); signature = type.toString(); name = getName(); StringBuffer buf = new StringBuffer(access + signature + " " + name); String value = getInitValue(); if(value != null) buf.append(" = " + value); return buf.toString(); }
.getName(), handlerField.getType())); if (dataField.isStatic()) { il.append(fac.createGetStatic(clazz.getClassName(), dataField .getName(), dataField.getType())); } else { il.append(InstructionFactory.createThis()); il.append(fac.createGetField(clazz.getClassName(), dataField .getName(), dataField.getType()));
FieldGen handlerFieldGen = new FieldGen(Constants.ACC_PRIVATE | Constants.ACC_FINAL, translate(handlerClass), Util .handlerFieldName(), cp); newStubClass.addField(handlerFieldGen.getField()); FieldGen initializerFieldGen = new FieldGen(Constants.ACC_PRIVATE | Constants.ACC_STATIC, translate(StubInitializer.class), Util .initializerFieldName(), cp); newStubClass.addField(initializerFieldGen.getField()); MethodRef method = methods[i]; dataFieldGens[i] = new FieldGen(Constants.ACC_PRIVATE | Constants.ACC_STATIC, typeOfDataFields, Util .methodFieldName(i), cp); newStubClass.addField(dataFieldGens[i].getField()); try { java.lang.reflect.Field f = proxyClass .getDeclaredField(dataFieldGens[i].getName()); Level.WARNING, "cannot find field " + dataFieldGens[i].getName() + " for stub class " + className
/** * 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()); }
@Override public int hashCode( final Object o ) { final FieldGen THIS = (FieldGen) o; return THIS.getSignature().hashCode() ^ THIS.getName().hashCode(); } };
/** * Return string representation close to declaration format, * `public static final short MAX = 100', e.g.. * * @return String representation of field */ @Override public final String toString() { String name; String signature; String access; // Short cuts to constant pool access = Utility.accessToString(super.getAccessFlags()); access = access.isEmpty() ? "" : (access + " "); signature = super.getType().toString(); name = getName(); final StringBuilder buf = new StringBuilder(32); // CHECKSTYLE IGNORE MagicNumber buf.append(access).append(signature).append(" ").append(name); final String value = getInitValue(); if (value != null) { buf.append(" = ").append(value); } return buf.toString(); }
/** * generate a field declaration of the form... * <pre> * * <code> * private InvocationHandler invocationHandler; * </code> * * </pre> * * @return the method * */ public Field createInvocationHandlerField() { FieldGen fg = new FieldGen(Constants.ACC_PRIVATE, INVOCATION_HANDLER_T, INVOCATION_HANDLER_FN, constPool); return fg.getField(); }
/** * generate a field declaration of the form... * <pre> * * <code> * public static Runtime runtime; * </code> * * </pre> * * @return the method * */ public Field createRuntimeField() { FieldGen fg = new FieldGen(Constants.ACC_PUBLIC | Constants.ACC_STATIC, RUNTIME_T, Runtime.RUNTIME_FN, constPool); return fg.getField(); }