|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.sun.tools.javac.jvm.ClassFile
com.sun.tools.javac.jvm.ClassReader
public class ClassReader
This class provides operations to read a classfile into an internal representation. The internal representation is anchored in a ClassSymbol which contains in its scope symbol representations for all other definitions in the classfile. Top-level Classes themselves appear as members of the scopes of PackageSymbols.
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 |
ClassReader.AnnotationCompleter
|
(package private) class |
ClassReader.AnnotationDefaultCompleter
|
(package private) class |
ClassReader.AnnotationDeproxy
|
(package private) static class |
ClassReader.ArrayAttributeProxy
|
class |
ClassReader.BadClassFile
Error Diagnoses |
(package private) static class |
ClassReader.CompoundAnnotationProxy
A temporary proxy representing a compound attribute. |
(package private) static class |
ClassReader.EnumAttributeProxy
|
(package private) static interface |
ClassReader.ProxyVisitor
|
static interface |
ClassReader.SourceCompleter
|
private static class |
ClassReader.SourceFileObject
A subclass of JavaFileObject for the sourcefile attribute found in a classfile. |
| Nested classes/interfaces inherited from class com.sun.tools.javac.jvm.ClassFile |
|---|
ClassFile.NameAndType |
| Field Summary | |
|---|---|
(package private) boolean |
allowAnnotations
Switch: allow annotations. |
(package private) boolean |
allowGenerics
Switch: read GJ signature information. |
(package private) boolean |
allowVarargs
Switch: read varargs attribute. |
(package private) Annotate |
annotate
|
(package private) int |
bp
The current input pointer. |
(package private) byte[] |
buf
The buffer containing the currently read class file. |
private boolean |
cacheCompletionFailure
Switch: cache completion failures unless -XDdev is used |
private Symbol.CompletionFailure |
cachedCompletionFailure
|
(package private) boolean |
checkClassFile
Switch: check class file for correct minor version, unrecognized attributes. |
private java.util.Map<Name,Symbol.ClassSymbol> |
classes
A hashtable containing the encountered top-level and member classes, indexed by flat names. |
protected static Context.Key<ClassReader> |
classReaderKey
The context key for the class reader. |
(package private) Name |
completionFailureName
Force a completion failure on this name |
protected JavaFileObject |
currentClassFile
The path name of the class file currently being read. |
protected JavaFileManager.Location |
currentLoc
|
protected Symbol |
currentOwner
The class or method currently being read. |
(package private) JCDiagnostic.Factory |
diagFactory
Factory for diagnostics |
private JavaFileManager |
fileManager
Access to files |
private boolean |
filling
We can only read a single class file at a time; this flag keeps track of when we are currently reading a class file. |
private List<Type> |
foundTypeVariables
|
(package private) Log |
log
The log to use for verbose output |
private List<Type> |
missingTypeVariables
|
(package private) Names |
names
The name table. |
private java.util.Map<Name,Symbol.PackageSymbol> |
packages
A hashtable containing the encountered packages. |
(package private) int[] |
poolIdx
For every constant pool entry, an index into buf where the defining section of the entry is found. |
(package private) java.lang.Object[] |
poolObj
The objects of the constant pool. |
boolean |
preferSource
Switch: prefer source files instead of newer when both source and class are available |
boolean |
readAllOfClassFile
Switch: read constant pool and code sections. |
private boolean |
readingClassAttr
|
boolean |
saveParameterNames
Switch: preserve parameter names from the variable table. |
(package private) int |
sbp
|
(package private) boolean |
sigEnterPhase
|
(package private) int |
siglimit
|
(package private) byte[] |
signature
The unread portion of the currently read type is signature[sigp..siglimit-1]. |
(package private) byte[] |
signatureBuffer
|
(package private) int |
sigp
|
ClassReader.SourceCompleter |
sourceCompleter
Can be reassigned from outside: the completer to be used for ".java" files. |
private boolean |
suppressFlush
|
(package private) Symtab |
syms
The symbol table. |
(package private) Types |
types
|
protected Scope |
typevars
The current scope where type variables are entered. |
(package private) boolean |
verbose
Switch: verbose output. |
private boolean |
verbosePath
|
| 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 | |
|---|---|
protected |
ClassReader(Context context,
boolean definitive)
Construct a new class reader, optionally treated as the definitive classreader for this invocation. |
| Method Summary | |
|---|---|
(package private) long |
adjustClassFlags(long flags)
|
(package private) long |
adjustFieldFlags(long flags)
Adjusting flags |
(package private) long |
adjustMethodFlags(long flags)
|
(package private) void |
attachAnnotationDefault(Symbol sym)
Attach the default value for an annotation element. |
(package private) void |
attachAnnotations(Symbol sym)
Attach annotations. |
(package private) void |
attachParameterAnnotations(Symbol method)
Attach parameter annotations. |
ClassReader.BadClassFile |
badClassFile(java.lang.String key,
java.lang.Object... args)
|
(package private) Type |
classSigToType()
Convert class signature to type, where signature is implicit. |
void |
complete(Symbol sym)
Completion for classes to be loaded. |
private void |
completeEnclosing(Symbol.ClassSymbol c)
Tries to complete lexically enclosing classes if c looks like a nested class. |
private void |
completeOwners(Symbol o)
complete up through the enclosing package. |
private JCDiagnostic |
createBadClassFileDiagnostic(JavaFileObject file,
JCDiagnostic diag)
|
Symbol.ClassSymbol |
defineClass(Name name,
Symbol owner)
Define a new class given its name and owner. |
private static byte[] |
ensureCapacity(byte[] buf,
int needed)
|
Symbol.ClassSymbol |
enterClass(Name flatname)
Create a new member or toplevel class symbol with given flat name and enter in `classes' unless already there. |
Symbol.ClassSymbol |
enterClass(Name flatName,
JavaFileObject classFile)
Creates a new toplevel class symbol with given flat name and given class (or source) file. |
Symbol.ClassSymbol |
enterClass(Name name,
Symbol.TypeSymbol owner)
Create a new toplevel or member class symbol with given name and owner and enter in `classes' unless already there. |
private void |
enterMember(Symbol.ClassSymbol c,
Symbol sym)
Add member to class unless it is synthetic. |
Symbol.PackageSymbol |
enterPackage(Name fullname)
Make a package, given its fully qualified name. |
Symbol.PackageSymbol |
enterPackage(Name name,
Symbol.PackageSymbol owner)
Make a package, given its unqualified name and enclosing package. |
protected void |
enterTypevars(Symbol sym)
|
protected void |
enterTypevars(Type t)
Enter type variables of this classtype and all enclosing ones in `typevars'. |
protected void |
extraFileActions(Symbol.PackageSymbol pack,
JavaFileObject fe)
this is used to support javadoc |
private void |
fillIn(Symbol.ClassSymbol c)
Fill in definition of class `c' from corresponding class or source file. |
private void |
fillIn(Symbol.PackageSymbol p)
Load directory of package into members scope. |
private void |
fillIn(Symbol.PackageSymbol p,
JavaFileManager.Location location,
java.lang.Iterable<JavaFileObject> files)
|
private Symbol.MethodSymbol |
findMethod(ClassFile.NameAndType nt,
Scope scope,
long flags)
|
(package private) Type |
findTypeVar(Name name)
Find type variable with given name in `typevars' scope. |
(package private) char |
getChar(int bp)
Extract a character at position bp from buf. |
(package private) double |
getDouble(int bp)
Extract a double at position bp from buf. |
(package private) float |
getFloat(int bp)
Extract a float at position bp from buf. |
(package private) int |
getInt(int bp)
Extract an integer at position bp from buf. |
(package private) long |
getLong(int bp)
Extract a long integer at position bp from buf. |
protected java.util.EnumSet<JavaFileObject.Kind> |
getPackageFileKinds()
specifies types of files to be read when filling in a package symbol |
protected void |
includeClassFile(Symbol.PackageSymbol p,
JavaFileObject file)
Include class corresponding to given class file in package, unless (1) we already have one the same kind (.class or .java), or (2) we have one of the other kind, and the given class file is older. |
(package private) void |
indexPool()
Index all constant pool entries, writing their start addresses into poolIdx. |
void |
init(Symtab syms)
Initialize classes and packages, treating this as the definitive classreader. |
private void |
init(Symtab syms,
boolean definitive)
Initialize classes and packages, optionally treating this as the definitive classreader. |
static ClassReader |
instance(Context context)
Get the ClassReader instance for this invocation. |
private static boolean |
isAsciiDigit(char c)
Character.isDigit answers true to some non-ascii digits. |
private boolean |
isSameBinaryType(Type.MethodType mt1,
Type.MethodType mt2)
Similar to Types.isSameType but avoids completion |
Symbol.ClassSymbol |
loadClass(Name flatname)
Load a toplevel class with given fully qualified name The class is entered into `classes' only if load was successful. |
private Symbol.CompletionFailure |
newCompletionFailure(Symbol.TypeSymbol c,
JCDiagnostic diag)
Static factory for CompletionFailure objects. |
(package private) char |
nextChar()
Read a character. |
(package private) int |
nextInt()
Read an integer. |
boolean |
packageExists(Name fullname)
Check to see if a package exists, given its fully qualified name. |
protected JavaFileObject |
preferredFileObject(JavaFileObject a,
JavaFileObject b)
Implement policy to choose to derive information from a source file or a class file when both are present. |
private void |
printCCF(java.lang.String key,
java.lang.Object arg)
Output for "-checkclassfile" option. |
private void |
printVerbose(java.lang.String key,
java.lang.CharSequence arg)
Output for "-verbose" option. |
(package private) Attribute |
readAttributeValue()
|
(package private) void |
readClass(Symbol.ClassSymbol c)
Read contents of a given class symbol `c'. |
(package private) void |
readClassAttr(Symbol.ClassSymbol c,
Name attrName,
int attrLen)
Read class attribute. |
(package private) void |
readClassAttrs(Symbol.ClassSymbol c)
Read class attributes. |
private void |
readClassFile(Symbol.ClassSymbol c)
Read a class file. |
(package private) java.lang.Object |
readClassOrType(int i)
If name is an array type or class signature, return the corresponding type; otherwise return a ClassSymbol with given name. |
(package private) Symbol.ClassSymbol |
readClassSymbol(int i)
Read class entry. |
(package private) Code |
readCode(Symbol owner)
Read code block. |
(package private) ClassReader.CompoundAnnotationProxy |
readCompoundAnnotation()
|
(package private) void |
readEnclosingMethodAttr(Symbol sym)
|
(package private) Type |
readEnumType(int i)
|
(package private) Symbol.VarSymbol |
readField()
Read a field. |
(package private) void |
readInnerClasses(Symbol.ClassSymbol c)
Read inner class info. |
private static byte[] |
readInputStream(byte[] buf,
java.io.InputStream s)
|
(package private) void |
readMemberAttr(Symbol sym,
Name attrName,
int attrLen)
Read member attribute. |
(package private) void |
readMemberAttrs(Symbol sym)
Read member attributes. |
(package private) Symbol.MethodSymbol |
readMethod()
Read a method. |
(package private) Name |
readName(int i)
Read name. |
(package private) java.lang.Object |
readPool(int i)
Read constant pool entry at start address i, use pool as a cache. |
(package private) Type |
readType(int i)
Read signature and convert to type. |
(package private) Type |
readTypeOrClassSymbol(int i)
|
(package private) List<Type> |
readTypeParams(int i)
Read signature and convert to type parameters. |
(package private) Type |
sigToType()
Convert signature to type, where signature is implicit. |
(package private) Type |
sigToType(byte[] sig,
int offset,
int len)
Convert signature to type, where signature is a byte array segment. |
(package private) Type |
sigToTypeParam()
Convert (implicit) signature to type parameter. |
(package private) List<Type> |
sigToTypeParams()
Convert signature to type parameters, where signature is implicit. |
(package private) List<Type> |
sigToTypeParams(byte[] sig,
int offset,
int len)
Convert signature to type parameters, where signature is a byte array segment. |
(package private) List<Type> |
sigToTypes(char terminator)
Convert (implicit) signature to list of types until `terminator' is encountered. |
private Name |
simpleBinaryName(Name self,
Name enclosing)
|
(package private) void |
skipMember()
Skip a field or method |
(package private) void |
unrecognized(Name attrName)
Report unrecognized attribute. |
| 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 |
|---|
protected static final Context.Key<ClassReader> classReaderKey
Annotate annotate
boolean verbose
boolean checkClassFile
public boolean readAllOfClassFile
boolean allowGenerics
boolean allowVarargs
boolean allowAnnotations
public boolean saveParameterNames
private boolean cacheCompletionFailure
public boolean preferSource
final Log log
Symtab syms
Types types
final Names names
final Name completionFailureName
private final JavaFileManager fileManager
JCDiagnostic.Factory diagFactory
public ClassReader.SourceCompleter sourceCompleter
private java.util.Map<Name,Symbol.ClassSymbol> classes
private java.util.Map<Name,Symbol.PackageSymbol> packages
protected Scope typevars
protected JavaFileObject currentClassFile
protected Symbol currentOwner
byte[] buf
int bp
java.lang.Object[] poolObj
int[] poolIdx
byte[] signature
int sigp
int siglimit
boolean sigEnterPhase
byte[] signatureBuffer
int sbp
private boolean readingClassAttr
private List<Type> missingTypeVariables
private List<Type> foundTypeVariables
private boolean suppressFlush
private boolean filling
private Symbol.CompletionFailure cachedCompletionFailure
protected JavaFileManager.Location currentLoc
private boolean verbosePath
| Constructor Detail |
|---|
protected ClassReader(Context context,
boolean definitive)
| Method Detail |
|---|
public static ClassReader instance(Context context)
public void init(Symtab syms)
private void init(Symtab syms,
boolean definitive)
private void enterMember(Symbol.ClassSymbol c,
Symbol sym)
private JCDiagnostic createBadClassFileDiagnostic(JavaFileObject file,
JCDiagnostic diag)
public ClassReader.BadClassFile badClassFile(java.lang.String key,
java.lang.Object... args)
char nextChar()
int nextInt()
char getChar(int bp)
int getInt(int bp)
long getLong(int bp)
float getFloat(int bp)
double getDouble(int bp)
void indexPool()
java.lang.Object readPool(int i)
Type readType(int i)
java.lang.Object readClassOrType(int i)
List<Type> readTypeParams(int i)
Symbol.ClassSymbol readClassSymbol(int i)
Name readName(int i)
Type sigToType(byte[] sig,
int offset,
int len)
Type sigToType()
Type classSigToType()
List<Type> sigToTypes(char terminator)
List<Type> sigToTypeParams(byte[] sig,
int offset,
int len)
List<Type> sigToTypeParams()
Type sigToTypeParam()
Type findTypeVar(Name name)
void unrecognized(Name attrName)
void readMemberAttr(Symbol sym,
Name attrName,
int attrLen)
void readEnclosingMethodAttr(Symbol sym)
private Name simpleBinaryName(Name self,
Name enclosing)
private Symbol.MethodSymbol findMethod(ClassFile.NameAndType nt,
Scope scope,
long flags)
private boolean isSameBinaryType(Type.MethodType mt1,
Type.MethodType mt2)
private static boolean isAsciiDigit(char c)
void readMemberAttrs(Symbol sym)
void readClassAttr(Symbol.ClassSymbol c,
Name attrName,
int attrLen)
void readClassAttrs(Symbol.ClassSymbol c)
Code readCode(Symbol owner)
void attachAnnotations(Symbol sym)
void attachParameterAnnotations(Symbol method)
void attachAnnotationDefault(Symbol sym)
Type readTypeOrClassSymbol(int i)
Type readEnumType(int i)
ClassReader.CompoundAnnotationProxy readCompoundAnnotation()
Attribute readAttributeValue()
Symbol.VarSymbol readField()
Symbol.MethodSymbol readMethod()
void skipMember()
protected void enterTypevars(Type t)
protected void enterTypevars(Symbol sym)
void readClass(Symbol.ClassSymbol c)
void readInnerClasses(Symbol.ClassSymbol c)
private void readClassFile(Symbol.ClassSymbol c)
throws java.io.IOException
java.io.IOExceptionlong adjustFieldFlags(long flags)
long adjustMethodFlags(long flags)
long adjustClassFlags(long flags)
public Symbol.ClassSymbol defineClass(Name name,
Symbol owner)
public Symbol.ClassSymbol enterClass(Name name,
Symbol.TypeSymbol owner)
public Symbol.ClassSymbol enterClass(Name flatName,
JavaFileObject classFile)
flatName - a fully qualified binary class nameclassFile - the class file or compilation unit defining
the class (may be null)
java.lang.AssertionError - if the class symbol already existspublic Symbol.ClassSymbol enterClass(Name flatname)
public void complete(Symbol sym)
throws Symbol.CompletionFailure
complete in interface Symbol.CompleterSymbol.CompletionFailureprivate void completeOwners(Symbol o)
private void completeEnclosing(Symbol.ClassSymbol c)
private void fillIn(Symbol.ClassSymbol c)
private static byte[] readInputStream(byte[] buf,
java.io.InputStream s)
throws java.io.IOException
java.io.IOException
private static byte[] ensureCapacity(byte[] buf,
int needed)
private Symbol.CompletionFailure newCompletionFailure(Symbol.TypeSymbol c,
JCDiagnostic diag)
public Symbol.ClassSymbol loadClass(Name flatname)
throws Symbol.CompletionFailure
Symbol.CompletionFailurepublic boolean packageExists(Name fullname)
public Symbol.PackageSymbol enterPackage(Name fullname)
public Symbol.PackageSymbol enterPackage(Name name,
Symbol.PackageSymbol owner)
protected void includeClassFile(Symbol.PackageSymbol p,
JavaFileObject file)
protected JavaFileObject preferredFileObject(JavaFileObject a,
JavaFileObject b)
protected java.util.EnumSet<JavaFileObject.Kind> getPackageFileKinds()
protected void extraFileActions(Symbol.PackageSymbol pack,
JavaFileObject fe)
private void fillIn(Symbol.PackageSymbol p)
throws java.io.IOException
java.io.IOException
private void fillIn(Symbol.PackageSymbol p,
JavaFileManager.Location location,
java.lang.Iterable<JavaFileObject> files)
private void printVerbose(java.lang.String key,
java.lang.CharSequence arg)
key - The key to look up the correct internationalized string.arg - An argument for substitution into the output string.
private void printCCF(java.lang.String key,
java.lang.Object arg)
key - The key to look up the correct internationalized string.arg - An argument for substitution into the output string.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||