|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ClassFab.java | - | - | - | - |
|
1 |
// Copyright 2004, 2005 The Apache Software Foundation
|
|
2 |
//
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
5 |
// You may obtain a copy of the License at
|
|
6 |
//
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8 |
//
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12 |
// See the License for the specific language governing permissions and
|
|
13 |
// limitations under the License.
|
|
14 |
|
|
15 |
package org.apache.hivemind.service;
|
|
16 |
|
|
17 |
/**
|
|
18 |
* Used when fabricating a new class. Represents a wrapper around
|
|
19 |
* the Javassist library.
|
|
20 |
*
|
|
21 |
* <p>
|
|
22 |
* The core concept of Javassist is how method bodies (as well as constructor bodies, etc.)
|
|
23 |
* are specified ... as a very Java-like scripting language. The
|
|
24 |
* {@link org.apache.hivemind.service.BodyBuilder} class is <em>very</em> useful for assembling
|
|
25 |
* this method bodies. Details are available at the
|
|
26 |
* <a href="http://jboss.org/products/javassist">Javassist home page</a>.
|
|
27 |
*
|
|
28 |
* <p>
|
|
29 |
* Method bodies look largely like Java. References to java classes must be fully qualified.
|
|
30 |
* Several special variables are used:
|
|
31 |
* <ul>
|
|
32 |
* <li><code>$0</code> first parameter, equivalent to <code>this</code> in Java code (and can't
|
|
33 |
* be used when creating a static method)
|
|
34 |
* <li><code>$1, $2, ...</code> actual parameters to the method
|
|
35 |
* <li><code>$args</code> all the parameters as an <code>Object[]</code>
|
|
36 |
* <li><code>$r</code> the return type of the method, typically used as <code>return ($r) ...</code>.
|
|
37 |
* <code>$r</code> is valid with method that return <code>void</code>. This also handles conversions
|
|
38 |
* between wrapper types and primitive types.
|
|
39 |
* <li><code>$w</code> conversion from primitive type to wrapper type, used as <code>($w) foo()</code> where
|
|
40 |
* <code>foo()</code> returns a primitive type and a wrapper type is needed
|
|
41 |
* <li>
|
|
42 |
* </ul>
|
|
43 |
*
|
|
44 |
* @author Howard Lewis Ship
|
|
45 |
*/
|
|
46 |
public interface ClassFab |
|
47 |
{ |
|
48 |
/**
|
|
49 |
* Adds the specified interface as an interface implemented by this class.
|
|
50 |
*/
|
|
51 |
public void addInterface(Class interfaceClass); |
|
52 |
|
|
53 |
/**
|
|
54 |
* Adds a new field with the given name and type. The field is
|
|
55 |
* added as a private field.
|
|
56 |
*/
|
|
57 |
|
|
58 |
public void addField(String name, Class type); |
|
59 |
|
|
60 |
/**
|
|
61 |
* Adds a method. The method is a public instance method.
|
|
62 |
* @return a method fabricator, used to add catch handlers.
|
|
63 |
* @param modifiers Modifiers for the method (see {@link java.lang.reflect.Modifier}).
|
|
64 |
* @param signature defines the name, return type, parameters and exceptions thrown
|
|
65 |
* @param body The body of the method.
|
|
66 |
* @throws ApplicationRuntimeException if a method with that signature has already
|
|
67 |
* been added, or if there is a Javassist compilation error
|
|
68 |
*/
|
|
69 |
|
|
70 |
public MethodFab addMethod(int modifiers, MethodSignature signature, String body); |
|
71 |
|
|
72 |
/**
|
|
73 |
* Returns a previous defined method so that it can be further enhanced
|
|
74 |
* (perhaps by adding additional catches, etc.).
|
|
75 |
*
|
|
76 |
* @param signature the signature of the method previously added
|
|
77 |
* @return the MethodFab for that method, or null if the method has not been added yet
|
|
78 |
*/
|
|
79 |
|
|
80 |
public MethodFab getMethodFab(MethodSignature signature);
|
|
81 |
|
|
82 |
/**
|
|
83 |
* Adds a constructor to the class. The constructor will be public.
|
|
84 |
* @param parameterTypes the type of each parameter, or null if the constructor takes no parameters.
|
|
85 |
* @param exceptions the type of each exception, or null if the constructor throws no exceptions.
|
|
86 |
* @param body The body of the constructor.
|
|
87 |
*/
|
|
88 |
public void addConstructor(Class[] parameterTypes, Class[] exceptions, String body); |
|
89 |
|
|
90 |
/**
|
|
91 |
* Invoked last to create the class. This will enforce that
|
|
92 |
* all abstract methods have been implemented in the (concrete) class.
|
|
93 |
*/
|
|
94 |
public Class createClass();
|
|
95 |
} |
|
96 |
|
|