javassist.bytecode.annotation
Class Annotation

java.lang.Object
  extended byjavassist.bytecode.annotation.Annotation

public class Annotation
extends java.lang.Object

The annotation structure.

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

Author:
Bill Burke, Shigeru Chiba
See Also:
AnnotationsAttribute.getAnnotations(), ParameterAnnotationsAttribute.getAnnotations()

Constructor Summary
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.
 
Method Summary
 void addMemberValue(int nameIndex, MemberValue value)
          Adds a new member.
 void addMemberValue(java.lang.String name, MemberValue value)
          Adds a new member.
 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.String toString()
          Returns a string representation of this object.
 void write(AnnotationsWriter writer)
          Writes this annotation.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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 by addMemberValue().

Parameters:
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.
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 by addMemberValue().

Parameters:
typeName - the 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 by clazz. The values of the members are not specified.

Parameters:
cp - the constant pool table.
clazz - the interface.
Method Detail

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 a CONSTANT_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 this object.


getTypeName

public java.lang.String getTypeName()
Obtains the name of the annotation type.


getMemberNames

public java.util.Set 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.

Returns:
null if the member cannot be found.

write

public void write(AnnotationsWriter writer)
           throws java.io.IOException
Writes this annotation.

Parameters:
writer - the output.
Throws:
java.io.IOException


Javassist, a Java-bytecode translator toolkit. Copyright (C) 1999-2005 Shigeru Chiba. All Rights Reserved.