|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavassist.bytecode.AttributeInfo
javassist.bytecode.AnnotationDefaultAttribute
public class AnnotationDefaultAttribute
A class representing AnnotationDefault_attribute.
For example, if you declare the following annotation type:
@interface Author {
String name() default "Shakespeare";
int age() default 99;
}
The defautl values of name and age
are stored as annotation default attributes in Author.class.
The following code snippet obtains the default value of name:
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 age
If 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));
AnnotationsAttribute,
MemberValue| Field Summary | |
|---|---|
static java.lang.String |
tag
The name of the AnnotationDefault attribute. |
| Constructor Summary | |
|---|---|
AnnotationDefaultAttribute(ConstPool cp)
Constructs an empty AnnotationDefault_attribute. |
|
AnnotationDefaultAttribute(ConstPool cp,
byte[] info)
Constructs an AnnotationDefault_attribute. |
|
| Method Summary | |
|---|---|
AttributeInfo |
copy(ConstPool newCp,
java.util.Map classnames)
Copies this attribute and returns a new copy. |
MemberValue |
getDefaultValue()
Obtains the default value represented by this attribute. |
void |
setDefaultValue(MemberValue value)
Changes the default value represented by this attribute. |
java.lang.String |
toString()
Returns a string representation of this object. |
| Methods inherited from class javassist.bytecode.AttributeInfo |
|---|
get, getConstPool, getName, length, set |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String tag
AnnotationDefault attribute.
| Constructor Detail |
|---|
public AnnotationDefaultAttribute(ConstPool cp,
byte[] info)
AnnotationDefault_attribute.
cp - constant poolinfo - the contents of this attribute. It does not
include attribute_name_index or
attribute_length.public AnnotationDefaultAttribute(ConstPool cp)
AnnotationDefault_attribute.
The default value can be set by setDefaultValue().
cp - constant poolsetDefaultValue(javassist.bytecode.annotation.MemberValue)| Method Detail |
|---|
public AttributeInfo copy(ConstPool newCp,
java.util.Map classnames)
copy in class AttributeInfonewCp - the constant pool table used by the new copy.classnames - pairs of replaced and substituted
class names.public MemberValue getDefaultValue()
public void setDefaultValue(MemberValue value)
value - the new value.Annotation.createMemberValue(ConstPool, CtClass)public java.lang.String toString()
toString in class java.lang.Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||