private static void addAnnotations(FieldInfo fieldInfo, Class<?>[] annotations) { AnnotationsAttribute annotationsAttribute = (AnnotationsAttribute) fieldInfo.getAttribute( AnnotationsAttribute.visibleTag ); if ( annotationsAttribute == null ) { annotationsAttribute = new AnnotationsAttribute( fieldInfo.getConstPool(), AnnotationsAttribute.visibleTag ); fieldInfo.addAttribute( annotationsAttribute ); } for (Class<?> annotation : annotations) { annotationsAttribute.addAnnotation( new Annotation( annotation.getName(), fieldInfo.getConstPool() ) ); } }
/** * Set the generic signature of the field. * It represents a type including type variables. * See {@link javassist.CtClass#setGenericSignature(String)} * for a code sample. * * @param sig a new generic signature. * @see javassist.bytecode.SignatureAttribute.ObjectType#encode() * @since 3.17 */ public void setGenericSignature(String sig) { declaringClass.checkModify(); fieldInfo.addAttribute(new SignatureAttribute(fieldInfo.getConstPool(), sig)); }
/** * Adds an attribute. The attribute is saved in the class file. * * <p>Note that an attribute is a data block specified by * the class file format. * See {@link javassist.bytecode.AttributeInfo}. * * @param name attribute name * @param data attribute value */ public void setAttribute(String name, byte[] data) { declaringClass.checkModify(); fieldInfo.addAttribute(new AttributeInfo(fieldInfo.getConstPool(), name, data)); }
/** * Set the generic signature of the field. * It represents a type including type variables. * See {@link javassist.CtClass#setGenericSignature(String)} * for a code sample. * * @param sig a new generic signature. * @see javassist.bytecode.SignatureAttribute.ObjectType#encode() * @since 3.17 */ @Override public void setGenericSignature(String sig) { declaringClass.checkModify(); fieldInfo.addAttribute(new SignatureAttribute(fieldInfo.getConstPool(), sig)); }
return null; ConstPool cp = fieldInfo.getConstPool(); switch (cp.getTag(index)) { case ConstPool.CONST_Long :
/** * Adds an attribute. The attribute is saved in the class file. * * <p>Note that an attribute is a data block specified by * the class file format. * See {@link javassist.bytecode.AttributeInfo}. * * @param name attribute name * @param data attribute value */ @Override public void setAttribute(String name, byte[] data) { declaringClass.checkModify(); fieldInfo.addAttribute(new AttributeInfo(fieldInfo.getConstPool(), name, data)); }
FieldInfo fi = fieldInfo; fi.setAccessFlags(src.fieldInfo.getAccessFlags()); ConstPool cp = fi.getConstPool(); while (iterator.hasNext()) { AttributeInfo ainfo = (AttributeInfo)iterator.next();
return null; ConstPool cp = fieldInfo.getConstPool(); switch (cp.getTag(index)) { case ConstPool.CONST_Long :
/** * 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)); }
String fieldType = finfo.getDescriptor(); String desc = "()" + fieldType; ConstPool cp = finfo.getConstPool(); MethodInfo minfo = new MethodInfo(cp, methodName, desc); minfo.setAccessFlags(AccessFlag.PUBLIC);
String fieldType = finfo.getDescriptor(); String desc = "(" + fieldType + ")V"; ConstPool cp = finfo.getConstPool(); MethodInfo minfo = new MethodInfo(cp, methodName, desc); minfo.setAccessFlags(AccessFlag.PUBLIC);
String fieldType = finfo.getDescriptor(); String desc = "()" + fieldType; ConstPool cp = finfo.getConstPool(); MethodInfo minfo = new MethodInfo(cp, methodName, desc); minfo.setAccessFlags(AccessFlag.PUBLIC);
String fieldType = finfo.getDescriptor(); String desc = "(" + fieldType + ")V"; ConstPool cp = finfo.getConstPool(); MethodInfo minfo = new MethodInfo(cp, methodName, desc); minfo.setAccessFlags(AccessFlag.PUBLIC);
public static void addSyntheticAttribute(CtField field) { FieldInfo info = field.getFieldInfo(); ConstPool cp = info.getConstPool(); info.addAttribute(new SyntheticAttribute(cp)); }
public static void addSignature(CtField field, String signature) { FieldInfo fieldInfo = field.getFieldInfo(); ConstPool constPool = fieldInfo.getConstPool(); SignatureAttribute signatureAttribute = new SignatureAttribute(constPool, signature); fieldInfo.addAttribute(signatureAttribute); }
private static void copyFieldAttributes(FieldInfo oldField, FieldInfo newField) { AnnotationsAttribute annotations = (AnnotationsAttribute) oldField.getAttribute(AnnotationsAttribute.visibleTag); SignatureAttribute sigAt = (SignatureAttribute) oldField.getAttribute(SignatureAttribute.tag); if (annotations != null) { AttributeInfo newAnnotations = annotations.copy(newField.getConstPool(), Collections.EMPTY_MAP); newField.addAttribute(newAnnotations); } if (sigAt != null) { AttributeInfo newAnnotations = sigAt.copy(newField.getConstPool(), Collections.EMPTY_MAP); newField.addAttribute(newAnnotations); } }
public static AnnotationsAttribute getFieldAnnotationsAttribute(final CtField field) { FieldInfo fieldInfo = field.getFieldInfo(); AnnotationsAttribute attribute = (AnnotationsAttribute) fieldInfo.getAttribute(AnnotationsAttribute.visibleTag); if (attribute == null) { attribute = new AnnotationsAttribute(fieldInfo.getConstPool(), AnnotationsAttribute.visibleTag); } return attribute; }
public static void addSignature(CtField field, String signature) { FieldInfo fieldInfo = field.getFieldInfo(); ConstPool constPool = fieldInfo.getConstPool(); SignatureAttribute signatureAttribute = new SignatureAttribute(constPool, signature); fieldInfo.addAttribute(signatureAttribute); }
public static void addFieldAnnotation(CtField field, javassist.bytecode.annotation.Annotation annotation) { FieldInfo fieldInfo = field.getFieldInfo(); AnnotationsAttribute attribute = (AnnotationsAttribute) fieldInfo.getAttribute(AnnotationsAttribute.visibleTag); if (attribute == null) attribute = new AnnotationsAttribute(fieldInfo.getConstPool(), AnnotationsAttribute.visibleTag); attribute.addAnnotation(annotation); fieldInfo.addAttribute(attribute); }
/** * Retrieve all field annotations. */ static AnnotationsAttribute getAnnotations(CtField ctField) { AnnotationsAttribute annotationsAttribute = (AnnotationsAttribute) ctField.getFieldInfo().getAttribute(AnnotationsAttribute.visibleTag); if (annotationsAttribute == null) { annotationsAttribute = new AnnotationsAttribute(ctField.getFieldInfo().getConstPool(), AnnotationsAttribute.visibleTag); ctField.getFieldInfo().addAttribute(annotationsAttribute); } return annotationsAttribute; }