Java Doc for CtNewMethod.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.CtNewMethod

CtNewMethod
public class CtNewMethod (Code)
A collection of static methods for creating a CtMethod. An instance of this class does not make any sense.
See Also:   CtClass.addMethod(CtMethod)




Method Summary
public static  CtMethodabstractMethod(CtClass returnType, String mname, CtClass[] parameters, CtClass[] exceptions, CtClass declaring)
     Creates a public abstract method.
public static  CtMethodcopy(CtMethod src, CtClass declaring, ClassMap map)
     Creates a copy of a method.
public static  CtMethodcopy(CtMethod src, String name, CtClass declaring, ClassMap map)
     Creates a copy of a method with a new name.
public static  CtMethoddelegator(CtMethod delegate, CtClass declaring)
     Creates a method forwarding to a delegate in a super class.
public static  CtMethodgetter(String methodName, CtField field)
     Creates a public getter method.
public static  CtMethodmake(String src, CtClass declaring)
     Compiles the given source code and creates a method. The source code must include not only the method body but the whole declaration, for example,
    "public Object id(Object obj) { return obj; }"

Parameters:
  src - the source text.
public static  CtMethodmake(String src, CtClass declaring, String delegateObj, String delegateMethod)
     Compiles the given source code and creates a method. The source code must include not only the method body but the whole declaration, for example,
    "public Object id(Object obj) { return obj; }"

If the source code includes $proceed(), then it is compiled into a method call on the specified object.
Parameters:
  src - the source text.

public static  CtMethodmake(CtClass returnType, String mname, CtClass[] parameters, CtClass[] exceptions, String body, CtClass declaring)
     Creates a public (non-static) method.
public static  CtMethodmake(int modifiers, CtClass returnType, String mname, CtClass[] parameters, CtClass[] exceptions, String body, CtClass declaring)
     Creates a method.
public static  CtMethodsetter(String methodName, CtField field)
     Creates a public setter method.
public static  CtMethodwrapped(CtClass returnType, String mname, CtClass[] parameterTypes, CtClass[] exceptionTypes, CtMethod body, ConstParameter constParam, CtClass declaring)
     Creates a wrapped method.



Method Detail
abstractMethod
public static CtMethod abstractMethod(CtClass returnType, String mname, CtClass[] parameters, CtClass[] exceptions, CtClass declaring) throws NotFoundException(Code)
Creates a public abstract method.
Parameters:
  returnType - the type of the returned value
Parameters:
  mname - the method name
Parameters:
  parameters - a list of the parameter types
Parameters:
  exceptions - a list of the exception types
Parameters:
  declaring - the class to which the created method is added.
See Also:   CtMethod.CtMethod(CtClassStringCtClass[]CtClass)



copy
public static CtMethod copy(CtMethod src, CtClass declaring, ClassMap map) throws CannotCompileException(Code)
Creates a copy of a method. This method is provided for creating a new method based on an existing method.
Parameters:
  src - the source method.
Parameters:
  declaring - the class to which the created method is added.
Parameters:
  map - the hashtable associating original class nameswith substituted names.It can be null.
See Also:   CtMethod.CtMethod(CtMethodCtClassClassMap)



copy
public static CtMethod copy(CtMethod src, String name, CtClass declaring, ClassMap map) throws CannotCompileException(Code)
Creates a copy of a method with a new name. This method is provided for creating a new method based on an existing method.
Parameters:
  src - the source method.
Parameters:
  name - the name of the created method.
Parameters:
  declaring - the class to which the created method is added.
Parameters:
  map - the hashtable associating original class nameswith substituted names.It can be null.
See Also:   CtMethod.CtMethod(CtMethodCtClassClassMap)



delegator
public static CtMethod delegator(CtMethod delegate, CtClass declaring) throws CannotCompileException(Code)
Creates a method forwarding to a delegate in a super class. The created method calls a method specified by delegate with all the parameters passed to the created method. If the delegate method returns a value, the created method returns that value to the caller. The delegate method must be declared in a super class.

The following method is an example of the created method.

    int f(int p, int q) {
     return super.f(p, q);
     }

The name of the created method can be changed by setName().
Parameters:
  delegate - the method that the created method forwards to.
Parameters:
  declaring - the class to which the created method isadded.




getter
public static CtMethod getter(String methodName, CtField field) throws CannotCompileException(Code)
Creates a public getter method. The getter method returns the value of the specified field in the class to which this method is added. The created method is initially not static even if the field is static. Change the modifiers if the method should be static.
Parameters:
  methodName - the name of the getter
Parameters:
  field - the field accessed.



make
public static CtMethod make(String src, CtClass declaring) throws CannotCompileException(Code)
Compiles the given source code and creates a method. The source code must include not only the method body but the whole declaration, for example,
    "public Object id(Object obj) { return obj; }"

Parameters:
  src - the source text.
Parameters:
  declaring - the class to which the created method is added.



make
public static CtMethod make(String src, CtClass declaring, String delegateObj, String delegateMethod) throws CannotCompileException(Code)
Compiles the given source code and creates a method. The source code must include not only the method body but the whole declaration, for example,
    "public Object id(Object obj) { return obj; }"

If the source code includes $proceed(), then it is compiled into a method call on the specified object.
Parameters:
  src - the source text.
Parameters:
  declaring - the class to which the created method is added.
Parameters:
  delegateObj - the source text specifying the objectthat is called on by $proceed().
Parameters:
  delegateMethod - the name of the methodthat is called by $proceed().




make
public static CtMethod make(CtClass returnType, String mname, CtClass[] parameters, CtClass[] exceptions, String body, CtClass declaring) throws CannotCompileException(Code)
Creates a public (non-static) method. The created method cannot be changed to a static method later.
Parameters:
  returnType - the type of the returned value.
Parameters:
  mname - the method name.
Parameters:
  parameters - a list of the parameter types.
Parameters:
  exceptions - a list of the exception types.
Parameters:
  body - the source text of the method body.It must be a block surrounded by {}.If it is null, the created methoddoes nothing except returning zero or null.
Parameters:
  declaring - the class to which the created method is added.



make
public static CtMethod make(int modifiers, CtClass returnType, String mname, CtClass[] parameters, CtClass[] exceptions, String body, CtClass declaring) throws CannotCompileException(Code)
Creates a method.
Parameters:
  modifiers - access modifiers.
Parameters:
  returnType - the type of the returned value.
Parameters:
  mname - the method name.
Parameters:
  parameters - a list of the parameter types.
Parameters:
  exceptions - a list of the exception types.
Parameters:
  body - the source text of the method body.It must be a block surrounded by {}.If it is null, the created methoddoes nothing except returning zero or null.
Parameters:
  declaring - the class to which the created method is added.
See Also:   Modifier



setter
public static CtMethod setter(String methodName, CtField field) throws CannotCompileException(Code)
Creates a public setter method. The setter method assigns the value of the first parameter to the specified field in the class to which this method is added. The created method is not static even if the field is static. You may not change it to be static by setModifiers() in CtBehavior.
Parameters:
  methodName - the name of the setter
Parameters:
  field - the field accessed.



wrapped
public static CtMethod wrapped(CtClass returnType, String mname, CtClass[] parameterTypes, CtClass[] exceptionTypes, CtMethod body, ConstParameter constParam, CtClass declaring) throws CannotCompileException(Code)
Creates a wrapped method. The wrapped method receives parameters in the form of an array of Object.

The body of the created method is a copy of the body of a method specified by body. However, it is wrapped in parameter-conversion code.

The method specified by body must have this singature:

    Object method(Object[] params, <type> cvalue)

The type of the cvalue depends on constParam. If constParam is null, the signature must be:

    Object method(Object[] params)

The method body copied from body is wrapped in parameter-conversion code, which converts parameters specified by parameterTypes into an array of Object. The returned value is also converted from the Object type to the type specified by returnType. Thus, the resulting method body is as follows:

    Object[] params = new Object[] { p0, p1, ... };
     <type> cvalue = <constant-value>;
     ... copied method body ...
     Object result = <returned value>
     return (<returnType>)result;
     

The variables p0, p2, ... represent formal parameters of the created method. The value of cvalue is specified by constParam.

If the type of a parameter or a returned value is a primitive type, then the value is converted into a wrapper object such as java.lang.Integer. If the type of the returned value is void, the returned value is discarded.

Example:

    ClassPool pool = ... ;
     CtClass vec = pool.makeClass("intVector");
     vec.setSuperclass(pool.get("java.util.Vector"));
     CtMethod addMethod = pool.getMethod("Sample", "add0");
     CtClass[] argTypes = { CtClass.intType };
     CtMethod m = CtNewMethod.wrapped(CtClass.voidType, "add", argTypes,
     null, addMethod, null, vec);
     vec.addMethod(m);

where the class Sample is as follows:

    public class Sample extends java.util.Vector {
     public Object add0(Object[] args) {
     super.addElement(args[0]);
     return null;
     }
     }

This program produces a class intVector:

    public class intVector extends java.util.Vector {
     public void add(int p0) {
     Object[] args = new Object[] { p0 };
     // begin of copied body
     super.addElement(args[0]);
     Object result = null;
     // end
     }
     }

Note that the type of the parameter to add() depends only on the value of argTypes passed to CtNewMethod.wrapped(). Thus, it is easy to modify this program to produce a StringVector class, which is a vector containing only String objects, and other vector classes.
Parameters:
  returnType - the type of the returned value.
Parameters:
  mname - the method name.
Parameters:
  parameterTypes - a list of the parameter types.
Parameters:
  exceptionTypes - a list of the exception types.
Parameters:
  body - the method body(must not be a static method).
Parameters:
  constParam - the constant parameter(maybe null).
Parameters:
  declaring - the class to which the created method isadded.




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.