Top Description Inners Fields Constructors Methods
javassist.bytecode.annotation

public Class Annotation

extends Object
Class Inheritance
Imports
java.io.IOException, java.util.LinkedHashMap, .Map, .Set, javassist.ClassPool, .CtClass, .CtMethod, .NotFoundException, javassist.bytecode.ConstPool, .Descriptor

The annotation structure.

An instance of this class is returned by getAnnotations() in AnnotationsAttribute or in ParameterAnnotationsAttribute.

Authors
Bill Burke, Shigeru Chiba, Adrian Brock
See Also
javassist.bytecode.AnnotationsAttribute#getAnnotations(), javassist.bytecode.ParameterAnnotationsAttribute#getAnnotations(), MemberValue, MemberValueVisitor, AnnotationsWriter

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
pack-priv Map<String, Annotation.Pair>
pack-priv ConstPool
pack-priv int

Constructor Summary

AccessConstructor and Description
public
Annotation(int
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.
type
,
ConstPool
the constant pool table.
cp
)

Constructs an annotation including no members.

public
Annotation(String
the fully-qualified name of the annotation interface type.
typeName
,
ConstPool
the constant pool table.
cp
)

Constructs an annotation including no members.

public
Annotation(ConstPool
the constant pool table.
cp
,
CtClass
the interface.
clazz
)

Constructs an annotation that can be accessed through the interface represented by clazz.

Method Summary

Modifier and TypeMethod and Description
public void
addMemberValue(int
the index into the constant pool table. The entry at that index must be a CONSTANT_Utf8_info structure. structure representing the member name.
nameIndex
,
MemberValue
the member value.
value
)

Adds a new member.

public void
addMemberValue(String
the member name.
name
,
MemberValue
the member value.
value
)

Adds a new member.

private void
public static MemberValue

Returns:

the member value
createMemberValue
(ConstPool
the constant pool table.
cp
,
CtClass
the type of the member.
type
)

Makes an instance of MemberValue.

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Returns true if the given object represents the same annotation as this object.

public Set<String>

Returns:

null if no members are defined.
getMemberNames
()

Obtains all the member names.

public MemberValue

Returns:

null if the member cannot be found or if the value is the default value.
getMemberValue
(String
the member name
name
)

Obtains the member value with the given name.

public String

Returns:

the type name
getTypeName
()

Obtains the name of the annotation type.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public Object

Returns:

the annotation
toAnnotationType
(ClassLoader
class loader for loading an annotation type.
cl
,
ClassPool
class pool for obtaining class files.
cp
)

Constructs an annotation-type object representing this annotation.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the annotation.

public void
write(AnnotationsWriter
the output.
writer
)

Writes this annotation.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

membersback to summary
pack-priv Map<String, Annotation.Pair> members
poolback to summary
pack-priv ConstPool pool
typeIndexback to summary
pack-priv int typeIndex

Constructor Detail

Annotationback to summary
public Annotation(int type, ConstPool cp)

Constructs an annotation including no members. A member can be later added to the created annotation by addMemberValue().

Parameters
type:int

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:ConstPool

the constant pool table.

See Also
addMemberValue(String, MemberValue)
Annotationback to summary
public Annotation(String typeName, ConstPool cp)

Constructs an annotation including no members. A member can be later added to the created annotation by addMemberValue().

Parameters
typeName:String

the fully-qualified name of the annotation interface type.

cp:ConstPool

the constant pool table.

See Also
addMemberValue(String, MemberValue)
Annotationback to summary
public Annotation(ConstPool cp, CtClass clazz) throws NotFoundException

Constructs an annotation that can be accessed through the interface represented by clazz. The values of the members are not specified.

Parameters
cp:ConstPool

the constant pool table.

clazz:CtClass

the interface.

Exceptions
NotFoundException:
when the clazz is not found

Method Detail

addMemberValueback to summary
public void addMemberValue(int nameIndex, MemberValue value)

Adds a new member.

Parameters
nameIndex:int

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:MemberValue

the member value.

addMemberValueback to summary
public void addMemberValue(String name, MemberValue value)

Adds a new member.

Parameters
name:String

the member name.

value:MemberValue

the member value.

addMemberValueback to summary
private void addMemberValue(Annotation.Pair pair)
createMemberValueback to summary
public static MemberValue createMemberValue(ConstPool cp, CtClass type) throws NotFoundException

Makes an instance of MemberValue.

Parameters
cp:ConstPool

the constant pool table.

type:CtClass

the type of the member.

Returns:MemberValue

the member value

Exceptions
NotFoundException:
when the type is not found
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Returns true if the given object represents the same annotation as this object. The equality test checks the member values.

Parameters
obj:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getMemberNamesback to summary
public Set<String> getMemberNames()

Obtains all the member names.

Returns:Set<String>

null if no members are defined.

getMemberValueback to summary
public MemberValue getMemberValue(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:String

the member name

Returns:MemberValue

null if the member cannot be found or if the value is the default value.

See Also
javassist.bytecode.AnnotationDefaultAttribute
getTypeNameback to summary
public String getTypeName()

Obtains the name of the annotation type.

Returns:String

the type name

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
toAnnotationTypeback to summary
public Object toAnnotationType(ClassLoader cl, ClassPool cp) throws ClassNotFoundException, NoSuchClassError

Constructs an annotation-type object representing this annotation. For example, if this annotation represents @Author, this method returns an Author object.

Parameters
cl:ClassLoader

class loader for loading an annotation type.

cp:ClassPool

class pool for obtaining class files.

Returns:Object

the annotation

Exceptions
ClassNotFoundException:
if the class cannot found.
NoSuchClassError:
if the class linkage fails.
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of the annotation.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object

Annotations
@Override
writeback to summary
public void write(AnnotationsWriter writer) throws IOException

Writes this annotation.

Parameters
writer:AnnotationsWriter

the output.

Exceptions
IOException:
for an error during the write
javassist.bytecode.annotation back to summary

pack-priv Class Annotation.Pair

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv MemberValue

Constructor Summary

AccessConstructor and Description
pack-priv
Pair()

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

nameback to summary
pack-priv int name
valueback to summary
pack-priv MemberValue value

Constructor Detail

Pairback to summary
pack-priv Pair()