final class ClassFile extends ConcreteSourceElement
Represents a single class file which either defines a class type or an interface type.
(Annotation
types are also interface types and Enum
s are class types.)
- Source
- ClassFile.scala
- Note
Equality of
ClassFile
objects is reference based and a class file's hash code is the same as the underlying ObjectType's hash code; i.e., 'thisType
's hash code.
- Alphabetic
- By Inheritance
- ClassFile
- ConcreteSourceElement
- SourceElement
- CommonSourceElementAttributes
- CommonAttributes
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
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 _UNSAFE_addMethod(methodTemplate: MethodTemplate): ClassFile
Creates a new class file object with the given method.
Creates a new class file object with the given method.
This class file must not contain a method with the same name and descriptor!
The old class file object must not be used after this call; if this cannot be guaranteed
copy
has to be used; otherwise the back-references (field -> class file and method -> class file) are broken!- Note
This method is primarily intended to be used to perform load-time transformations!
- def _UNSAFE_replaceAttributes(newAttributes: Attributes): ClassFile
Creates a new class file object which has the specified attributes.
Creates a new class file object which has the specified attributes.
The old class file object must not be used after this call; if this cannot be guaranteed
copy
has to be used; otherwise the back-references (field -> class file and method -> class file) are broken!- Note
This method is primarily intended to be used to perform load-time transformations!
- def _UNSAFE_replaceMethod(oldMethod: Method, newMethod: MethodTemplate): ClassFile.this.type
Creates a new class file object where the method
oldMethod
is replaced by thenewMethod
.Creates a new class file object where the method
oldMethod
is replaced by thenewMethod
. Hence, the old method must be defined by this class file!Both methods have to have the same name and descriptor!
The old class file object must not be used after this call; if this cannot be guaranteed
copy
has to be used; otherwise the back-references (field -> class file and method -> class file) are broken!- Note
This method is primarily intended to be used to perform load-time transformations!
- val accessFlags: Int
- Definition Classes
- ClassFile → ConcreteSourceElement
- def annotations: Annotations
The list of all annotations.
The list of all annotations. In general, if a specific annotation is searched for the method runtimeVisibleAnnotations or runtimeInvisibleAnnotations should be used.
- Definition Classes
- CommonSourceElementAttributes
- def asClassFile: ClassFile.this.type
- Definition Classes
- ClassFile → SourceElement
- def asField: Field
- Definition Classes
- SourceElement
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def asMethod: Method
- Definition Classes
- SourceElement
- def asVirtualClass: VirtualClass
- val attributes: Attributes
- Definition Classes
- ClassFile → CommonAttributes
- def bootstrapMethodTable: Option[BootstrapMethodTable]
Returns this class file's bootstrap method table.
Returns this class file's bootstrap method table.
- Note
A class file's bootstrap method table may be removed at load time if the corresponding org.opalj.br.instructions.INVOKEDYNAMIC instructions are rewritten.
- def classSignature: Option[ClassSignature]
Each class file optionally defines a class signature.
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @IntrinsicCandidate()
- def compareAttributes(other: Attributes, config: SimilarityTestConfiguration): Option[AnyRef]
Compares this element's attributes with the given one.
Compares this element's attributes with the given one.
- returns
None, if both attribute lists are similar; Some(<description of the difference>) otherwise.
- Attributes
- protected[this]
- Definition Classes
- CommonAttributes
- def constructors: Iterator[Method]
All constructors/instance initialization methods (
<init>
) defined by this class.All constructors/instance initialization methods (
<init>
) defined by this class.(This does not include the static initializer.)
- def copy(version: UShortPair = this.version, accessFlags: Int = this.accessFlags, thisType: ObjectType = this.thisType, superclassType: Option[ObjectType] = this.superclassType, interfaceTypes: ObjectTypes = this.interfaceTypes, fields: FieldTemplates = this.fields.map[FieldTemplate](f => f.copy()), methods: MethodTemplates = this.methods.map[MethodTemplate](m => m.copy()), attributes: Attributes = this.attributes): ClassFile
Creates a deep copy of this class file object which also copies the methods and fields.
Creates a deep copy of this class file object which also copies the methods and fields.
- Note
If the requirements of
unsafeReplaceMethod
are met you should use that method!
- def enclosingMethod: Option[EnclosingMethod]
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(other: Any): Boolean
- Definition Classes
- ClassFile → AnyRef → Any
- val fields: Fields
- final def findDirectlyOverridingMethod(packageName: String, method: Method): Result[Method]
- def findDirectlyOverridingMethod(packageName: String, visibility: Option[VisibilityModifier], name: String, descriptor: MethodDescriptor): Result[Method]
Returns the method which directly overrides a method with the given properties.
Returns the method which directly overrides a method with the given properties. The result is
Success(<Method>)
if we can find a method;
Emptyif no method can be found and
Failure
if a method is found which supposedly overrides the specified method, but which is less visible.- Note
This method is only defined for proper virtual methods. I.e., asking for overridings of a private methods is not supported.
- def findDissimilarity(other: ClassFile, config: SimilarityTestConfiguration = CompareAllConfiguration): Option[AnyRef]
Compares this class file with the given one; returns (the first) differences if any.
Compares this class file with the given one; returns (the first) differences if any. The comparison tries to be stable in the presence of difference that are not runtime relevant. For example, the precise structure of the constant pool is completely irrelevant. Additionally, some variance in the bytecode (e.g.,
bipush(2)
vsiconst_2
) is generally irrelevant and also the order in which Attributes are found.The degree to which the two class files have to be similar can be configured using a SimilarityTestConfiguration object. By default, all parts will be compared and have to be equal except of irrelevant differences. The default (CompareAllConfiguration) compares all parts.
- returns
None
if this class file and the other are equal - i.e., if both effectively implement the same class.
- def findField(name: String, fieldType: FieldType): Option[Field]
Returns the field with the given name and type.
- def findField(name: String): List[Field]
Returns the field with the given name, if any.
Returns the field with the given name, if any.
- Note
The complexity is O(log2 n); this algorithm uses binary search.
- def findMethod(name: String, descriptor: MethodDescriptor, matcher: AccessFlagsMatcher): Option[Method]
- def findMethod(name: String, descriptor: MethodDescriptor): Option[Method]
Returns the method with the given name and descriptor that is declared by this class file.
Returns the method with the given name and descriptor that is declared by this class file.
- Note
The complexity is O(log2 n); this algorithm uses a binary search algorithm.
- def findMethod(name: String): List[Method]
Returns the methods (including constructors and static initializers) with the given name, if any.
Returns the methods (including constructors and static initializers) with the given name, if any.
- Note
The complexity is O(log2 n); this algorithm uses binary search.
- def foreachNestedClass(f: (ClassFile) => Unit)(implicit classFileRepository: ClassFileRepository): Unit
Iterates over all direct and indirect nested classes of this class file.
Iterates over all direct and indirect nested classes of this class file.
To collect all nested types:
var allNestedTypes: Set[ObjectType] = Set.empty foreachNestedClasses(innerclassesProject, { nc => allNestedTypes += nc.thisType })
Example: - final def foreachTypeAnnotation[U](f: (TypeAnnotation) => U): Unit
- Definition Classes
- CommonAttributes
- def fqn: String
The fully qualified name of the type defined by this class file.
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
- def hasDefaultConstructor: Boolean
Returns
true
if this class defines a so-called default constructor.Returns
true
if this class defines a so-called default constructor. A default constructor needs to be present, e.g., when the class is serializable.The default constructor is the constructor that takes no parameters.
- Note
The result is recomputed.
- def hasFlags(accessFlags: Int): Boolean
- Definition Classes
- ConcreteSourceElement
- def hashCode(): Int
This class file's
hasCode
.This class file's
hasCode
. ThehashCode
is (by purpose) identical to the id of theObjectType
it implements.- Definition Classes
- ClassFile → AnyRef → Any
- def id: Int
The unique id associated with the type defined by this class file.
- def innerClasses: Option[InnerClasses]
Returns the
inner classes attribute
, if defined.Returns the
inner classes attribute
, if defined.- Note
The inner classes attribute contains (for inner classes) also a reference to its outer class. Furthermore, it contains references to other inner classes that are not an inner class of this class. If you are just interested in the inner classes of this class, use the method nested classes.
- See also
- def instanceMethods: Iterator[Method]
All defined instance methods.
All defined instance methods. I.e., all methods that are not static, constructors, or static initializers.
- val interfaceTypes: ObjectTypes
- def isAbstract: Boolean
- def isAnnotationDeclaration: Boolean
- def isAnonymousInnerClass: Boolean
Returns
true
if this class file defines an anonymous inner class.Returns
true
if this class file defines an anonymous inner class.This method relies on the inner classes attribute to identify anonymous inner classes.
- def isClass: Boolean
- Definition Classes
- ClassFile → SourceElement
- def isClassDeclaration: Boolean
- def isDeprecated: Boolean
Returns true if this (field, method, class) declaration is declared as deprecated.
Returns true if this (field, method, class) declaration is declared as deprecated.
Note
The deprecated attribute is always set by the Java compiler when either the deprecated annotation or the JavaDoc tag is used.
- Definition Classes
- CommonSourceElementAttributes
- def isEffectivelyFinal: Boolean
Returns
true
if the class is final or if it only defines private constructors and it is therefore not possible to inherit from this class.Returns
true
if the class is final or if it only defines private constructors and it is therefore not possible to inherit from this class.An abstract type (abstract classes and interfaces) is never effectively final.
- def isEnumDeclaration: Boolean
- def isField: Boolean
- Definition Classes
- SourceElement
- def isFinal: Boolean
- def isInnerClass: Boolean
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def isInterfaceDeclaration: Boolean
Returns true if this class file represents an interface.
Returns true if this class file represents an interface.
- Note
From the JVM point-of-view annotations are also interfaces!
- See also
org.opalj.br.analyses.Project to determine if this interface declaration is a functional interface.
- def isMethod: Boolean
- Definition Classes
- SourceElement
- def isModuleDeclaration: Boolean
- def isPackageVisible: Boolean
true
if the class file has package visibility.true
if the class file has package visibility. Iffalse
the methodisPublic
will returntrue
.- Note
A class file cannot have private or protected visibility.
- def isPublic: Boolean
true
if the class file has public visibility.true
if the class file has public visibility. Iffalse
the methodisPackageVisible
will returntrue
.- Note
There is no private or protected visibility.
- def isSynthetic: Boolean
True
if this element was created by the compiler and the attributeSynthetic
is present.True
if this element was created by the compiler and the attributeSynthetic
is present. Compilers are, however, free to use the attribute or the corresponding access flag.- Definition Classes
- CommonSourceElementAttributes
- def isVirtual: Boolean
- Definition Classes
- SourceElement
- def isVirtualType: Boolean
Returns
true
if this class file has no direct representation in the source code.Returns
true
if this class file has no direct representation in the source code.- See also
VirtualTypeFlag for further information.
- def jdkVersion: String
- def majorVersion: UShort
- def methodBodies: Iterator[Code]
- val methods: Methods
- def methodsWithBody: Iterator[Method]
- def minorVersion: UShort
- def module: Option[Module]
Returns Java 9's module attribute if defined.
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def nestedClasses(implicit classFileRepository: ClassFileRepository): Seq[ObjectType]
Returns the set of all immediate nested classes of this class.
Returns the set of all immediate nested classes of this class. I.e., returns those nested classes that are not defined in the scope of a nested class of this class.
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
- def outerType: Option[(ObjectType, Int)]
Each class has at most one explicit, direct outer type.
Each class has at most one explicit, direct outer type. Note that a local class (a class defined in the scope of a method) or an anonymous class do not specify an outer type.
- returns
The object type of the outer type as well as the access flags of this inner class.
- def runtimeInvisibleAnnotations: Annotations
- Definition Classes
- CommonSourceElementAttributes
- def runtimeInvisibleTypeAnnotations: TypeAnnotations
- Definition Classes
- CommonAttributes
- def runtimeVisibleAnnotations: Annotations
- Definition Classes
- CommonSourceElementAttributes
- def runtimeVisibleTypeAnnotations: TypeAnnotations
- Definition Classes
- CommonAttributes
- def similar(other: ClassFile, config: SimilarityTestConfiguration = CompareAllConfiguration): Boolean
Compares this class file with the given one to check if both define the same class modulo those parts which are not considered relevant.
Compares this class file with the given one to check if both define the same class modulo those parts which are not considered relevant.
- config
Configures which parts of the class files should be compared.
- See also
findDissimilarity for further information.
- def sourceDebugExtension: Option[Array[Byte]]
The SourceDebugExtension attribute is an optional attribute [...].
The SourceDebugExtension attribute is an optional attribute [...]. There can be at most one
SourceDebugExtension
attribute. The data (which is modified UTF8 String may, however, not be representable using a String object (see the spec. for further details.)The returned Array must not be mutated.
- def sourceFile: Option[String]
The SourceFile attribute is an optional attribute [...].
The SourceFile attribute is an optional attribute [...]. There can be at most one
SourceFile
attribute. - def staticInitializer: Option[Method]
The static initializer of this class.
The static initializer of this class.
- Note
The way how the static initializer is identified has changed with Java 7. In a class file whose version number is 51.0 or above, the method must have its ACC_STATIC flag set. Other methods named <clinit> in a class file are of no consequence.
- val superclassType: Option[ObjectType]
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def synthesizedClassFiles: Option[SynthesizedClassFiles]
Returns OPAL's SynthesizedClassFiles attribute if it is defined.
- val thisType: ObjectType
- def toString(): String
- Definition Classes
- ClassFile → AnyRef → Any
- val version: UShortPair
- def visibilityModifier: Option[VisibilityModifier]
- Definition Classes
- ConcreteSourceElement
- 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