Package javassist
Class CtMember
- java.lang.Object
-
- javassist.CtMember
-
- Direct Known Subclasses:
CtBehavior
,CtField
,CtMember.Cache
public abstract class CtMember extends java.lang.Object
An instance ofCtMember
represents a field, a constructor, or a method.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
CtMember.Cache
-
Field Summary
Fields Modifier and Type Field Description protected CtClass
declaringClass
(package private) CtMember
next
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
extendToString(java.lang.StringBuffer buffer)
Invoked bytoString()
to add to the buffer and provide the complete value.abstract java.lang.Object
getAnnotation(java.lang.Class annotationType)
Returns the annotation if the class has the specified annotation type.abstract java.lang.Object[]
getAnnotations()
Returns the annotations associated with this member.abstract byte[]
getAttribute(java.lang.String name)
Obtains a user-defined attribute with the given name.abstract java.lang.Object[]
getAvailableAnnotations()
Returns the annotations associated with this member.CtClass
getDeclaringClass()
Returns the class that declares this member.abstract java.lang.String
getGenericSignature()
Returns the generic signature of the member.abstract int
getModifiers()
Obtains the modifiers of the member.abstract java.lang.String
getName()
Obtains the name of the member.abstract java.lang.String
getSignature()
Returns the character string representing the signature of the member.boolean
hasAnnotation(java.lang.Class clz)
Returns true if the class has the specified annotation type.abstract boolean
hasAnnotation(java.lang.String annotationTypeName)
Returns true if the class has the specified annotation type.(package private) void
nameReplaced()
This method is invoked when setName() or replaceClassName() in CtClass is called.(package private) CtMember
next()
abstract void
setAttribute(java.lang.String name, byte[] data)
Adds a user-defined attribute.abstract void
setGenericSignature(java.lang.String sig)
Sets the generic signature of the member.abstract void
setModifiers(int mod)
Sets the encoded modifiers of the member.java.lang.String
toString()
boolean
visibleFrom(CtClass clazz)
Returns true if this member is accessible from the given class.
-
-
-
Constructor Detail
-
CtMember
protected CtMember(CtClass clazz)
-
-
Method Detail
-
next
final CtMember next()
-
nameReplaced
void nameReplaced()
This method is invoked when setName() or replaceClassName() in CtClass is called.- See Also:
CtMethod.nameReplaced()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
extendToString
protected abstract void extendToString(java.lang.StringBuffer buffer)
Invoked bytoString()
to add to the buffer and provide the complete value. Subclasses should invoke this method, adding a space before each token. The modifiers for the member are provided first; subclasses should provide additional data such as return type, field or method name, etc.
-
getDeclaringClass
public CtClass getDeclaringClass()
Returns the class that declares this member.
-
visibleFrom
public boolean visibleFrom(CtClass clazz)
Returns true if this member is accessible from the given class.
-
getModifiers
public abstract int getModifiers()
Obtains the modifiers of the member.- Returns:
- modifiers encoded with
javassist.Modifier
. - See Also:
Modifier
-
setModifiers
public abstract void setModifiers(int mod)
Sets the encoded modifiers of the member.- See Also:
Modifier
-
hasAnnotation
public boolean hasAnnotation(java.lang.Class clz)
Returns true if the class has the specified annotation type.- Parameters:
clz
- the annotation type.- Returns:
true
if the annotation is found, otherwisefalse
.- Since:
- 3.11
-
hasAnnotation
public abstract boolean hasAnnotation(java.lang.String annotationTypeName)
Returns true if the class has the specified annotation type.- Parameters:
annotationTypeName
- the name of annotation type.- Returns:
true
if the annotation is found, otherwisefalse
.- Since:
- 3.21
-
getAnnotation
public abstract java.lang.Object getAnnotation(java.lang.Class annotationType) throws java.lang.ClassNotFoundException
Returns the annotation if the class has the specified annotation type. For example, if an annotation@Author
is associated with this member, anAuthor
object is returned. The member values can be obtained by calling methods on theAuthor
object.- Parameters:
annotationType
- the annotation type.- Returns:
- the annotation if found, otherwise
null
. - Throws:
java.lang.ClassNotFoundException
- Since:
- 3.11
-
getAnnotations
public abstract java.lang.Object[] getAnnotations() throws java.lang.ClassNotFoundException
Returns the annotations associated with this member. For example, if an annotation@Author
is associated with this member, the returned array contains anAuthor
object. The member values can be obtained by calling methods on theAuthor
object.- Returns:
- an array of annotation-type objects.
- Throws:
java.lang.ClassNotFoundException
- See Also:
CtClass.getAnnotations()
-
getAvailableAnnotations
public abstract java.lang.Object[] getAvailableAnnotations()
Returns the annotations associated with this member. This method is equivalent togetAnnotations()
except that, if any annotations are not on the classpath, they are not included in the returned array.- Returns:
- an array of annotation-type objects.
- Since:
- 3.3
- See Also:
getAnnotations()
,CtClass.getAvailableAnnotations()
-
getName
public abstract java.lang.String getName()
Obtains the name of the member.As for constructor names, see
getName()
inCtConstructor
.- See Also:
CtConstructor.getName()
-
getSignature
public abstract java.lang.String getSignature()
Returns the character string representing the signature of the member. If two members have the same signature (parameter types etc.),getSignature()
returns the same string.
-
getGenericSignature
public abstract java.lang.String getGenericSignature()
Returns the generic signature of the member.
-
setGenericSignature
public abstract void setGenericSignature(java.lang.String sig)
Sets the generic signature of the member.- Parameters:
sig
- a new generic signature.- Since:
- 3.17
- See Also:
SignatureAttribute.ObjectType.encode()
,SignatureAttribute.MethodSignature.encode()
,CtClass.setGenericSignature(String)
-
getAttribute
public abstract byte[] getAttribute(java.lang.String name)
Obtains a user-defined attribute with the given name. If that attribute is not found in the class file, this method returns null.Note that an attribute is a data block specified by the class file format. See
AttributeInfo
.- Parameters:
name
- attribute name
-
setAttribute
public abstract void setAttribute(java.lang.String name, byte[] data)
Adds a user-defined attribute. The attribute is saved in the class file.Note that an attribute is a data block specified by the class file format. See
AttributeInfo
.- Parameters:
name
- attribute namedata
- attribute value
-
-