APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.tools.javac.jvm

public Class ClassWriter

extends ClassFile
Class Inheritance
Imports
java.io.*, java.util.LinkedHashMap, .Map, .Set, .LinkedHashSet, java.util.function.ToIntFunction, javax.tools.JavaFileManager, .FileObject, .JavaFileManager.Location, .JavaFileObject, com.sun.tools.javac.code.*, .Attribute.RetentionPolicy, com.sun.tools.javac.code.Directive.*, com.sun.tools.javac.code.Symbol.*, com.sun.tools.javac.code.Type.*, .Types.SignatureGenerator.InvalidSignatureException, com.sun.tools.javac.comp.Check, com.sun.tools.javac.file.PathFileObject, com.sun.tools.javac.jvm.PoolConstant.LoadableConstant, .PoolConstant.Dynamic.BsmKey, com.sun.tools.javac.resources.CompilerProperties.Errors, .CompilerProperties.Fragments, com.sun.tools.javac.util.*, .List

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

This is NOT part of any supported API. 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 and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class
ClassWriter.AttributeWriter

A visitor to write an attribute including its leading single-character marker.

public static class
ClassWriter.PoolOverflow

Thrown when the constant pool is over full.

pack-priv abstract static class
ClassWriter.StackMapTableFrame

An entry in the JSR202 StackMapTable

public static class

Field Summary

Modifier and TypeField and Description
pack-priv ClassWriter.AttributeWriter
private Check
pack-priv static final int
protected static final Context.Key<ClassWriter>
pack-priv static final int
DATA_BUF_SIZE

The initial sizes of the data and constant pool buffers.

public ByteBuffer
databuf

An output buffer for member info.

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
private boolean
private boolean
private boolean
emitSourceFile

Switch: emit source file attribute.

private List<ToIntFunction<Symbol>>
private final JavaFileManager
fileManager

Access to files.

private static final String[]
pack-priv static final int
private boolean
genCrt

Switch: generate CharacterRangeTable attribute.

private final Log
log

The log to use for verbose output.

pack-priv static final int
public boolean
multiModuleMode

If true, class files will be written in module-specific subdirectories of the CLASS_OUTPUT location.

private final Names
names

The name table.

private final Options
pack-priv ByteBuffer
poolbuf

An output buffer for the constant pool.

pack-priv final PoolWriter
poolWriter

The constant pool writer.

private Preview
preview

Preview language level.

pack-priv static final int
pack-priv static final int
SAME_FRAME_SIZE

The tags and constants used in compressed stackmap.

pack-priv static final int
private Source
source

Source language version.

private Target
target

Target class version.

private Types
types

Type utilities.

private boolean
verbose

Switch: verbose output.

Inherited from com.sun.tools.javac.jvm.ClassFile:
CONSTANT_ClassCONSTANT_DoubleCONSTANT_DynamicCONSTANT_FieldrefCONSTANT_FloatCONSTANT_IntegerCONSTANT_InterfaceMethodrefCONSTANT_InvokeDynamicCONSTANT_LongCONSTANT_MethodHandleCONSTANT_MethodrefCONSTANT_MethodTypeCONSTANT_ModuleCONSTANT_NameandTypeCONSTANT_PackageCONSTANT_StringCONSTANT_UnicodeCONSTANT_Utf8JAVA_MAGICMAX_ANNOTATIONSMAX_CODEMAX_DIMENSIONSMAX_LOCALSMAX_PARAMETERSMAX_STACKPREVIEW_MINOR_VERSIONREF_getFieldREF_getStaticREF_invokeInterfaceREF_invokeSpecialREF_invokeStaticREF_invokeVirtualREF_newInvokeSpecialREF_putFieldREF_putStatic

Constructor Summary

AccessConstructor and Description
protected
ClassWriter(Context context)

Construct a class writer, given an options table.

Method Summary

Modifier and TypeMethod and Description
public void
pack-priv int
adjustFlags(final long flags)

pack-priv int
beginAttrs()

Leave space for attribute count and return index for number of attributes field.

private void
public void
endAttr(int index)

Fill in attribute length.

pack-priv void
endAttrs(int index, int count)

Fill in number of attributes.

public static String
flagNames(long flags)

Return flags as a string, separated by " ".

pack-priv long
public static ClassWriter
instance(Context context)

Get the ClassWriter instance for this context.

private void
private boolean
pack-priv void
putChar(ByteBuffer buf, int op, int x)

Write a character into given byte buffer; byte buffer will not be grown.

pack-priv void
putInt(ByteBuffer buf, int adr, int x)

Write an integer into given byte buffer; byte buffer will not be grown.

private boolean
private boolean
public int
writeAttr(Name attrName)

Write header for an attribute to data buffer and return position past attribute length index.

pack-priv void
writeBootstrapMethods()

Write "bootstrapMethods" attribute.

public JavaFileObject
writeClass(Symbol.ClassSymbol
The class from which a class file is generated.
c
)

Emit a class file for a given class.

public void
writeClassFile(OutputStream out, Symbol.ClassSymbol c)

Write class `c' to outstream `out'.

pack-priv void
writeCode(Code code)

Write code attribute of method.

pack-priv void
writeCompoundAttribute(Attribute.Compound c)

Write a compound attribute excluding the '@' marker.

pack-priv int
writeEnclosingMethodAttribute(Symbol.ClassSymbol c)

Write the EnclosingMethod attribute if needed.

protected int
writeEnclosingMethodAttribute(Name attributeName, Symbol.ClassSymbol c)

Write the EnclosingMethod attribute with a specified name.

protected int

Returns:

the number of attributes written
writeExtraAttributes
(Symbol sym)

Allows friends to write additional attributes

protected int

Returns:

the number of attributes written
writeExtraClassAttributes
(Symbol.ClassSymbol c)

Allows subclasses to write additional class attributes

pack-priv void
writeField(Symbol.VarSymbol v)

Write field symbol, entering all references into constant pool.

pack-priv void
pack-priv int
writeFlagAttrs(long flags)

Write flag attributes; return number of attributes written.

pack-priv void
writeInnerClasses()

Write "inner classes" attribute.

pack-priv int
writeJavaAnnotations(List<Attribute.Compound> attrs)

Write Java-language annotations; return number of JVM attributes written (zero or one).

pack-priv int
writeMemberAttrs(Symbol sym, boolean isRecordComponent)

Write member (field or method) attributes; return number of attributes written.

pack-priv void
writeMethod(Symbol.MethodSymbol m)

Write method symbol, entering all references into constant pool.

pack-priv int
writeMethodParametersAttr(Symbol.MethodSymbol m, boolean writeParamNames)

Write method parameter names attribute.

pack-priv void
pack-priv int
writeModuleAttribute(Symbol.ClassSymbol c)

Write the Module attribute if needed.

pack-priv int
writeNestHostIfNeeded(Symbol.ClassSymbol csym)

Write NestHost attribute (if needed)

pack-priv int
writeNestMembersIfNeeded(Symbol.ClassSymbol csym)

Write NestMembers attribute (if needed)

private void
private void
pack-priv int
writeParameterAttrs(List<Symbol.VarSymbol> vars)

Write method parameter annotations; return number of attributes written.

pack-priv int
writePermittedSubclassesIfNeeded(Symbol.ClassSymbol csym)

Write "PermittedSubclasses" attribute.

pack-priv void
pack-priv int
pack-priv void
pack-priv void
pack-priv void
pack-priv int
writeTypeAnnotations(List<Attribute.TypeCompound> typeAnnos, boolean inCode)

Inherited from com.sun.tools.javac.jvm.ClassFile:
externalizeexternalizeinternalizeinternalize