asVariableResolver method

VariableResolver? asVariableResolver()

Adapts this ResolvableType to a VariableResolver for type variable resolution.

This method creates a VariableResolver that can be used to resolve type variables in the context of this ResolvableType. This is useful when working with generic types that need to resolve their type parameters.

Returns:

  • VariableResolver instance that can resolve type variables
  • null if this ResolvableType is NONE

Example:

final listType = ResolvableType.forClass(List<String>);
final resolver = listType.asVariableResolver();

// Use resolver to resolve type variables in generic contexts
if (resolver != null) {
  final resolved = resolver.resolveVariable(someTypeVariable);
  print("Resolved type variable to: ${resolved?.resolve()?.getType()}");
}

// Useful for creating type contexts
VariableResolver? createTypeContext(ResolvableType contextType) {
  return contextType.asVariableResolver();
}

Implementation

VariableResolver? asVariableResolver() {
  if (this == NONE) return null;
  return _DefaultVariableResolver(this);
}