| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.src.generated.declaration_resolver; | 5 library analyzer.src.generated.declaration_resolver; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/token.dart'; | 8 import 'package:analyzer/dart/ast/token.dart'; |
| 9 import 'package:analyzer/dart/ast/visitor.dart'; | 9 import 'package:analyzer/dart/ast/visitor.dart'; |
| 10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 }); | 272 }); |
| 273 _resolveMetadata(node, node.metadata, element); | 273 _resolveMetadata(node, node.metadata, element); |
| 274 return null; | 274 return null; |
| 275 } else { | 275 } else { |
| 276 return super.visitFunctionTypedFormalParameter(node); | 276 return super.visitFunctionTypedFormalParameter(node); |
| 277 } | 277 } |
| 278 } | 278 } |
| 279 | 279 |
| 280 @override | 280 @override |
| 281 Object visitGenericFunctionType(GenericFunctionType node) { | 281 Object visitGenericFunctionType(GenericFunctionType node) { |
| 282 GenericFunctionTypeElement element = node.type.element; | 282 if (_walker.elementBuilder != null) { |
| 283 _setGenericFunctionType(node.returnType, element.returnType); | 283 _walker.elementBuilder.visitGenericFunctionType(node); |
| 284 _walk(new ElementWalker.forGenericFunctionType(element), () { | 284 } else { |
| 285 super.visitGenericFunctionType(node); | 285 DartType type = node.type; |
| 286 }); | 286 if (type != null) { |
| 287 Element element = type.element; |
| 288 if (element is GenericFunctionTypeElement) { |
| 289 _setGenericFunctionType(node.returnType, element.returnType); |
| 290 _walk(new ElementWalker.forGenericFunctionType(element), () { |
| 291 super.visitGenericFunctionType(node); |
| 292 }); |
| 293 } |
| 294 } |
| 295 } |
| 287 return null; | 296 return null; |
| 288 } | 297 } |
| 289 | 298 |
| 290 @override | 299 @override |
| 291 Object visitGenericTypeAlias(GenericTypeAlias node) { | 300 Object visitGenericTypeAlias(GenericTypeAlias node) { |
| 292 GenericTypeAliasElementImpl element = | 301 GenericTypeAliasElementImpl element = |
| 293 _match(node.name, _walker.getTypedef()); | 302 _match(node.name, _walker.getTypedef()); |
| 294 _setGenericFunctionType(node.functionType, element.function?.type); | 303 _setGenericFunctionType(node.functionType, element.function?.type); |
| 295 _walk(new ElementWalker.forGenericTypeAlias(element), () { | 304 _walk(new ElementWalker.forGenericTypeAlias(element), () { |
| 296 super.visitGenericTypeAlias(node); | 305 super.visitGenericTypeAlias(node); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 _resolveAnnotations(parent, nodes, element.metadata); | 548 _resolveAnnotations(parent, nodes, element.metadata); |
| 540 } | 549 } |
| 541 } | 550 } |
| 542 | 551 |
| 543 /** | 552 /** |
| 544 * If the given [typeNode] is a [GenericFunctionType], set its [type]. | 553 * If the given [typeNode] is a [GenericFunctionType], set its [type]. |
| 545 */ | 554 */ |
| 546 void _setGenericFunctionType(TypeAnnotation typeNode, DartType type) { | 555 void _setGenericFunctionType(TypeAnnotation typeNode, DartType type) { |
| 547 if (typeNode is GenericFunctionTypeImpl) { | 556 if (typeNode is GenericFunctionTypeImpl) { |
| 548 typeNode.type = type; | 557 typeNode.type = type; |
| 558 } else if (typeNode is NamedType) { |
| 559 typeNode.type = type; |
| 560 if (type is ParameterizedType) { |
| 561 List<TypeAnnotation> nodes = |
| 562 typeNode.typeArguments?.arguments ?? const []; |
| 563 List<DartType> types = type.typeArguments; |
| 564 if (nodes.length == types.length) { |
| 565 for (int i = 0; i < nodes.length; i++) { |
| 566 _setGenericFunctionType(nodes[i], types[i]); |
| 567 } |
| 568 } |
| 569 } |
| 549 } | 570 } |
| 550 } | 571 } |
| 551 | 572 |
| 552 /** | 573 /** |
| 553 * Recurses through the element model and AST, verifying that all elements are | 574 * Recurses through the element model and AST, verifying that all elements are |
| 554 * matched. | 575 * matched. |
| 555 * | 576 * |
| 556 * Executes [callback] with [_walker] pointing to the given [walker] (which | 577 * Executes [callback] with [_walker] pointing to the given [walker] (which |
| 557 * should be a new instance of [ElementWalker]). Once [callback] returns, | 578 * should be a new instance of [ElementWalker]). Once [callback] returns, |
| 558 * uses [ElementWalker.validate] to verify that all expected elements have | 579 * uses [ElementWalker.validate] to verify that all expected elements have |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 class _ElementMismatchException extends AnalysisException { | 815 class _ElementMismatchException extends AnalysisException { |
| 795 /** | 816 /** |
| 796 * Creates an exception to refer to the given [compilationUnit], [element], | 817 * Creates an exception to refer to the given [compilationUnit], [element], |
| 797 * and [cause]. | 818 * and [cause]. |
| 798 */ | 819 */ |
| 799 _ElementMismatchException( | 820 _ElementMismatchException( |
| 800 CompilationUnitElement compilationUnit, Element element, | 821 CompilationUnitElement compilationUnit, Element element, |
| 801 [CaughtException cause = null]) | 822 [CaughtException cause = null]) |
| 802 : super('Element mismatch in $compilationUnit at $element', cause); | 823 : super('Element mismatch in $compilationUnit at $element', cause); |
| 803 } | 824 } |
| OLD | NEW |