Java Reference
In-Depth Information
MethodDescriptor ::=
(
fParameterDescriptorg
)
ReturnDescriptor
ParameterDescriptor ::= FieldType
ReturnDescriptor ::= FieldType j
V
For example, the table below indicates the method descriptors for various constructor
and method declarations:
Constructor/Method
Descriptor
publicQueue() ()V
publicFile[]listFiles() ()[Ljava/io/File;
publicBooleanisPrime(intn) (I)Ljava/lang/Boolean;
publicstaticvoidmain(String[]args)([L/java/lang/String;)V
D.4
CLEmitter
D.4.1
CLEmitter
Operation
The j-- compiler's purpose is to produce a class le. Given the complexity of class les we
supply a tool called the
CLEmitter
to ease the generation of code and the creation of class
files. The
CLEmitter
6
has a relatively small set of methods that support
The creation of a class or an interface;
The addition of fields and methods to the class;
The addition of instructions, exception handlers, and code attributes to methods;
The addition of inner classes;
Optional field, method, and class attributes;
Checking for errors; and
The writing of the class file to the file system.
While it is much simpler to work with an interface like
CLEmitter
, one still must be
aware of certain aspects of the target machine, such as the instruction set.
Figure D.3 outlines the necessary steps for creating an in-memory representation of a
class file using the
CLEmitter
interface, and then writing that class file to the file system.
6
This is a class in the
jminusminus
package under
$j/j--/src
folder. The classes that
CLEmitter
depends on are also in that package and have a
CL
prex.
Search WWH ::
Custom Search