public class Annotation extends Object
annotation structure.
An instance of this class is returned by
getAnnotations() in AnnotationsAttribute
or in ParameterAnnotationsAttribute.
AnnotationsAttribute.getAnnotations(),
ParameterAnnotationsAttribute.getAnnotations(),
MemberValue,
MemberValueVisitor,
AnnotationsWriter| Constructor and Description |
|---|
Annotation(ConstPool cp,
CtClass clazz)
Constructs an annotation that can be accessed through the interface
represented by
clazz. |
Annotation(int type,
ConstPool cp)
Constructs an annotation including no members.
|
Annotation(String typeName,
ConstPool cp)
Constructs an annotation including no members.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addMemberValue(int nameIndex,
MemberValue value)
Adds a new member.
|
void |
addMemberValue(String name,
MemberValue value)
Adds a new member.
|
static MemberValue |
createMemberValue(ConstPool cp,
CtClass type)
Makes an instance of
MemberValue. |
boolean |
equals(Object obj)
Returns true if the given object represents the same annotation
as this object.
|
Set |
getMemberNames()
Obtains all the member names.
|
MemberValue |
getMemberValue(String name)
Obtains the member value with the given name.
|
String |
getTypeName()
Obtains the name of the annotation type.
|
Object |
toAnnotationType(ClassLoader cl,
ClassPool cp)
Constructs an annotation-type object representing this annotation.
|
String |
toString()
Returns a string representation of the annotation.
|
void |
write(AnnotationsWriter writer)
Writes this annotation.
|
public Annotation(int type,
ConstPool cp)
addMemberValue().type - the index into the constant pool table.
the entry at that index must be the
CONSTANT_Utf8_Info structure
repreenting the name of the annotation interface type.cp - the constant pool table.addMemberValue(String, MemberValue)public Annotation(String typeName, ConstPool cp)
addMemberValue().typeName - the fully-qualified name of the annotation interface type.cp - the constant pool table.addMemberValue(String, MemberValue)public Annotation(ConstPool cp, CtClass clazz) throws NotFoundException
clazz. The values of the members are
not specified.cp - the constant pool table.clazz - the interface.NotFoundException - when the clazz is not foundpublic static MemberValue createMemberValue(ConstPool cp, CtClass type) throws NotFoundException
MemberValue.cp - the constant pool table.type - the type of the member.NotFoundException - when the type is not foundpublic void addMemberValue(int nameIndex,
MemberValue value)
nameIndex - the index into the constant pool table.
The entry at that index must be
a CONSTANT_Utf8_info structure.
structure representing the member name.value - the member value.public void addMemberValue(String name, MemberValue value)
name - the member name.value - the member value.public String toString()
public String getTypeName()
public Set getMemberNames()
public MemberValue getMemberValue(String name)
If this annotation does not have a value for the
specified member,
this method returns null. It does not return a
MemberValue with the default value.
The default value can be obtained from the annotation type.
name - the member nameAnnotationDefaultAttributepublic Object toAnnotationType(ClassLoader cl, ClassPool cp) throws ClassNotFoundException, NoSuchClassError
@Author,
this method returns an Author object.cl - class loader for loading an annotation type.cp - class pool for obtaining class files.ClassNotFoundException - if the class cannot found.NoSuchClassError - if the class linkage fails.public void write(AnnotationsWriter writer) throws IOException
writer - the output.IOException - for an error during the writeCopyright © 2016 Shigeru Chiba, www.javassist.org. All Rights Reserved.