Index: pkg/analyzer/lib/src/dart/element/element.dart |
diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart |
index cf4d49346a521c67f48c3003cc3d1039a87b7412..4ed332041ff40e884d8e446b0f9a23fd0b4c5bf6 100644 |
--- a/pkg/analyzer/lib/src/dart/element/element.dart |
+++ b/pkg/analyzer/lib/src/dart/element/element.dart |
@@ -811,6 +811,9 @@ class ClassElementImpl extends AbstractClassElementImpl |
} |
@override |
+ List<kernel.TypeParameter> get kernelTypeParams => _kernel?.typeParameters; |
+ |
+ @override |
List<ElementAnnotation> get metadata { |
if (_unlinkedClass != null) { |
return _metadata ??= |
@@ -888,19 +891,30 @@ class ClassElementImpl extends AbstractClassElementImpl |
@override |
InterfaceType get supertype { |
- if (_unlinkedClass != null && _supertype == null) { |
- if (_unlinkedClass.supertype != null) { |
- DartType type = enclosingUnit.resynthesizerContext |
- .resolveTypeRef(this, _unlinkedClass.supertype); |
- if (_isClassInterfaceType(type)) { |
- _supertype = type; |
+ if (_supertype == null) { |
+ if (_kernel != null) { |
+ if (_kernel.supertype != null) { |
+ _supertype = enclosingUnit._kernelContext |
+ .getInterfaceType(this, _kernel.supertype); |
+ _supertype ??= context.typeProvider.objectType; |
+ } else { |
+ return null; |
+ } |
+ } |
+ if (_unlinkedClass != null) { |
+ if (_unlinkedClass.supertype != null) { |
+ DartType type = enclosingUnit.resynthesizerContext |
+ .resolveTypeRef(this, _unlinkedClass.supertype); |
+ if (_isClassInterfaceType(type)) { |
+ _supertype = type; |
+ } else { |
+ _supertype = context.typeProvider.objectType; |
+ } |
+ } else if (_unlinkedClass.hasNoSupertype) { |
+ return null; |
} else { |
_supertype = context.typeProvider.objectType; |
} |
- } else if (_unlinkedClass.hasNoSupertype) { |
- return null; |
- } else { |
- _supertype = context.typeProvider.objectType; |
} |
} |
return _supertype; |
@@ -3831,6 +3845,9 @@ abstract class ExecutableElementImpl extends ElementImpl |
bool get isSynchronous => !isAsynchronous; |
@override |
+ List<kernel.TypeParameter> get kernelTypeParams => null; |
+ |
+ @override |
List<ElementAnnotation> get metadata { |
if (serializedExecutable != null) { |
return _metadata ??= |
@@ -4665,6 +4682,9 @@ class FunctionTypeAliasElementImpl extends ElementImpl |
_enclosingElement as CompilationUnitElementImpl; |
@override |
+ List<kernel.TypeParameter> get kernelTypeParams => null; |
+ |
+ @override |
ElementKind get kind => ElementKind.FUNCTION_TYPE_ALIAS; |
@override |
@@ -4879,6 +4899,9 @@ class GenericFunctionTypeElementImpl extends ElementImpl |
String get identifier => '-'; |
@override |
+ List<kernel.TypeParameter> get kernelTypeParams => null; |
+ |
+ @override |
ElementKind get kind => ElementKind.GENERIC_FUNCTION_TYPE; |
@override |
@@ -5106,6 +5129,9 @@ class GenericTypeAliasElementImpl extends ElementImpl |
} |
@override |
+ List<kernel.TypeParameter> get kernelTypeParams => null; |
+ |
+ @override |
ElementKind get kind => ElementKind.FUNCTION_TYPE_ALIAS; |
@override |
@@ -5563,6 +5589,18 @@ class ImportElementImpl extends UriReferencedElementImpl |
*/ |
abstract class KernelLibraryResynthesizerContext { |
kernel.Library get library; |
+ |
+ /** |
+ * Return the [InterfaceType] for the given Kernel [type], or `null` if the |
+ * [type] does not correspond to an [InterfaceType]. |
+ */ |
+ InterfaceType getInterfaceType(ElementImpl context, kernel.Supertype type); |
+ |
+ /** |
+ * Return the [DartType] for the given Kernel [type], or `null` if the [type] |
+ * does not correspond to a [DartType]. |
+ */ |
+ DartType getType(ElementImpl context, kernel.DartType type); |
} |
/** |
@@ -8451,6 +8489,11 @@ class TypeParameterElementImpl extends ElementImpl |
final int nestingLevel; |
/** |
+ * The kernel of the element. |
+ */ |
+ final kernel.TypeParameter _kernel; |
+ |
+ /** |
* The type defined by this type parameter. |
*/ |
TypeParameterType _type; |
@@ -8468,14 +8511,25 @@ class TypeParameterElementImpl extends ElementImpl |
TypeParameterElementImpl(String name, int offset) |
: _unlinkedTypeParam = null, |
nestingLevel = null, |
+ _kernel = null, |
super(name, offset); |
/** |
+ * Initialize using the given kernel. |
+ */ |
+ TypeParameterElementImpl.forKernel( |
+ TypeParameterizedElementMixin enclosingElement, this._kernel) |
+ : _unlinkedTypeParam = null, |
+ nestingLevel = null, |
+ super.forSerialized(enclosingElement); |
+ |
+ /** |
* Initialize a newly created type parameter element to have the given [name]. |
*/ |
TypeParameterElementImpl.forNode(Identifier name) |
: _unlinkedTypeParam = null, |
nestingLevel = null, |
+ _kernel = null, |
super.forNode(name); |
/** |
@@ -8483,7 +8537,8 @@ class TypeParameterElementImpl extends ElementImpl |
*/ |
TypeParameterElementImpl.forSerialized(this._unlinkedTypeParam, |
TypeParameterizedElementMixin enclosingElement, this.nestingLevel) |
- : super.forSerialized(enclosingElement); |
+ : _kernel = null, |
+ super.forSerialized(enclosingElement); |
/** |
* Initialize a newly created synthetic type parameter element to have the |
@@ -8492,18 +8547,26 @@ class TypeParameterElementImpl extends ElementImpl |
TypeParameterElementImpl.synthetic(String name) |
: _unlinkedTypeParam = null, |
nestingLevel = null, |
+ _kernel = null, |
super(name, -1) { |
isSynthetic = true; |
} |
DartType get bound { |
- if (_unlinkedTypeParam != null) { |
- if (_unlinkedTypeParam.bound == null) { |
- return null; |
+ if (_bound == null) { |
+ if (_kernel != null) { |
+ _bound = enclosingUnit._kernelContext.getType(this, _kernel.bound); |
+ // TODO(scheglov) Add a flag for explicit bound. |
+ if (_bound != null && _bound.isObject) _bound = null; |
+ } |
+ if (_unlinkedTypeParam != null) { |
+ if (_unlinkedTypeParam.bound == null) { |
+ return null; |
+ } |
+ _bound = enclosingUnit.resynthesizerContext.resolveTypeRef( |
+ this, _unlinkedTypeParam.bound, |
+ instantiateToBoundsAllowed: false, declaredType: true); |
} |
- return _bound ??= enclosingUnit.resynthesizerContext.resolveTypeRef( |
- this, _unlinkedTypeParam.bound, |
- instantiateToBoundsAllowed: false, declaredType: true); |
} |
return _bound; |
} |
@@ -8546,6 +8609,9 @@ class TypeParameterElementImpl extends ElementImpl |
@override |
String get name { |
+ if (_kernel != null) { |
+ return _kernel.name; |
+ } |
if (_unlinkedTypeParam != null) { |
return _unlinkedTypeParam.name; |
} |
@@ -8651,6 +8717,12 @@ abstract class TypeParameterizedElementMixin |
*/ |
CompilationUnitElementImpl get enclosingUnit; |
+ /** |
+ * Get the [kernel.TypeParameter]s declared by this element, or `null` if |
+ * this elements isn't from a kernel. |
+ */ |
+ List<kernel.TypeParameter> get kernelTypeParams; |
+ |
@override |
TypeParameterizedElementMixin get typeParameterContext => this; |
@@ -8664,6 +8736,17 @@ abstract class TypeParameterizedElementMixin |
@override |
List<TypeParameterElement> get typeParameters { |
if (_typeParameterElements == null) { |
+ List<kernel.TypeParameter> kernelParams = kernelTypeParams; |
+ if (kernelParams != null) { |
+ int numTypeParameters = kernelParams.length; |
+ _typeParameterElements = |
+ new List<TypeParameterElement>(numTypeParameters); |
+ for (int i = 0; i < numTypeParameters; i++) { |
+ _typeParameterElements[i] = |
+ new TypeParameterElementImpl.forKernel(this, kernelParams[i]); |
+ } |
+ } |
+ |
List<UnlinkedTypeParam> unlinkedParams = unlinkedTypeParams; |
if (unlinkedParams != null) { |
int enclosingNestingLevel = |