Class SelfType
java.lang.Object
org.sonar.plugins.python.api.types.v2.SelfType
- All Implemented Interfaces:
PythonType
Represents typing.Self or typing_extensions.Self type as defined in PEP 673.
The Self type is used to indicate that a method returns an instance of the same type as the enclosing class. This is particularly useful in methods that return instances of the class, such as constructors or builder methods.
Important invariants:
- A SelfType must NOT wrap an ObjectType - instead the ObjectType should wrap the SelfType
- A SelfType must NOT wrap a UnionType - instead the UnionType should wrap the SelfType
Use the static factory method of(PythonType) to create instances, which ensures these invariants are maintained.
- See Also:
-
Field Summary
Fields inherited from interface org.sonar.plugins.python.api.types.v2.PythonType
UNKNOWN -
Method Summary
Modifier and TypeMethodDescriptionbooleanstatic PythonTypefromTypeWrapper(TypeWrapper typeWrapper) inthashCode()booleanisCompatibleWith(PythonType another) key()name()static PythonTypeof(PythonType type) Creates a SelfType wrapping the given type.resolveMember(String memberName) Attempts to resolve a PythonType's member It should return Optional.empty() when the member doesn't exist, and PythonType.UNKNOWN when the member may exist but can't be resolvedtoString()
-
Method Details
-
of
Creates a SelfType wrapping the given type.This factory method ensures the following invariants:
- If the type is null, UNKNOWN, or not a supported type, it returns UNKNOWN
- If the type is already a SelfType, it returns it unchanged
- The type
ObjectType[ClassType[A]]is converted toObjectType[SelfType[ClassType[A]]] - The type ObjectType[UnionType[ClassType[A], ClassType[B]]] is converted to ObjectType[UnionType[SelfType[ClassType[A]], SelfType[ClassType[B]]]]
- The type ClassType[A] is converted to SelfType[ClassType[A]]
- Parameters:
type- the type to wrap in a SelfType (can be null, in which case UNKNOWN is returned)- Returns:
- a PythonType representing Self[type], with proper structure maintained, or UNKNOWN if the type is not supported
-
fromTypeWrapper
-
innerType
-
typeWrapper
-
name
- Specified by:
namein interfacePythonType
-
displayName
- Specified by:
displayNamein interfacePythonType
-
instanceDisplayName
- Specified by:
instanceDisplayNamein interfacePythonType
-
isCompatibleWith
- Specified by:
isCompatibleWithin interfacePythonType
-
key
- Specified by:
keyin interfacePythonType
-
resolveMember
Description copied from interface:PythonTypeAttempts to resolve a PythonType's member It should return Optional.empty() when the member doesn't exist, and PythonType.UNKNOWN when the member may exist but can't be resolved- Specified by:
resolveMemberin interfacePythonType
-
hasMember
- Specified by:
hasMemberin interfacePythonType
-
definitionLocation
- Specified by:
definitionLocationin interfacePythonType
-
unwrappedType
- Specified by:
unwrappedTypein interfacePythonType
-
typeSource
- Specified by:
typeSourcein interfacePythonType
-
equals
-
hashCode
public int hashCode() -
toString
-