edu.rit.classfile
Class SynthesizedClassDescription

java.lang.Object
  extended by edu.rit.classfile.TypeReference
      extended by edu.rit.classfile.ArrayOrClassReference
          extended by edu.rit.classfile.ClassReference
              extended by edu.rit.classfile.ClassDescription
                  extended by edu.rit.classfile.SynthesizedClassOrInterfaceDescription
                      extended by edu.rit.classfile.SynthesizedClassDescription

public class SynthesizedClassDescription
extends SynthesizedClassOrInterfaceDescription

Class SynthesizedClassDescription is used to synthesize a class description for some actual class. This lets a program synthesize a class directly, instead of having to generate Java source and run the Java compiler. To synthesize a class:

  1. Create an instance of class SynthesizedClassDescription, specifying the class name and the superclass.

  2. Modify the class's access flags (public, final, abstract) if necessary. See these methods: setPublic(), setRegularClass(), setFinalClass(), setAbstractClass().

  3. Add superinterfaces to the class as necessary. See this method: addSuperinterface().

  4. Add fields to the class as necessary. See these classes: SynthesizedClassConstantFieldDescription, SynthesizedClassFieldDescription.

  5. Add subroutines (constructors, methods, class initializer) to the class as necessary. See these classes: SynthesizedConstructorDescription, SynthesizedMethodDescription, SynthesizedAbstractMethodDescription, SynthesizedClassInitializerDescription.

  6. Emit the class's binary classfile into an output stream, e.g. a FileOutputStream or a ByteArrayOutputStream. See this method: emit().

  7. Load the classfile byte array directly into a classloader; or store the classfile in a place from which a classloader can retrieve it, such as a codebase server URL.

In the documentation below, the term "described class" means "the class described by this class description object."

To synthesize a class description for an interface, see class SynthesizedInterfaceDescription.


Constructor Summary
SynthesizedClassDescription(String theClassName)
          Construct a synthesized class description for an actual class with the given name whose superclass is "java.lang.Object".
SynthesizedClassDescription(String theClassName, ClassReference theSuperclass)
          Construct a synthesized class description for an actual class with the given name and the given superclass.
 
Method Summary
 void setAbstractClass()
          Specify that the described class is an abstract class.
 void setFinalClass()
          Specify that the described class is a final class.
 void setRegularClass()
          Specify that the described class is a non-final non-abstract class.
 
Methods inherited from class edu.rit.classfile.SynthesizedClassOrInterfaceDescription
addSuperinterface, emit, setPublic
 
Methods inherited from class edu.rit.classfile.ClassDescription
getFields, getSubroutines, getSuperclass, getSuperinterfaces, isAbstract, isFinal, isInterface, isPublic
 
Methods inherited from class edu.rit.classfile.ClassReference
getClassName, getSimpleName
 
Methods inherited from class edu.rit.classfile.ArrayOrClassReference
getClassInternalName
 
Methods inherited from class edu.rit.classfile.TypeReference
equals, getTypeDescriptor, getWordCount, hashCode, read, toString, write
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SynthesizedClassDescription

public SynthesizedClassDescription(String theClassName)
Construct a synthesized class description for an actual class with the given name whose superclass is "java.lang.Object". Initially, the described class is a public, non-final, non-abstract class with no superinterfaces, fields, constructors, methods, or class initializer.

Parameters:
theClassName - Described class's fully-qualified name. The fully qualified class name uses periods, for example: "com.foo.Bar".
Throws:
NullPointerException - (unchecked exception) Thrown if theClassName is null.
IllegalArgumentException - (unchecked exception) Thrown if theClassName is zero length.

SynthesizedClassDescription

public SynthesizedClassDescription(String theClassName,
                                   ClassReference theSuperclass)
Construct a synthesized class description for an actual class with the given name and the given superclass. Initially, the described class is a public, non-final, non-abstract class with no superinterfaces, fields, constructors, methods, or class initializer.

Parameters:
theClassName - Described class's fully-qualified name. The fully qualified class name uses periods, for example: "com.foo.Bar".
theSuperclass - Described class's superclass.
Throws:
NullPointerException - (unchecked exception) Thrown if theClassName is null or theSuperclass is null.
IllegalArgumentException - (unchecked exception) Thrown if theClassName is zero length.
Method Detail

setRegularClass

public void setRegularClass()
Specify that the described class is a non-final non-abstract class.


setFinalClass

public void setFinalClass()
Specify that the described class is a final class.


setAbstractClass

public void setAbstractClass()
Specify that the described class is an abstract class.



Copyright © 2001-2006 by Alan Kaminsky. All rights reserved. Send comments to ark­@­cs.rit.edu.