resolveType method
Resolves this type by a single level, returning the resolved value or NONE.
This method attempts to resolve one level of type indirection, such as resolving type variables through their bounds or resolving types through type providers and variable resolvers.
Returns:
- ResolvableType representing the resolved type
- ResolvableType.NONE if resolution is not possible
- this if no resolution is needed
Example:
// For a type variable T with bounds
final typeVariable = ResolvableType.forTypeVariable(someTypeVariable);
final resolved = typeVariable.resolveType();
// resolved might be the bound type or a more concrete type
// For array types with unresolved component types
final arrayType = ResolvableType.forArrayComponent(someUnresolvedType);
final resolvedArray = arrayType.resolveType();
// resolvedArray has a resolved component type
// Useful for incremental type resolution
ResolvableType fullyResolve(ResolvableType type) {
ResolvableType current = type;
ResolvableType resolved = current.resolveType();
while (resolved != current && resolved != ResolvableType.NONE) {
current = resolved;
resolved = current.resolveType();
}
return current;
}
Implementation
ResolvableType resolveType() {
if (this == NONE) return NONE;
// Try to resolve the type through the type provider
if (_typeProvider != null) {
final providerType = _typeProvider.getType();
if (providerType != null && providerType != _type) {
return forType(providerType);
}
}
// Try to resolve through variable resolver
if (_variableResolver != null) {
final resolved = _variableResolver.resolveVariable(_type);
if (resolved != null && resolved != this) {
return resolved;
}
}
// Try to resolve generic bounds
if (_isUnresolvableTypeVariable()) {
// For type variables, try to get bounds
final resolved = resolve();
if (resolved != null) {
return forType(resolved.getType());
}
}
// For arrays, ensure component type is resolved
if (isArray() && _componentType == null) {
final componentType = _resolveComponentType();
if (componentType != NONE) {
return ResolvableType._(_type, _typeProvider, _variableResolver, componentType: componentType);
}
}
return this;
}