Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Unified Diff: pkg/analyzer/lib/src/generated/declaration_resolver.dart

Issue 2770143002: More generic function type cases working (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/dart/element/element.dart ('k') | pkg/analyzer/lib/src/generated/error_verifier.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/declaration_resolver.dart
diff --git a/pkg/analyzer/lib/src/generated/declaration_resolver.dart b/pkg/analyzer/lib/src/generated/declaration_resolver.dart
index 333fdef5a36027721180209f373f14e6b99f8572..e240504436e2fd52b19de6186c9e712f313a115c 100644
--- a/pkg/analyzer/lib/src/generated/declaration_resolver.dart
+++ b/pkg/analyzer/lib/src/generated/declaration_resolver.dart
@@ -127,7 +127,7 @@ class DeclarationResolver extends RecursiveAstVisitor<Object> {
ParameterElement element =
_match(normalParameter.identifier, _walker.getParameter());
if (normalParameter is SimpleFormalParameterImpl) {
- normalParameter.element = node.identifier.staticElement;
+ normalParameter.element = element;
}
Expression defaultValue = node.defaultValue;
if (defaultValue != null) {
@@ -276,6 +276,28 @@ class DeclarationResolver extends RecursiveAstVisitor<Object> {
}
@override
+ Object visitGenericFunctionType(GenericFunctionType node) {
+ GenericFunctionTypeElement element = node.type.element;
+ _walk(new ElementWalker.forGenericFunctionType(element), () {
+ super.visitGenericFunctionType(node);
+ });
+ return null;
+ }
+
+ @override
+ Object visitGenericTypeAlias(GenericTypeAlias node) {
+ GenericTypeAliasElementImpl element =
+ _match(node.name, _walker.getTypedef());
+ (node.functionType as GenericFunctionTypeImpl)?.type =
+ element.function?.type;
+ _walk(new ElementWalker.forGenericTypeAlias(element), () {
+ super.visitGenericTypeAlias(node);
+ });
+ _resolveMetadata(node, node.metadata, element);
+ return null;
+ }
+
+ @override
Object visitImportDirective(ImportDirective node) {
super.visitImportDirective(node);
List<ElementAnnotation> annotations =
@@ -370,8 +392,11 @@ class DeclarationResolver extends RecursiveAstVisitor<Object> {
if (node.parent is! DefaultFormalParameter) {
ParameterElement element =
_match(node.identifier, _walker.getParameter());
- (node as SimpleFormalParameterImpl).element =
- node.identifier.staticElement;
+ (node as SimpleFormalParameterImpl).element = element;
+ TypeAnnotation type = node.type;
+ if (type is GenericFunctionTypeImpl) {
+ type.type = element.type;
+ }
_walk(new ElementWalker.forParameter(element), () {
super.visitSimpleFormalParameter(node);
});
@@ -461,7 +486,7 @@ class DeclarationResolver extends RecursiveAstVisitor<Object> {
SimpleIdentifier identifier, Element/*=E*/ element,
{String elementName, int offset}) {
elementName ??= identifier?.name ?? '';
- offset ??= identifier.offset;
+ offset ??= identifier?.offset ?? -1;
if (element.name != elementName) {
throw new StateError(
'Expected an element matching `$elementName`, got `${element.name}`');
@@ -617,6 +642,23 @@ class ElementWalker {
: this._forExecutable(element, compilationUnit, new ElementHolder());
/**
+ * Creates an [ElementWalker] which walks the child elements of a typedef
+ * element.
+ */
+ ElementWalker.forGenericFunctionType(GenericFunctionTypeElement element)
+ : element = element,
+ _parameters = element.parameters,
+ _typeParameters = element.typeParameters;
+
+ /**
+ * Creates an [ElementWalker] which walks the child elements of a typedef
+ * element defined using a generic function type.
+ */
+ ElementWalker.forGenericTypeAlias(FunctionTypeAliasElement element)
+ : element = element,
+ _typeParameters = element.typeParameters;
+
+ /**
* Creates an [ElementWalker] which walks the child elements of a parameter
* element.
*/
« no previous file with comments | « pkg/analyzer/lib/src/dart/element/element.dart ('k') | pkg/analyzer/lib/src/generated/error_verifier.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698