Top Description Fields Constructors Methods
javassist.bytecode

public Class AnnotationDefaultAttribute

extends AttributeInfo
Class Inheritance
Imports
java.io.ByteArrayOutputStream, .DataInputStream, .IOException, java.util.Map, javassist.CtClass, javassist.bytecode.annotation.AnnotationsWriter, .MemberValue

A class representing AnnotationDefault_attribute.

For example, if you declare the following annotation type:

@interface Author {
  String name() default "Shakespeare";
  int age() default 99;
}

The defautl values of name and age are stored as annotation default attributes in Author.class. The following code snippet obtains the default value of name:

ClassPool pool = ...
CtClass cc = pool.get("Author");
CtMethod cm = cc.getDeclaredMethod("age");
MethodInfo minfo = cm.getMethodInfo();
AnnotationDefaultAttribute ada
        = (AnnotationDefaultAttribute)
          minfo.getAttribute(AnnotationDefaultAttribute.tag);
MemberValue value = ada.getDefaultValue());    // default value of age

If the following statement is executed after the code above, the default value of age is set to 80:

ada.setDefaultValue(new IntegerMemberValue(minfo.getConstPool(), 80));
See Also
AnnotationsAttribute, javassist.bytecode.annotation.MemberValue

Field Summary

Modifier and TypeField and Description
public static final String
tag

The name of the AnnotationDefault attribute.

Inherited from javassist.bytecode.AttributeInfo:
constPoolinfoname

Constructor Summary

AccessConstructor and Description
public
AnnotationDefaultAttribute(ConstPool
constant pool
cp
,
byte[]
the contents of this attribute. It does not include attribute_name_index or attribute_length.
info
)

Constructs an AnnotationDefault_attribute.

public
AnnotationDefaultAttribute(ConstPool
constant pool
cp
)

Constructs an empty AnnotationDefault_attribute.

pack-priv
AnnotationDefaultAttribute(ConstPool cp, int
the attribute name.
n
,
DataInputStream in)

Method Summary

Modifier and TypeMethod and Description
public AttributeInfo
copy(ConstPool
the constant pool table used by the new copy.
newCp
,
Map<String, String>
pairs of replaced and substituted class names.
classnames
)

Overrides javassist.bytecode.AttributeInfo.copy.

Copies this attribute and returns a new copy.

public MemberValue
getDefaultValue()

Obtains the default value represented by this attribute.

pack-priv void
pack-priv void
public void
setDefaultValue(MemberValue
the new value.
value
)

Changes the default value represented by this attribute.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of this object.

Inherited from javassist.bytecode.AttributeInfo:
copyAllgetgetConstPoolgetLengthgetNamegetRefClassesgetRefClasseslengthlookupreadremoverenameClassrenameClasssetwritewriteAll

Field Detail

tagback to summary
public static final String tag

The name of the AnnotationDefault attribute.

Constructor Detail

AnnotationDefaultAttributeback to summary
public AnnotationDefaultAttribute(ConstPool cp, byte[] info)

Constructs an AnnotationDefault_attribute.

Parameters
cp:ConstPool

constant pool

info:byte[]

the contents of this attribute. It does not include attribute_name_index or attribute_length.

AnnotationDefaultAttributeback to summary
public AnnotationDefaultAttribute(ConstPool cp)

Constructs an empty AnnotationDefault_attribute. The default value can be set by setDefaultValue().

Parameters
cp:ConstPool

constant pool

See Also
setDefaultValue(javassist.bytecode.annotation.MemberValue)
AnnotationDefaultAttributeback to summary
pack-priv AnnotationDefaultAttribute(ConstPool cp, int n, DataInputStream in) throws IOException
Parameters
n:int

the attribute name.

Method Detail

copyback to summary
public AttributeInfo copy(ConstPool newCp, Map<String, String> classnames)

Overrides javassist.bytecode.AttributeInfo.copy.

Copies this attribute and returns a new copy.

Parameters
newCp:ConstPool

Doc from javassist.bytecode.AttributeInfo.copy.

the constant pool table used by the new copy.

classnames:Map<String, String>

Doc from javassist.bytecode.AttributeInfo.copy.

pairs of replaced and substituted class names.

Annotations
@Override
getDefaultValueback to summary
public MemberValue getDefaultValue()

Obtains the default value represented by this attribute.

renameClassback to summary
pack-priv void renameClass(String oldname, String newname)

Overrides javassist.bytecode.AttributeInfo.renameClass.

Annotations
@Override
renameClassback to summary
pack-priv void renameClass(Map<String, String> classnames)

Overrides javassist.bytecode.AttributeInfo.renameClass.

Annotations
@Override
setDefaultValueback to summary
public void setDefaultValue(MemberValue value)

Changes the default value represented by this attribute.

Parameters
value:MemberValue

the new value.

See Also
javassist.bytecode.annotation.Annotation#createMemberValue(ConstPool, CtClass)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of this object.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object

Annotations
@Override