public class ClassFile
extends java.lang.Object
implements java.lang.Cloneable
Constructor and 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.
|
Modifier and Type | Method and 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.
|
public ClassFile(int modifiers, java.lang.String name, java.lang.Class<?> superClass, java.lang.Class[] interfaces, LocalField[] fields)
Sizes of fAccess, fNames and fTypes arrays must be the same.
modifiers
- sum of one or more of PUBLIC, FINAL,
INTERFACE, ABSTRACT
constants of java.lang.reflect.Modifiername
- 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 classinterfaces
- array of interfaces this class implementsfields
- fields this class will havepublic ClassFile clone()
This is used in JEL to avoid step-by step creation of service
methods of gnu.jel.CompiledExpression (
clone
in class java.lang.Object
public void newMethod(LocalMethod m, java.lang.Class[] vars)
m
- method descriptor.vars
- types of local variables by number.public byte[] getImage()
public void noteStk(int s, int a)
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.
s
- typeid to be put on stack (-1 if none).a
- typeid to be taken off Java stack (-1 if none).public final void codeB(long op)
public final void codeM(java.lang.reflect.Member m)
public final void code(long op)
Additionally to Java bytecodes this method accepts (and interprets) some more commands. See the implementation.
op
- operations to code (least significant bytes coded first).public final void codeLDC(java.lang.Object o, int primitiveID)
o
- reflection object or String containing the constantprimitiveID
- type ID to save lookups.public int getIndex(java.lang.Object item, int typeid)
item
- an item to create or get an index fortypeid
- identifies type of argument to avoid linear searchesCopyright © 1998-2016 Konstantin L. Metlov All Rights Reserved.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the JEL manual.