Packages

  • package root
    Definition Classes
    root
  • package org
    Definition Classes
    root
  • package opalj

    OPAL is a Scala-based framework for the static analysis, manipulation and creation of Java bytecode.

    OPAL is a Scala-based framework for the static analysis, manipulation and creation of Java bytecode. OPAL is designed with performance, scalability and adaptability in mind.

    Its main components are:

    • a library (Common) which provides generally useful data-structures and algorithms for static analyses.
    • a framework for implementing lattice based static analyses (Static Analysis Infrastructure)
    • a framework for parsing Java bytecode (Bytecode Infrastructure) that can be used to create arbitrary representations.
    • a library to create a one-to-one in-memory representation of Java bytecode (Bytecode Disassembler).
    • a library to create a representation of Java bytecode that facilitates writing simple static analyses (Bytecode Representation - org.opalj.br).
    • a scalable, easily customizable framework for the abstract interpretation of Java bytecode (Abstract Interpretation Framework - org.opalj.ai).
    • a library to extract dependencies between code elements and to facilitate checking architecture definitions.
    • a library for the lightweight manipulation and creation of Java bytecode (Bytecode Assembler).

    General Design Decisions

    Thread Safety

    Unless explicitly noted, OPAL is thread safe. I.e., the classes defined by OPAL can be considered to be thread safe unless otherwise stated. (For example, it is possible to read and process class files concurrently without explicit synchronization on the client side.)

    No null Values

    Unless explicitly noted, OPAL does not null values I.e., fields that are accessible will never contain null values and methods will never return null. If a method accepts null as a value for a parameter or returns a null value it is always explicitly documented. In general, the behavior of methods that are passed null values is undefined unless explicitly documented.

    No Typecasts for Collections

    For efficiency reasons, OPAL sometimes uses mutable data-structures internally. After construction time, these data-structures are generally represented using their generic interfaces (e.g., scala.collection.{Set,Map}). However, a downcast (e.g., to add/remove elements) is always forbidden as it would effectively prevent thread-safety.

    Assertions

    OPAL makes heavy use of Scala's Assertion Facility to facilitate writing correct code. Hence, for production builds (after thorough testing(!)) it is highly recommend to build OPAL again using -Xdisable-assertions.

    Definition Classes
    org
  • package br

    In this representation of Java bytecode references to a Java class file's constant pool and to attributes are replaced by direct references to the corresponding constant pool entries.

    In this representation of Java bytecode references to a Java class file's constant pool and to attributes are replaced by direct references to the corresponding constant pool entries. This facilitates developing analyses and fosters comprehension.

    Based on the fact that indirect references to constant pool entries are resolved and replaced by direct references this representation is called the resolved representation.

    This representation of Java bytecode is considered as OPAL's standard representation for writing Scala based analyses. This representation is engineered such that it facilitates writing analyses that use pattern matching.

    Definition Classes
    opalj
  • package analyses

    Defines commonly useful type aliases.

    Defines commonly useful type aliases.

    Definition Classes
    br
  • package cg
    Definition Classes
    analyses
  • Analysis
  • AnalysisApplication
  • AnalysisException
  • BasicMethodInfo
  • BasicReport
  • DeclaredMethods
  • DeclaredMethodsKey
  • FieldAccessInformation
  • FieldAccessInformationAnalysis
  • FieldAccessInformationKey
  • InconsistentProjectException
  • JavaProject
  • MethodAnalysisApplication
  • MethodDeclarationContext
  • MethodDeclarationContextOrdering
  • MethodInfo
  • ModuleDefinition
  • OneStepAnalysis
  • ProgressEvents
  • ProgressManagement
  • Project
  • ProjectAnalysisApplication
  • ProjectBasedAnalysis
  • ProjectIndex
  • ProjectIndexKey
  • ProjectInformationKey
  • ProjectLike
  • ReportableAnalysisResult
  • StringConstantsInformationKey
  • VirtualFormalParameter
  • VirtualFormalParameters
  • VirtualFormalParametersKey

abstract class ProjectLike extends ClassFileRepository

Enables project wide lookups of methods and fields as required to determine the target(s) of an invoke or field access instruction.

Self Type
ProjectLike
Source
ProjectLike.scala
Note

The current implementation is based on the correct project assumption; i.e., if the bytecode of the project as a whole is not valid, the result is generally undefined. Just one example of a violation of the assumption would be, if we have two interfaces which define a non-abstract method with the same signature and both interfaces are implemented by a third interface which does not override these methods. In this case the result of a resolveMethodReference is not defined, because the code base as a whole is not valid.

Linear Supertypes
ClassFileRepository, AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ProjectLike
  2. ClassFileRepository
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new ProjectLike()

Abstract Value Members

  1. abstract val MethodHandleClassFile: Option[ClassFile]

    The class file of java.lang.invoke.MethodHandle, if available.

  2. abstract val MethodHandleSubtypes: Set[ObjectType]

    The set of all subtypes of java.lang.invoke.MethodHandle; in particular required to resolve signature polymorphic method calls.

  3. abstract val ObjectClassFile: Option[ClassFile]

    The class file of java.lang.Object, if available.

  4. abstract val VarHandleClassFile: Option[ClassFile]

    The class file of java.lang.invoke.VarHandle, if available.

  5. abstract val VarHandleSubtypes: Set[ObjectType]

    The set of all subtypes of java.lang.invoke.VarHandle; in particular required to resolve signature polymorphic method calls.

  6. abstract val allClassFiles: Iterable[ClassFile]
    Attributes
    protected[this]
  7. abstract def classFile(objectType: ObjectType): Option[ClassFile]
    Definition Classes
    ClassFileRepository
  8. implicit abstract val classHierarchy: ClassHierarchy
  9. implicit abstract val config: Config
  10. abstract val instanceMethods: Map[ObjectType, ArraySeq[MethodDeclarationContext]]

    Returns the set of all non-private, non-abstract, non-static methods that are not initializers and which are potentially callable by clients when we have an object that has the specified type and a method is called using org.opalj.br.instructions.INVOKEINTERFACE, org.opalj.br.instructions.INVOKEVIRTUAL or org.opalj.br.instructions.INVOKEDYNAMIC.

    Returns the set of all non-private, non-abstract, non-static methods that are not initializers and which are potentially callable by clients when we have an object that has the specified type and a method is called using org.opalj.br.instructions.INVOKEINTERFACE, org.opalj.br.instructions.INVOKEVIRTUAL or org.opalj.br.instructions.INVOKEDYNAMIC.

    The array of methods is sorted using MethodDeclarationContextOrdering to enable fast look-up of the target method. (See MethodDeclarationContext's compareAccessibilityAware method for further details.)

    Attributes
    protected[this]
  11. implicit abstract def logContext: LogContext
    Definition Classes
    ClassFileRepository
  12. abstract val nests: Map[ObjectType, ObjectType]

    Returns the nest host (see JVM 11 Spec.

    Returns the nest host (see JVM 11 Spec. 5.4.4) for the given type, if explicitly given. For classes without an explicit NestHost or NestMembers attribute, the type itself is the nest host, but this is NOT recorded in this map.

  13. abstract val overridingMethods: Map[Method, Set[Method]]

    Stores for each non-private, non-initializer method the set of methods which override a specific method.

    Stores for each non-private, non-initializer method the set of methods which override a specific method. If the given method is a concrete method, this method is also included in the set of overridingMethods.

    Attributes
    protected[this]

Concrete Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @IntrinsicCandidate()
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  8. def findMaximallySpecificSuperinterfaceMethods(superinterfaceTypes: UIDSet[ObjectType], name: String, descriptor: MethodDescriptor, analyzedSuperinterfaceTypes: UIDSet[ObjectType]): (UIDSet[ObjectType], Set[Method])

    Computes the maximally specific superinterface method with the given name and descriptor

    Computes the maximally specific superinterface method with the given name and descriptor

    superinterfaceTypes

    A set of interfaces which potentially declare a method with the given name and descriptor.

  9. def findMaximallySpecificSuperinterfaceMethods(superinterfaceType: ObjectType, name: String, descriptor: MethodDescriptor, analyzedSuperinterfaceTypes: UIDSet[ObjectType] = UIDSet.empty): (UIDSet[ObjectType], Set[Method])

    Computes the set of maximally specific superinterface methods with the given name and descriptor.

    Computes the set of maximally specific superinterface methods with the given name and descriptor.

    Note

    This method does not consider methods defined by java.lang.Object! Those methods have precedence over respective methods defined by superinterfaces! A corresponding check needs to be done before calling this method.

  10. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @IntrinsicCandidate()
  11. def hasVirtualMethod(objectType: ObjectType, method: Method): Answer

    Tests if the given method belongs to the interface of an object identified by the given objectType.

    Tests if the given method belongs to the interface of an object identified by the given objectType. I.e., returns true if a virtual method call, where the receiver type is known to have the given objectType, would lead to the direct invocation of the given method. The given method can be an inherited method, but it will never return Yes if the given method is overridden by objectType or a supertype of it which is a sub type of the declaring type of method.

    Note

    The computation is based on the computed set of instanceMethods and generally requires at most O(n log n) steps where n is the number of callable instance methods of the given object type; the class hierarchy is not traversed.

  12. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @IntrinsicCandidate()
  13. def instanceCall(callerClassType: ObjectType, receiverType: ReferenceType, name: String, descriptor: MethodDescriptor): Result[Method]

    Returns the (instance) method that would be called when we have an instance of the given receiver type.

    Returns the (instance) method that would be called when we have an instance of the given receiver type. I.e., using this method is suitable only when the runtime type, which is the receiver of the method call, is precisely known!

    Examples

    class A {def foo() = {} }
    class B extends A {/*inherits, but does not override foo()*/}
    class C extends B { def foo() = {} }
    val b = new B();
    b.foo() // <= in this case the method defined by A will be returned.
    val c = new C();
    c.foo() // <= in this case the method defined by C will be returned.

    This method supports default methods and signature polymorphic calls; i.e., the descriptor of the retuned methods may not be equal to the given method descriptor.

    callerClassType

    The object type which defines the method which performs the call. This information is required if the call target has (potentially) default visibility. (Note that this - in general - does not replace the need to perform an accessibility check.)

    receiverType

    A class type or an array type; never an interface type.

  14. def interfaceCall(callerType: ObjectType, declaringClass: ObjectType, name: String, descriptor: MethodDescriptor): Set[Method]

    Returns the methods that may be called by an org.opalj.br.instructions.INVOKEINTERFACE call if the precise runtime type is not known.

    Returns the methods that may be called by an org.opalj.br.instructions.INVOKEINTERFACE call if the precise runtime type is not known. (If the precise runtime type is known, use instanceCall to get the target method.)

    returns

    The set of potentially called methods. The set will be empty if the target class is not defined as part of the analyzed code base.

    Note

    Caching the result (in particular when the call graph is computed) is recommended as the computation is expensive. In other words, this function is meant to be used as a foundation for call graph construction algorithms.

    ,

    Keep in mind that the following is legal (byte)code:

    class X { void m(){ System.out.println("X.m"); } }
    interface I { void m(); }
    class Z extends X implements I {}

    Hence, we also have to consider inherited methods and just considering the methods defined by subclasses is not sufficient! In other words, the result can contain methods (here, X.m) defined by classes which are not subtypes of the given interface type!

  15. def interfaceCall(callerType: ObjectType, i: INVOKEINTERFACE): Set[Method]
  16. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  17. def isSignaturePolymorphic(definingClassType: ObjectType, name: String, descriptor: MethodDescriptor): Boolean

    Returns true if the signature is a signature polymorphic method for the given class type.

    Returns true if the signature is a signature polymorphic method for the given class type. (See JVM 9 Spec. for details.)

  18. def isSignaturePolymorphic(definingClassType: ObjectType, descriptor: MethodDescriptor): Boolean

    Returns true if the descriptor is a signature polymorphic method for the given class type.

    Returns true if the descriptor is a signature polymorphic method for the given class type. (See JVM 9 Spec. for details.)

  19. def isSignaturePolymorphic(definingClassType: ObjectType, method: Method): Boolean

    Returns true if the method defined by the given class type is a signature polymorphic method.

    Returns true if the method defined by the given class type is a signature polymorphic method. (See JVM 9 Spec. for details.)

  20. def lookupVirtualMethod(callingContextType: ObjectType, receiverType: ObjectType, name: String, descriptor: MethodDescriptor): Result[MethodDeclarationContext]

    Looks up the method (declaration context) which is accessible/callable by an org.opalj.br.instructions.INVOKEVIRTUAL or org.opalj.br.instructions.INVOKEINTERFACE call which was done by a method belonging to callingContextType.

    Looks up the method (declaration context) which is accessible/callable by an org.opalj.br.instructions.INVOKEVIRTUAL or org.opalj.br.instructions.INVOKEINTERFACE call which was done by a method belonging to callingContextType. The callingContextType is only relevant in case the target method has default visibility; in this case it is checked whether the caller belongs to the same context.

    returns

    Success if the method is found; Empty$ if the method cannot be found and Failure$ if the method cannot be found because the project is definitively inconsistent. Failure$ is used on a best-effort basis.

    Note

    This method uses the pre-computed information about instance methods and, therefore, does not require a type hierarchy based lookup.

    ,

    It supports the lookup of polymorphic methods.

  21. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  22. def nonVirtualCall(callerClassType: ObjectType, i: NonVirtualMethodInvocationInstruction): Result[Method]
  23. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @IntrinsicCandidate()
  24. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @IntrinsicCandidate()
  25. def overriddenBy(m: Method): Set[Method]

    Returns the set of methods which directly override the given method.

    Returns the set of methods which directly override the given method. Note that overriddenBy is not context aware. I.e., if a given method m is an interface method, then it may happen that we have an implementation of that method in a class which is inherited from a superclass which is not a subtype of the interface. That method - since it is not defined by a subtype of the interface - would not be included in the returned set. An example is shown next:

    class X { void m(){ System.out.println("X.m"); }
    interface Y { default void m(){ System.out.println("Y.m"); }
    class Z extends X implements Y {
     // Z inherits m() from X; hence, X.m() (in this context) "overrides" Y.m(), but is not
     // returned by this function. To also identify X.m() you have to combine the results
     // of overridenBy and instanceMethods(!).
    }
  26. def requiredJVMVersion: Int

    Returns the minimum version number of the JVM required to run the code of the project, i.e., the maximum class file major version number of any class file in the project.

  27. def resolveAllMethodReferences(declaringClassType: ReferenceType, name: String, descriptor: MethodDescriptor): Set[Method]

    Resolves a method reference to all possible methods.

    Resolves a method reference to all possible methods. I.e., this is identical to resolveMethodReference or resolveInterfaceMethodReference for class and interface types respectively except for the case where there are multiple maximally specific interface methods in which case all of them are returned instead of only a single one.

    declaringClassType

    The type of the object that receives the method call. The type may be a class or interface type.

    returns

    The set of resolved methods; empty if the resolution fails, more than one if resolution finds several maximally specific interface methods - in the latter case it is not possible to call the method on objects of the declaring class type, but only on subclasses overriding the method uniquely.

  28. def resolveClassMethodReference(receiverType: ObjectType, name: String, descriptor: MethodDescriptor): Result[Method]

    Resolves a symbolic reference to a method defined by a class (not interface) type.

    Resolves a symbolic reference to a method defined by a class (not interface) type.

    returns

    org.opalj.Success(method) if the method was found; Empty if the project is incomplete and the method could not be found; Failure if the method could not be found though the project is seemingly complete. I.e., if Failure is returned the method is not defined by a concrete class and is either a default method defined by an interface or the analyzed code basis is inconsistent.

  29. final def resolveFieldReference(fieldAccess: FieldAccess): Option[Field]

  30. def resolveFieldReference(declaringClassFile: ClassFile, fieldName: String, fieldType: FieldType): Option[Field]

    Resolves a symbolic reference to a field.

    Resolves a symbolic reference to a field. Basically, the search starts with the given class c and then continues with c's superinterfaces before the search is continued with c's superclass (as prescribed by the JVM specification for the resolution of unresolved symbolic references).

    Resolving a symbolic reference is particularly required to, e.g., get a field's annotations or to get a field's value (if it is static, final and has a constant value).

    declaringClassFile

    The class (or a superclass thereof) that is expected to define the specified field.

    fieldName

    The name of the field.

    fieldType

    The type of the field (the field descriptor).

    Note

    This implementation does not check for IllegalAccessError. This check needs to be done by the caller. The same applies for the check that the field is non-static if get-/putfield is used and static if a get-/putstatic is used to access the field. In the latter case the JVM would throw a LinkingException. Furthermore, if the field cannot be found, it is the responsibility of the caller to handle that situation.

    ,

    Resolution is final. I.e., either this algorithm has found the defining field or the field is not defined by one of the loaded classes. Searching for the field in subclasses is not meaningful as it is not possible to override fields.

  31. final def resolveFieldReference(declaringClassType: ObjectType, fieldName: String, fieldType: FieldType): Option[Field]

  32. def resolveInterfaceMethodReference(i: INVOKEINTERFACE): Option[Method]

    See #resolveInterfaceMethodReference(declaringClassType:* for details.

  33. def resolveInterfaceMethodReference(declaringClassType: ObjectType, name: String, descriptor: MethodDescriptor): Option[Method]
  34. def resolveMethodReference(i: INVOKEVIRTUAL): Option[Method]

    See #resolveMethodReference(declaringClassType:* for details.

  35. def resolveMethodReference(declaringClassType: ReferenceType, name: String, descriptor: MethodDescriptor, forceLookupInSuperinterfacesOnFailure: Boolean = false): Option[Method]

    Tries to resolve a method reference as specified by the JVM specification.

    Tries to resolve a method reference as specified by the JVM specification. I.e., the algorithm tries to find the class that actually declares the referenced method. Resolution of signature polymorphic method calls is also supported.

    This method can be used as the basis for the implementation of the semantics of the invokeXXX instructions. However, it does not check whether the resolved method can be accessed by the caller or if it is abstract. Additionally, it is still necessary that the caller makes a distinction between the statically (at compile time) identified declaring class and the dynamic type of the receiver in case of invokevirtual and invokeinterface instructions. I.e., additional processing is necessary on the client side.

    declaringClassType

    The type of the object that receives the method call. The type must be a class type and must not be an interface type. No check w.r.t. a potential IncompatibleClassChangeError is done by this method.

    forceLookupInSuperinterfacesOnFailure

    If true (default: false) the method tries to look up the method in a super interface if it can't find it in the available super classes.

    returns

    The resolved method Some(METHOD) or None. (To get the defining class file use the project's respective method.)

    Note

    This method just resolves a method reference. Additional checks, such as whether the resolved method is accessible, may be necessary.

  36. def specialCall(callerClassType: ObjectType, initialDeclaringClassType: ObjectType, isInterface: Boolean, name: String, descriptor: MethodDescriptor): Result[Method]

    Returns the instance method/initializer which is called by an invokespecial instruction.

    Returns the instance method/initializer which is called by an invokespecial instruction.

    returns

    One of the following three values:

    • org.opalj.Success (method) if the method was found;
    • Failure if the project is inconsistent; i.e., the target class file is found, but the method cannot be found. Failure is returned on a best effort basis.
    • Empty.
    Note

    Virtual method call resolution is not necessary; the call target is either a constructor, a method in the given class or a super method/constructor. However, in the first and last case it may be possible that we can't find the method because of an inconsistent or incomplete project.

  37. def specialCall(callerClassType: ObjectType, i: INVOKESPECIAL): Result[Method]
  38. def staticCall(callerClassType: ObjectType, declaringClassType: ObjectType, isInterface: Boolean, name: String, descriptor: MethodDescriptor): Result[Method]

    Returns the method that will be called by the respective invokestatic call.

    Returns the method that will be called by the respective invokestatic call.

    returns

    org.opalj.Success (method) if the method was found; Failure if the project is inconsistent. Empty if the method could not be found in the available classes (i.e., the project is incomplete).

  39. def staticCall(callerClassType: ObjectType, i: INVOKESTATIC): Result[Method]

    Returns the method which will be called by the respective org.opalj.br.instructions.INVOKESTATIC instruction.

  40. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  41. def toString(): String
    Definition Classes
    AnyRef → Any
  42. def virtualCall(callerType: ObjectType, declaringType: ReferenceType, name: String, descriptor: MethodDescriptor): Set[Method]

    Returns the set of methods that may be called by an invokevirtual call, if the receiver type is unknown or effectively encompasses all subtypes it is recommended to use instanceCall.

    Returns the set of methods that may be called by an invokevirtual call, if the receiver type is unknown or effectively encompasses all subtypes it is recommended to use instanceCall.

    Note

    As in case of instance call, the returned method may have a different descriptor if we have a signature polymorphic call!

  43. def virtualCall(callerType: ObjectType, i: INVOKEVIRTUAL): Set[Method]

    Convenience method; see virtualCall(callerPackageName:String,declaringType:ReferenceType* for details.

  44. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  45. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  46. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

Inherited from ClassFileRepository

Inherited from AnyRef

Inherited from Any

Ungrouped