Package spoon.support.visitor
Class ClassTypingContext
java.lang.Object
spoon.support.visitor.ClassTypingContext
- All Implemented Interfaces:
GenericTypeAdapter
Helper class created from type X or reference to X.
It provides access to actual type arguments
of any super type of type X adapted to type X.
Example:
Example:
//reference to `ArrayList` with actual type argument `Integer` CtTypeReference arrayListRef = ... //ArrayList<Integer> //type java.util.List with type parameter `E` CtType list = ... //List<E> //adapting of type parameter `E` to scope of arrayListRef CtTypeReference typeParamE_adaptedTo_arrayListRef = new ClassTypingContext(arrayListRef).adaptType(list.getFormalCtTypeParameters().get(0)) //the value of `E` in scope of arrayListRef is `Integer` assertEquals(Integer.class.getName(), typeParamE_adaptedTo_arrayListRef.getQualifiedName());
-
Constructor Summary
ConstructorDescriptionClassTypingContext(CtType<?> type)
ClassTypingContext(CtTypeReference<?> typeReference)
-
Method Summary
Modifier and TypeMethodDescriptionadaptType(CtTypeInformation type)
adapts `type` to theCtTypeReference
of the scope of thisGenericTypeAdapter
This mapping function is able to resolveCtTypeParameter
of:
A) input type or any super class or any enclosing class of input type or it's super class
B) super interfaces of input type or super interfaces of it's super classes.
The type reference is adapted recursive including all it's actual type arguments and bounds.protected @Nullable CtTypeReference<?>
adaptTypeParameter(CtTypeParameter typeParam)
adapts `typeParam` to theCtTypeReference
of scope of thisClassTypingContext
In can beCtTypeParameterReference
again - depending actual type arguments of thisClassTypingContext
.protected ClassTypingContext
createEnclosingHierarchy(CtType<?> enclosingType)
might be used to create custom chain of super type hierarchiesprotected ClassTypingContext
createEnclosingHierarchy(CtTypeReference<?> enclosingTypeRef)
might be used to create custom chain of super type hierarchiesCtType<?>
boolean
isOverriding(CtMethod<?> thisMethod, CtMethod<?> thatMethod)
thisMethod overrides thatMethod if 1) thisMethod class is a subclass of thatMethod class 2) thisMethod is a subsignature of thatMethod See http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.4.8.1boolean
isSameSignature(CtExecutable<?> thisExecutable, CtMethod<?> thatExecutable)
Two methods are considered as having the same signature if they have the same name and argument types See https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.4.2boolean
isSubSignature(CtMethod<?> thisMethod, CtMethod<?> thatMethod)
isSubsignature is defined as an oriented relation between two methods as defined in See https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.4.2 thisMethod is subsignature of thatMethod if either A) thisMethod is same signature like thatMethod B) thisMethod is same signature like type erasure of thatMethodboolean
isSubtypeOf(CtTypeReference<?> superTypeRef)
detects if `superTypeRef` is a super type of the type or type reference, which was send to constructor of this instance.@Nullable List<CtTypeReference<?>>
resolveActualTypeArgumentsOf(CtTypeReference<?> typeRef)
resolve actual type argument values of the provided type reference
-
Constructor Details
-
ClassTypingContext
- Parameters:
typeReference
-CtTypeReference
whose actual type arguments are used for resolving of input type parameters
-
ClassTypingContext
- Parameters:
type
-CtType
whose formal type parameters are transformed toCtTypeReference
s, which plays role of actual type arguments, used for resolving of input type parameters
-
-
Method Details
-
getAdaptationScope
- Returns:
- the scope of this type adapter
-
isSubtypeOf
detects if `superTypeRef` is a super type of the type or type reference, which was send to constructor of this instance. It takes into account the actual type arguments of this type and `superTypeRef` So for example:
CtTypeReference listInteger = ...//List<Integer> CtTypeReference listString = ...//List<Integer> assertFalse(new ClassTypingContext(listInteger).isSubtypeOf(listString)) CtTypeReference listExtendsNumber = ...//List<? extends Number> assertTrue(new ClassTypingContext(listInteger).isSubtypeOf(listExtendsNumber))
- Parameters:
superTypeRef
- the reference- Returns:
- true if this type (including actual type arguments) is a subtype of superTypeRef
-
resolveActualTypeArgumentsOf
resolve actual type argument values of the provided type reference- Parameters:
typeRef
- the reference to the type whose actual type argument values has to be resolved in scope of `scope` type- Returns:
- actual type arguments of `typeRef` in scope of `scope` element or null if typeRef is not a super type of `scope`
-
isOverriding
thisMethod overrides thatMethod if 1) thisMethod class is a subclass of thatMethod class 2) thisMethod is a subsignature of thatMethod See http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.4.8.1- Parameters:
thisMethod
- - the scope methodthatMethod
- - to be checked method- Returns:
- true if thisMethod overrides thatMethod
-
isSubSignature
isSubsignature is defined as an oriented relation between two methods as defined in See https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.4.2 thisMethod is subsignature of thatMethod if either A) thisMethod is same signature like thatMethod B) thisMethod is same signature like type erasure of thatMethod- Parameters:
thisMethod
- - the scope method to be checked withthatMethod
- - the checked method- Returns:
- true if thisMethod is subsignature of thatMethod
-
isSameSignature
Two methods are considered as having the same signature if they have the same name and argument types See https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.4.2- Parameters:
thisExecutable
- - the scope method to be checked withthatExecutable
- - the checked method- Returns:
- true if this method and thatMethod has same signature
-
getEnclosingGenericTypeAdapter
- Returns:
- the
GenericTypeAdapter
, which adapts generic types of enclosing type
-
createEnclosingHierarchy
might be used to create custom chain of super type hierarchies -
createEnclosingHierarchy
might be used to create custom chain of super type hierarchies -
adaptTypeParameter
adapts `typeParam` to theCtTypeReference
of scope of thisClassTypingContext
In can beCtTypeParameterReference
again - depending actual type arguments of thisClassTypingContext
.- Parameters:
typeParam
- to be resolvedCtTypeParameter
- Returns:
CtTypeReference
orCtTypeParameterReference
adapted to scope of thisClassTypingContext
or null if `typeParam` cannot be adapted to target `scope`
-
adaptType
Description copied from interface:GenericTypeAdapter
adapts `type` to theCtTypeReference
of the scope of thisGenericTypeAdapter
This mapping function is able to resolveCtTypeParameter
of:
A) input type or any super class or any enclosing class of input type or it's super class
B) super interfaces of input type or super interfaces of it's super classes.
The type reference is adapted recursive including all it's actual type arguments and bounds.- Specified by:
adaptType
in interfaceGenericTypeAdapter
- Parameters:
type
- to be adapted type- Returns:
CtTypeReference
adapted to scope of thisClassTypingContext
or null if type cannot be adapted to this `scope`.
-