Package gnu.jel

# Class ClassFile

java.lang.Object
gnu.jel.ClassFile

All Implemented Interfaces:
  `Cloneable`

public class ClassFile extends Object implements Cloneable
This class represents a classfile image in JEL.

## Constructor Summary

Constructors
Constructor
Description
`ClassFile(int modifiers, String name, Class<?> superClass, Class<?>[] interfaces, LocalField[] fields)`
Starts creation of a new class file.

## Method Summary

Modifier and Type
Method
Description
`ClassFile`
`clone()`
Makes a clone of this object.
`final void`
`code(long op)`
code up to 8 operations.
`final void`
`codeB(long op)`
`final void`
`codeLDC(Object o, int primitiveID)`
generates code for code loading constant of primitive type or string.
`final void`
`codeM(Member m)`
`byte[]`
`getImage()`
Finishes class and returns the resulting bytecode.
`int`
`getIndex(Object item, int typeid)`
Used to determine an old CP index or to create a new one for an item.
`void`
`newMethod(LocalMethod m, Class<?>[] vars)`
Starts a new method of this class.
`void`
`noteStk(int s, int a)`
Notes removal of typeID s and subsequent addition of typeID a to Java stack.

### Methods inherited from class java.lang.Object

`equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### ClassFile

public ClassFile(int modifiers, String name, Class<?> superClass, 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

### clone

public ClassFile clone()
Makes a clone of this object.

This is used in JEL to avoid step-by step creation of service methods of gnu.jel.CompiledExpression (<init>, 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:
  `clone` in class `Object`
Returns:
  a clone of this object

### newMethod

public void newMethod(LocalMethod m, Class<?>[] vars)
Starts a new method of this class.

Parameters:
  `m` - method descriptor.
  `vars` - types of local variables by number.

### getImage

public byte[] getImage()
Finishes class and returns the resulting bytecode.

Returns:
  array of bytes of the resulting *.class file.

### noteStk

public 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).

### codeB

public final void codeB(long op)

### codeM

public final void codeM(Member m)

### code

public 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).

### codeLDC

public final void codeLDC(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.

### getIndex

public int getIndex(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)