/** * Internal-use only. * <code>CtClass.getRefClasses()</code> calls this method. */ public final void getRefClasses(Map classnames) { constPool.renameClass(classnames); AttributeInfo.getRefClasses(attributes, classnames); ArrayList list = methods; int n = list.size(); for (int i = 0; i < n; ++i) { MethodInfo minfo = (MethodInfo)list.get(i); String desc = minfo.getDescriptor(); Descriptor.rename(desc, classnames); AttributeInfo.getRefClasses(minfo.getAttributes(), classnames); } list = fields; n = list.size(); for (int i = 0; i < n; ++i) { FieldInfo finfo = (FieldInfo)list.get(i); String desc = finfo.getDescriptor(); Descriptor.rename(desc, classnames); AttributeInfo.getRefClasses(finfo.getAttributes(), classnames); } }
declaring); java.util.ListIterator iterator = src.fieldInfo.getAttributes().listIterator(); FieldInfo fi = fieldInfo; fi.setAccessFlags(src.fieldInfo.getAccessFlags());
+ " " + finfo.getName() + "\t" + finfo.getDescriptor()); printAttributes(finfo.getAttributes(), out, 'f');
String desc = finfo.getDescriptor(); finfo.setDescriptor(Descriptor.rename(desc, oldname, newname)); AttributeInfo.renameClass(finfo.getAttributes(), oldname, newname);
String desc = finfo.getDescriptor(); finfo.setDescriptor(Descriptor.rename(desc, classnames)); AttributeInfo.renameClass(finfo.getAttributes(), classnames);
ConstPool constantPool = classFile.getConstPool(); for (FieldInfo myField : fieldInfos) { List<?> attributes = myField.getAttributes(); Iterator<?> itr = attributes.iterator(); AnnotationsAttribute annotationsAttribute = new AnnotationsAttribute(constantPool, AnnotationsAttribute.visibleTag);
for (Object o : field.getFieldInfo().getAttributes()) { if (o instanceof AnnotationsAttribute) { AnnotationsAttribute templateAnnotations = (AnnotationsAttribute) o; for (Object attribute : fieldFromMainClass.getFieldInfo().getAttributes()) { if (attribute instanceof AnnotationsAttribute) { for (Annotation annotation : copied.getAnnotations()) {
+ " " + finfo.getName() + "\t" + finfo.getDescriptor()); printAttributes(finfo.getAttributes(), out, 'f');
List<?> attributes = myField.getAttributes(); AnnotationsAttribute annotationsAttribute = stripAnnotation(constantPool, attributes); myField.addAttribute(annotationsAttribute);
for (Object o : field.getFieldInfo().getAttributes()) { if (o instanceof AnnotationsAttribute) { AnnotationsAttribute templateAnnotations = (AnnotationsAttribute) o; for (Object attribute : fieldFromMainClass.getFieldInfo().getAttributes()) { if (attribute instanceof AnnotationsAttribute) { Annotation[] annotations = null;
/** * Creates a copy of the given field. * The created field must be added to a class * with <code>CtClass.addField()</code>. * An initial value of the field is specified * by a <code>CtField.Initializer</code> object. * * <p>If getter and setter methods are needed, * call <code>CtNewMethod.getter()</code> and * <code>CtNewMethod.setter()</code>. * * @param src the original field * @param declaring the class to which the field will be added. * @see CtNewMethod#getter(String,CtField) * @see CtNewMethod#setter(String,CtField) * @see CtField.Initializer */ public CtField(CtField src, CtClass declaring) throws CannotCompileException { this(src.fieldInfo.getDescriptor(), src.fieldInfo.getName(), declaring); FieldInfo fi = fieldInfo; fi.setAccessFlags(src.fieldInfo.getAccessFlags()); ConstPool cp = fi.getConstPool(); List<AttributeInfo> attributes = src.fieldInfo.getAttributes(); for (AttributeInfo ainfo : attributes) fi.addAttribute(ainfo.copy(cp, null)); }
/** * Internal-use only. * <code>CtClass.getRefClasses()</code> calls this method. */ public final void getRefClasses(Map<String,String> classnames) { constPool.renameClass(classnames); AttributeInfo.getRefClasses(attributes, classnames); for (MethodInfo minfo:methods) { String desc = minfo.getDescriptor(); Descriptor.rename(desc, classnames); AttributeInfo.getRefClasses(minfo.getAttributes(), classnames); } for (FieldInfo finfo:fields) { String desc = finfo.getDescriptor(); Descriptor.rename(desc, classnames); AttributeInfo.getRefClasses(finfo.getAttributes(), classnames); } }
String desc = finfo.getDescriptor(); finfo.setDescriptor(Descriptor.rename(desc, oldname, newname)); AttributeInfo.renameClass(finfo.getAttributes(), oldname, newname);
/** * Replaces all occurrences of several class names in the class file. * * @param classnames * specifies which class name is replaced with which new name. * Class names must be described with the JVM-internal * representation like <code>java/lang/Object</code>. * @see #renameClass(String,String) */ public final void renameClass(Map<String,String> classnames) { String jvmNewThisName = classnames.get(Descriptor .toJvmName(thisclassname)); if (jvmNewThisName != null) thisclassname = Descriptor.toJavaName(jvmNewThisName); constPool.renameClass(classnames); AttributeInfo.renameClass(attributes, classnames); for (MethodInfo minfo:methods) { String desc = minfo.getDescriptor(); minfo.setDescriptor(Descriptor.rename(desc, classnames)); AttributeInfo.renameClass(minfo.getAttributes(), classnames); } for (FieldInfo finfo:fields) { String desc = finfo.getDescriptor(); finfo.setDescriptor(Descriptor.rename(desc, classnames)); AttributeInfo.renameClass(finfo.getAttributes(), classnames); } }
private List<AnnotationMetadata> annotationsFor( FieldInfo field ) { List<AnnotationMetadata> annotations = new LinkedList<AnnotationMetadata>(); for (Object ob : field.getAttributes()) { AttributeInfo att = (AttributeInfo)ob; if (att instanceof AnnotationsAttribute) { for (Annotation ann : ((AnnotationsAttribute)att).getAnnotations()) { annotations.add(new AnnotationMetadata(ann)); } } } return Collections.unmodifiableList(annotations); }
private List<AnnotationMetadata> annotationsFor( FieldInfo field ) { List<AnnotationMetadata> annotations = new LinkedList<AnnotationMetadata>(); for (Object ob : field.getAttributes()) { AttributeInfo att = (AttributeInfo)ob; if (att instanceof AnnotationsAttribute) { for (Annotation ann : ((AnnotationsAttribute)att).getAnnotations()) { annotations.add(new AnnotationMetadata(ann)); } } } return Collections.unmodifiableList(annotations); }
private List<AnnotationMetadata> annotationsFor( FieldInfo field ) { List<AnnotationMetadata> annotations = new LinkedList<AnnotationMetadata>(); for (Object ob : field.getAttributes()) { AttributeInfo att = (AttributeInfo)ob; if (att instanceof AnnotationsAttribute) { for (Annotation ann : ((AnnotationsAttribute)att).getAnnotations()) { annotations.add(new AnnotationMetadata(ann)); } } } return Collections.unmodifiableList(annotations); }
private void addFieldAnnotationDependencies(CtClass ctClass, Collection<String> imports) { for (CtField field : ctClass.getDeclaredFields()) { List<?> attributes = field.getFieldInfo2().getAttributes(); addAnnotationsForAttributes(imports, attributes); } }
private void addFieldAnnotationDependencies(CtClass ctClass, Collection<String> imports) { for (CtField field : ctClass.getDeclaredFields()) { List<?> attributes = field.getFieldInfo2().getAttributes(); addAnnotationsForAttributes(imports, attributes); } }
@Override public boolean matches(CtField ctField) { List attributes = ctField.getFieldInfo().getAttributes(); boolean hasAnnotation = hasAnnotation(attributes); if (!hasAnnotation) { CtClass declaringClass = ctField.getDeclaringClass(); hasAnnotation = hasAnnotation(declaringClass.getClassFile().getAttributes()); if (!hasAnnotation) { try { declaringClass = declaringClass.getDeclaringClass(); if (declaringClass != null) { hasAnnotation = hasAnnotation(declaringClass.getClassFile().getAttributes()); } } catch (NotFoundException e) { LOGGER.log(Level.FINE, "Failed to load class '" + declaringClass.getName() + "': " + e.getLocalizedMessage(), e); } } } return hasAnnotation; }