/** * Returns a String representation of the object. */ public String toString() { return getDeclaringClass().getName() + "." + getName() + ":" + fieldInfo.getDescriptor(); }
static boolean isFieldInSuper(CtClass clazz, CtClass fclass, String fname) { if (!clazz.subclassOf(fclass)) return false; try { CtField f = clazz.getField(fname); return f.getDeclaringClass() == fclass; } catch (NotFoundException e) {} return false; }
/** * 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 ); }
static boolean isFieldInSuper(CtClass clazz, CtClass fclass, String fname) { if (!clazz.subclassOf(fclass)) return false; try { CtField f = clazz.getField(fname); return f.getDeclaringClass() == fclass; } catch (NotFoundException e) {} return false; }
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 int addFieldrefInfo(CtField f, FieldInfo finfo) { ConstPool cp = bytecode.getConstPool(); String cname = f.getDeclaringClass().getName(); int ci = cp.addClassInfo(cname); String name = finfo.getName(); String type = finfo.getDescriptor(); return cp.addFieldrefInfo(ci, name, type); }
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; }
/** * 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 }
@Override public void edit(FieldAccess f) throws CannotCompileException { try { put(f.getField().getDeclaringClass().getName() + "." + f.getFieldName(), f.getLineNumber(), key); } catch (NotFoundException e) { throw new ReflectionsException("Could not find member " + f.getFieldName() + " in " + key, e); } } });
@Override public void edit(FieldAccess f) throws CannotCompileException { try { put(f.getField().getDeclaringClass().getName() + "." + f.getFieldName(), f.getLineNumber(), key); } catch (NotFoundException e) { throw new ReflectionsException("Could not find member " + f.getFieldName() + " in " + key, e); } } });
private int addFieldrefInfo(CtField f, FieldInfo finfo) { ConstPool cp = bytecode.getConstPool(); String cname = f.getDeclaringClass().getName(); int ci = cp.addClassInfo(cname); String name = finfo.getName(); String type = finfo.getDescriptor(); return cp.addFieldrefInfo(ci, name, type); }
private Object[] getAnnotations(boolean ignoreNotFound) throws ClassNotFoundException { FieldInfo fi = getFieldInfo2(); AnnotationsAttribute ainfo = (AnnotationsAttribute) fi.getAttribute(AnnotationsAttribute.invisibleTag); AnnotationsAttribute ainfo2 = (AnnotationsAttribute) fi.getAttribute(AnnotationsAttribute.visibleTag); return CtClassType.toAnnotationType(ignoreNotFound, getDeclaringClass().getClassPool(), ainfo, ainfo2); }
/** * Returns true if the class has the specified annotation type. * * @param typeName the name of annotation type. * @return <code>true</code> if the annotation is found, otherwise <code>false</code>. * @since 3.21 */ public boolean hasAnnotation(String typeName) { FieldInfo fi = getFieldInfo2(); AnnotationsAttribute ainfo = (AnnotationsAttribute) fi.getAttribute(AnnotationsAttribute.invisibleTag); AnnotationsAttribute ainfo2 = (AnnotationsAttribute) fi.getAttribute(AnnotationsAttribute.visibleTag); return CtClassType.hasAnnotationType(typeName, getDeclaringClass().getClassPool(), ainfo, ainfo2); }
/** * Returns the annotation if the class has the specified annotation class. * For example, if an annotation <code>@Author</code> is associated * with this field, an <code>Author</code> object is returned. * The member values can be obtained by calling methods on * the <code>Author</code> object. * * @param clz the annotation class. * @return the annotation if found, otherwise <code>null</code>. * @since 3.11 */ public Object getAnnotation(Class clz) throws ClassNotFoundException { FieldInfo fi = getFieldInfo2(); AnnotationsAttribute ainfo = (AnnotationsAttribute) fi.getAttribute(AnnotationsAttribute.invisibleTag); AnnotationsAttribute ainfo2 = (AnnotationsAttribute) fi.getAttribute(AnnotationsAttribute.visibleTag); return CtClassType.getAnnotationType(clz, getDeclaringClass().getClassPool(), ainfo, ainfo2); }
private Object[] getAnnotations(boolean ignoreNotFound) throws ClassNotFoundException { FieldInfo fi = getFieldInfo2(); AnnotationsAttribute ainfo = (AnnotationsAttribute) fi.getAttribute(AnnotationsAttribute.invisibleTag); AnnotationsAttribute ainfo2 = (AnnotationsAttribute) fi.getAttribute(AnnotationsAttribute.visibleTag); return CtClassType.toAnnotationType(ignoreNotFound, getDeclaringClass().getClassPool(), ainfo, ainfo2); }
private void atFieldAssignCore(CtField f, boolean is_static, int fi, boolean is2byte) throws CompileError { if (fi != 0) { if (is_static) { bytecode.add(PUTSTATIC); bytecode.growStack(is2byte ? -2 : -1); } else { bytecode.add(PUTFIELD); bytecode.growStack(is2byte ? -3 : -2); } bytecode.addIndex(fi); } else { CtClass declClass = f.getDeclaringClass(); AccessorMaker maker = declClass.getAccessorMaker(); // make should be non null. FieldInfo finfo = f.getFieldInfo2(); MethodInfo minfo = maker.getFieldSetter(finfo, is_static); bytecode.addInvokestatic(declClass, minfo.getName(), minfo.getDescriptor()); } }
/** * Generates bytecode for reading a field value. * It returns a fieldref_info index or zero if the field is a private * one declared in an enclosing class. */ private int atFieldRead(CtField f, boolean isStatic) throws CompileError { FieldInfo finfo = f.getFieldInfo2(); boolean is2byte = setFieldType(finfo); AccessorMaker maker = isAccessibleField(f, finfo); if (maker != null) { MethodInfo minfo = maker.getFieldGetter(finfo, isStatic); bytecode.addInvokestatic(f.getDeclaringClass(), minfo.getName(), minfo.getDescriptor()); return 0; } else { int fi = addFieldrefInfo(f, finfo); if (isStatic) { bytecode.add(GETSTATIC); bytecode.growStack(is2byte ? 2 : 1); } else { bytecode.add(GETFIELD); bytecode.growStack(is2byte ? 1 : 0); } bytecode.addIndex(fi); return fi; } }