org.eclipse.jdt.internal.compiler.classfmt
Class ClassFileReader

java.lang.Object
  extended by org.eclipse.jdt.internal.compiler.classfmt.ClassFileStruct
      extended by org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader
All Implemented Interfaces:
IBinaryType, IDependent, IGenericType

public class ClassFileReader
extends ClassFileStruct
implements IBinaryType


Field Summary
 
Fields inherited from interface org.eclipse.jdt.internal.compiler.env.IBinaryType
NoField, NoInterface, NoMethod, NoNestedType
 
Fields inherited from interface org.eclipse.jdt.internal.compiler.env.IDependent
JAR_FILE_ENTRY_SEPARATOR
 
Constructor Summary
ClassFileReader(byte[] classFileBytes, char[] fileName)
           
ClassFileReader(byte[] classFileBytes, char[] fileName, boolean fullyInitialize)
           
 
Method Summary
 int accessFlags()
          Answer the receiver's access flags.
 IBinaryAnnotation[] getAnnotations()
          Answer the runtime visible and invisible annotations for this type or null if none.
 int[] getConstantPoolOffsets()
          Answer the int array that corresponds to all the offsets of each entry in the constant pool
 char[] getEnclosingTypeName()
          Answer the resolved name of the enclosing type in the class file format as specified in section 4.2 of the Java 2 VM spec or null if the receiver is a top level type.
 IBinaryField[] getFields()
          Answer the receiver's this.fields or null if the array is empty.
 char[] getFileName()
          Answer the file name which defines the type.
 char[] getGenericSignature()
          Answer the receiver's signature which describes the parameter & return types as specified in section 4.4.4 of the Java 2 VM spec 3rd edition.
 char[] getInnerSourceName()
          Answer the source name if the receiver is a inner type.
 char[][] getInterfaceNames()
          Answer the resolved names of the receiver's interfaces in the class file format as specified in section 4.2 of the Java 2 VM spec or null if the array is empty.
 IBinaryNestedType[] getMemberTypes()
          Answer the receiver's nested types or null if the array is empty.
 IBinaryMethod[] getMethods()
          Answer the receiver's this.methods or null if the array is empty.
 char[][][] getMissingTypeNames()
          Answer the list of missing type names which were referenced from the problem classfile.
 int getModifiers()
          Answer an int whose bits are set according the access constants defined by the VM spec.
 char[] getName()
          Answer the resolved name of the type in the class file format as specified in section 4.2 of the Java 2 VM spec.
 char[] getSourceName()
          Answer the simple name of the type in the class file.
 char[] getSuperclassName()
          Answer the resolved name of the receiver's superclass in the class file format as specified in section 4.2 of the Java 2 VM spec or null if it does not have one.
 long getTagBits()
          Answer the tagbits set according to the bits for annotations.
 long getVersion()
          Answer the major/minor version defined in this class file according to the VM spec.
 boolean hasStructuralChanges(byte[] newBytes)
          Check if the receiver has structural changes compare to the byte array in argument.
 boolean hasStructuralChanges(byte[] newBytes, boolean orderRequired, boolean excludesSynthetic)
          Check if the receiver has structural changes compare to the byte array in argument.
 boolean isAnonymous()
          Answer true if the receiver is an anonymous type, false otherwise
 boolean isBinaryType()
          Answer whether the receiver contains the resolved binary form or the unresolved source form of the type.
 boolean isLocal()
          Answer true if the receiver is a local type, false otherwise
 boolean isMember()
          Answer true if the receiver is a member type, false otherwise
 boolean isNestedType()
          Answer true if the receiver is a nested type, false otherwise
static ClassFileReader read(java.io.File file)
           
static ClassFileReader read(java.io.File file, boolean fullyInitialize)
           
static ClassFileReader read(java.io.InputStream stream, java.lang.String fileName)
           
static ClassFileReader read(java.io.InputStream stream, java.lang.String fileName, boolean fullyInitialize)
           
static ClassFileReader read(java.lang.String fileName)
           
static ClassFileReader read(java.lang.String fileName, boolean fullyInitialize)
           
static ClassFileReader read(java.util.zip.ZipFile zip, java.lang.String filename)
           
static ClassFileReader read(java.util.zip.ZipFile zip, java.lang.String filename, boolean fullyInitialize)
           
 char[] sourceFileName()
          Answer the source file name attribute.
 java.lang.String toString()
           
 
Methods inherited from class org.eclipse.jdt.internal.compiler.classfmt.ClassFileStruct
doubleAt, floatAt, i4At, i8At, u1At, u2At, u4At, utf8At
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ClassFileReader

public ClassFileReader(byte[] classFileBytes,
                       char[] fileName)
                throws ClassFormatException
Parameters:
classFileBytes - Actual bytes of a .class file
fileName - Actual name of the file that contains the bytes, can be null
Throws:
ClassFormatException

ClassFileReader

public ClassFileReader(byte[] classFileBytes,
                       char[] fileName,
                       boolean fullyInitialize)
                throws ClassFormatException
Parameters:
classFileBytes - byte[] Actual bytes of a .class file
fileName - char[] Actual name of the file that contains the bytes, can be null
fullyInitialize - boolean Flag to fully initialize the new object
Throws:
ClassFormatException
Method Detail

read

public static ClassFileReader read(java.io.File file)
                            throws ClassFormatException,
                                   java.io.IOException
Throws:
ClassFormatException
java.io.IOException

read

public static ClassFileReader read(java.io.File file,
                                   boolean fullyInitialize)
                            throws ClassFormatException,
                                   java.io.IOException
Throws:
ClassFormatException
java.io.IOException

read

public static ClassFileReader read(java.io.InputStream stream,
                                   java.lang.String fileName)
                            throws ClassFormatException,
                                   java.io.IOException
Throws:
ClassFormatException
java.io.IOException

read

public static ClassFileReader read(java.io.InputStream stream,
                                   java.lang.String fileName,
                                   boolean fullyInitialize)
                            throws ClassFormatException,
                                   java.io.IOException
Throws:
ClassFormatException
java.io.IOException

read

public static ClassFileReader read(java.util.zip.ZipFile zip,
                                   java.lang.String filename)
                            throws ClassFormatException,
                                   java.io.IOException
Throws:
ClassFormatException
java.io.IOException

read

public static ClassFileReader read(java.util.zip.ZipFile zip,
                                   java.lang.String filename,
                                   boolean fullyInitialize)
                            throws ClassFormatException,
                                   java.io.IOException
Throws:
ClassFormatException
java.io.IOException

read

public static ClassFileReader read(java.lang.String fileName)
                            throws ClassFormatException,
                                   java.io.IOException
Throws:
ClassFormatException
java.io.IOException

read

public static ClassFileReader read(java.lang.String fileName,
                                   boolean fullyInitialize)
                            throws ClassFormatException,
                                   java.io.IOException
Throws:
ClassFormatException
java.io.IOException

accessFlags

public int accessFlags()
Answer the receiver's access flags. The value of the access_flags item is a mask of modifiers used with class and interface declarations.

Returns:
int

getAnnotations

public IBinaryAnnotation[] getAnnotations()
Description copied from interface: IBinaryType
Answer the runtime visible and invisible annotations for this type or null if none.

Specified by:
getAnnotations in interface IBinaryType
Returns:
the annotations or null if there is none.

getConstantPoolOffsets

public int[] getConstantPoolOffsets()
Answer the int array that corresponds to all the offsets of each entry in the constant pool

Returns:
int[]

getEnclosingTypeName

public char[] getEnclosingTypeName()
Description copied from interface: IBinaryType
Answer the resolved name of the enclosing type in the class file format as specified in section 4.2 of the Java 2 VM spec or null if the receiver is a top level type. For example, java.lang.String is java/lang/String.

Specified by:
getEnclosingTypeName in interface IBinaryType

getFields

public IBinaryField[] getFields()
Answer the receiver's this.fields or null if the array is empty.

Specified by:
getFields in interface IBinaryType
Returns:
org.eclipse.jdt.internal.compiler.api.IBinaryField[]

getFileName

public char[] getFileName()
Description copied from interface: IDependent
Answer the file name which defines the type. The path part (optional) must be separated from the actual file proper name by a separator suitable for the type (java.io.File.separator for example), e.g. "c:\\source\\com\\p\\X.java" or "/com/p/Y.java". The path to the zip or jar file (optional) must be separated from the actual path part by JAR_FILE_ENTRY_SEPARATOR, e.g. "c:\\lib\\some.jar|/com/p/X.class" or "/lib/some.zip|/com/q/Y.class". The proper file name includes the suffix extension (e.g. ".java") e.g. "c:/org/eclipse/jdt/internal/compileri/env/IDependent.java" Return null if no file defines the type.

Specified by:
getFileName in interface IDependent
See Also:
IDependent.getFileName()

getGenericSignature

public char[] getGenericSignature()
Description copied from interface: IBinaryType
Answer the receiver's signature which describes the parameter & return types as specified in section 4.4.4 of the Java 2 VM spec 3rd edition. Returns null if none.

Specified by:
getGenericSignature in interface IBinaryType
Returns:
the receiver's signature, null if none

getInnerSourceName

public char[] getInnerSourceName()
Answer the source name if the receiver is a inner type. Return null if it is an anonymous class or if the receiver is a top-level class. e.g. public class A { public class B { } public void foo() { class C {} } public Runnable bar() { return new Runnable() { public void run() {} }; } } It returns {'B'} for the member A$B It returns null for A It returns {'C'} for the local class A$1$C It returns null for the anonymous A$1

Returns:
char[]

getInterfaceNames

public char[][] getInterfaceNames()
Answer the resolved names of the receiver's interfaces in the class file format as specified in section 4.2 of the Java 2 VM spec or null if the array is empty. For example, java.lang.String is java/lang/String.

Specified by:
getInterfaceNames in interface IBinaryType
Returns:
char[][]

getMemberTypes

public IBinaryNestedType[] getMemberTypes()
Answer the receiver's nested types or null if the array is empty. This nested type info is extracted from the inner class attributes. Ask the name environment to find a member type using its compound name

Specified by:
getMemberTypes in interface IBinaryType
Returns:
org.eclipse.jdt.internal.compiler.api.IBinaryNestedType[]

getMethods

public IBinaryMethod[] getMethods()
Answer the receiver's this.methods or null if the array is empty.

Specified by:
getMethods in interface IBinaryType
Returns:
org.eclipse.jdt.internal.compiler.api.env.IBinaryMethod[]

getMissingTypeNames

public char[][][] getMissingTypeNames()
Description copied from interface: IBinaryType
Answer the list of missing type names which were referenced from the problem classfile. This list is encoded via an extra attribute.

Specified by:
getMissingTypeNames in interface IBinaryType

getModifiers

public int getModifiers()
Answer an int whose bits are set according the access constants defined by the VM spec. Set the AccDeprecated and AccSynthetic bits if necessary

Specified by:
getModifiers in interface IGenericType
Returns:
int

getName

public char[] getName()
Answer the resolved name of the type in the class file format as specified in section 4.2 of the Java 2 VM spec. For example, java.lang.String is java/lang/String.

Specified by:
getName in interface IBinaryType
Returns:
char[]

getSourceName

public char[] getSourceName()
Description copied from interface: IBinaryType
Answer the simple name of the type in the class file. For member A$B, will answer B. For anonymous will answer null.

Specified by:
getSourceName in interface IBinaryType

getSuperclassName

public char[] getSuperclassName()
Answer the resolved name of the receiver's superclass in the class file format as specified in section 4.2 of the Java 2 VM spec or null if it does not have one. For example, java.lang.String is java/lang/String.

Specified by:
getSuperclassName in interface IBinaryType
Returns:
char[]

getTagBits

public long getTagBits()
Description copied from interface: IBinaryType
Answer the tagbits set according to the bits for annotations.

Specified by:
getTagBits in interface IBinaryType

getVersion

public long getVersion()
Answer the major/minor version defined in this class file according to the VM spec. as a long: (major<<16)+minor

Returns:
the major/minor version found

hasStructuralChanges

public boolean hasStructuralChanges(byte[] newBytes)
Check if the receiver has structural changes compare to the byte array in argument. Structural changes are: - modifiers changes for the class, the this.fields or the this.methods - signature changes for this.fields or this.methods. - changes in the number of this.fields or this.methods - changes for field constants - changes for thrown exceptions - change for the super class or any super interfaces. - changes for member types name or modifiers If any of these changes occurs, the method returns true. false otherwise. The synthetic fields are included and the members are not required to be sorted.

Parameters:
newBytes - the bytes of the .class file we want to compare the receiver to
Returns:
boolean Returns true is there is a structural change between the two .class files, false otherwise

hasStructuralChanges

public boolean hasStructuralChanges(byte[] newBytes,
                                    boolean orderRequired,
                                    boolean excludesSynthetic)
Check if the receiver has structural changes compare to the byte array in argument. Structural changes are: - modifiers changes for the class, the this.fields or the this.methods - signature changes for this.fields or this.methods. - changes in the number of this.fields or this.methods - changes for field constants - changes for thrown exceptions - change for the super class or any super interfaces. - changes for member types name or modifiers If any of these changes occurs, the method returns true. false otherwise.

Parameters:
newBytes - the bytes of the .class file we want to compare the receiver to
orderRequired - a boolean indicating whether the members should be sorted or not
excludesSynthetic - a boolean indicating whether the synthetic members should be used in the comparison
Returns:
boolean Returns true is there is a structural change between the two .class files, false otherwise

isAnonymous

public boolean isAnonymous()
Answer true if the receiver is an anonymous type, false otherwise

Specified by:
isAnonymous in interface IBinaryType
Returns:
boolean

isBinaryType

public boolean isBinaryType()
Answer whether the receiver contains the resolved binary form or the unresolved source form of the type.

Specified by:
isBinaryType in interface IGenericType
Returns:
boolean

isLocal

public boolean isLocal()
Answer true if the receiver is a local type, false otherwise

Specified by:
isLocal in interface IBinaryType
Returns:
boolean

isMember

public boolean isMember()
Answer true if the receiver is a member type, false otherwise

Specified by:
isMember in interface IBinaryType
Returns:
boolean

isNestedType

public boolean isNestedType()
Answer true if the receiver is a nested type, false otherwise

Returns:
boolean

sourceFileName

public char[] sourceFileName()
Answer the source file name attribute. Return null if there is no source file attribute for the receiver.

Specified by:
sourceFileName in interface IBinaryType
Returns:
char[]

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object