getSuperType method
Returns a ResolvableType representing the direct supertype of this type.
This method returns the immediate parent class of this type in the inheritance hierarchy. For Object or interface types, this may return ResolvableType.NONE.
Returns:
- ResolvableType representing the direct supertype
- ResolvableType.NONE if no supertype exists
Example:
final stringType = ResolvableType.forClass(String);
final listType = ResolvableType.forClass(List<int>);
final objectType = ResolvableType.forClass(Object);
final stringSuperType = stringType.getSuperType();
print(stringSuperType.resolve()?.getType()); // Object
final listSuperType = listType.getSuperType();
print(listSuperType.resolve()?.getType()); // Object (in Dart)
final objectSuperType = objectType.getSuperType();
print(objectSuperType == ResolvableType.NONE); // true
// Useful for inheritance traversal
void printInheritanceChain(ResolvableType type) {
ResolvableType current = type;
while (current != ResolvableType.NONE) {
print(current.resolve()?.getType());
current = current.getSuperType();
}
}
Implementation
ResolvableType getSuperType() {
final resolved = resolve();
if (resolved == null) return NONE;
try {
final superClass = resolved.getSuperClass();
if (superClass == null) return NONE;
ResolvableType? superType = _superType;
if (superType == null) {
superType = forType(superClass.getType(), this);
_superType = superType;
}
return superType;
} catch (e) {
return NONE;
}
}