public class Annotation
extends java.lang.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(java.lang.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(java.lang.String name,
MemberValue value)
Adds a new member.
|
static MemberValue |
createMemberValue(ConstPool cp,
CtClass type)
Makes an instance of
MemberValue. |
boolean |
equals(java.lang.Object obj)
Returns true if the given object represents the same annotation
as this object.
|
java.util.Set |
getMemberNames()
Obtains all the member names.
|
MemberValue |
getMemberValue(java.lang.String name)
Obtains the member value with the given name.
|
java.lang.String |
getTypeName()
Obtains the name of the annotation type.
|
java.lang.Object |
toAnnotationType(java.lang.ClassLoader cl,
ClassPool cp)
Constructs an annotation-type object representing this annotation.
|
java.lang.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(java.lang.String typeName,
ConstPool cp)
addMemberValue().typeName - the 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(java.lang.String name,
MemberValue value)
name - the member name.value - the member value.public java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String getTypeName()
public java.util.Set getMemberNames()
public MemberValue getMemberValue(java.lang.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 java.lang.Object toAnnotationType(java.lang.ClassLoader cl,
ClassPool cp)
throws java.lang.ClassNotFoundException,
NoSuchClassError
@Author,
this method returns an Author object.cl - class loader for loading an annotation type.cp - class pool for obtaining class files.java.lang.ClassNotFoundException - if the class cannot found.NoSuchClassError - if the class linkage fails.public void write(AnnotationsWriter writer) throws java.io.IOException
writer - the output.java.io.IOException - for an error during the writepublic boolean equals(java.lang.Object obj)
equals in class java.lang.ObjectJavassist, a Java-bytecode translator toolkit.
Copyright (C) 1999- Shigeru Chiba. All Rights Reserved.