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 Summary

    Constructors 
    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 Summary

    Modifier and Type Method Description
    ClassFile clone()
    Makes a clone of this object.
    void code​(long op)
    code up to 8 operations.
    void codeB​(long op)  
    void codeLDC​(java.lang.Object o, int primitiveID)
    generates code for code loading constant of primitive type or string.
    void codeM​(java.lang.reflect.Member m)  
    byte[] getImage()
    Finishes class and returns the resulting bytecode.
    int getIndex​(java.lang.Object item, int typeid)
    Used to determine an old CP index or to create a new one for an item.
    void newMethod​(LocalMethod m, java.lang.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, 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

    • 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 (, 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 java.lang.Object
      Returns:
      a clone of this object
    • newMethod

      public void newMethod​(LocalMethod m, java.lang.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​(java.lang.reflect.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​(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.
    • getIndex

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