Package gnu.jel
Class ClassFile
java.lang.Object
gnu.jel.ClassFile
- All Implemented Interfaces:
- java.lang.Cloneable
public class ClassFile
extends java.lang.Object
implements java.lang.Cloneable
This class represents a classfile image in JEL.
- 
Constructor SummaryConstructors Constructor Description ClassFile(int modifiers, java.lang.String name, java.lang.Class<?> superClass, java.lang.Class<?>[] interfaces, LocalField[] fields)Starts creation of a new class file.
- 
Method SummaryModifier and Type Method Description ClassFileclone()Makes a clone of this object.voidcode(long op)code up to 8 operations.voidcodeB(long op)voidcodeLDC(java.lang.Object o, int primitiveID)generates code for code loading constant of primitive type or string.voidcodeM(java.lang.reflect.Member m)byte[]getImage()Finishes class and returns the resulting bytecode.intgetIndex(java.lang.Object item, int typeid)Used to determine an old CP index or to create a new one for an item.voidnewMethod(LocalMethod m, java.lang.Class<?>[] vars)Starts a new method of this class.voidnoteStk(int s, int a)Notes removal of typeID s and subsequent addition of typeID a to Java stack.
- 
Constructor Details- 
ClassFilepublic ClassFile(int modifiers, java.lang.String name, java.lang.Class<?> superClass, java.lang.Class<?>[] interfaces, LocalField[] fields)Starts creation of a new class file.Sizes of fAccess, fNames and fTypes arrays must be the same. - Parameters:
- modifiers- sum of one or more of PUBLIC, FINAL, INTERFACE, ABSTRACT constants of java.lang.reflect.Modifier
- name- is the name of new class (must be in Java historical form, i.e. with dots replaced by slashes '/')
- superClass- is the superclass of this class
- interfaces- array of interfaces this class implements
- fields- fields this class will have
 
 
- 
- 
Method Details- 
cloneMakes a clone of this object.This is used in JEL to avoid step-by step creation of service methods of gnu.jel.CompiledExpression ( , getType, ...). They are created only once, and then the resulting ClassFile is cloned at the point, when it is ready to accept the code for evaluation method. - Overrides:
- clonein class- java.lang.Object
- Returns:
- a clone of this object
 
- 
newMethodStarts a new method of this class.- Parameters:
- m- method descriptor.
- vars- types of local variables by number.
 
- 
getImagepublic byte[] getImage()Finishes class and returns the resulting bytecode.- Returns:
- array of bytes of the resulting *.class file.
 
- 
noteStkpublic void noteStk(int s, int a)Notes removal of typeID s and subsequent addition of typeID a to Java stack.If either is negative the corresponding operation (addition/removal) is skipped. This method is needed to allow ClassFile to compute the maximum stack occupation for the generated code. It is responsibility of the user (of this class) to call noteStk() each time the stack is changed from within the code. - Parameters:
- s- typeid to be put on stack (-1 if none).
- a- typeid to be taken off Java stack (-1 if none).
 
- 
codeBpublic final void codeB(long op)
- 
codeMpublic final void codeM(java.lang.reflect.Member m)
- 
codepublic final void code(long op)code up to 8 operations.Additionally to Java bytecodes this method accepts (and interprets) some more commands. See the implementation. - Parameters:
- op- operations to code (least significant bytes coded first).
 
- 
codeLDCpublic final void codeLDC(java.lang.Object o, int primitiveID)generates code for code loading constant of primitive type or string.- Parameters:
- o- reflection object or String containing the constant
- primitiveID- type ID to save lookups.
 
- 
getIndexpublic int getIndex(java.lang.Object item, int typeid)Used to determine an old CP index or to create a new one for an item.- Parameters:
- item- an item to create or get an index for
- typeid- identifies type of argument to avoid linear searches
- Returns:
- index for an item (negative if it has to be written)
 
 
-