Package javassist.bytecode
Class AnnotationDefaultAttribute
- java.lang.Object
 - 
- javassist.bytecode.AttributeInfo
 - 
- javassist.bytecode.AnnotationDefaultAttribute
 
 
 
- 
public class AnnotationDefaultAttribute extends AttributeInfo
A class representingAnnotationDefault_attribute.For example, if you declare the following annotation type:
@interface Author { String name() default "Shakespeare"; int age() default 99; }The defautl values of
nameandageare stored as annotation default attributes inAuthor.class. The following code snippet obtains the default value ofname:ClassPool pool = ... CtClass cc = pool.get("Author"); CtMethod cm = cc.getDeclaredMethod("age"); MethodInfo minfo = cm.getMethodInfo(); AnnotationDefaultAttribute ada = (AnnotationDefaultAttribute) minfo.getAttribute(AnnotationDefaultAttribute.tag); MemberValue value = ada.getDefaultValue()); // default value of ageIf the following statement is executed after the code above, the default value of age is set to 80:
ada.setDefaultValue(new IntegerMemberValue(minfo.getConstPool(), 80));
- See Also:
 AnnotationsAttribute,MemberValue
 
- 
- 
Field Summary
Fields Modifier and Type Field Description static java.lang.StringtagThe name of theAnnotationDefaultattribute. 
- 
Constructor Summary
Constructors Constructor Description AnnotationDefaultAttribute(ConstPool cp)Constructs an emptyAnnotationDefault_attribute.AnnotationDefaultAttribute(ConstPool cp, byte[] info)Constructs anAnnotationDefault_attribute. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AttributeInfocopy(ConstPool newCp, java.util.Map<java.lang.String,java.lang.String> classnames)Copies this attribute and returns a new copy.MemberValuegetDefaultValue()Obtains the default value represented by this attribute.voidsetDefaultValue(MemberValue value)Changes the default value represented by this attribute.java.lang.StringtoString()Returns a string representation of this object.- 
Methods inherited from class javassist.bytecode.AttributeInfo
get, getConstPool, getName, length, set 
 - 
 
 - 
 
- 
- 
Field Detail
- 
tag
public static final java.lang.String tag
The name of theAnnotationDefaultattribute.- See Also:
 - Constant Field Values
 
 
 - 
 
- 
Constructor Detail
- 
AnnotationDefaultAttribute
public AnnotationDefaultAttribute(ConstPool cp, byte[] info)
Constructs anAnnotationDefault_attribute.- Parameters:
 cp- constant poolinfo- the contents of this attribute. It does not includeattribute_name_indexorattribute_length.
 
- 
AnnotationDefaultAttribute
public AnnotationDefaultAttribute(ConstPool cp)
Constructs an emptyAnnotationDefault_attribute. The default value can be set bysetDefaultValue().- Parameters:
 cp- constant pool- See Also:
 setDefaultValue(javassist.bytecode.annotation.MemberValue)
 
 - 
 
- 
Method Detail
- 
copy
public AttributeInfo copy(ConstPool newCp, java.util.Map<java.lang.String,java.lang.String> classnames)
Copies this attribute and returns a new copy.- Overrides:
 copyin classAttributeInfo- Parameters:
 newCp- the constant pool table used by the new copy.classnames- pairs of replaced and substituted class names.
 
- 
getDefaultValue
public MemberValue getDefaultValue()
Obtains the default value represented by this attribute. 
- 
setDefaultValue
public void setDefaultValue(MemberValue value)
Changes the default value represented by this attribute.- Parameters:
 value- the new value.- See Also:
 Annotation.createMemberValue(ConstPool, CtClass)
 
- 
toString
public java.lang.String toString()
Returns a string representation of this object.- Overrides:
 toStringin classjava.lang.Object
 
 - 
 
 -