001: /*
002:
003: Derby - Class org.apache.derby.iapi.services.compiler.ClassBuilder
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.iapi.services.compiler;
023:
024: import org.apache.derby.iapi.services.loader.GeneratedClass;
025: import org.apache.derby.iapi.error.StandardException;
026: import org.apache.derby.iapi.util.ByteArray;
027:
028: /**
029: * ClassBuilder is used to construct a java class's byte array
030: * representation.
031: *
032: * Limitations:
033: * No checking for language use violations such as invalid modifiers
034: * or duplicate field names.
035: * All classes must have a superclass; java.lang.Object must be
036: * supplied if there is no superclass.
037: *
038: * <p>
039: * When a class is first created, it has:
040: * <ul>
041: * <li> a superclass
042: * <li> modifiers
043: * <li> a name
044: * <li> a package
045: * <li> no superinterfaces, methods, fields, or constructors
046: * <li> an empty static initializer
047: * </ul>
048: * <p>
049: * MethodBuilder implementations are required to get code out of the
050: * constructs within their bodies in some manner.
051: * Most typically, they may have a stream to which the statement and
052: * expression constructs write the code that they represent,
053: * and they walk over the statements and expressions in the appropriate order.
054: *
055: * @author ames
056: */
057: public interface ClassBuilder {
058:
059: /**
060: * add a field to this class. Fields cannot
061: * be initialized here, they must be initialized
062: * in the static initializer code (static fields)
063: * or in the constructors.
064: * <p>
065: * Methods are added when they are created with the JavaFactory.
066: * @param type The type of the field in java language.
067: * @param name The name of the field.
068: * @param modifiers The | of the modifier values such as
069: * public, static, etc.
070: * @see ClassBuilder#newMethodBuilder
071: * @see #newConstructorBuilder
072: */
073: LocalField addField(String type, String name, int modifiers);
074:
075: /**
076: Fully create the bytecode and load the
077: class using the ClassBuilder's ClassFactory.
078:
079: @exception StandardException Standard Cloudscape policy
080: */
081: GeneratedClass getGeneratedClass() throws StandardException;
082:
083: /**
084: * At the time the class is completed and bytecode
085: * generated, if there are no constructors then
086: * the default no-arg constructor will be defined.
087: */
088: ByteArray getClassBytecode() throws StandardException;
089:
090: /**
091: * the class's unqualified name
092: */
093: String getName();
094:
095: /**
096: * the class's qualified name
097: */
098: String getFullName();
099:
100: /**
101: * a method. Once it is created, parameters, thrown
102: * exceptions, statements, and local variable declarations
103: * must be added to it. It is put into its defining class
104: * when it is created.
105: * <verbatim>
106: Java: #modifiers #returnType #methodName() {}
107: // modifiers is the | of the JVM constants for
108: // the modifiers such as static, public, etc.
109: </verbatim>
110: <p>
111: * This is used to start a constructor as well; pass in
112: * null for the returnType when used in that manner.
113: *
114: * @param modifiers the | of the Modifier
115: * constants representing the visibility and control of this
116: * method.
117: * @param returnType the return type of the method as its
118: * Java language type name.
119: * @param methodName the name of the method.
120: *
121: * @return the method builder.
122: * @see java.lang.reflect.Modifier
123: */
124: MethodBuilder newMethodBuilder(int modifiers, String returnType,
125: String methodName);
126:
127: /**
128: * a method with parameters. Once it is created, thrown
129: * exceptions, statements, and local variable declarations
130: * must be added to it. It is put into its defining class
131: * when it is created.
132: * <verbatim>
133: Java: #modifiers #returnType #methodName() {}
134: // modifiers is the | of the JVM constants for
135: // the modifiers such as static, public, etc.
136: </verbatim>
137: <p>
138: * This is used to start a constructor as well; pass in
139: * null for the returnType when used in that manner.
140: *
141: * @param modifiers the | of the Modifier
142: * constants representing the visibility and control of this
143: * method.
144: * @param returnType the return type of the method as its
145: * Java language type name.
146: * @param methodName the name of the method.
147: * @param parms an array of String representing the
148: * method's parameter types
149: *
150: * @return the method builder.
151: * @see java.lang.reflect.Modifier
152: */
153: MethodBuilder newMethodBuilder(int modifiers, String returnType,
154: String methodName, String[] parms);
155:
156: /**
157: * a constructor. Once it is created, parameters, thrown
158: * exceptions, statements, and local variable declarations
159: * must be added to it. It is put into its defining class
160: * when it is created.
161: * <verbatim>
162: Java: #modifiers #className() {}
163: // modifiers is the | of the JVM constants for
164: // the modifiers such as static, public, etc.
165: // className is taken from definingClass.name()
166: </verbatim>
167: * <p>
168: * This is used to start a constructor as well; pass in
169: * null for the returnType when used in that manner.
170: *
171: * @param modifiers the | of the Modifier
172: * constants representing the visibility and control of this
173: * method.
174: *
175: * @return the method builder for the constructor.
176: * @see java.lang.reflect.Modifier
177: */
178: MethodBuilder newConstructorBuilder(int modifiers);
179:
180: /**
181: Create a new private field and its getter and setter methods.
182:
183: @param getter getter for field
184: @param setter setter for field
185: @param methodModifier modifier for method
186: @param staticField true if the field is static
187: @param type type of the field, return type of the get method and
188: parameter type of the set method.
189:
190: */
191: void newFieldWithAccessors(String getter, String setter,
192: int methodModifier, boolean staticField, String type);
193: }
|