Package javassist.bytecode.annotation
Class Annotation
- java.lang.Object
-
- javassist.bytecode.annotation.Annotation
-
public class Annotation extends java.lang.Object
Theannotation
structure.An instance of this class is returned by
getAnnotations()
inAnnotationsAttribute
or inParameterAnnotationsAttribute
.- Author:
- Bill Burke, Shigeru Chiba, Adrian Brock
- See Also:
AnnotationsAttribute.getAnnotations()
,ParameterAnnotationsAttribute.getAnnotations()
,MemberValue
,MemberValueVisitor
,AnnotationsWriter
-
-
Constructor Summary
Constructors Constructor Description Annotation(int type, ConstPool cp)
Constructs an annotation including no members.Annotation(java.lang.String typeName, ConstPool cp)
Constructs an annotation including no members.Annotation(ConstPool cp, CtClass clazz)
Constructs an annotation that can be accessed through the interface represented byclazz
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 ofMemberValue
.boolean
equals(java.lang.Object obj)
Returns true if the given object represents the same annotation as this object.java.util.Set<java.lang.String>
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.int
hashCode()
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.
-
-
-
Constructor Detail
-
Annotation
public Annotation(int type, ConstPool cp)
Constructs an annotation including no members. A member can be later added to the created annotation byaddMemberValue()
.- Parameters:
type
- the index into the constant pool table. the entry at that index must be theCONSTANT_Utf8_Info
structure repreenting the name of the annotation interface type.cp
- the constant pool table.- See Also:
addMemberValue(String, MemberValue)
-
Annotation
public Annotation(java.lang.String typeName, ConstPool cp)
Constructs an annotation including no members. A member can be later added to the created annotation byaddMemberValue()
.- Parameters:
typeName
- the fully-qualified name of the annotation interface type.cp
- the constant pool table.- See Also:
addMemberValue(String, MemberValue)
-
Annotation
public Annotation(ConstPool cp, CtClass clazz) throws NotFoundException
Constructs an annotation that can be accessed through the interface represented byclazz
. The values of the members are not specified.- Parameters:
cp
- the constant pool table.clazz
- the interface.- Throws:
NotFoundException
- when the clazz is not found
-
-
Method Detail
-
createMemberValue
public static MemberValue createMemberValue(ConstPool cp, CtClass type) throws NotFoundException
Makes an instance ofMemberValue
.- Parameters:
cp
- the constant pool table.type
- the type of the member.- Returns:
- the member value
- Throws:
NotFoundException
- when the type is not found
-
addMemberValue
public void addMemberValue(int nameIndex, MemberValue value)
Adds a new member.- Parameters:
nameIndex
- the index into the constant pool table. The entry at that index must be aCONSTANT_Utf8_info
structure. structure representing the member name.value
- the member value.
-
addMemberValue
public void addMemberValue(java.lang.String name, MemberValue value)
Adds a new member.- Parameters:
name
- the member name.value
- the member value.
-
toString
public java.lang.String toString()
Returns a string representation of the annotation.- Overrides:
toString
in classjava.lang.Object
-
getTypeName
public java.lang.String getTypeName()
Obtains the name of the annotation type.- Returns:
- the type name
-
getMemberNames
public java.util.Set<java.lang.String> getMemberNames()
Obtains all the member names.- Returns:
- null if no members are defined.
-
getMemberValue
public MemberValue getMemberValue(java.lang.String name)
Obtains the member value with the given 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.- Parameters:
name
- the member name- Returns:
- null if the member cannot be found or if the value is the default value.
- See Also:
AnnotationDefaultAttribute
-
toAnnotationType
public java.lang.Object toAnnotationType(java.lang.ClassLoader cl, ClassPool cp) throws java.lang.ClassNotFoundException, NoSuchClassError
Constructs an annotation-type object representing this annotation. For example, if this annotation represents@Author
, this method returns anAuthor
object.- Parameters:
cl
- class loader for loading an annotation type.cp
- class pool for obtaining class files.- Returns:
- the annotation
- Throws:
java.lang.ClassNotFoundException
- if the class cannot found.NoSuchClassError
- if the class linkage fails.
-
write
public void write(AnnotationsWriter writer) throws java.io.IOException
Writes this annotation.- Parameters:
writer
- the output.- Throws:
java.io.IOException
- for an error during the write
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
Returns true if the given object represents the same annotation as this object. The equality test checks the member values.- Overrides:
equals
in classjava.lang.Object
-
-