class ClassHierarchy extends AnyRef
Represents a project's class hierarchy. The class hierarchy only contains
information about those classes that were explicitly added to it. Hence, the class hierarchy
may contain holes. However, the type java.lang.Object is always part of the class hierarchy.
Thread safety
This class is effectively immutable; concurrent access to the class hierarchy is supported.
- Source
- ClassHierarchy.scala
- Note
Java 9 module definitions are completely ignored.
,Unless explicitly documented, it is an error to pass an instance of
ClassTypeto any method if theClassTypewas not previously added. If in doubt, first check if the type is known (isKnown/ifKnown).
- Alphabetic
- By Inheritance
- ClassHierarchy
- 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 allSubclassTypes(classType: ClassType, reflexive: Boolean): Iterator[ClassType]
Returns all (direct and indirect) subclass types of the given class type.
Returns all (direct and indirect) subclass types of the given class type.
- Note
No explicit
isKnowncheck is required; if the type is unknown, an empty iterator is returned.
- def allSubtypes(classType: ClassType, reflexive: Boolean): Set[ClassType]
The set of all class- and interface-types that (directly or indirectly) inherit from the given type.
The set of all class- and interface-types that (directly or indirectly) inherit from the given type.
- classType
An
ClassType.- reflexive
If
truethe given type is also included in the returned set.- returns
The set of all direct and indirect subtypes of the given type.
- Note
No explicit
,isKnowncheck is required; if the type is unknown the returned set will be empty unlessreflexiveis true.If you don't need the set, it is more efficient to use
,foreachSubtype.If the type hierarchy is not complete, the answer may also be incomplete. E.g., if x inherits from y and y inherits from z, but y is not known to the class hierarchy then x will not be in the set of all (known) subtypes of z.
- def allSubtypesForeachIterator(classType: ClassType, reflexive: Boolean): ForeachRefIterator[ClassType]
- def allSubtypesIterator(classType: ClassType, reflexive: Boolean): Iterator[ClassType]
- def allSuperclassTypesInInitializationOrder(classType: ClassType): QualifiedCollection[List[ClassType]]
Returns the list of all super types in initialization order.
Returns the list of all super types in initialization order. I.e., it will return the top level super class first - i.e.,
java.lang.Objectand then all sub class types.If the given type is
java.lang.Object, the empty list is returned.Interfaces are not further considered, because they generally don't need any instance initialization. If the given type is an interface type, the returned list will hence only contain
java.lang.Object.- Note
If the class hierarchy is not complete, it may happen that the super class chain is not complete. In this case an org.opalj.collection.IncompleteCollection will be returned.
- def allSuperclassesIterator(ct: ClassType, reflexive: Boolean = false)(implicit project: ClassFileRepository): Iterator[ClassFile]
Efficient, best-effort iterator over all super types of the given type.
- def allSuperinterfacetypes(classType: ClassType, reflexive: Boolean = false): UIDSet[ClassType]
Returns the set of all interfaces directly or indirectly implemented by the given type.
Returns the set of all interfaces directly or indirectly implemented by the given type.
- reflexive
If
truethe returned set will also contain the given type if it is an interface type.
- Exceptions thrown
NullPointerExceptionif the project is very broken (e.g., if a class states that it inherits from class C, but class C is actually an interface).
- def allSupertypes(classType: ClassType, reflexive: Boolean = false): UIDSet[ClassType]
The set of all supertypes of the given type.
The set of all supertypes of the given type.
- reflexive
If
true, the returned set will also contain the given type.
- Note
Whenever possible, one of the higher-order functions should be used to avoid the creation of intermediate data-structures.
- def allSupertypesOf(types: UIDSet[ClassType], reflexive: Boolean): UIDSet[ClassType]
Calculates the set of all supertypes of the given
types. - final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def asTSV: String
A dump of the class hierarchy information in TSV format.
A dump of the class hierarchy information in TSV format. The following information will be dumped:
- type
- id
- (is) interface
- (is) final
- (is) root type
- (is) leaf type
- (is) supertype information complete
- super class
- super interfaces
- sub classes
- sub interfaces
- final def canBeStoredIn(elementValueType: FieldType, elementValueTypeIsPrecise: Boolean, arrayType: ArrayType, arrayTypeIsPrecise: Boolean): Answer
Determines if a value of type
elementValueTypecan be stored in an array of typearrayType.Determines if a value of type
elementValueTypecan be stored in an array of typearrayType. E.g., a value of typeIntegerTypecan be stored in an array (one-dimensional) of typeArrayType(IntegerType). This method takes the fact that a type may just model an upper type bound into account.- elementValueType
The type of the value that should be stored in the array. This type is compared against the component type of the array.
- elementValueTypeIsPrecise
Specifies if the type information is precise; i.e., whether
elementValueTypemodels the precise runtime type (true) or just an upper bound (false). If theelementValueTypeis a base/ primitive type, then this value should betrue; but actually it is ignored.- arrayType
The type of the array.
- arrayTypeIsPrecise
Specifies if the type information is precise; i.e., whether arrayType models the precise runtime type (
true) or just an upper bound (false).
- Annotations
- @tailrec()
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @IntrinsicCandidate()
- def directSubclassesOf(classType: ClassType): UIDSet[ClassType]
- def directSubinterfacesOf(classType: ClassType): UIDSet[ClassType]
- def directSubtypesCount(classTypeId: Int): Int
- def directSubtypesCount(classType: ClassType): Int
- def directSubtypesOf(upperTypeBound: UIDSet[ClassType]): UIDSet[ClassType]
Computes the set of types which are subtypes (reflexive) of all types identified by the given
upper type bound.Computes the set of types which are subtypes (reflexive) of all types identified by the given
upper type bound. E.g., the class X which implements I and J, would be a direct subtype of the upper type bound consisting of I and J. If the bound consists of only one type, then the bound is returned.- upperTypeBound
A set of types that are in no inheritance relationship.
upperTypeBoundmust not be empty.
- def directSubtypesOf(classType: ClassType): Iterator[ClassType]
The direct subtypes of the given type (not reflexive).
- def directSuperinterfacesOf(classType: ClassType): UIDSet[ClassType]
- def directSupertypes(classType: ClassType): UIDSet[ClassType]
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def existsSubclass(classType: ClassType, project: ClassFileRepository)(p: (ClassFile) => Boolean): Boolean
Tests if a subtype of the given
ClassTypeexists that satisfies the given predicate.Tests if a subtype of the given
ClassTypeexists that satisfies the given predicate. In this case the subtype relation is not reflexive.Subtypes for which no
ClassFileobject is available are ignored.- Note
No explicit
isKnowncheck is required; if the type is unknown nothing will happen.
- def foreachDirectSubclassType[T](classType: ClassType, project: ClassFileRepository)(f: (ClassFile) => T): Unit
Executes the given function
ffor each known direct subclass of the givenClassType.Executes the given function
ffor each known direct subclass of the givenClassType. In this case the subclass relation is not reflexive and interfaces inheriting from the given class type are ignored.Subtypes for which no
ClassFileobject is available are ignored.- Note
No explicit
isKnowncheck is required; if the type is unknown nothing will happen.
- def foreachDirectSubtypeOf[U](classType: ClassType)(f: (ClassType) => U): Unit
- def foreachDirectSupertype(classType: ClassType)(f: (ClassType) => Unit): Unit
- def foreachDirectSupertypeCF[U](classType: ClassType)(f: (ClassFile) => U)(implicit project: ClassFileRepository): Unit
- def foreachKnownType[T](f: (ClassType) => T): Unit
Calls the given function
ffor each type that is known to the class hierarchy. - def foreachSubclass(classType: ClassType, project: ClassFileRepository)(f: (ClassFile) => Unit): Unit
Executes the given function
ffor each subclass of the givenClassType.Executes the given function
ffor each subclass of the givenClassType. In this case the subclass relation is not reflexive. Furthermore, it may be possible that f is invoked multiple times using the sameClassFileobject if the given classType identifies an interface.Subtypes for which no
ClassFileobject is available are ignored.- Note
No explicit
,isKnowncheck is required; if the type is unknown nothing will happen.For details regarding incomplete class hierarchies see
foreachSubtype.
- def foreachSubinterfaceType(interfaceType: ClassType)(f: (ClassType) => Boolean): Unit
Iterates over all subinterfaces of the given interface type (or java.lang.Object) until the callback function returns "false".
- def foreachSubtype(classType: ClassType, reflexive: Boolean = false)(process: (ClassType) => Boolean): Unit
Iterates over all subtypes of the given type, by first iterating over the subclass types and then iterating over the subinterface types (if the given class type defines an interface or identifies
java.lang.Object).Iterates over all subtypes of the given type, by first iterating over the subclass types and then iterating over the subinterface types (if the given class type defines an interface or identifies
java.lang.Object).- process
The process function will be called for each subtype of the given type. If process returns false, subtypes of the current type will no longer be traversed. However, if a subtype of the current type is reachable via another path (by means of interface inheritance) then that subtype may be processed.
- Note
Classes are always traversed first.
- def foreachSubtype(classType: ClassType)(f: (ClassType) => Unit): Unit
Calls the function
ffor each known (direct or indirect) subtype of the given type.Calls the function
ffor each known (direct or indirect) subtype of the given type.- classType
An
ClassType.
- Note
No explicit
,isKnowncheck is required; if the type is unknown nothing will happen.For details regarding incomplete class hierarchies see allSubtypes. *
- def foreachSubtypeCF(classType: ClassType, reflexive: Boolean = false)(process: (ClassFile) => Boolean)(implicit project: ClassFileRepository): Unit
- def foreachSuperclass(classType: ClassType, project: ClassFileRepository)(f: (ClassFile) => Unit): Unit
Calls the function
ffor each supertype of the given class type for which the classfile is available.Calls the function
ffor each supertype of the given class type for which the classfile is available.It is possible that the class file of the same super interface type
Iis passed multiple times tofwhenIis implemented multiple times by the given type's supertypes.The algorithm first iterates over the type's super classes before it iterates over the super interfaces.
- Note
See foreachSupertype for details.
- def foreachSuperinterfaceType(t: ClassType)(f: (ClassType) => Boolean): Unit
Iterates over all direct and indirect (also by means of super classes) superinterfaces of the type until the callback function returns "false".
- def foreachSupertype(ct: ClassType, reflexive: Boolean = false)(f: (ClassType) => Unit): Unit
Calls the given function
ffor each of the given type's supertypes. - final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
- final def getClassType(classTypeId: Int): ClassType
Returns the
ClassTypewith the given Id.Returns the
ClassTypewith the given Id. The id has to be the id of a valid ClassType. - def getSupertypeDeclaration(subtype: ClassSignature, supertype: ClassType)(implicit project: ClassFileRepository): Option[ClassTypeSignature]
Determines whether the given ClassSignature of
subtypeimplements or extends the givensupertype.Determines whether the given ClassSignature of
subtypeimplements or extends the givensupertype. In case that thesubtypedoes implement or extend thesupertype, anOptionof ClassTypeSignature is returned. Otherwise None will be returned.- subtype
Any type or interface.
- supertype
Any type or interface.
- returns
Optionof ClassTypeSignature if thesubtypeextends or implements the givensupertype,Noneotherwise.
subtype: ClassSignature from class A where A extends List<String> supertype: List as ClassType This method scans all super classes and super interfaces of A in order to find the concrete class declaration of List where it is bound to String. The above example would yield the ClassTypeSignature of List<String>.
Example: - def hasSubtypes(classType: ClassType): Answer
Returns
Yesif the class hierarchy contains subtypes of the given type andNoif it contains no subtypes.Returns
Yesif the class hierarchy contains subtypes of the given type andNoif it contains no subtypes.Unknownis returned if the given type is not known.Please note, that the answer will be
Noeven though the (running) project contains (in)direct subtypes of the given type, but the class hierarchy is not complete. I.e., not all class files (libraries) used by the project are analyzed. A second case is that some class files are generated at runtime that inherit from the givenClassType.- classType
Some
ClassType.
- Note
No explicit
isKnowncheck is required.
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
- final def ifKnown[T](classType: ClassType)(f: (ClassType) => T): Option[T]
Tests if the given classType is known and if so executes the given function.
Tests if the given classType is known and if so executes the given function.
- Annotations
- @inline()
ifKnown(ClassType.Serializable){isDirectSupertypeInformationComplete}
Example: - def isASubtypeOf(subtype: ClassTypeSignature, supertype: FormalTypeParameter)(implicit p: ClassFileRepository): Answer
Determines if the given class or interface type encoded in a ClassTypeSignature
subtypeis actually a subtype of the class, interface or intersection type encoded in the FormalTypeParameter of thesupertypeparameter.Determines if the given class or interface type encoded in a ClassTypeSignature
subtypeis actually a subtype of the class, interface or intersection type encoded in the FormalTypeParameter of thesupertypeparameter. The subtype relation is fulfilled if the subtype is a subtype of the class bound and/or all interface types that are prescribed by the formal type specification.- subtype
Any
ClassTypeSignature.- supertype
Any
FormalTypeParameter.- returns
Yesifsubtypeis a subtype of the givensupertype.Noifsubtypeis not a subtype ofsupertypeandUnknownif the analysis is not conclusive. The latter can happen if the class hierarchy is not complete and hence precise information about a type's supertypes is not available.
- Note
This method does consider generics types specified within the FormalTypeParameter.
- def isASubtypeOf(subtype: ClassTypeSignature, supertype: ClassTypeSignature)(implicit project: ClassFileRepository): Answer
Determines if the given class or interface type encoded by the ClassTypeSignature
subtypeis actually a subtype of the class or interface type encoded in the ClassTypeSignature of thesupertype.Determines if the given class or interface type encoded by the ClassTypeSignature
subtypeis actually a subtype of the class or interface type encoded in the ClassTypeSignature of thesupertype.- subtype
Any
ClassTypeSignature.- supertype
Any
ClassTypeSignature.- returns
Yesifsubtypeis a subtype of the givensupertype.Noifsubtypeis not a subtype ofsupertypeandUnknownif the analysis is not conclusive. The latter can happen if the class hierarchy is not complete and hence precise information about a type's supertypes is not available.
Introduction
Before looking in some examples, we have to set up the terminology. Type definition: List<String, ? extends Number, ?> ContainerType - A ContainerType is a type with parameters. In the previous type definition is
Listthe ContainerType. TypeArgument - A TypeArgument is one of the parameters of the ContainerType. The above type definition has three TypeArguments. (String, ? extends Number and ?) VarianceIndicator - A VarianceIndicator is defined in the context of TypeArguments. There is a CovariantIndicator which can be defined in the type definition by using theextendskeyword. (? extends Number is a covariant TypeArgument). The other one is the ContravariantIndicator which is defined using thesuperkeyword. , 1
instance // definition subtype: List<String> // List<E> supertype: List<String> // List<E> If the ContainerType of the
subtypeis equal to the ContainerType of thesupertypeand non of the TypeArguments has a VarianceIndicator, then exists a subtype relation if and only if all of the TypeArguments are equal. , 2
subtype: SomeClass // SomeClass extends SomeInterface<String> supertype: SomeInterface<String> // SomeInterface<E> Is the
subtypea ConcreteType without org.opalj.br.FormalTypeParameters and thesupertypeis a GenericType then we first have to check whether thesubtypeis a subtype of the givensupertype. If not, then thesubtypeis not an actual subtype of the givensupertype. Otherwise we have to find the definition of thesupertypein the type definition or the type definition of a super class or a super interface (interface definition of SomeInterface<String>). Once found thesupertype, we can compare all TypeArguments of the supertype definition of thesubtypeand the givensupertype. (We are comparing String and String in this example) If all of them are equal,subtypeis an actual subtype of thesupertype. , 3
subtype: Foo<Integer, String> // Foo<T,E> extends Bar<E> supertype: Bar<String> // Bar<E> Does the
subtypeandsupertypehave FormalTypeParameters and the ContainerType of thesubtypeis a subtype of the ContainerType of thesupertype, we have to compare the shared TypeArguments. In our example the subtype Foo has two FormalTypeParameter (T,E) and the supertype Bar has only one FormalTypeParameter (E). Since both of them specify E in the ClassSignature of Foo, they share E as FormalTypeParameter. So it is necessary to check whether the actual bound TypeArgument at the position of E is equal. At first we have to locate the shared parameter in the ClassSignature, so it is possible to find the correct TypeArguments. The above example shows that the shared parameter E is in the second position of the FormalTypeParameters of Foo and at the first position of the FormalTypeParameters of Bar. Second and last we know can compare the according TypeArguments. All other parameters can be ignored because they are no important to decide the subtype relation.- Note
This method relies – in case of a comparison of non generic types – on
isSubtypeOf(org.opalj.br.ClassType,org.opalj.br.ClassType)ofProjectwhich performs an upwards search only. E.g., given the following type hierarchy:class D inherits from Cclass E inherits from Dand the query isSubtypeOf(D,E) the answer will beUnknownifCisUnknownandNootherwise.
Examples: - def isASubtypeOf(subtypes: UIDSet[_ <: ReferenceType], supertype: ReferenceType): Answer
- def isASubtypeOf(subtype: ReferenceType, supertypes: UIDSet[_ <: ReferenceType]): Answer
Returns
Yesif the subtype is a subtype of all given supertypes.Returns
Yesif the subtype is a subtype of all given supertypes. Hence, supertypes should not contain more than one class type. - def isASubtypeOf(subtypes: UIDSet[_ <: ReferenceType], supertypes: UIDSet[_ <: ReferenceType]): Answer
Determines if the type described by the first set of upper type bounds is a subtype of the second type.
Determines if the type described by the first set of upper type bounds is a subtype of the second type. I.e., it checks, if for all types of the
subtypesupper type bound, a type in thesupertypestype exists that is a supertype of the respective subtype. Ifsubtypesis empty,Yeswill be returned; an empty upper type bound is expected to modelnull. - final def isASubtypeOf(subtype: ReferenceType, supertype: ReferenceType): Answer
Determines if
subtypeis a subtype ofsupertypeusing this class hierarchy.Determines if
subtypeis a subtype ofsupertypeusing this class hierarchy.This method can be used as a foundation for implementing the logic of the JVM's
instanceofandclasscastinstructions. But, in both cases additional logic for handlingnullvalues and for considering the runtime type needs to be implemented by the caller of this method.- subtype
Any class, interface or array type.
- supertype
Any class, interface or array type.
- returns
Yesifsubtypeis indeed a subtype of the givensupertype.Noifsubtypeis not a subtype ofsupertypeandUnknownif the analysis is not conclusive. The latter can happen if the class hierarchy is not completely available and hence precise information about a type's supertypes is not available.
- Annotations
- @tailrec()
- Note
The answer
Nodoes not necessarily imply that two runtime values for which the given types are only upper bounds are not (w.r.t. their runtime types) in a subtype relation. E.g., ifsubtypedenotes the typejava.util.Listandsupertypedenotes the typejava.util.ArrayListthen the answer is clearlyNo. But, at runtime, this may not be the case. I.e., only the answerYesis conclusive. In case ofNofurther information needs to be taken into account by the caller to determine what it means that the (upper) type (bounds) of the underlying values are not in an inheritance relation.
- def isASubtypeOf(subtype: ClassType, theSupertype: ClassType): Answer
Determines if the given class or interface type
subtypeis actually a subtype of the class or interface typesupertype.Determines if the given class or interface type
subtypeis actually a subtype of the class or interface typesupertype.This method can be used as a foundation for implementing the logic of the JVM's
instanceofandcheckcastinstructions. But, in that case additional logic for handlingnullvalues and for considering the runtime type needs to be implemented by the caller of this method.- subtype
Any
ClassType.- theSupertype
Any
ClassType.- returns
Yesifsubtypeis a subtype of the givensupertype.Noifsubtypeis not a subtype ofsupertypeandUnknownif the analysis is not conclusive. The latter can happen if the class hierarchy is not complete and hence precise information about a type's supertypes is not available.
- Note
No explicit
isKnowncheck is required.
- def isDirectSuperclassTypeInformationComplete(classType: ClassType): Boolean
Returns
trueif the type hierarchy information related to the given type's supertypes is complete.Returns
trueif the type hierarchy information related to the given type's supertypes is complete.- Annotations
- @inline()
- Note
No explicit
isKnowncheck is required.
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def isInterface(classType: ClassType): Answer
Returns
trueif the givenclassTypeis known and defines an interface type.Returns
trueif the givenclassTypeis known and defines an interface type.- classType
An
ClassType.
- Annotations
- @inline()
- Note
No explicit
isKnowncheck is required.
- final def isKnown(classTypeId: Int): Boolean
- Annotations
- @inline()
- final def isKnown(classType: ClassType): Boolean
Returns
trueif the class hierarchy has some information about the given type.Returns
trueif the class hierarchy has some information about the given type.- Annotations
- @inline()
- Note
Consider using isKnown(classTypeId : Int) if you need the object ids anyway.
- def isKnownToBeFinal(referenceType: ReferenceType): Boolean
Returns
trueif the given type is known and isfinal.Returns
trueif the given type is known and isfinal. I.e., the declaring class was explicitly declared final or – if the type identifies an array type – the component type is either known to be final or is a primitive/base type.- returns
falseis returned if:- the class type/component type is unknown,
- the class type/component type is known not to be final or
- the information about the class type/component type is incomplete
- Annotations
- @inline()
- Note
No explicit
isKnowncheck is required.
- def isKnownToBeFinal(classTypeId: Int): Boolean
- Annotations
- @inline()
- def isKnownToBeFinal(classType: ClassType): Boolean
Returns
trueif the given type isfinal.Returns
trueif the given type isfinal. I.e., the declaring class was explicitly declaredfinaland no subtypes exist.- returns
falseis returned if:- the class type is unknown,
- the class type is known not to be final or
- the information is incomplete
- Annotations
- @inline()
- Note
No explicit
isKnowncheck is required.
- def isSubtypeOf(subtypes: UIDSet[_ <: ReferenceType], supertype: ReferenceType): Boolean
- def isSubtypeOf(subtype: ReferenceType, supertypes: UIDSet[_ <: ReferenceType]): Boolean
Returns
trueif the subtype is a subtype of all given supertypes.Returns
trueif the subtype is a subtype of all given supertypes. Hence, supertypes should not contain more than one class type. - def isSubtypeOf(subtypes: UIDSet[_ <: ReferenceType], supertypes: UIDSet[_ <: ReferenceType]): Boolean
Determines if the type described by the first set of upper type bounds is a subtype of the second type.
Determines if the type described by the first set of upper type bounds is a subtype of the second type. I.e., it checks, if for all types of the
subtypesupper type bound, a type in thesupertypestype exists that is a supertype of the respective subtype. Ifsubtypesis empty,truewill be returned; an empty upper type bound is expected to modelnull. - def isSubtypeOf(subtype: ClassType, theSupertype: ClassType): Boolean
Returns
trueif subtype is a subtype ofsupertype;falseis returned if the subtyping relationship is unknown ORsubtypeis not a subtype ofsupertype.Returns
trueif subtype is a subtype ofsupertype;falseis returned if the subtyping relationship is unknown ORsubtypeis not a subtype ofsupertype.isSubtypeOfis reflexive.See
isASubtypeOfif more precise information about the subtyping relationship is required. - final def isSubtypeOf(subtype: ReferenceType, supertype: ReferenceType): Boolean
Determines if
subtypeis a subtype ofsupertypeusing this class hierarchy.Determines if
subtypeis a subtype ofsupertypeusing this class hierarchy.This method can be used as a foundation for implementing the logic of the JVM's
instanceofandclasscastinstructions. But, in both cases additional logic for handlingnullvalues and for considering the runtime type needs to be implemented by the caller of this method.- subtype
Any class, interface or array type.
- supertype
Any class, interface or array type.
- returns
trueifsubtypeis indeed a subtype of the givensupertype.falseis returned if the typing relation is unknown OR ifsubtypeis definitively not a subtype ofsupertype.
- Annotations
- @tailrec()
- Note
The answer
falsedoes not necessarily imply that two runtime values for which the given types are only upper bounds are not (w.r.t. their runtime types) in a subtype relation. E.g., ifsubtypedenotes the typejava.util.Listandsupertypedenotes the typejava.util.ArrayListthen the answer is clearlyfalse. But, at runtime, this may not be the case. I.e., only the answertrueis conclusive. In case offalsefurther information needs to be taken into account by the caller to determine what it means that the (upper) type (bounds) of the underlying values are not in an inheritance relation.
- final def isSupertypeInformationComplete(classType: ClassType): Boolean
Returns
trueif the type hierarchy has complete information about all supertypes of the given type.Returns
trueif the type hierarchy has complete information about all supertypes of the given type.- Annotations
- @inline()
- Note
No explicit
isKnowncheck is required.
- final def isUnknown(classTypeId: Int): Boolean
- Annotations
- @inline()
- final def isUnknown(classType: ClassType): Boolean
Returns
trueif the type is unknown.Returns
trueif the type is unknown. This istruefor all types that are referred to in the body of a method, but which are not referred to in the declarations of the class files that were analyzed.- Annotations
- @inline()
- Note
Consider using isUnknown(classTypeId : Int) if you need the object ids anyway.
- def joinAnyArrayTypeWithClassType(thatUpperTypeBound: ClassType): UIDSet[ClassType]
Calculates the most specific common supertype of any array type and some class-/interface type.
Calculates the most specific common supertype of any array type and some class-/interface type.
Recall that (Java) arrays implement
CloneableandSerializable. - def joinAnyArrayTypeWithMultipleTypesBound(thatUpperTypeBound: UIDSet[ClassType]): UIDSet[ClassType]
Calculates the most specific common supertype of any array type and some class-/interface type.
Calculates the most specific common supertype of any array type and some class-/interface type.
Recall that (Java) arrays implement
CloneableandSerializable. - def joinArrayType(upperTypeBoundA: ArrayType, upperTypeBoundB: UIDSet[_ <: ReferenceType]): UIDSet[_ <: ReferenceType]
- def joinArrayTypes(thisUpperTypeBound: ArrayType, thatUpperTypeBound: ArrayType): Either[ArrayType, UIDSet[ClassType]]
Calculates the most specific common supertype of two array types.
Calculates the most specific common supertype of two array types.
- returns
Left(<SOME_ARRAYTYPE>)if the calculated type can be represented using anArrayTypeandRight(UIDList(ClassType.Serializable, ClassType.Cloneable))if the two arrays do not have anArrayTypeas a most specific common supertype.
- def joinClassTypes(upperTypeBoundA: ClassType, upperTypeBoundB: ClassType, reflexive: Boolean): UIDSet[ClassType]
Tries to calculate the most specific common supertype of the two given types.
Tries to calculate the most specific common supertype of the two given types. If
reflexiveisfalse, the two types do not have to be in an inheritance relation.If the class hierarchy is not complete, a best guess is made.
- def joinClassTypes(upperTypeBoundA: ClassType, upperTypeBoundB: UIDSet[ClassType], reflexive: Boolean): UIDSet[ClassType]
Tries to calculate the most specific common supertype of the given types.
Tries to calculate the most specific common supertype of the given types. If
reflexiveisfalse, the given types do not have to be in an inheritance relation.- upperTypeBoundB
A list (set) of
ClassTypes that are not in a mutual inheritance relation.- returns
(I) Returns (if reflexive is
true)upperTypeBoundAif it is a supertype of at least one type ofupperTypeBoundB. (II) ReturnsupperTypeBoundBifupperTypeBoundAis a subtype of all types ofupperTypeBoundB. Otherwise a new upper type bound is calculated and returned.
- def joinClassTypesUntilSingleUpperBound(upperTypeBound: UIDSet[ClassType]): ClassType
Given an upper type bound a most specific type that is a common supertype of the given types is determined.
Given an upper type bound a most specific type that is a common supertype of the given types is determined.
- See also
joinClassTypesUntilSingleUpperBound(upperTypeBoundA: ClassType, upperTypeBoundB: ClassType, reflexive: Boolean)for further details.
- def joinClassTypesUntilSingleUpperBound(upperTypeBoundA: ClassType, upperTypeBoundB: ClassType, reflexive: Boolean): ClassType
- def joinReferenceType(upperTypeBoundA: ReferenceType, upperTypeBoundB: UIDSet[_ <: ReferenceType]): UIDSet[_ <: ReferenceType]
- def joinReferenceTypes(upperTypeBoundA: UIDSet[_ <: ReferenceType], upperTypeBoundB: UIDSet[_ <: ReferenceType]): UIDSet[_ <: ReferenceType]
- def joinReferenceTypesUntilSingleUpperBound(upperTypeBound: UIDSet[_ <: ReferenceType]): ReferenceType
- def joinUpperTypeBounds(utbA: UIDSet[_ <: ReferenceType], utbB: UIDSet[_ <: ReferenceType]): UIDSet[_ <: ReferenceType]
- def joinUpperTypeBounds(upperTypeBoundsA: UIDSet[ClassType], upperTypeBoundsB: UIDSet[ClassType], reflexive: Boolean): UIDSet[ClassType]
Calculates the most specific common supertype of the given types.
Calculates the most specific common supertype of the given types. If
reflexiveisfalse, no two types across both sets have to be in an inheritance relation; if in doubt usetrue.- upperTypeBoundsB
A list (set) of
ClassTypes that are not in an inheritance relation if reflexive isfalse.
/* Consider the following type hierarchy: * Object <- Collection <- List * Object <- Collection <- Set * Object <- Externalizable * Object <- Serializable */ Object o = new ... if (...) { Set s = (Set) o; (( Externalizable)s).save(...) // => o(s) has to be a subtype of Set AND Externalizable } else { List l = (List) l; ((Serializable)l).store(...) // => o(l) has to be a subtype of List AND Serializable } // Here, o is either a set or a list. Hence, it is at least a Collection, // but we cannot deduce anything w.r.t. Serializable and Externalizable.
Example: - def leafClassTypesIterator: Iterator[ClassType]
- def leafTypes(types: UIDSet[ClassType]): UIDSet[ClassType]
Selects all types of the given set of types that do not have any subtype in the given set.
Selects all types of the given set of types that do not have any subtype in the given set. If the given set is empty, a set containing
java.lang.Objectis returned. A set which contains only one type will directly be returned.- types
A set of types that contains for each type stored in the set all direct and indirect supertypes or none. For example, the intersection of the sets of all supertypes (as returned, e.g., by
ClassHierarchy.allSupertypes) of two (independent) types satisfies this condition. Iftypesis empty, the returned leaf type isClassType.Object. which should always be a safe fallback.
- val leafTypes: UIDSet[ClassType]
- implicit val logContext: LogContext
- 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 processSubtypes[T](classType: ClassType, reflexive: Boolean = false)(initial: T)(f: (T, ClassType) => (T, Boolean, Boolean)): T
Enables the guided processing of all subtypes of the given type.
Enables the guided processing of all subtypes of the given type. This function enables you to compute some value based on the subtypes of the given type and – at the same time – to control the process of traversing the subtypes.
- initial
The initial value of the computation. This is also the value that will be returned if the given type has no subtypes and
reflexiveisfalse.- f
A function that computes the new value given the current value and which also returns the information whether the computation should be aborted using the current value of type
tor if the subtypes of the current subtype should be traversed. The commented signature offis:f: (T, ClassType) => (T /*result*/ , Boolean /*skip subtypes*/ , Boolean /*abort*/ )
- def rootClassTypesIterator: Iterator[ClassType]
The set of all class types (excluding interfaces) which have no super type or for which the supertype information is incomplete; that is all (pseudo) root types.
The set of all class types (excluding interfaces) which have no super type or for which the supertype information is incomplete; that is all (pseudo) root types. If the class hierarchy is complete, then this set contains exactly one element and that element must identify
java.lang.Object.- Note
The returned root class types are not necessarily a subset of
,rootTypes. A class which has an unknown super class, but implements a known interface is considered to belong to be a root class type but is not a member ofrootTypesbecause some supertype information exists!If we load an application and all the jars used to implement it or a library and all the library it depends on, then the class hierarchy should not contain multiple root types. However, the (complete) JDK contains some references to Eclipse classes which are not part of the JDK.
- def rootInterfaceTypes(collection: Growable[ClassType]): rootInterfaceTypes.collection.type
Iterates over all interfaces which only inherit from
java.lang.Objectand adds the types to the givenGrowablecollection.Iterates over all interfaces which only inherit from
java.lang.Objectand adds the types to the givenGrowablecollection. I.e., iterates over all interfaces which are at the top of the interface inheritance hierarchy. - val rootTypes: UIDSet[ClassType]
- def statistics: String
Returns some statistical data about the class hierarchy.
- def subtypeInformation(classType: ClassType): Option[SubtypeInformation]
Returns the subtype information if the given type is known.
Returns the subtype information if the given type is known. If the given type is unknown
Noneis returned. - def superclassType(classTypeId: Int): ClassType
Returns the supertype of the class type identified by the given class type id or
nullif the type is unknown or if the type has no supertype. - def superclassType(classType: ClassType): Option[ClassType]
Returns the immediate superclass of the given class type, if the given type is known and if it has a superclass.
Returns the immediate superclass of the given class type, if the given type is known and if it has a superclass. I.e., in case of
java.lang.ObjectNone is returned. - def superclasses(classType: ClassType, project: ClassFileRepository)(classFileFilter: (ClassFile) => Boolean = _ => true): Iterable[ClassFile]
Returns the set of all classes/interfaces from which the given type inherits and for which the respective class file is available.
Returns the set of all classes/interfaces from which the given type inherits and for which the respective class file is available.
- returns
An
Iterableover all class files of all super types of the givenclassTypethat pass the given filter and for which the class file is available.
- Note
It may be more efficient to use
foreachSuperclass(ClassType, ClassType => Option[ClassFile])(ClassFile => Unit)
- def superinterfaceTypes(classType: ClassType): Option[UIDSet[ClassType]]
Returns
Some(<SUPERTYPES>)if this type is known and information about the supertypes is available.Returns
Some(<SUPERTYPES>)if this type is known and information about the supertypes is available. I.e., if this type is not known,Noneis returned; if the given type's superinterfaces are known (even if this class does not implement (directly or indirectly) any interface)Some(UIDSet(<CLASSTYPES>))is returned. - def supertypeInformation(classType: ClassType): Option[SupertypeInformation]
Returns the supertype information if the given type is known.
Returns the supertype information if the given type is known. If the given type is unknown
Noneis returned. - def supertypes(classType: ClassType): UIDSet[ClassType]
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toGraph(): Node
Returns a view of the class hierarchy as a graph (which can then be transformed into a dot representation Graphviz).
Returns a view of the class hierarchy as a graph (which can then be transformed into a dot representation Graphviz). This graph can be a multi-graph if the class hierarchy contains holes.
- def toString(): String
- Definition Classes
- ClassHierarchy → AnyRef → Any
- def updatedLogContext(newLogContext: LogContext): ClassHierarchy
- 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
- Deprecated