Java Doc for CtClass.java in  » Byte-Code » Javassist » javassist » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Byte Code » Javassist » javassist 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   javassist.CtClass

All known Subclasses:   javassist.CtClassType,  javassist.CtPrimitiveType,  javassist.CtArray,
CtClass
abstract public class CtClass (Code)
An instance of CtClass represents a class. It is obtained from ClassPool.
See Also:   ClassPool.get(String)

Inner Class :static class DelayedFileOutputStream extends OutputStream

Field Summary
public static  CtClassbooleanType
     The CtClass object representing the boolean type.
public static  CtClassbyteType
     The CtClass object representing the byte type.
public static  CtClasscharType
     The CtClass object representing the char type.
public static  CtClassdoubleType
     The CtClass object representing the double type.
public static  CtClassfloatType
     The CtClass object representing the float type.
public static  CtClassintType
     The CtClass object representing the int type.
final static  StringjavaLangObject
    
public static  CtClasslongType
     The CtClass object representing the long type.
static  CtClass[]primitiveTypes
    
protected  StringqualifiedName
    
public static  CtClassshortType
     The CtClass object representing the short type.
final public static  Stringversion
     The version number of this release.
public static  CtClassvoidType
     The CtClass object representing the void type.

Constructor Summary
protected  CtClass(String name)
    

Method Summary
public  voidaddConstructor(CtConstructor c)
     Adds a constructor.
public  voidaddField(CtField f)
     Adds a field.
public  voidaddField(CtField f, String init)
     Adds a field with an initial value.

The CtField belonging to another CtClass cannot be directly added to this class. Only a field created for this class can be added.

The initial value is given as an expression written in Java. Any regular Java expression can be used for specifying the initial value.

public  voidaddField(CtField f, CtField.Initializer init)
     Adds a field with an initial value.

The CtField belonging to another CtClass cannot be directly added to this class. Only a field created for this class can be added.

For example,

     CtClass cc = ...;
     addField(new CtField(CtClass.intType, "i", cc),
     CtField.Initializer.constant(1));
     

This code adds an int field named "i".

public  voidaddInterface(CtClass anInterface)
     Adds an interface.
public  voidaddMethod(CtMethod m)
     Adds a method.
 voidcheckModify()
    
public  voiddebugWriteFile()
     Writes a class file as writeFile() does although this method does not prune or freeze the class after writing the class file.
public  voiddefrost()
     Defrosts the class so that the class can be modified again.

To avoid changes that will be never reflected, the class is frozen to be unmodifiable if it is loaded or written out.

public  voiddetach()
     Removes this CtClass object from the ClassPool.
protected  voidextendToString(StringBuffer buffer)
     Implemented in subclasses to add to the CtClass.toString() result.
 voidfreeze()
    
public  javassist.compiler.AccessorMakergetAccessorMaker()
     Undocumented method.
public  Object[]getAnnotations()
     Returns the annotations associated with this class. For example, if an annotation @Author is associated with this class, the returned array contains an Author object.
public  byte[]getAttribute(String name)
     Obtains an attribute with the given name. If that attribute is not found in the class file, this method returns null.

This is a convenient method mainly for obtaining a user-defined attribute.

public  Object[]getAvailableAnnotations()
     Returns the annotations associated with this class.
public  ClassFilegetClassFile()
     Returns a class file for this class.
public  ClassFilegetClassFile2()
     Returns a class file for this class (read only). Normal applications do not need calling this method.
public  CtConstructorgetClassInitializer()
     Gets the class initializer (static constructor) declared in the class.
public  ClassPoolgetClassPool()
     Returns a ClassPool for this class.
public  CtClassgetComponentType()
     If this object represents an array, this method returns the component type of the array.
public  CtConstructorgetConstructor(String desc)
     Returns the constructor with the given signature, which is represented by a character string called method descriptor.
public  CtConstructor[]getConstructors()
     Returns an array containing CtConstructor objects representing all the non-private constructors of the class.
public  CtBehavior[]getDeclaredBehaviors()
     Gets all the constructors and methods declared in the class.
public  CtConstructorgetDeclaredConstructor(CtClass[] params)
     Returns a constructor receiving the specified parameters.
public  CtConstructor[]getDeclaredConstructors()
     Gets all the constructors declared in the class.
public  CtFieldgetDeclaredField(String name)
     Retrieves the field with the specified name among the fields declared in the class.
public  CtField[]getDeclaredFields()
     Gets all the fields declared in the class.
public  CtMethodgetDeclaredMethod(String name, CtClass[] params)
     Retrieves the method with the specified name and parameter types among the methods declared in the class.
public  CtMethodgetDeclaredMethod(String name)
     Retrieves the method with the specified name among the methods declared in the class.
public  CtMethod[]getDeclaredMethods()
     Gets all methods declared in the class.
public  CtClassgetDeclaringClass()
     If this class is a member class or interface of another class, then the class enclosing this class is returned.
public  CtMethodgetEnclosingMethod()
     Returns the immediately enclosing method of this class.
public  CtFieldgetField(String name)
     Returns the field with the specified name.
 CtFieldgetField2(String name)
    
public  CtField[]getFields()
     Returns an array containing CtField objects representing all the non-private fields of the class.
public  CtClass[]getInterfaces()
     Obtains the class objects representing the interfaces implemented by the class or, if this object represents an interface, the interfaces extended by that interface.
public  CtMethodgetMethod(String name, String desc)
     Returns the method with the given name and signature.
public  CtMethod[]getMethods()
     Returns an array containing CtMethod objects representing all the non-private methods of the class.
public  intgetModifiers()
     Returns the modifiers for this class, encoded in an integer. For decoding, use javassist.Modifier.

If the class is a static nested class (a.k.a.

public  StringgetName()
     Obtains the fully-qualified name of the class.
public  CtClass[]getNestedClasses()
     Returns an array of nested classes declared in the class.
final public  StringgetPackageName()
     Obtains the package name.
public  CollectiongetRefClasses()
     Returns a collection of the names of all the classes referenced in this class.
final public  StringgetSimpleName()
     Obtains the not-qualified class name.
public  CtClassgetSuperclass()
     Obtains the class object representing the superclass of the class.
public  URLgetURL()
     Returns the uniform resource locator (URL) of the class file.
 voidincGetCounter()
    
public  voidinstrument(CodeConverter converter)
     Applies the given converter to all methods and constructors declared in the class.
public  voidinstrument(ExprEditor editor)
     Modifies the bodies of all methods and constructors declared in the class.
public  booleanisAnnotation()
     Determines whether this object represents an annotation type.
public  booleanisArray()
     Returns true if this object represents an array type.
public  booleanisEnum()
     Determines whether this object represents an enum.
public  booleanisFrozen()
     Returns true if the class has been loaded or written out and thus it cannot be modified any more.
public  booleanisInterface()
     Determines whether this object represents a class or an interface.
public  booleanisModified()
     Returns true if the definition of the class has been modified.
public  booleanisPrimitive()
     Returns true if this object represents a primitive Java type: boolean, byte, char, short, int, long, float, double, or void.
public static  voidmain(String[] args)
     Prints the version number and the copyright notice.
public  CtConstructormakeClassInitializer()
     Makes an empty class initializer (static constructor).
public  CtClassmakeNestedClass(String name, boolean isStatic)
     Makes a new public nested class.
public  StringmakeUniqueName(String prefix)
     Makes a unique member name.
public  voidprune()
     Discards unnecessary attributes, in particuar, CodeAttributes (method bodies) of the class, to minimize the memory footprint. After calling this method, the class is read only. It cannot be modified any more. Furthermore, toBytecode(), writeFile(), toClass(), or instrument() cannot be called. However, the method names and signatures in the class etc. are still accessible.

toBytecode(), writeFile(), and toClass() internally call this method.

public  voidremoveConstructor(CtConstructor c)
     Removes a constructor declared in this class.
public  voidremoveField(CtField f)
     Removes a field declared in this class.
public  voidremoveMethod(CtMethod m)
     Removes a method declared in this class.
public  voidreplaceClassName(String oldName, String newName)
     Substitutes newName for all occurrences of a class name oldName in the class file.
public  voidreplaceClassName(ClassMap map)
     Changes class names appearing in the class file according to the given map.

All the class names appearing in the class file are tested with map to determine whether each class name is replaced or not.

public  voidsetAttribute(String name, byte[] data)
     Adds a named attribute. An arbitrary data (smaller than 64Kb) can be saved in the class file.
public  voidsetInterfaces(CtClass[] list)
     Sets implemented interfaces.
public  voidsetModifiers(int mod)
     Sets the modifiers.

If the class is a nested class, this method also modifies the class declaring that nested class (i.e.

public  voidsetName(String name)
    
public  voidsetSuperclass(CtClass clazz)
     Changes a super class unless this object represents an interface.
public  booleanstopPruning(boolean stop)
     Disallows (or allows) automatically pruning this CtClass object.

Javassist can automatically prune a CtClass object when toBytecode() (or toClass(), writeFile()) is called. Since a ClassPool holds all instances of CtClass even after toBytecode() (or toClass(), writeFile()) is called, pruning may significantly save memory consumption.

If ClassPool.doPruning is true, the automatic pruning is on by default.

public  booleansubclassOf(CtClass superclass)
     Determines whether the class directly or indirectly extends the given class.
public  booleansubtypeOf(CtClass clazz)
     Returns true if this class extends or implements clazz.
public  byte[]toBytecode()
     Converts this class to a class file.
public  voidtoBytecode(DataOutputStream out)
     Converts this class to a class file.
public  ClasstoClass()
     Converts this class to a java.lang.Class object. Once this method is called, further modifications are not allowed any more. To load the class, this method uses the context class loader of the current thread.
public  ClasstoClass(ClassLoader loader, ProtectionDomain domain)
     Converts this class to a java.lang.Class object. Once this method is called, further modifications are not allowed any more.

The class file represented by this CtClass is loaded by the given class loader to construct a java.lang.Class object.

final public  ClasstoClass(ClassLoader loader)
     Converts this class to a java.lang.Class object.
public  StringtoString()
     Converts the object to a string.
public  voidwriteFile()
     Writes a class file represented by this CtClass object in the current directory.
public  voidwriteFile(String directoryName)
     Writes a class file represented by this CtClass object on a local disk.

Field Detail
booleanType
public static CtClass booleanType(Code)
The CtClass object representing the boolean type.



byteType
public static CtClass byteType(Code)
The CtClass object representing the byte type.



charType
public static CtClass charType(Code)
The CtClass object representing the char type.



doubleType
public static CtClass doubleType(Code)
The CtClass object representing the double type.



floatType
public static CtClass floatType(Code)
The CtClass object representing the float type.



intType
public static CtClass intType(Code)
The CtClass object representing the int type.



javaLangObject
final static String javaLangObject(Code)



longType
public static CtClass longType(Code)
The CtClass object representing the long type.



primitiveTypes
static CtClass[] primitiveTypes(Code)



qualifiedName
protected String qualifiedName(Code)



shortType
public static CtClass shortType(Code)
The CtClass object representing the short type.



version
final public static String version(Code)
The version number of this release.



voidType
public static CtClass voidType(Code)
The CtClass object representing the void type.




Constructor Detail
CtClass
protected CtClass(String name)(Code)




Method Detail
addConstructor
public void addConstructor(CtConstructor c) throws CannotCompileException(Code)
Adds a constructor. To add a class initializer (static constructor), call makeClassInitializer().
See Also:   CtClass.makeClassInitializer()



addField
public void addField(CtField f) throws CannotCompileException(Code)
Adds a field.

The CtField belonging to another CtClass cannot be directly added to this class. Only a field created for this class can be added.
See Also:   javassist.CtField.CtField(CtFieldCtClass)




addField
public void addField(CtField f, String init) throws CannotCompileException(Code)
Adds a field with an initial value.

The CtField belonging to another CtClass cannot be directly added to this class. Only a field created for this class can be added.

The initial value is given as an expression written in Java. Any regular Java expression can be used for specifying the initial value. The followings are examples.

     cc.addField(f, "0")               // the initial value is 0.
     cc.addField(f, "i + 1")           // i + 1.
     cc.addField(f, "new Point()");    // a Point object.
     

Here, the type of variable cc is CtClass. The type of f is CtField.
Parameters:
  init - an expression for the initial value.
See Also:   javassist.CtField.Initializer.byExpr(String)
See Also:   javassist.CtField.CtField(CtFieldCtClass)




addField
public void addField(CtField f, CtField.Initializer init) throws CannotCompileException(Code)
Adds a field with an initial value.

The CtField belonging to another CtClass cannot be directly added to this class. Only a field created for this class can be added.

For example,

     CtClass cc = ...;
     addField(new CtField(CtClass.intType, "i", cc),
     CtField.Initializer.constant(1));
     

This code adds an int field named "i". The initial value of this field is 1.
Parameters:
  init - specifies the initial value of the field.
See Also:   javassist.CtField.CtField(CtFieldCtClass)




addInterface
public void addInterface(CtClass anInterface)(Code)
Adds an interface.
Parameters:
  anInterface - the added interface.



addMethod
public void addMethod(CtMethod m) throws CannotCompileException(Code)
Adds a method.



checkModify
void checkModify() throws RuntimeException(Code)



debugWriteFile
public void debugWriteFile()(Code)
Writes a class file as writeFile() does although this method does not prune or freeze the class after writing the class file. Note that, once writeFile() or toBytecode() is called, it cannot be called again since the class is pruned and frozen. This method would be useful for debugging.



defrost
public void defrost()(Code)
Defrosts the class so that the class can be modified again.

To avoid changes that will be never reflected, the class is frozen to be unmodifiable if it is loaded or written out. This method should be called only in a case that the class will be reloaded or written out later again.

If defrost() will be called later, pruning must be disallowed in advance.
See Also:   CtClass.isFrozen()
See Also:   CtClass.stopPruning(boolean)
See Also:   CtClass.detach()




detach
public void detach()(Code)
Removes this CtClass object from the ClassPool. After this method is called, any method cannot be called on the removed CtClass object.

If get() in ClassPool is called with the name of the removed method, the ClassPool will read the class file again and constructs another CtClass object representing the same class.




extendToString
protected void extendToString(StringBuffer buffer)(Code)
Implemented in subclasses to add to the CtClass.toString() result. Subclasses should put a space before each token added to the buffer.



freeze
void freeze()(Code)



getAccessorMaker
public javassist.compiler.AccessorMaker getAccessorMaker()(Code)
Undocumented method. Do not use; internal-use only.



getAnnotations
public Object[] getAnnotations() throws ClassNotFoundException(Code)
Returns the annotations associated with this class. For example, if an annotation @Author is associated with this class, the returned array contains an Author object. The member values can be obtained by calling methods on the Author object. an array of annotation-type objects.
See Also:   CtMember.getAnnotations
since:
   3.1



getAttribute
public byte[] getAttribute(String name)(Code)
Obtains an attribute with the given name. If that attribute is not found in the class file, this method returns null.

This is a convenient method mainly for obtaining a user-defined attribute. For dealing with attributes, see the javassist.bytecode package. For example, the following expression returns all the attributes of a class file.

     getClassFile().getAttributes()
     

Parameters:
  name - attribute name
See Also:   javassist.bytecode.AttributeInfo



getAvailableAnnotations
public Object[] getAvailableAnnotations()(Code)
Returns the annotations associated with this class. This method is equivalent to getAnnotations() except that, if any annotations are not on the classpath, they are not included in the returned array. an array of annotation-type objects.
See Also:   CtClass.getAnnotations()
See Also:   CtMember.getAvailableAnnotations
since:
   3.3



getClassFile
public ClassFile getClassFile()(Code)
Returns a class file for this class.

This method is not available if isFrozen() is true.




getClassFile2
public ClassFile getClassFile2()(Code)
Returns a class file for this class (read only). Normal applications do not need calling this method. Use getClassFile().

The ClassFile object obtained by this method is read only. Changes to this object might not be reflected on a class file generated by toBytecode(), toClass(), etc.

This method is available even if isFrozen() is true. However, if the class is frozen, it might be also pruned.
See Also:   CtClass.getClassFile
See Also:   CtClass.isFrozen
See Also:   CtClass.prune




getClassInitializer
public CtConstructor getClassInitializer()(Code)
Gets the class initializer (static constructor) declared in the class. This method returns null if no class initializer is not declared.
See Also:   CtClass.makeClassInitializer()
See Also:   javassist.CtConstructor



getClassPool
public ClassPool getClassPool()(Code)
Returns a ClassPool for this class.



getComponentType
public CtClass getComponentType() throws NotFoundException(Code)
If this object represents an array, this method returns the component type of the array. Otherwise, it returns null.



getConstructor
public CtConstructor getConstructor(String desc) throws NotFoundException(Code)
Returns the constructor with the given signature, which is represented by a character string called method descriptor. For details of the method descriptor, see the JVM specification or javassist.bytecode.Descriptor.
Parameters:
  desc - method descriptor
See Also:   javassist.bytecode.Descriptor



getConstructors
public CtConstructor[] getConstructors()(Code)
Returns an array containing CtConstructor objects representing all the non-private constructors of the class.



getDeclaredBehaviors
public CtBehavior[] getDeclaredBehaviors()(Code)
Gets all the constructors and methods declared in the class.



getDeclaredConstructor
public CtConstructor getDeclaredConstructor(CtClass[] params) throws NotFoundException(Code)
Returns a constructor receiving the specified parameters.
Parameters:
  params - parameter types.



getDeclaredConstructors
public CtConstructor[] getDeclaredConstructors()(Code)
Gets all the constructors declared in the class.
See Also:   javassist.CtConstructor



getDeclaredField
public CtField getDeclaredField(String name) throws NotFoundException(Code)
Retrieves the field with the specified name among the fields declared in the class.

Note: this method does not search the superclasses.




getDeclaredFields
public CtField[] getDeclaredFields()(Code)
Gets all the fields declared in the class. The inherited fields are not included.

Note: the result does not include inherited fields.




getDeclaredMethod
public CtMethod getDeclaredMethod(String name, CtClass[] params) throws NotFoundException(Code)
Retrieves the method with the specified name and parameter types among the methods declared in the class.

Note: this method does not search the superclasses.
Parameters:
  name - method name
Parameters:
  params - parameter types
See Also:   javassist.CtMethod




getDeclaredMethod
public CtMethod getDeclaredMethod(String name) throws NotFoundException(Code)
Retrieves the method with the specified name among the methods declared in the class. If there are multiple methods with the specified name, then this method returns one of them.

Note: this method does not search the superclasses.
See Also:   javassist.CtMethod




getDeclaredMethods
public CtMethod[] getDeclaredMethods()(Code)
Gets all methods declared in the class. The inherited methods are not included.
See Also:   javassist.CtMethod



getDeclaringClass
public CtClass getDeclaringClass() throws NotFoundException(Code)
If this class is a member class or interface of another class, then the class enclosing this class is returned. null if this class is a top-level class or an anonymous class.



getEnclosingMethod
public CtMethod getEnclosingMethod() throws NotFoundException(Code)
Returns the immediately enclosing method of this class. This method works only with JDK 1.5 or later. null if this class is not a local class or an anonymousclass.



getField
public CtField getField(String name) throws NotFoundException(Code)
Returns the field with the specified name. The returned field may be a private field declared in a super class or interface.



getField2
CtField getField2(String name)(Code)
null if the specified field is not found.



getFields
public CtField[] getFields()(Code)
Returns an array containing CtField objects representing all the non-private fields of the class. That array includes non-private fields inherited from the superclasses.



getInterfaces
public CtClass[] getInterfaces() throws NotFoundException(Code)
Obtains the class objects representing the interfaces implemented by the class or, if this object represents an interface, the interfaces extended by that interface.



getMethod
public CtMethod getMethod(String name, String desc) throws NotFoundException(Code)
Returns the method with the given name and signature. The returned method may be declared in a super class. The method signature is represented by a character string called method descriptor, which is defined in the JVM specification.
Parameters:
  name - method name
Parameters:
  desc - method descriptor
See Also:   CtBehavior.getSignature
See Also:   javassist.bytecode.Descriptor



getMethods
public CtMethod[] getMethods()(Code)
Returns an array containing CtMethod objects representing all the non-private methods of the class. That array includes pon-private methods inherited from the superclasses.



getModifiers
public int getModifiers()(Code)
Returns the modifiers for this class, encoded in an integer. For decoding, use javassist.Modifier.

If the class is a static nested class (a.k.a. static inner class), the returned modifiers include Modifier.STATIC.
See Also:   Modifier




getName
public String getName()(Code)
Obtains the fully-qualified name of the class.



getNestedClasses
public CtClass[] getNestedClasses() throws NotFoundException(Code)
Returns an array of nested classes declared in the class. Nested classes are inner classes, anonymous classes, local classes, and static nested classes.
since:
   3.2



getPackageName
final public String getPackageName()(Code)
Obtains the package name. It may be null.



getRefClasses
public Collection getRefClasses()(Code)
Returns a collection of the names of all the classes referenced in this class. That collection includes the name of this class.

This method may return null.




getSimpleName
final public String getSimpleName()(Code)
Obtains the not-qualified class name.



getSuperclass
public CtClass getSuperclass() throws NotFoundException(Code)
Obtains the class object representing the superclass of the class. It returns null if this object represents the java.lang.Object class and thus it does not have the super class.

If this object represents an interface, this method always returns the java.lang.Object class. To obtain the super interfaces extended by that interface, call getInterfaces().




getURL
public URL getURL() throws NotFoundException(Code)
Returns the uniform resource locator (URL) of the class file.



incGetCounter
void incGetCounter()(Code)



instrument
public void instrument(CodeConverter converter) throws CannotCompileException(Code)
Applies the given converter to all methods and constructors declared in the class. This method calls instrument() on every CtMethod and CtConstructor object in the class.
Parameters:
  converter - specifies how to modify.



instrument
public void instrument(ExprEditor editor) throws CannotCompileException(Code)
Modifies the bodies of all methods and constructors declared in the class. This method calls instrument() on every CtMethod and CtConstructor object in the class.
Parameters:
  editor - specifies how to modify.



isAnnotation
public boolean isAnnotation()(Code)
Determines whether this object represents an annotation type. It returns true if this object represents an annotation type.
since:
   3.2



isArray
public boolean isArray()(Code)
Returns true if this object represents an array type.



isEnum
public boolean isEnum()(Code)
Determines whether this object represents an enum. It returns true if this object represents an enum.
since:
   3.2



isFrozen
public boolean isFrozen()(Code)
Returns true if the class has been loaded or written out and thus it cannot be modified any more.
See Also:   CtClass.defrost()
See Also:   CtClass.detach()



isInterface
public boolean isInterface()(Code)
Determines whether this object represents a class or an interface. It returns true if this object represents an interface.



isModified
public boolean isModified()(Code)
Returns true if the definition of the class has been modified.



isPrimitive
public boolean isPrimitive()(Code)
Returns true if this object represents a primitive Java type: boolean, byte, char, short, int, long, float, double, or void.



main
public static void main(String[] args)(Code)
Prints the version number and the copyright notice.

The following command invokes this method:

    java -jar javassist.jar



makeClassInitializer
public CtConstructor makeClassInitializer() throws CannotCompileException(Code)
Makes an empty class initializer (static constructor). If the class already includes a class initializer, this method returns it.
See Also:   CtClass.getClassInitializer()



makeNestedClass
public CtClass makeNestedClass(String name, boolean isStatic)(Code)
Makes a new public nested class. If this method is called, the CtClass, which encloses the nested class, is modified since a class file includes a list of nested classes.

The current implementation only supports a static nested class. isStatic must be true.
Parameters:
  name - the simple name of the nested class.
Parameters:
  isStatic - true if the nested class is static.




makeUniqueName
public String makeUniqueName(String prefix)(Code)
Makes a unique member name. This method guarantees that the returned name is not used as a prefix of any methods or fields visible in this class. If the returned name is XYZ, then any method or field names in this class do not start with XYZ.
Parameters:
  prefix - the prefix of the member name.



prune
public void prune()(Code)
Discards unnecessary attributes, in particuar, CodeAttributes (method bodies) of the class, to minimize the memory footprint. After calling this method, the class is read only. It cannot be modified any more. Furthermore, toBytecode(), writeFile(), toClass(), or instrument() cannot be called. However, the method names and signatures in the class etc. are still accessible.

toBytecode(), writeFile(), and toClass() internally call this method.
See Also:   CtClass.toBytecode()
See Also:   CtClass.toClass()
See Also:   CtClass.writeFile()
See Also:   CtClass.instrument(CodeConverter)
See Also:   CtClass.instrument(ExprEditor)
See Also:   CtClass.stopPruning(boolean)




removeConstructor
public void removeConstructor(CtConstructor c) throws NotFoundException(Code)
Removes a constructor declared in this class.
Parameters:
  c - removed constructor.
throws:
  NotFoundException - if the constructor is not found.



removeField
public void removeField(CtField f) throws NotFoundException(Code)
Removes a field declared in this class.
Parameters:
  f - removed field.
throws:
  NotFoundException - if the field is not found.



removeMethod
public void removeMethod(CtMethod m) throws NotFoundException(Code)
Removes a method declared in this class.
Parameters:
  m - removed method.
throws:
  NotFoundException - if the method is not found.



replaceClassName
public void replaceClassName(String oldName, String newName)(Code)
Substitutes newName for all occurrences of a class name oldName in the class file.
Parameters:
  oldName - replaced class name
Parameters:
  newName - substituted class name



replaceClassName
public void replaceClassName(ClassMap map)(Code)
Changes class names appearing in the class file according to the given map.

All the class names appearing in the class file are tested with map to determine whether each class name is replaced or not. Thus this method can be used for collecting all the class names in the class file. To do that, first define a subclass of ClassMap so that get() records all the given parameters. Then, make an instance of that subclass as an empty hash-table. Finally, pass that instance to this method. After this method finishes, that instance would contain all the class names appearing in the class file.
Parameters:
  map - the hashtable associating replaced class nameswith substituted names.




setAttribute
public void setAttribute(String name, byte[] data)(Code)
Adds a named attribute. An arbitrary data (smaller than 64Kb) can be saved in the class file. Some attribute name are reserved by the JVM. The attributes with the non-reserved names are ignored when a class file is loaded into the JVM. If there is already an attribute with the same name, this method substitutes the new one for it.

This is a convenient method mainly for adding a user-defined attribute. For dealing with attributes, see the javassist.bytecode package. For example, the following expression adds an attribute info to a class file.

     getClassFile().addAttribute(info)
     

Parameters:
  name - attribute name
Parameters:
  data - attribute value
See Also:   javassist.bytecode.AttributeInfo



setInterfaces
public void setInterfaces(CtClass[] list)(Code)
Sets implemented interfaces. If this object represents an interface, this method sets the interfaces extended by that interface.
Parameters:
  list - a list of the CtClass objectsrepresenting interfaces, ornull if the class implementsno interfaces.



setModifiers
public void setModifiers(int mod)(Code)
Sets the modifiers.

If the class is a nested class, this method also modifies the class declaring that nested class (i.e. the enclosing class is modified).
Parameters:
  mod - modifiers encoded byjavassist.Modifier
See Also:   Modifier




setName
public void setName(String name)(Code)
Sets the class name
Parameters:
  name - fully-qualified name



setSuperclass
public void setSuperclass(CtClass clazz) throws CannotCompileException(Code)
Changes a super class unless this object represents an interface. The new super class must be compatible with the old one.

If this object represents an interface, this method is equivalent to addInterface(); it appends clazz to the list of the super interfaces extended by that interface. Note that an interface can extend multiple super interfaces.




stopPruning
public boolean stopPruning(boolean stop)(Code)
Disallows (or allows) automatically pruning this CtClass object.

Javassist can automatically prune a CtClass object when toBytecode() (or toClass(), writeFile()) is called. Since a ClassPool holds all instances of CtClass even after toBytecode() (or toClass(), writeFile()) is called, pruning may significantly save memory consumption.

If ClassPool.doPruning is true, the automatic pruning is on by default. Otherwise, it is off.
Parameters:
  stop - disallow pruning if true. Otherwise, allow. the previous status of pruning. true if pruning is already stopped.
See Also:   CtClass.detach()
See Also:   CtClass.prune()
See Also:   ClassPool.doPruning




subclassOf
public boolean subclassOf(CtClass superclass)(Code)
Determines whether the class directly or indirectly extends the given class. If this class extends a class A and the class A extends a class B, then subclassof(B) returns true.

This method returns true if the given class is identical to the class represented by this object.




subtypeOf
public boolean subtypeOf(CtClass clazz) throws NotFoundException(Code)
Returns true if this class extends or implements clazz. It also returns true if this class is the same as clazz.



toBytecode
public byte[] toBytecode() throws IOException, CannotCompileException(Code)
Converts this class to a class file. Once this method is called, further modifications are not possible any more. the contents of the class file.



toBytecode
public void toBytecode(DataOutputStream out) throws CannotCompileException, IOException(Code)
Converts this class to a class file. Once this method is called, further modifications are not possible any more.

This method dose not close the output stream in the end.
Parameters:
  out - the output stream that a class file is written to.




toClass
public Class toClass() throws CannotCompileException(Code)
Converts this class to a java.lang.Class object. Once this method is called, further modifications are not allowed any more. To load the class, this method uses the context class loader of the current thread. If the program is running on some application server, the context class loader might be inappropriate to load the class.

This method is provided for convenience. If you need more complex functionality, you should write your own class loader.

Note: this method calls toClass() in ClassPool.

Warining: A Class object returned by this method may not work with a security manager or a signed jar file because a protection domain is not specified.
See Also:   CtClass.toClass(java.lang.ClassLoader,ProtectionDomain)
See Also:   ClassPool.toClass(CtClass)




toClass
public Class toClass(ClassLoader loader, ProtectionDomain domain) throws CannotCompileException(Code)
Converts this class to a java.lang.Class object. Once this method is called, further modifications are not allowed any more.

The class file represented by this CtClass is loaded by the given class loader to construct a java.lang.Class object. Since a private method on the class loader is invoked through the reflection API, the caller must have permissions to do that.

An easy way to obtain ProtectionDomain object is to call getProtectionDomain() in java.lang.Class. It returns the domain that the class belongs to.

This method is provided for convenience. If you need more complex functionality, you should write your own class loader.

Note: this method calls toClass() in ClassPool.
Parameters:
  loader - the class loader used to load this class.If it is null, the class loader returned byClassPool.getClassLoader is used.
Parameters:
  domain - the protection domain that the class belongs to.If it is null, the default domain createdby java.lang.ClassLoader is used.
See Also:   ClassPool.toClass(CtClassjava.lang.ClassLoader)
since:
   3.3




toClass
final public Class toClass(ClassLoader loader) throws CannotCompileException(Code)
Converts this class to a java.lang.Class object.

Warining: A Class object returned by this method may not work with a security manager or a signed jar file because a protection domain is not specified. CtClass.toClass(ClassLoader,ProtectionDomain)




toString
public String toString()(Code)
Converts the object to a string.



writeFile
public void writeFile() throws NotFoundException, IOException, CannotCompileException(Code)
Writes a class file represented by this CtClass object in the current directory. Once this method is called, further modifications are not possible any more.



writeFile
public void writeFile(String directoryName) throws CannotCompileException, IOException(Code)
Writes a class file represented by this CtClass object on a local disk. Once this method is called, further modifications are not possible any more.
Parameters:
  directoryName - it must end without a directory separator.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.