Package javassist
Class CtMember
- java.lang.Object
-
- javassist.CtMember
-
- Direct Known Subclasses:
CtBehavior,CtField
public abstract class CtMember extends Object
An instance ofCtMemberrepresents a field, a constructor, or a method.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract ObjectgetAnnotation(Class<?> annotationType)Returns the annotation if the class has the specified annotation type.abstract Object[]getAnnotations()Returns the annotations associated with this member.abstract byte[]getAttribute(String name)Obtains a user-defined attribute with the given name.abstract Object[]getAvailableAnnotations()Returns the annotations associated with this member.CtClassgetDeclaringClass()Returns the class that declares this member.abstract StringgetGenericSignature()Returns the generic signature of the member.abstract intgetModifiers()Obtains the modifiers of the member.abstract StringgetName()Obtains the name of the member.abstract StringgetSignature()Returns the character string representing the signature of the member.booleanhasAnnotation(Class<?> clz)Returns true if the class has the specified annotation type.abstract booleanhasAnnotation(String annotationTypeName)Returns true if the class has the specified annotation type.abstract voidsetAttribute(String name, byte[] data)Adds a user-defined attribute.abstract voidsetGenericSignature(String sig)Sets the generic signature of the member.abstract voidsetModifiers(int mod)Sets the encoded modifiers of the member.StringtoString()booleanvisibleFrom(CtClass clazz)Returns true if this member is accessible from the given class.
-
-
-
Method Detail
-
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(Class<?> clz)
Returns true if the class has the specified annotation type.- Parameters:
clz- the annotation type.- Returns:
trueif the annotation is found, otherwisefalse.- Since:
- 3.11
-
hasAnnotation
public abstract boolean hasAnnotation(String annotationTypeName)
Returns true if the class has the specified annotation type.- Parameters:
annotationTypeName- the name of annotation type.- Returns:
trueif the annotation is found, otherwisefalse.- Since:
- 3.21
-
getAnnotation
public abstract Object getAnnotation(Class<?> annotationType) throws ClassNotFoundException
Returns the annotation if the class has the specified annotation type. For example, if an annotation@Authoris associated with this member, anAuthorobject is returned. The member values can be obtained by calling methods on theAuthorobject.- Parameters:
annotationType- the annotation type.- Returns:
- the annotation if found, otherwise
null. - Throws:
ClassNotFoundException- Since:
- 3.11
-
getAnnotations
public abstract Object[] getAnnotations() throws ClassNotFoundException
Returns the annotations associated with this member. For example, if an annotation@Authoris associated with this member, the returned array contains anAuthorobject. The member values can be obtained by calling methods on theAuthorobject.- Returns:
- an array of annotation-type objects.
- Throws:
ClassNotFoundException- See Also:
CtClass.getAnnotations()
-
getAvailableAnnotations
public abstract 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 String getName()
Obtains the name of the member.As for constructor names, see
getName()inCtConstructor.- See Also:
CtConstructor.getName()
-
getSignature
public abstract 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 String getGenericSignature()
Returns the generic signature of the member.
-
setGenericSignature
public abstract void setGenericSignature(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(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(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
-
-