Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/apache/derby/iapi/services/compiler/ClassBuilder.java


1   /*
2   
3      Derby - Class org.apache.derby.iapi.services.compiler.ClassBuilder
4   
5      Copyright 1997, 2004 The Apache Software Foundation or its licensors, as applicable.
6   
7      Licensed under the Apache License, Version 2.0 (the "License");
8      you may not use this file except in compliance with the License.
9      You may obtain a copy of the License at
10  
11        http://www.apache.org/licenses/LICENSE-2.0
12  
13     Unless required by applicable law or agreed to in writing, software
14     distributed under the License is distributed on an "AS IS" BASIS,
15     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16     See the License for the specific language governing permissions and
17     limitations under the License.
18  
19   */
20  
21  package org.apache.derby.iapi.services.compiler;
22  
23  import org.apache.derby.iapi.services.loader.GeneratedClass;
24  import org.apache.derby.iapi.error.StandardException;
25  import org.apache.derby.iapi.util.ByteArray;
26  
27  /**
28   * ClassBuilder is used to construct a java class's byte array
29   * representation.
30   *
31   * Limitations:
32   *   No checking for language use violations such as invalid modifiers
33   *  or duplicate field names.
34   *   All classes must have a superclass; java.lang.Object must be
35   *      supplied if there is no superclass.
36   *
37   * <p>
38   * When a class is first created, it has:
39   * <ul>
40   * <li> a superclass
41   * <li> modifiers
42   * <li> a name
43   * <li> a package
44   * <li> no superinterfaces, methods, fields, or constructors
45   * <li> an empty static initializer
46   * </ul>
47   * <p>
48   * MethodBuilder implementations are required to get code out of the
49   * constructs within their bodies in some manner. 
50   * Most typically, they may have a stream to which the statement and 
51   * expression constructs write the code that they represent,
52   * and they walk over the statements and expressions in the appropriate order.
53   *
54   * @author ames
55   */
56  public interface ClassBuilder {
57  
58    /**
59     * add a field to this class. Fields cannot
60     * be initialized here, they must be initialized
61     * in the static initializer code (static fields)
62     * or in the constructors.
63     * <p>
64     * Methods are added when they are created with the JavaFactory.
65     * @param type  The type of the field in java language.
66     * @param name  The name of the field.
67     * @param modifiers  The | of the modifier values such as
68     *          public, static, etc.
69     * @see ClassBuilder#newMethodBuilder
70     * @see #newConstructorBuilder
71     */
72    LocalField addField(String type, String name, int modifiers);
73  
74    /**
75      Fully create the bytecode and load the
76      class using the ClassBuilder's ClassFactory.
77  
78      @exception StandardException Standard Cloudscape policy
79    */
80    GeneratedClass getGeneratedClass() throws StandardException;
81  
82    /**
83     * At the time the class is completed and bytecode
84     * generated, if there are no constructors then
85     * the default no-arg constructor will be defined.
86     */
87    ByteArray getClassBytecode() throws StandardException;
88  
89    /**
90     * the class's unqualified name
91     */
92    String getName();
93  
94    /**
95     * the class's qualified name
96     */
97    String getFullName();
98  
99    /**
100    * a method. Once it is created, parameters, thrown
101    * exceptions, statements, and local variable declarations
102    * must be added to it. It is put into its defining class
103    * when it is created.
104    * <verbatim>
105      Java: #modifiers #returnType #methodName() {}
106         // modifiers is the | of the JVM constants for
107         // the modifiers such as static, public, etc.
108        </verbatim>
109      <p>
110    * This is used to start a constructor as well; pass in
111    * null for the returnType when used in that manner.
112    *
113    * @param modifiers the | of the Modifier
114    *  constants representing the visibility and control of this
115    *  method.
116    * @param returnType the return type of the method as its
117    *  Java language type name.
118    * @param methodName the name of the method.
119    *
120    * @return the method builder.
121    * @see java.lang.reflect.Modifier
122    */
123   MethodBuilder newMethodBuilder(int modifiers, String returnType,
124     String methodName);
125   
126   /**
127    * a method with parameters. Once it is created, thrown
128    * exceptions, statements, and local variable declarations
129    * must be added to it. It is put into its defining class
130    * when it is created.
131    * <verbatim>
132      Java: #modifiers #returnType #methodName() {}
133         // modifiers is the | of the JVM constants for
134         // the modifiers such as static, public, etc.
135        </verbatim>
136      <p>
137    * This is used to start a constructor as well; pass in
138    * null for the returnType when used in that manner.
139    *
140    * @param modifiers the | of the Modifier
141    *  constants representing the visibility and control of this
142    *  method.
143    * @param returnType the return type of the method as its
144    *  Java language type name.
145    * @param methodName the name of the method.
146    * @param parms  an array of String representing the
147    *        method's parameter types
148    *
149    * @return the method builder.
150    * @see java.lang.reflect.Modifier
151    */
152   MethodBuilder newMethodBuilder(int modifiers, String returnType,
153     String methodName, String[] parms);
154 
155   /**
156    * a constructor. Once it is created, parameters, thrown
157    * exceptions, statements, and local variable declarations
158    * must be added to it. It is put into its defining class
159    * when it is created.
160    * <verbatim>
161      Java: #modifiers #className() {}
162         // modifiers is the | of the JVM constants for
163         // the modifiers such as static, public, etc.
164         // className is taken from definingClass.name()
165        </verbatim>
166    * <p>
167    * This is used to start a constructor as well; pass in
168    * null for the returnType when used in that manner.
169    *
170    * @param modifiers the | of the Modifier
171    *  constants representing the visibility and control of this
172    *  method.
173    *
174    * @return the method builder for the constructor.
175    * @see java.lang.reflect.Modifier
176    */
177   MethodBuilder newConstructorBuilder(int modifiers);
178 
179   /**
180     Create a new private field and its getter and setter methods.
181 
182     @param name basename for the methods, methods will have 'set' or 'get' prepended.
183     @param methodModifier modifier for method
184     @param boolean staticField true if the field is static
185     @param type type of the field, return type of the get method and
186     parameter type of the set method.
187 
188   */
189   void newFieldWithAccessors(String getter, String setter, int methodModifer,
190     boolean staticField, String type);
191 }