| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 engine.resolver.element_resolver; | 5 library engine.resolver.element_resolver; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'ast.dart'; | 9 import 'ast.dart'; |
| 10 import 'element.dart'; | 10 import 'element.dart'; |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 } | 193 } |
| 194 | 194 |
| 195 @override | 195 @override |
| 196 Object visitBreakStatement(BreakStatement node) { | 196 Object visitBreakStatement(BreakStatement node) { |
| 197 node.target = _lookupBreakOrContinueTarget(node, node.label, false); | 197 node.target = _lookupBreakOrContinueTarget(node, node.label, false); |
| 198 return null; | 198 return null; |
| 199 } | 199 } |
| 200 | 200 |
| 201 @override | 201 @override |
| 202 Object visitClassDeclaration(ClassDeclaration node) { | 202 Object visitClassDeclaration(ClassDeclaration node) { |
| 203 _setMetadata(node.element, node); | 203 setMetadata(node.element, node); |
| 204 return null; |
| 205 } |
| 206 @override |
| 207 Object visitClassTypeAlias(ClassTypeAlias node) { |
| 208 setMetadata(node.element, node); |
| 204 return null; | 209 return null; |
| 205 } | 210 } |
| 206 | 211 |
| 207 @override | |
| 208 Object visitClassTypeAlias(ClassTypeAlias node) { | |
| 209 _setMetadata(node.element, node); | |
| 210 return null; | |
| 211 } | |
| 212 | |
| 213 @override | 212 @override |
| 214 Object visitCommentReference(CommentReference node) { | 213 Object visitCommentReference(CommentReference node) { |
| 215 Identifier identifier = node.identifier; | 214 Identifier identifier = node.identifier; |
| 216 if (identifier is SimpleIdentifier) { | 215 if (identifier is SimpleIdentifier) { |
| 217 SimpleIdentifier simpleIdentifier = identifier; | 216 SimpleIdentifier simpleIdentifier = identifier; |
| 218 Element element = _resolveSimpleIdentifier(simpleIdentifier); | 217 Element element = _resolveSimpleIdentifier(simpleIdentifier); |
| 219 if (element == null) { | 218 if (element == null) { |
| 220 // | 219 // |
| 221 // This might be a reference to an imported name that is missing the | 220 // This might be a reference to an imported name that is missing the |
| 222 // prefix. | 221 // prefix. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 constructorElement.redirectedConstructor = redirectedElement; | 324 constructorElement.redirectedConstructor = redirectedElement; |
| 326 } else { | 325 } else { |
| 327 // set redirected generative constructor | 326 // set redirected generative constructor |
| 328 for (ConstructorInitializer initializer in node.initializers) { | 327 for (ConstructorInitializer initializer in node.initializers) { |
| 329 if (initializer is RedirectingConstructorInvocation) { | 328 if (initializer is RedirectingConstructorInvocation) { |
| 330 ConstructorElement redirectedElement = initializer.staticElement; | 329 ConstructorElement redirectedElement = initializer.staticElement; |
| 331 constructorElement.redirectedConstructor = redirectedElement; | 330 constructorElement.redirectedConstructor = redirectedElement; |
| 332 } | 331 } |
| 333 } | 332 } |
| 334 } | 333 } |
| 335 _setMetadata(constructorElement, node); | 334 setMetadata(constructorElement, node); |
| 336 } | 335 } |
| 337 return null; | 336 return null; |
| 338 } | 337 } |
| 339 | 338 |
| 340 @override | 339 @override |
| 341 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) { | 340 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) { |
| 342 SimpleIdentifier fieldName = node.fieldName; | 341 SimpleIdentifier fieldName = node.fieldName; |
| 343 ClassElement enclosingClass = _resolver.enclosingClass; | 342 ClassElement enclosingClass = _resolver.enclosingClass; |
| 344 FieldElement fieldElement = enclosingClass.getField(fieldName.name); | 343 FieldElement fieldElement = enclosingClass.getField(fieldName.name); |
| 345 fieldName.staticElement = fieldElement; | 344 fieldName.staticElement = fieldElement; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 } | 380 } |
| 382 | 381 |
| 383 @override | 382 @override |
| 384 Object visitContinueStatement(ContinueStatement node) { | 383 Object visitContinueStatement(ContinueStatement node) { |
| 385 node.target = _lookupBreakOrContinueTarget(node, node.label, true); | 384 node.target = _lookupBreakOrContinueTarget(node, node.label, true); |
| 386 return null; | 385 return null; |
| 387 } | 386 } |
| 388 | 387 |
| 389 @override | 388 @override |
| 390 Object visitDeclaredIdentifier(DeclaredIdentifier node) { | 389 Object visitDeclaredIdentifier(DeclaredIdentifier node) { |
| 391 _setMetadata(node.element, node); | 390 setMetadata(node.element, node); |
| 392 return null; | 391 return null; |
| 393 } | 392 } |
| 394 | 393 |
| 395 @override | 394 @override |
| 396 Object visitEnumDeclaration(EnumDeclaration node) { | 395 Object visitEnumDeclaration(EnumDeclaration node) { |
| 397 _setMetadata(node.element, node); | 396 setMetadata(node.element, node); |
| 398 return null; | 397 return null; |
| 399 } | 398 } |
| 400 | 399 |
| 401 @override | 400 @override |
| 402 Object visitExportDirective(ExportDirective node) { | 401 Object visitExportDirective(ExportDirective node) { |
| 403 ExportElement exportElement = node.element; | 402 ExportElement exportElement = node.element; |
| 404 if (exportElement != null) { | 403 if (exportElement != null) { |
| 405 // The element is null when the URI is invalid | 404 // The element is null when the URI is invalid |
| 406 // TODO(brianwilkerson) Figure out whether the element can ever be | 405 // TODO(brianwilkerson) Figure out whether the element can ever be |
| 407 // something other than an ExportElement | 406 // something other than an ExportElement |
| 408 _resolveCombinators(exportElement.exportedLibrary, node.combinators); | 407 _resolveCombinators(exportElement.exportedLibrary, node.combinators); |
| 409 _setMetadata(exportElement, node); | 408 setMetadata(exportElement, node); |
| 410 } | 409 } |
| 411 return null; | 410 return null; |
| 412 } | 411 } |
| 413 | 412 |
| 414 @override | 413 @override |
| 415 Object visitFieldFormalParameter(FieldFormalParameter node) { | 414 Object visitFieldFormalParameter(FieldFormalParameter node) { |
| 416 _setMetadataForParameter(node.element, node); | 415 _setMetadataForParameter(node.element, node); |
| 417 return super.visitFieldFormalParameter(node); | 416 return super.visitFieldFormalParameter(node); |
| 418 } | 417 } |
| 419 | 418 |
| 420 @override | 419 @override |
| 421 Object visitFunctionDeclaration(FunctionDeclaration node) { | 420 Object visitFunctionDeclaration(FunctionDeclaration node) { |
| 422 _setMetadata(node.element, node); | 421 setMetadata(node.element, node); |
| 423 return null; | 422 return null; |
| 424 } | 423 } |
| 425 | 424 |
| 426 @override | 425 @override |
| 427 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { | 426 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { |
| 428 // TODO(brianwilkerson) Can we ever resolve the function being invoked? | 427 // TODO(brianwilkerson) Can we ever resolve the function being invoked? |
| 429 Expression expression = node.function; | 428 Expression expression = node.function; |
| 430 if (expression is FunctionExpression) { | 429 if (expression is FunctionExpression) { |
| 431 FunctionExpression functionExpression = expression; | 430 FunctionExpression functionExpression = expression; |
| 432 ExecutableElement functionElement = functionExpression.element; | 431 ExecutableElement functionElement = functionExpression.element; |
| 433 ArgumentList argumentList = node.argumentList; | 432 ArgumentList argumentList = node.argumentList; |
| 434 List<ParameterElement> parameters = | 433 List<ParameterElement> parameters = |
| 435 _resolveArgumentsToFunction(false, argumentList, functionElement); | 434 _resolveArgumentsToFunction(false, argumentList, functionElement); |
| 436 if (parameters != null) { | 435 if (parameters != null) { |
| 437 argumentList.correspondingStaticParameters = parameters; | 436 argumentList.correspondingStaticParameters = parameters; |
| 438 } | 437 } |
| 439 } | 438 } |
| 440 return null; | 439 return null; |
| 441 } | 440 } |
| 442 | 441 |
| 443 @override | 442 @override |
| 444 Object visitFunctionTypeAlias(FunctionTypeAlias node) { | 443 Object visitFunctionTypeAlias(FunctionTypeAlias node) { |
| 445 _setMetadata(node.element, node); | 444 setMetadata(node.element, node); |
| 446 return null; | 445 return null; |
| 447 } | 446 } |
| 448 | 447 |
| 449 @override | 448 @override |
| 450 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { | 449 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { |
| 451 _setMetadataForParameter(node.element, node); | 450 _setMetadataForParameter(node.element, node); |
| 452 return null; | 451 return null; |
| 453 } | 452 } |
| 454 | 453 |
| 455 @override | 454 @override |
| 456 Object visitImportDirective(ImportDirective node) { | 455 Object visitImportDirective(ImportDirective node) { |
| 457 SimpleIdentifier prefixNode = node.prefix; | 456 SimpleIdentifier prefixNode = node.prefix; |
| 458 if (prefixNode != null) { | 457 if (prefixNode != null) { |
| 459 String prefixName = prefixNode.name; | 458 String prefixName = prefixNode.name; |
| 460 for (PrefixElement prefixElement in _definingLibrary.prefixes) { | 459 for (PrefixElement prefixElement in _definingLibrary.prefixes) { |
| 461 if (prefixElement.displayName == prefixName) { | 460 if (prefixElement.displayName == prefixName) { |
| 462 prefixNode.staticElement = prefixElement; | 461 prefixNode.staticElement = prefixElement; |
| 463 break; | 462 break; |
| 464 } | 463 } |
| 465 } | 464 } |
| 466 } | 465 } |
| 467 ImportElement importElement = node.element; | 466 ImportElement importElement = node.element; |
| 468 if (importElement != null) { | 467 if (importElement != null) { |
| 469 // The element is null when the URI is invalid | 468 // The element is null when the URI is invalid |
| 470 LibraryElement library = importElement.importedLibrary; | 469 LibraryElement library = importElement.importedLibrary; |
| 471 if (library != null) { | 470 if (library != null) { |
| 472 _resolveCombinators(library, node.combinators); | 471 _resolveCombinators(library, node.combinators); |
| 473 } | 472 } |
| 474 _setMetadata(importElement, node); | 473 setMetadata(importElement, node); |
| 475 } | 474 } |
| 476 return null; | 475 return null; |
| 477 } | 476 } |
| 478 | 477 |
| 479 @override | 478 @override |
| 480 Object visitIndexExpression(IndexExpression node) { | 479 Object visitIndexExpression(IndexExpression node) { |
| 481 Expression target = node.realTarget; | 480 Expression target = node.realTarget; |
| 482 DartType staticType = _getStaticType(target); | 481 DartType staticType = _getStaticType(target); |
| 483 DartType propagatedType = _getPropagatedType(target); | 482 DartType propagatedType = _getPropagatedType(target); |
| 484 String getterMethodName = sc.TokenType.INDEX.lexeme; | 483 String getterMethodName = sc.TokenType.INDEX.lexeme; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 List<ParameterElement> parameters = _resolveArgumentsToFunction( | 546 List<ParameterElement> parameters = _resolveArgumentsToFunction( |
| 548 node.isConst, argumentList, invokedConstructor); | 547 node.isConst, argumentList, invokedConstructor); |
| 549 if (parameters != null) { | 548 if (parameters != null) { |
| 550 argumentList.correspondingStaticParameters = parameters; | 549 argumentList.correspondingStaticParameters = parameters; |
| 551 } | 550 } |
| 552 return null; | 551 return null; |
| 553 } | 552 } |
| 554 | 553 |
| 555 @override | 554 @override |
| 556 Object visitLibraryDirective(LibraryDirective node) { | 555 Object visitLibraryDirective(LibraryDirective node) { |
| 557 _setMetadata(node.element, node); | 556 setMetadata(node.element, node); |
| 558 return null; | 557 return null; |
| 559 } | 558 } |
| 560 | 559 |
| 561 @override | 560 @override |
| 562 Object visitMethodDeclaration(MethodDeclaration node) { | 561 Object visitMethodDeclaration(MethodDeclaration node) { |
| 563 _setMetadata(node.element, node); | 562 setMetadata(node.element, node); |
| 564 return null; | 563 return null; |
| 565 } | 564 } |
| 566 | 565 |
| 567 @override | 566 @override |
| 568 Object visitMethodInvocation(MethodInvocation node) { | 567 Object visitMethodInvocation(MethodInvocation node) { |
| 569 SimpleIdentifier methodName = node.methodName; | 568 SimpleIdentifier methodName = node.methodName; |
| 570 // | 569 // |
| 571 // Synthetic identifiers have been already reported during parsing. | 570 // Synthetic identifiers have been already reported during parsing. |
| 572 // | 571 // |
| 573 if (methodName.isSynthetic) { | 572 if (methodName.isSynthetic) { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 } | 738 } |
| 740 String targetTypeName = targetType == null ? null : targetType.name; | 739 String targetTypeName = targetType == null ? null : targetType.name; |
| 741 _resolver.reportErrorForNode(StaticTypeWarningCode.UNDEFINED_SUPER_METHOD, | 740 _resolver.reportErrorForNode(StaticTypeWarningCode.UNDEFINED_SUPER_METHOD, |
| 742 methodName, [methodName.name, targetTypeName]); | 741 methodName, [methodName.name, targetTypeName]); |
| 743 } | 742 } |
| 744 return null; | 743 return null; |
| 745 } | 744 } |
| 746 | 745 |
| 747 @override | 746 @override |
| 748 Object visitPartDirective(PartDirective node) { | 747 Object visitPartDirective(PartDirective node) { |
| 749 _setMetadata(node.element, node); | 748 setMetadata(node.element, node); |
| 750 return null; | 749 return null; |
| 751 } | 750 } |
| 752 | 751 |
| 753 @override | 752 @override |
| 754 Object visitPartOfDirective(PartOfDirective node) { | 753 Object visitPartOfDirective(PartOfDirective node) { |
| 755 _setMetadata(node.element, node); | 754 setMetadata(node.element, node); |
| 756 return null; | 755 return null; |
| 757 } | 756 } |
| 758 | 757 |
| 759 @override | 758 @override |
| 760 Object visitPostfixExpression(PostfixExpression node) { | 759 Object visitPostfixExpression(PostfixExpression node) { |
| 761 Expression operand = node.operand; | 760 Expression operand = node.operand; |
| 762 String methodName = _getPostfixOperator(node); | 761 String methodName = _getPostfixOperator(node); |
| 763 DartType staticType = _getStaticType(operand); | 762 DartType staticType = _getStaticType(operand); |
| 764 MethodElement staticMethod = _lookUpMethod(operand, staticType, methodName); | 763 MethodElement staticMethod = _lookUpMethod(operand, staticType, methodName); |
| 765 node.staticElement = staticMethod; | 764 node.staticElement = staticMethod; |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1089 Object visitSuperExpression(SuperExpression node) { | 1088 Object visitSuperExpression(SuperExpression node) { |
| 1090 if (!_isSuperInValidContext(node)) { | 1089 if (!_isSuperInValidContext(node)) { |
| 1091 _resolver.reportErrorForNode( | 1090 _resolver.reportErrorForNode( |
| 1092 CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT, node); | 1091 CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT, node); |
| 1093 } | 1092 } |
| 1094 return super.visitSuperExpression(node); | 1093 return super.visitSuperExpression(node); |
| 1095 } | 1094 } |
| 1096 | 1095 |
| 1097 @override | 1096 @override |
| 1098 Object visitTypeParameter(TypeParameter node) { | 1097 Object visitTypeParameter(TypeParameter node) { |
| 1099 _setMetadata(node.element, node); | 1098 setMetadata(node.element, node); |
| 1100 return null; | 1099 return null; |
| 1101 } | 1100 } |
| 1102 | 1101 |
| 1103 @override | 1102 @override |
| 1104 Object visitVariableDeclaration(VariableDeclaration node) { | 1103 Object visitVariableDeclaration(VariableDeclaration node) { |
| 1105 _setMetadata(node.element, node); | 1104 setMetadata(node.element, node); |
| 1106 return null; | 1105 return null; |
| 1107 } | 1106 } |
| 1108 | 1107 |
| 1109 /** | 1108 /** |
| 1110 * Generate annotation elements for each of the annotations in the | |
| 1111 * [annotationList] and add them to the given list of [annotations]. | |
| 1112 */ | |
| 1113 void _addAnnotations(List<ElementAnnotationImpl> annotationList, | |
| 1114 NodeList<Annotation> annotations) { | |
| 1115 int annotationCount = annotations.length; | |
| 1116 for (int i = 0; i < annotationCount; i++) { | |
| 1117 Annotation annotation = annotations[i]; | |
| 1118 Element resolvedElement = annotation.element; | |
| 1119 if (resolvedElement != null) { | |
| 1120 ElementAnnotationImpl elementAnnotation = | |
| 1121 new ElementAnnotationImpl(resolvedElement); | |
| 1122 annotation.elementAnnotation = elementAnnotation; | |
| 1123 annotationList.add(elementAnnotation); | |
| 1124 } | |
| 1125 } | |
| 1126 } | |
| 1127 | |
| 1128 /** | |
| 1129 * Given that we have found code to invoke the given [element], return the | 1109 * Given that we have found code to invoke the given [element], return the |
| 1130 * error code that should be reported, or `null` if no error should be | 1110 * error code that should be reported, or `null` if no error should be |
| 1131 * reported. The [target] is the target of the invocation, or `null` if there | 1111 * reported. The [target] is the target of the invocation, or `null` if there |
| 1132 * was no target. The flag [useStaticContext] should be `true` if the | 1112 * was no target. The flag [useStaticContext] should be `true` if the |
| 1133 * invocation is in a static constant (does not have access to instance state. | 1113 * invocation is in a static constant (does not have access to instance state. |
| 1134 */ | 1114 */ |
| 1135 ErrorCode _checkForInvocationError( | 1115 ErrorCode _checkForInvocationError( |
| 1136 Expression target, bool useStaticContext, Element element) { | 1116 Expression target, bool useStaticContext, Element element) { |
| 1137 // Prefix is not declared, instead "prefix.id" are declared. | 1117 // Prefix is not declared, instead "prefix.id" are declared. |
| 1138 if (element is PrefixElement) { | 1118 if (element is PrefixElement) { |
| (...skipping 1494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2633 return bound; | 2613 return bound; |
| 2634 } | 2614 } |
| 2635 return type; | 2615 return type; |
| 2636 } | 2616 } |
| 2637 | 2617 |
| 2638 /** | 2618 /** |
| 2639 * Given a [node] that can have annotations associated with it and the | 2619 * Given a [node] that can have annotations associated with it and the |
| 2640 * [element] to which that node has been resolved, create the annotations in | 2620 * [element] to which that node has been resolved, create the annotations in |
| 2641 * the element model representing the annotations on the node. | 2621 * the element model representing the annotations on the node. |
| 2642 */ | 2622 */ |
| 2643 void _setMetadata(Element element, AnnotatedNode node) { | |
| 2644 if (element is! ElementImpl) { | |
| 2645 return; | |
| 2646 } | |
| 2647 List<ElementAnnotationImpl> annotationList = | |
| 2648 new List<ElementAnnotationImpl>(); | |
| 2649 _addAnnotations(annotationList, node.metadata); | |
| 2650 if (node is VariableDeclaration && node.parent is VariableDeclarationList) { | |
| 2651 VariableDeclarationList list = node.parent as VariableDeclarationList; | |
| 2652 _addAnnotations(annotationList, list.metadata); | |
| 2653 if (list.parent is FieldDeclaration) { | |
| 2654 FieldDeclaration fieldDeclaration = list.parent as FieldDeclaration; | |
| 2655 _addAnnotations(annotationList, fieldDeclaration.metadata); | |
| 2656 } else if (list.parent is TopLevelVariableDeclaration) { | |
| 2657 TopLevelVariableDeclaration variableDeclaration = | |
| 2658 list.parent as TopLevelVariableDeclaration; | |
| 2659 _addAnnotations(annotationList, variableDeclaration.metadata); | |
| 2660 } | |
| 2661 } | |
| 2662 if (!annotationList.isEmpty) { | |
| 2663 (element as ElementImpl).metadata = annotationList; | |
| 2664 } | |
| 2665 } | |
| 2666 | |
| 2667 /** | |
| 2668 * Given a [node] that can have annotations associated with it and the | |
| 2669 * [element] to which that node has been resolved, create the annotations in | |
| 2670 * the element model representing the annotations on the node. | |
| 2671 */ | |
| 2672 void _setMetadataForParameter(Element element, NormalFormalParameter node) { | 2623 void _setMetadataForParameter(Element element, NormalFormalParameter node) { |
| 2673 if (element is! ElementImpl) { | 2624 if (element is! ElementImpl) { |
| 2674 return; | 2625 return; |
| 2675 } | 2626 } |
| 2676 List<ElementAnnotationImpl> annotationList = | 2627 List<ElementAnnotationImpl> annotationList = |
| 2677 new List<ElementAnnotationImpl>(); | 2628 new List<ElementAnnotationImpl>(); |
| 2678 _addAnnotations(annotationList, node.metadata); | 2629 _addAnnotations(annotationList, node.metadata); |
| 2679 if (!annotationList.isEmpty) { | 2630 if (!annotationList.isEmpty) { |
| 2680 (element as ElementImpl).metadata = annotationList; | 2631 (element as ElementImpl).metadata = annotationList; |
| 2681 } | 2632 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2703 if (!isConditional && expression is Identifier) { | 2654 if (!isConditional && expression is Identifier) { |
| 2704 Element staticElement = expression.staticElement; | 2655 Element staticElement = expression.staticElement; |
| 2705 if (staticElement is ClassElementImpl) { | 2656 if (staticElement is ClassElementImpl) { |
| 2706 return staticElement; | 2657 return staticElement; |
| 2707 } | 2658 } |
| 2708 } | 2659 } |
| 2709 return null; | 2660 return null; |
| 2710 } | 2661 } |
| 2711 | 2662 |
| 2712 /** | 2663 /** |
| 2664 * Given a [node] that can have annotations associated with it and the |
| 2665 * [element] to which that node has been resolved, create the annotations in |
| 2666 * the element model representing the annotations on the node. |
| 2667 */ |
| 2668 static void setMetadata(Element element, AnnotatedNode node) { |
| 2669 if (element is! ElementImpl) { |
| 2670 return; |
| 2671 } |
| 2672 List<ElementAnnotationImpl> annotationList = <ElementAnnotationImpl>[]; |
| 2673 _addAnnotations(annotationList, node.metadata); |
| 2674 if (node is VariableDeclaration && node.parent is VariableDeclarationList) { |
| 2675 VariableDeclarationList list = node.parent as VariableDeclarationList; |
| 2676 _addAnnotations(annotationList, list.metadata); |
| 2677 if (list.parent is FieldDeclaration) { |
| 2678 FieldDeclaration fieldDeclaration = list.parent as FieldDeclaration; |
| 2679 _addAnnotations(annotationList, fieldDeclaration.metadata); |
| 2680 } else if (list.parent is TopLevelVariableDeclaration) { |
| 2681 TopLevelVariableDeclaration variableDeclaration = |
| 2682 list.parent as TopLevelVariableDeclaration; |
| 2683 _addAnnotations(annotationList, variableDeclaration.metadata); |
| 2684 } |
| 2685 } |
| 2686 if (!annotationList.isEmpty) { |
| 2687 (element as ElementImpl).metadata = annotationList; |
| 2688 } |
| 2689 } |
| 2690 |
| 2691 /** |
| 2692 * Generate annotation elements for each of the annotations in the |
| 2693 * [annotationList] and add them to the given list of [annotations]. |
| 2694 */ |
| 2695 static void _addAnnotations(List<ElementAnnotationImpl> annotationList, |
| 2696 NodeList<Annotation> annotations) { |
| 2697 int annotationCount = annotations.length; |
| 2698 for (int i = 0; i < annotationCount; i++) { |
| 2699 Annotation annotation = annotations[i]; |
| 2700 Element resolvedElement = annotation.element; |
| 2701 if (resolvedElement != null) { |
| 2702 ElementAnnotationImpl elementAnnotation = |
| 2703 new ElementAnnotationImpl(resolvedElement); |
| 2704 annotation.elementAnnotation = elementAnnotation; |
| 2705 annotationList.add(elementAnnotation); |
| 2706 } |
| 2707 } |
| 2708 } |
| 2709 |
| 2710 /** |
| 2713 * Return `true` if the given [identifier] is the return type of a constructor | 2711 * Return `true` if the given [identifier] is the return type of a constructor |
| 2714 * declaration. | 2712 * declaration. |
| 2715 */ | 2713 */ |
| 2716 static bool _isConstructorReturnType(SimpleIdentifier identifier) { | 2714 static bool _isConstructorReturnType(SimpleIdentifier identifier) { |
| 2717 AstNode parent = identifier.parent; | 2715 AstNode parent = identifier.parent; |
| 2718 if (parent is ConstructorDeclaration) { | 2716 if (parent is ConstructorDeclaration) { |
| 2719 return identical(parent.returnType, identifier); | 2717 return identical(parent.returnType, identifier); |
| 2720 } | 2718 } |
| 2721 return false; | 2719 return false; |
| 2722 } | 2720 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2811 | 2809 |
| 2812 @override | 2810 @override |
| 2813 Element get staticElement => null; | 2811 Element get staticElement => null; |
| 2814 | 2812 |
| 2815 @override | 2813 @override |
| 2816 accept(AstVisitor visitor) => null; | 2814 accept(AstVisitor visitor) => null; |
| 2817 | 2815 |
| 2818 @override | 2816 @override |
| 2819 void visitChildren(AstVisitor visitor) {} | 2817 void visitChildren(AstVisitor visitor) {} |
| 2820 } | 2818 } |
| OLD | NEW |