com.sun.tools.javac.jvm
Class ClassWriter

java.lang.Object
  extended by com.sun.tools.javac.jvm.ClassFile
      extended by com.sun.tools.javac.jvm.ClassWriter

public class ClassWriter
extends ClassFile

This class provides operations to map an internal symbol table graph rooted in a ClassSymbol into a classfile.

This is NOT part of any API supported by Sun Microsystems. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.


Nested Class Summary
(package private)  class ClassWriter.AttributeWriter
          A visitor to write an attribute including its leading single-character marker.
static class ClassWriter.PoolOverflow
          Thrown when the constant pool is over full.
(package private) static class ClassWriter.RetentionPolicy
          A mirror of java.lang.annotation.RetentionPolicy.
(package private) static class ClassWriter.StackMapTableFrame
          An entry in the JSR202 StackMapTable
static class ClassWriter.StringOverflow
           
 
Nested classes/interfaces inherited from class com.sun.tools.javac.jvm.ClassFile
ClassFile.NameAndType
 
Field Summary
(package private)  ClassWriter.AttributeWriter awriter
           
protected static Context.Key<ClassWriter> classWriterKey
           
(package private) static int DATA_BUF_SIZE
          The initial sizes of the data and constant pool buffers.
(package private)  ByteBuffer databuf
          An output buffer for member info.
(package private)  boolean debugstackmap
          Switch: describe the generated stackmap
private  boolean dumpClassModifiers
          Value of option 'dumpmodifiers' is a string indicating which modifiers should be dumped for debugging: 'c' -- classes 'f' -- fields 'i' -- innerclass attributes 'm' -- methods For example, to dump everything: javac -XDdumpmodifiers=cifm MyProg.java
private  boolean dumpFieldModifiers
           
private  boolean dumpInnerClassModifiers
           
private  boolean dumpMethodModifiers
           
private  boolean emitSourceFile
          Switch: emit source file attribute.
private  JavaFileManager fileManager
          Access to files.
private static java.lang.String[] flagName
           
(package private) static int FULL_FRAME
           
private  boolean genCrt
          Switch: generate CharacterRangeTable attribute.
(package private)  java.util.Set<Symbol.ClassSymbol> innerClasses
          The inner classes to be written, as a set.
(package private)  ListBuffer<Symbol.ClassSymbol> innerClassesQueue
          The inner classes to be written, as a queue where enclosing classes come first.
private  Log log
          The log to use for verbose output.
(package private) static int MAX_LOCAL_LENGTH_DIFF
           
private  Names names
          The name table.
private  Options options
           
(package private)  Pool pool
          The constant pool.
(package private) static int POOL_BUF_SIZE
           
(package private)  ByteBuffer poolbuf
          An output buffer for the constant pool.
private  boolean retrofit
          Switch: retrofit mode.
(package private) static int SAME_FRAME_EXTENDED
           
(package private) static int SAME_FRAME_SIZE
          The tags and constants used in compressed stackmap.
(package private) static int SAME_LOCALS_1_STACK_ITEM_EXTENDED
           
private  boolean scramble
          Switch: scrable private names.
private  boolean scrambleAll
          Switch: scrable private names.
(package private)  ByteBuffer sigbuf
          An output buffer for type signatures.
private  Source source
          Source language version.
private  Symtab syms
           
private  Target target
          Target class version.
private  Types types
          Type utilities.
private  boolean verbose
          Switch: verbose output.
 
Fields inherited from class com.sun.tools.javac.jvm.ClassFile
CONSTANT_Class, CONSTANT_Double, CONSTANT_Fieldref, CONSTANT_Float, CONSTANT_Integer, CONSTANT_InterfaceMethodref, CONSTANT_Long, CONSTANT_Methodref, CONSTANT_NameandType, CONSTANT_String, CONSTANT_Unicode, CONSTANT_Utf8, JAVA_MAGIC, MAX_CODE, MAX_DIMENSIONS, MAX_LOCALS, MAX_PARAMETERS, MAX_STACK
 
Constructor Summary
private ClassWriter(Context context)
          Construct a class writer, given an options table.
 
Method Summary
(package private)  int adjustFlags(long flags)
           
(package private)  void assembleClassSig(Type type)
           
(package private)  void assembleParamsSig(List<Type> typarams)
           
(package private)  void assembleSig(List<Type> types)
           
(package private)  void assembleSig(Type type)
          Assemble signature of given type in string buffer.
(package private)  int beginAttrs()
          Leave space for attribute count and return index for number of attributes field.
(package private)  void endAttr(int index)
          Fill in attribute length.
(package private)  void endAttrs(int index, int count)
          Fill in number of attributes.
(package private)  void enterInner(Symbol.ClassSymbol c)
          Enter an inner class into the `innerClasses' set/queue.
(package private)  Name fieldName(Symbol sym)
          Given a field, return its name.
static java.lang.String flagNames(long flags)
          Return flags as a string, separated by " ".
(package private)  long getLastModified(FileObject filename)
           
(package private)  ClassWriter.RetentionPolicy getRetention(Symbol.TypeSymbol annotationType)
           
(package private)  boolean hasTypeVar(List<Type> l)
           
static ClassWriter instance(Context context)
          Get the ClassWriter instance for this context.
(package private)  ClassFile.NameAndType nameType(Symbol sym)
          Given a symbol, return its name-and-type.
(package private)  void putChar(ByteBuffer buf, int op, int x)
          Write a character into given byte buffer; byte buffer will not be grown.
(package private)  void putInt(ByteBuffer buf, int adr, int x)
          Write an integer into given byte buffer; byte buffer will not be grown.
(package private)  Name typeSig(Type type)
          Return signature of given type
(package private)  int writeAttr(Name attrName)
          Write header for an attribute to data buffer and return position past attribute length index.
 JavaFileObject writeClass(Symbol.ClassSymbol c)
          Emit a class file for a given class.
 void writeClassFile(java.io.OutputStream out, Symbol.ClassSymbol c)
          Write class `c' to outstream `out'.
(package private)  void writeCode(Code code)
          Write code attribute of method.
(package private)  void writeCompoundAttribute(Attribute.Compound c)
          Write a compound attribute excluding the '@' marker.
(package private)  int writeEnclosingMethodAttribute(Symbol.ClassSymbol c)
          Write the EnclosingMethod attribute if needed.
(package private)  void writeField(Symbol.VarSymbol v)
          Write field symbol, entering all references into constant pool.
(package private)  void writeFields(Scope.Entry e)
           
(package private)  int writeFlagAttrs(long flags)
          Write flag attributes; return number of attributes written.
(package private)  void writeInnerClasses()
          Write "inner classes" attribute.
(package private)  int writeJavaAnnotations(List<Attribute.Compound> attrs)
          Write Java-language annotations; return number of JVM attributes written (zero or one).
(package private)  int writeMemberAttrs(Symbol sym)
          Write member (field or method) attributes; return number of attributes written.
(package private)  void writeMethod(Symbol.MethodSymbol m)
          Write method symbol, entering all references into constant pool.
(package private)  void writeMethods(Scope.Entry e)
           
(package private)  int writeParameterAttrs(Symbol.MethodSymbol m)
          Write method parameter annotations; return number of attributes written.
(package private)  void writePool(Pool pool)
          Write constant pool to pool buffer.
(package private)  void writeStackMap(Code code)
           
(package private)  void writeStackMapType(Type t)
           
 Name xClassName(Type t)
          Given a type t, return the extended class name of its erasure in external representation.
 
Methods inherited from class com.sun.tools.javac.jvm.ClassFile
externalize, externalize, internalize, internalize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

classWriterKey

protected static final Context.Key<ClassWriter> classWriterKey

syms

private final Symtab syms

options

private final Options options

verbose

private boolean verbose
Switch: verbose output.


scramble

private boolean scramble
Switch: scrable private names.


scrambleAll

private boolean scrambleAll
Switch: scrable private names.


retrofit

private boolean retrofit
Switch: retrofit mode.


emitSourceFile

private boolean emitSourceFile
Switch: emit source file attribute.


genCrt

private boolean genCrt
Switch: generate CharacterRangeTable attribute.


debugstackmap

boolean debugstackmap
Switch: describe the generated stackmap


target

private Target target
Target class version.


source

private Source source
Source language version.


types

private Types types
Type utilities.


DATA_BUF_SIZE

static final int DATA_BUF_SIZE
The initial sizes of the data and constant pool buffers. sizes are increased when buffers get full.

See Also:
Constant Field Values

POOL_BUF_SIZE

static final int POOL_BUF_SIZE
See Also:
Constant Field Values

databuf

ByteBuffer databuf
An output buffer for member info.


poolbuf

ByteBuffer poolbuf
An output buffer for the constant pool.


sigbuf

ByteBuffer sigbuf
An output buffer for type signatures.


pool

Pool pool
The constant pool.


innerClasses

java.util.Set<Symbol.ClassSymbol> innerClasses
The inner classes to be written, as a set.


innerClassesQueue

ListBuffer<Symbol.ClassSymbol> innerClassesQueue
The inner classes to be written, as a queue where enclosing classes come first.


log

private final Log log
The log to use for verbose output.


names

private final Names names
The name table.


fileManager

private final JavaFileManager fileManager
Access to files.


SAME_FRAME_SIZE

static final int SAME_FRAME_SIZE
The tags and constants used in compressed stackmap.

See Also:
Constant Field Values

SAME_LOCALS_1_STACK_ITEM_EXTENDED

static final int SAME_LOCALS_1_STACK_ITEM_EXTENDED
See Also:
Constant Field Values

SAME_FRAME_EXTENDED

static final int SAME_FRAME_EXTENDED
See Also:
Constant Field Values

FULL_FRAME

static final int FULL_FRAME
See Also:
Constant Field Values

MAX_LOCAL_LENGTH_DIFF

static final int MAX_LOCAL_LENGTH_DIFF
See Also:
Constant Field Values

dumpClassModifiers

private final boolean dumpClassModifiers
Value of option 'dumpmodifiers' is a string indicating which modifiers should be dumped for debugging: 'c' -- classes 'f' -- fields 'i' -- innerclass attributes 'm' -- methods For example, to dump everything: javac -XDdumpmodifiers=cifm MyProg.java


dumpFieldModifiers

private final boolean dumpFieldModifiers

dumpInnerClassModifiers

private final boolean dumpInnerClassModifiers

dumpMethodModifiers

private final boolean dumpMethodModifiers

flagName

private static final java.lang.String[] flagName

awriter

ClassWriter.AttributeWriter awriter
Constructor Detail

ClassWriter

private ClassWriter(Context context)
Construct a class writer, given an options table.

Method Detail

instance

public static ClassWriter instance(Context context)
Get the ClassWriter instance for this context.


flagNames

public static java.lang.String flagNames(long flags)
Return flags as a string, separated by " ".


putChar

void putChar(ByteBuffer buf,
             int op,
             int x)
Write a character into given byte buffer; byte buffer will not be grown.


putInt

void putInt(ByteBuffer buf,
            int adr,
            int x)
Write an integer into given byte buffer; byte buffer will not be grown.


assembleSig

void assembleSig(Type type)
Assemble signature of given type in string buffer.


hasTypeVar

boolean hasTypeVar(List<Type> l)

assembleClassSig

void assembleClassSig(Type type)

assembleSig

void assembleSig(List<Type> types)

assembleParamsSig

void assembleParamsSig(List<Type> typarams)

typeSig

Name typeSig(Type type)
Return signature of given type


xClassName

public Name xClassName(Type t)
Given a type t, return the extended class name of its erasure in external representation.


writePool

void writePool(Pool pool)
         throws ClassWriter.PoolOverflow,
                ClassWriter.StringOverflow
Write constant pool to pool buffer. Note: during writing, constant pool might grow since some parts of constants still need to be entered.

Throws:
ClassWriter.PoolOverflow
ClassWriter.StringOverflow

fieldName

Name fieldName(Symbol sym)
Given a field, return its name.


nameType

ClassFile.NameAndType nameType(Symbol sym)
Given a symbol, return its name-and-type.


writeAttr

int writeAttr(Name attrName)
Write header for an attribute to data buffer and return position past attribute length index.


endAttr

void endAttr(int index)
Fill in attribute length.


beginAttrs

int beginAttrs()
Leave space for attribute count and return index for number of attributes field.


endAttrs

void endAttrs(int index,
              int count)
Fill in number of attributes.


writeEnclosingMethodAttribute

int writeEnclosingMethodAttribute(Symbol.ClassSymbol c)
Write the EnclosingMethod attribute if needed. Returns the number of attributes written (0 or 1).


writeFlagAttrs

int writeFlagAttrs(long flags)
Write flag attributes; return number of attributes written.


writeMemberAttrs

int writeMemberAttrs(Symbol sym)
Write member (field or method) attributes; return number of attributes written.


writeParameterAttrs

int writeParameterAttrs(Symbol.MethodSymbol m)
Write method parameter annotations; return number of attributes written.


writeJavaAnnotations

int writeJavaAnnotations(List<Attribute.Compound> attrs)
Write Java-language annotations; return number of JVM attributes written (zero or one).


getRetention

ClassWriter.RetentionPolicy getRetention(Symbol.TypeSymbol annotationType)

writeCompoundAttribute

void writeCompoundAttribute(Attribute.Compound c)
Write a compound attribute excluding the '@' marker.


enterInner

void enterInner(Symbol.ClassSymbol c)
Enter an inner class into the `innerClasses' set/queue.


writeInnerClasses

void writeInnerClasses()
Write "inner classes" attribute.


writeField

void writeField(Symbol.VarSymbol v)
Write field symbol, entering all references into constant pool.


writeMethod

void writeMethod(Symbol.MethodSymbol m)
Write method symbol, entering all references into constant pool.


writeCode

void writeCode(Code code)
Write code attribute of method.


writeStackMap

void writeStackMap(Code code)

writeStackMapType

void writeStackMapType(Type t)

writeFields

void writeFields(Scope.Entry e)

writeMethods

void writeMethods(Scope.Entry e)

writeClass

public JavaFileObject writeClass(Symbol.ClassSymbol c)
                          throws java.io.IOException,
                                 ClassWriter.PoolOverflow,
                                 ClassWriter.StringOverflow
Emit a class file for a given class.

Parameters:
c - The class from which a class file is generated.
Throws:
java.io.IOException
ClassWriter.PoolOverflow
ClassWriter.StringOverflow

writeClassFile

public void writeClassFile(java.io.OutputStream out,
                           Symbol.ClassSymbol c)
                    throws java.io.IOException,
                           ClassWriter.PoolOverflow,
                           ClassWriter.StringOverflow
Write class `c' to outstream `out'.

Throws:
java.io.IOException
ClassWriter.PoolOverflow
ClassWriter.StringOverflow

adjustFlags

int adjustFlags(long flags)

getLastModified

long getLastModified(FileObject filename)