trait ClassFileReader extends ClassFileReaderConfiguration with Constant_PoolAbstractions
Implements the template method to read in a Java class file. Additionally, several convenience methods are defined to read in class files from various sources (Streams, Files, JAR archives).
This library supports class files from version 45 (Java 1.1) up to version 54 (Java 10).
Notes for Implementors
Reading of the class file's major structures: the constant pool, fields, methods and the attributes is delegated to corresponding readers. This enables a very high-level of adaptability.
For further details see the JVM Specification: The ClassFile Structure.
- Source
- ClassFileReader.scala
- Alphabetic
- By Inheritance
- ClassFileReader
- Constant_PoolAbstractions
- ClassFileReaderConfiguration
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- abstract type Attributes
The type of the object that represents a class declaration's attributes (e.g., the source file attribute.)
- abstract type CONSTANT_Utf8_info <: Constant_Pool_Entry
- Definition Classes
- Constant_PoolAbstractions
- abstract type ClassFile
The type of the object that represents a Java class file.
The type of the object that represents a Java class file.
- Definition Classes
- ClassFileReader → Constant_PoolAbstractions
- final type Constant_Pool = Array[Constant_Pool_Entry]
- Definition Classes
- Constant_PoolAbstractions
- abstract type Constant_Pool_Entry <: ConstantPoolEntry
- Definition Classes
- Constant_PoolAbstractions
- final type Constant_Pool_Index = Int
- Definition Classes
- Constant_PoolAbstractions
- type DeferredActionsStore = Buffer[(ClassFile) => ClassFile] with Constant_Pool_Entry
A DeferredActionsStore stores all functions that need to perform post load actions.
A DeferredActionsStore stores all functions that need to perform post load actions.
One example is the resolution of references to attributes. (The constant pool is the only structure that is passed around and hence it is the only place where to store information/functions related to a specific class file).
- Definition Classes
- Constant_PoolAbstractions
- abstract type Fields
The type of the object that represents the fields of a class.
- final type Interfaces = Array[Constant_Pool_Index]
The inherited interfaces.
- abstract type Methods
The type of the object that represents all methods of a class.
Abstract Value Members
- abstract def Attributes(cp: Constant_Pool, ap: AttributeParent, ap_name_index: Constant_Pool_Index, ap_descriptor_index: Constant_Pool_Index, in: DataInputStream): Attributes
Reads all attributes using the given stream and constant pool.
Reads all attributes using the given stream and constant pool.
The given stream is positioned directly before a class file's "attributes_count" field. This method is called by the template method that reads in a class file to delegate the reading of the attributes.
From the Specification
The attributes [...] appearing in the attributes table of a ClassFile structure are the InnerClasses, EnclosingMethod, Synthetic, Signature, SourceFile, SourceDebugExtension, Deprecated, RuntimeVisibleAnnotations, RuntimeInvisibleAnnotations, BootstrapMethods, RuntimeVisibleTypeAnnotations, and RuntimeInvisibleTypeAnnotations attributes.
- Attributes
- protected
- abstract def ClassFile(cp: Constant_Pool, minor_version: Int, major_version: Int, access_flags: Int, this_class: Constant_Pool_Index, super_class: Constant_Pool_Index, interfaces: Interfaces, fields: Fields, methods: Methods, attributes: Attributes): ClassFile
Factory method to create the
ClassFile
object that represents the class file as a whole, plus anyClassFile
s that have been synthesized in the process of parsing it.Factory method to create the
ClassFile
object that represents the class file as a whole, plus anyClassFile
s that have been synthesized in the process of parsing it.The result will always contain at least one
ClassFile
object, namely the one that is created from this method's parameters. Regardless of how manyClassFile
s the result contains, theClassFile
created from this method's parameters will always be the result's first element.- Attributes
- protected
- abstract def Constant_Pool(in: DataInputStream): Constant_Pool
Reads the constant pool using the given stream.
Reads the constant pool using the given stream.
When this method is called the given stream has to be positioned at the very beginning of the constant pool. This method is called by the template method that reads in a class file to delegate the reading of the constant pool. Only information belonging to the constant pool are allowed to be read.
The stream must not be closed after reading the constant pool.
- Attributes
- protected
- abstract def Fields(cp: Constant_Pool, in: DataInputStream): Fields
Reads all field declarations using the given stream and constant pool.
Reads all field declarations using the given stream and constant pool.
The given stream is positioned directly before a class file's "fields_count" field. This method is called by the template method that reads in a class file to delegate the reading of the declared fields.
- Attributes
- protected
- abstract def Methods(cp: Constant_Pool, in: DataInputStream): Methods
Reads all method declarations using the given stream and constant pool.
Reads all method declarations using the given stream and constant pool.
The given stream is positioned directly before a class file's "methods_count" field. This method is called by the template method that reads in a class file to delegate the reading of the declared method.
- Attributes
- protected
- abstract def applyDeferredActions(cp: Constant_Pool, classFile: ClassFile): ClassFile
This method is called/needs to be called after the class file was completely loaded to perform class file specific transformations.
This method is called/needs to be called after the class file was completely loaded to perform class file specific transformations.
- Definition Classes
- Constant_PoolAbstractions
- implicit abstract val constantPoolEntryType: ClassTag[Constant_Pool_Entry]
- Definition Classes
- Constant_PoolAbstractions
- abstract def loadsInterfacesOnly: Boolean
If
true
method bodies are never loaded.If
true
method bodies are never loaded.- Definition Classes
- ClassFileReaderConfiguration
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def AllClassFiles(files: Iterable[File], exceptionHandler: ExceptionHandler = defaultExceptionHandler): Iterable[(ClassFile, URL)]
- def ClassFile(jarFileName: String, jarFileEntryName: String): List[ClassFile]
Reads in a single class file from a Jar file.
Reads in a single class file from a Jar file.
- jarFileName
the name of an existing ZIP/JAR file that contains class files.
- jarFileEntryName
the name of a class file stored in the specified ZIP/JAR file.
- Annotations
- @throws("if the file is empty or the entry cannot be found")
- def ClassFile(jarFile: File, jarFileEntryName: String): List[ClassFile]
Reads in a single class file from a Jar file.
Reads in a single class file from a Jar file.
- jarFile
An existing ZIP/JAR file that contains class files.
- jarFileEntryName
The name of a class file stored in the specified ZIP/JAR file.
- Annotations
- @throws("if the file is empty or the entry cannot be found")
- def ClassFile(jarFile: ZipFile, jarEntry: ZipEntry): List[ClassFile]
- Attributes
- protected[this]
- def ClassFile(create: () => InputStream): List[ClassFile]
Reads in a class file.
Reads in a class file.
- create
A function that creates a new
InputStream
and which must not returnnull
. If you already do have an open input stream which should not be closed after reading the class file use...ClassFileReader.ClassFile(java.io.DataInputStream) : ClassFile
instead. The (newly created)InputStream
returned by callingcreate
is closed by this method. The created input stream will automatically be wrapped by OPAL to enable efficient reading of the class file.
- def ClassFile(in: DataInputStream): List[ClassFile]
Template method that reads a Java class file from the given input stream.
Template method that reads a Java class file from the given input stream.
All other methods to read a class file use this method to eventually parse a class file.
Class File Structure
Parses a class file according to the specification:
ClassFile { u4 magic; u2 minor_version; u2 major_version; u2 constant_pool_count; cp_info constant_pool[constant_pool_count-1]; u2 access_flags; u2 this_class; u2 super_class; u2 interfaces_count; u2 interfaces[interfaces_count]; u2 fields_count; field_info fields[fields_count]; u2 methods_count; method_info methods[methods_count]; u2 attributes_count; attribute_info attributes[attributes_count]; }
- in
The
DataInputStream
from which the class file will be read. The stream is not closed by this method. It is highly recommended that the stream is buffered; otherwise the performance will be terrible!
- def ClassFiles(file: File, exceptionHandler: ExceptionHandler = defaultExceptionHandler): List[(ClassFile, URL)]
Loads class files from the given file location.
Loads class files from the given file location.
- If the file denotes a single ".class" file this class file is loaded.
- If the file object denotes a ".jar|.war|.ear|.zip" file, all class files in the jar file will be loaded.
- If the file object specifies a directory object, all ".class" files
in the directory and in all subdirectories are loaded as well as all
class files stored in ".jar" files in one of the directories. This class loads
all class files in parallel. However, this does not effect analyses working on the
resulting
List
.
- def ClassFiles(zipFile: ZipFile, classFileHandler: (ClassFile, URL) => Unit, exceptionHandler: ExceptionHandler): Unit
Reads in parallel all class files stored in the given jar file.
Reads in parallel all class files stored in the given jar file. For each successfully read class file the function
classFileHandler
is called.- zipFile
A valid zip file that contains
.class
files and other.jar
files; other files are ignored. Inner jar files are also unzipped.- classFileHandler
A function that is called for each class file in the given jar file. Given that the jarFile is read in parallel this function has to be thread safe.
- exceptionHandler
The exception handler that is called when the reading of a class file fails. This function has to be thread safe.
- def ClassFiles(in: => JarInputStream): List[(ClassFile, String)]
Reads the class files from the given JarInputStream
- def ClassFiles(jarFile: ZipFile, exceptionHandler: ExceptionHandler): List[(ClassFile, URL)]
Reads in parallel all class files stored in the given jar/zip file.
Reads in parallel all class files stored in the given jar/zip file.
- jarFile
Some valid (non-empty) jar File.
- returns
The loaded class files.
- def JRTClassFiles: Iterable[(String, List[(ClassFile, URL)])]
Returns the class files of the current Java Runtime Image grouped by module.
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @IntrinsicCandidate()
- implicit val config: Config
The
Config
object that will be used to read the configuration settings for reading in class files.The
Config
object that will be used to read the configuration settings for reading in class files.- Definition Classes
- ClassFileReaderConfiguration
- def defaultConfig: Config
- Definition Classes
- ClassFileReaderConfiguration
- final val defaultExceptionHandler: ExceptionHandler
- def defaultLogContext: LogContext
- Definition Classes
- ClassFileReaderConfiguration
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def findClassFile(files: Iterable[File], progressReporter: (File) => Unit, classFileFilter: (ClassFile) => Boolean, className: (ClassFile) => String, exceptionHandler: ExceptionHandler = defaultExceptionHandler): Either[(ClassFile, URL), Set[String]]
Searches for the first class file that is accepted by the filter.
Searches for the first class file that is accepted by the filter. If no class file can be found that is accepted by the filter the set of all class names is returned.
- files
Some file. If the file names a .jar file the .jar file is opened and searched for a corresponding class file. If the file identifies a "directory" then, all files in that directory are processed.
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
- def isClassFileRepository(filename: String, containerName: Option[String]): Boolean
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- implicit val logContext: LogContext
The org.opalj.log.LogContext that should be used to log rewritings.
The org.opalj.log.LogContext that should be used to log rewritings.
- Definition Classes
- ClassFileReaderConfiguration
- Note
The org.opalj.log.LogContext is typically either the org.opalj.log.GlobalLogContext or a project specific log context.
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
- def processClassFiles(files: Iterable[File], progressReporter: (File) => Unit, classFileProcessor: ((ClassFile, URL)) => Unit, exceptionHandler: ExceptionHandler = defaultExceptionHandler): Unit
Goes over all files in parallel and calls back the given function which has to be thread-safe!
- def registerClassFilePostProcessor(p: (List[ClassFile]) => List[ClassFile]): Unit
Register a class file post processor.
Register a class file post processor. A class file post processor can transform the completely read and reified class file. Post processors can only be registered before the usage of a class file reader. Registering new
ClassFilePostProcessors
while processing class files is not supported and the behavior is undefined.- Note
PostProcessors
will be executed in last-in-first-out order.
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated