protected void extendToString(StringBuffer buffer) { buffer.append(' '); buffer.append(getName()); buffer.append(' '); buffer.append(fieldInfo.getDescriptor()); }
@Override protected CtMethod generateFieldReader( CtClass managedCtClass, CtField persistentField, AttributeTypeDescriptor typeDescriptor) { String fieldName = persistentField.getName(); String readerName = EnhancerConstants.PERSISTENT_FIELD_READER_PREFIX + fieldName; return MethodWriter.addGetter( managedCtClass, fieldName, readerName ); }
@Override protected CtMethod generateFieldWriter( CtClass managedCtClass, CtField persistentField, AttributeTypeDescriptor typeDescriptor) { String fieldName = persistentField.getName(); String writerName = EnhancerConstants.PERSISTENT_FIELD_WRITER_PREFIX + fieldName; return MethodWriter.addSetter( managedCtClass, fieldName, writerName ); }
@Override protected void extendToString(StringBuffer buffer) { buffer.append(' '); buffer.append(getName()); buffer.append(' '); buffer.append(fieldInfo.getDescriptor()); }
/** * Returns a String representation of the object. */ public String toString() { return getDeclaringClass().getName() + "." + getName() + ":" + fieldInfo.getDescriptor(); }
/** * Returns a String representation of the object. */ @Override public String toString() { return getDeclaringClass().getName() + "." + getName() + ":" + fieldInfo.getDescriptor(); }
public static <T extends Annotation> T getAnnotation(CtField attribute, Class<T> annotation) { return getAnnotation( attribute.getDeclaringClass(), attribute.getName(), annotation ); }
public TransformReadField(Transformer next, CtField field, String methodClassname, String methodName) { super(next); this.fieldClass = field.getDeclaringClass(); this.fieldname = field.getName(); this.methodClassname = methodClassname; this.methodName = methodName; this.isPrivate = Modifier.isPrivate(field.getModifiers()); }
public TransformFieldAccess(Transformer next, CtField field, String newClassname, String newFieldname) { super(next); this.fieldClass = field.getDeclaringClass(); this.fieldname = field.getName(); this.isPrivate = Modifier.isPrivate(field.getModifiers()); this.newClassname = newClassname; this.newFieldname = newFieldname; this.constPool = null; }
private static RuntimeException barf( CtClass ct, CtField fld ) throws NotFoundException { return new RuntimeException(ct.getSimpleName()+"."+fld.getName()+" of type "+(fld.getType().getSimpleName())+": Serialization not implemented; does not extend Iced or DTask"); }
public TransformFieldAccess(Transformer next, CtField field, String newClassname, String newFieldname) { super(next); this.fieldClass = field.getDeclaringClass(); this.fieldname = field.getName(); this.isPrivate = Modifier.isPrivate(field.getModifiers()); this.newClassname = newClassname; this.newFieldname = newFieldname; this.constPool = null; }
public TransformReadField(Transformer next, CtField field, String methodClassname, String methodName) { super(next); this.fieldClass = field.getDeclaringClass(); this.fieldname = field.getName(); this.methodClassname = methodClassname; this.methodName = methodName; this.isPrivate = Modifier.isPrivate(field.getModifiers()); }
private PersistentAttributeAccessMethods enhancePersistentAttribute(CtClass managedCtClass, CtField persistentField) { try { AttributeTypeDescriptor typeDescriptor = AttributeTypeDescriptor.resolve( managedCtClass, persistentField ); return new PersistentAttributeAccessMethods( generateFieldReader( managedCtClass, persistentField, typeDescriptor ), generateFieldWriter( managedCtClass, persistentField, typeDescriptor ) ); } catch (Exception e) { final String msg = String.format( "Unable to enhance persistent attribute [%s:%s]", managedCtClass.getName(), persistentField.getName() ); throw new EnhancementException( msg, e ); } }
public void enhance(CtClass managedCtClass) { final IdentityHashMap<String, PersistentAttributeAccessMethods> attrDescriptorMap = new IdentityHashMap<String, PersistentAttributeAccessMethods>(); for ( CtField persistentField : collectPersistentFields( managedCtClass ) ) { attrDescriptorMap.put( persistentField.getName(), enhancePersistentAttribute( managedCtClass, persistentField ) ); } // find all references to the transformed fields and replace with calls to the added reader/writer methods enhanceAttributesAccess( managedCtClass, attrDescriptorMap ); // same thing for direct access to fields of other entities if ( this.enhancementContext.doExtendedEnhancement( managedCtClass ) ) { extendedEnhancement( managedCtClass ); } }
/** * Registers a reflective class. The field accesses to the instances * of this class are instrumented. */ private void registerReflectiveClass(CtClass clazz) { CtField[] fs = clazz.getDeclaredFields(); for (int i = 0; i < fs.length; ++i) { CtField f = fs[i]; int mod = f.getModifiers(); if ((mod & Modifier.PUBLIC) != 0 && (mod & Modifier.FINAL) == 0) { String name = f.getName(); converter.replaceFieldRead(f, clazz, readPrefix + name); converter.replaceFieldWrite(f, clazz, writePrefix + name); } } }
/** * Returns null if the field is accessible. Otherwise, it throws * an exception or it returns AccessorMaker if the field is a private * one declared in an enclosing class. */ private AccessorMaker isAccessibleField(CtField f, FieldInfo finfo) throws CompileError { if (AccessFlag.isPrivate(finfo.getAccessFlags()) && f.getDeclaringClass() != thisClass) { CtClass declClass = f.getDeclaringClass(); if (isEnclosing(declClass, thisClass)) { AccessorMaker maker = declClass.getAccessorMaker(); if (maker != null) return maker; else throw new CompileError("fatal error. bug?"); } else throw new CompileError("Field " + f.getName() + " in " + declClass.getName() + " is private."); } return null; // accessible field }
private int makeFieldInitializer(Bytecode code, CtClass[] parameters) throws CannotCompileException, NotFoundException { int stacksize = 0; Javac jv = new Javac(code, this); try { jv.recordParams(parameters, false); } catch (CompileError e) { throw new CannotCompileException(e); } for (FieldInitLink fi = fieldInitializers; fi != null; fi = fi.next) { CtField f = fi.field; if (!Modifier.isStatic(f.getModifiers())) { int s = fi.init.compile(f.getType(), f.getName(), code, parameters, jv); if (stacksize < s) stacksize = s; } } return stacksize; }
private void modifyClassConstructor(ClassFile cf) throws CannotCompileException, NotFoundException { if (fieldInitializers == null) return; Bytecode code = new Bytecode(cf.getConstPool(), 0, 0); Javac jv = new Javac(code, this); int stacksize = 0; boolean doInit = false; for (FieldInitLink fi = fieldInitializers; fi != null; fi = fi.next) { CtField f = fi.field; if (Modifier.isStatic(f.getModifiers())) { doInit = true; int s = fi.init.compileIfStatic(f.getType(), f.getName(), code, jv); if (stacksize < s) stacksize = s; } } if (doInit) // need an initializer for static fileds. modifyClassConstructor(cf, code, stacksize, 0); }