Chromium Code Reviews| 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 | |
|
Brian Wilkerson
2015/06/04 23:10:11
Re-insert the blank line between members? (Is this
| |
| 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 734 } | 733 } |
| 735 String targetTypeName = targetType == null ? null : targetType.name; | 734 String targetTypeName = targetType == null ? null : targetType.name; |
| 736 _resolver.reportErrorForNode(StaticTypeWarningCode.UNDEFINED_SUPER_METHOD, | 735 _resolver.reportErrorForNode(StaticTypeWarningCode.UNDEFINED_SUPER_METHOD, |
| 737 methodName, [methodName.name, targetTypeName]); | 736 methodName, [methodName.name, targetTypeName]); |
| 738 } | 737 } |
| 739 return null; | 738 return null; |
| 740 } | 739 } |
| 741 | 740 |
| 742 @override | 741 @override |
| 743 Object visitPartDirective(PartDirective node) { | 742 Object visitPartDirective(PartDirective node) { |
| 744 _setMetadata(node.element, node); | 743 setMetadata(node.element, node); |
| 745 return null; | 744 return null; |
| 746 } | 745 } |
| 747 | 746 |
| 748 @override | 747 @override |
| 749 Object visitPartOfDirective(PartOfDirective node) { | 748 Object visitPartOfDirective(PartOfDirective node) { |
| 750 _setMetadata(node.element, node); | 749 setMetadata(node.element, node); |
| 751 return null; | 750 return null; |
| 752 } | 751 } |
| 753 | 752 |
| 754 @override | 753 @override |
| 755 Object visitPostfixExpression(PostfixExpression node) { | 754 Object visitPostfixExpression(PostfixExpression node) { |
| 756 Expression operand = node.operand; | 755 Expression operand = node.operand; |
| 757 String methodName = _getPostfixOperator(node); | 756 String methodName = _getPostfixOperator(node); |
| 758 DartType staticType = _getStaticType(operand); | 757 DartType staticType = _getStaticType(operand); |
| 759 MethodElement staticMethod = _lookUpMethod(operand, staticType, methodName); | 758 MethodElement staticMethod = _lookUpMethod(operand, staticType, methodName); |
| 760 node.staticElement = staticMethod; | 759 node.staticElement = staticMethod; |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1080 Object visitSuperExpression(SuperExpression node) { | 1079 Object visitSuperExpression(SuperExpression node) { |
| 1081 if (!_isSuperInValidContext(node)) { | 1080 if (!_isSuperInValidContext(node)) { |
| 1082 _resolver.reportErrorForNode( | 1081 _resolver.reportErrorForNode( |
| 1083 CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT, node); | 1082 CompileTimeErrorCode.SUPER_IN_INVALID_CONTEXT, node); |
| 1084 } | 1083 } |
| 1085 return super.visitSuperExpression(node); | 1084 return super.visitSuperExpression(node); |
| 1086 } | 1085 } |
| 1087 | 1086 |
| 1088 @override | 1087 @override |
| 1089 Object visitTypeParameter(TypeParameter node) { | 1088 Object visitTypeParameter(TypeParameter node) { |
| 1090 _setMetadata(node.element, node); | 1089 setMetadata(node.element, node); |
| 1091 return null; | 1090 return null; |
| 1092 } | 1091 } |
| 1093 | 1092 |
| 1094 @override | 1093 @override |
| 1095 Object visitVariableDeclaration(VariableDeclaration node) { | 1094 Object visitVariableDeclaration(VariableDeclaration node) { |
| 1096 _setMetadata(node.element, node); | 1095 setMetadata(node.element, node); |
| 1097 return null; | 1096 return null; |
| 1098 } | 1097 } |
| 1099 | 1098 |
| 1100 /** | 1099 /** |
| 1101 * Generate annotation elements for each of the annotations in the | |
| 1102 * [annotationList] and add them to the given list of [annotations]. | |
| 1103 */ | |
| 1104 void _addAnnotations(List<ElementAnnotationImpl> annotationList, | |
| 1105 NodeList<Annotation> annotations) { | |
| 1106 int annotationCount = annotations.length; | |
| 1107 for (int i = 0; i < annotationCount; i++) { | |
| 1108 Annotation annotation = annotations[i]; | |
| 1109 Element resolvedElement = annotation.element; | |
| 1110 if (resolvedElement != null) { | |
| 1111 ElementAnnotationImpl elementAnnotation = | |
| 1112 new ElementAnnotationImpl(resolvedElement); | |
| 1113 annotation.elementAnnotation = elementAnnotation; | |
| 1114 annotationList.add(elementAnnotation); | |
| 1115 } | |
| 1116 } | |
| 1117 } | |
| 1118 | |
| 1119 /** | |
| 1120 * Given that we have found code to invoke the given [element], return the | 1100 * Given that we have found code to invoke the given [element], return the |
| 1121 * error code that should be reported, or `null` if no error should be | 1101 * error code that should be reported, or `null` if no error should be |
| 1122 * reported. The [target] is the target of the invocation, or `null` if there | 1102 * reported. The [target] is the target of the invocation, or `null` if there |
| 1123 * was no target. The flag [useStaticContext] should be `true` if the | 1103 * was no target. The flag [useStaticContext] should be `true` if the |
| 1124 * invocation is in a static constant (does not have access to instance state. | 1104 * invocation is in a static constant (does not have access to instance state. |
| 1125 */ | 1105 */ |
| 1126 ErrorCode _checkForInvocationError( | 1106 ErrorCode _checkForInvocationError( |
| 1127 Expression target, bool useStaticContext, Element element) { | 1107 Expression target, bool useStaticContext, Element element) { |
| 1128 // Prefix is not declared, instead "prefix.id" are declared. | 1108 // Prefix is not declared, instead "prefix.id" are declared. |
| 1129 if (element is PrefixElement) { | 1109 if (element is PrefixElement) { |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1348 element = MultiplyDefinedElementImpl.fromElements( | 1328 element = MultiplyDefinedElementImpl.fromElements( |
| 1349 _definingLibrary.context, element, importedElement); | 1329 _definingLibrary.context, element, importedElement); |
| 1350 } | 1330 } |
| 1351 } | 1331 } |
| 1352 } | 1332 } |
| 1353 } | 1333 } |
| 1354 return element; | 1334 return element; |
| 1355 } | 1335 } |
| 1356 | 1336 |
| 1357 /** | 1337 /** |
| 1338 * Return the best type of the given [expression] that is to be used for | |
| 1339 * type analysis. | |
| 1340 */ | |
| 1341 DartType _getBestType(Expression expression) { | |
| 1342 DartType bestType = _resolveTypeParameter(expression.bestType); | |
| 1343 if (bestType is FunctionType) { | |
| 1344 // | |
| 1345 // All function types are subtypes of 'Function', which is itself a | |
| 1346 // subclass of 'Object'. | |
| 1347 // | |
| 1348 bestType = _resolver.typeProvider.functionType; | |
| 1349 } | |
| 1350 return bestType; | |
| 1351 } | |
| 1352 | |
| 1353 /** | |
| 1358 * Assuming that the given [expression] is a prefix for a deferred import, | 1354 * Assuming that the given [expression] is a prefix for a deferred import, |
| 1359 * return the library that is being imported. | 1355 * return the library that is being imported. |
| 1360 */ | 1356 */ |
| 1361 LibraryElement _getImportedLibrary(Expression expression) { | 1357 LibraryElement _getImportedLibrary(Expression expression) { |
| 1362 PrefixElement prefixElement = | 1358 PrefixElement prefixElement = |
| 1363 (expression as SimpleIdentifier).staticElement as PrefixElement; | 1359 (expression as SimpleIdentifier).staticElement as PrefixElement; |
| 1364 List<ImportElement> imports = | 1360 List<ImportElement> imports = |
| 1365 prefixElement.enclosingElement.getImportsWithPrefix(prefixElement); | 1361 prefixElement.enclosingElement.getImportsWithPrefix(prefixElement); |
| 1366 return imports[0].importedLibrary; | 1362 return imports[0].importedLibrary; |
| 1367 } | 1363 } |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1385 } else if (operatorType == sc.TokenType.MINUS_MINUS) { | 1381 } else if (operatorType == sc.TokenType.MINUS_MINUS) { |
| 1386 return sc.TokenType.MINUS.lexeme; | 1382 return sc.TokenType.MINUS.lexeme; |
| 1387 } else if (operatorType == sc.TokenType.MINUS) { | 1383 } else if (operatorType == sc.TokenType.MINUS) { |
| 1388 return "unary-"; | 1384 return "unary-"; |
| 1389 } else { | 1385 } else { |
| 1390 return operator.lexeme; | 1386 return operator.lexeme; |
| 1391 } | 1387 } |
| 1392 } | 1388 } |
| 1393 | 1389 |
| 1394 /** | 1390 /** |
| 1395 * Return the best type of the given [expression] that is to be used for | |
| 1396 * type analysis. | |
| 1397 */ | |
| 1398 DartType _getBestType(Expression expression) { | |
| 1399 DartType bestType = _resolveTypeParameter(expression.bestType); | |
| 1400 if (bestType is FunctionType) { | |
| 1401 // | |
| 1402 // All function types are subtypes of 'Function', which is itself a | |
| 1403 // subclass of 'Object'. | |
| 1404 // | |
| 1405 bestType = _resolver.typeProvider.functionType; | |
| 1406 } | |
| 1407 return bestType; | |
| 1408 } | |
| 1409 | |
| 1410 /** | |
| 1411 * Return the propagated type of the given [expression] that is to be used for | 1391 * Return the propagated type of the given [expression] that is to be used for |
| 1412 * type analysis. | 1392 * type analysis. |
| 1413 */ | 1393 */ |
| 1414 DartType _getPropagatedType(Expression expression) { | 1394 DartType _getPropagatedType(Expression expression) { |
| 1415 DartType propagatedType = _resolveTypeParameter(expression.propagatedType); | 1395 DartType propagatedType = _resolveTypeParameter(expression.propagatedType); |
| 1416 if (propagatedType is FunctionType) { | 1396 if (propagatedType is FunctionType) { |
| 1417 // | 1397 // |
| 1418 // All function types are subtypes of 'Function', which is itself a | 1398 // All function types are subtypes of 'Function', which is itself a |
| 1419 // subclass of 'Object'. | 1399 // subclass of 'Object'. |
| 1420 // | 1400 // |
| (...skipping 1193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2614 return bound; | 2594 return bound; |
| 2615 } | 2595 } |
| 2616 return type; | 2596 return type; |
| 2617 } | 2597 } |
| 2618 | 2598 |
| 2619 /** | 2599 /** |
| 2620 * Given a [node] that can have annotations associated with it and the | 2600 * Given a [node] that can have annotations associated with it and the |
| 2621 * [element] to which that node has been resolved, create the annotations in | 2601 * [element] to which that node has been resolved, create the annotations in |
| 2622 * the element model representing the annotations on the node. | 2602 * the element model representing the annotations on the node. |
| 2623 */ | 2603 */ |
| 2624 void _setMetadata(Element element, AnnotatedNode node) { | |
| 2625 if (element is! ElementImpl) { | |
| 2626 return; | |
| 2627 } | |
| 2628 List<ElementAnnotationImpl> annotationList = | |
| 2629 new List<ElementAnnotationImpl>(); | |
| 2630 _addAnnotations(annotationList, node.metadata); | |
| 2631 if (node is VariableDeclaration && node.parent is VariableDeclarationList) { | |
| 2632 VariableDeclarationList list = node.parent as VariableDeclarationList; | |
| 2633 _addAnnotations(annotationList, list.metadata); | |
| 2634 if (list.parent is FieldDeclaration) { | |
| 2635 FieldDeclaration fieldDeclaration = list.parent as FieldDeclaration; | |
| 2636 _addAnnotations(annotationList, fieldDeclaration.metadata); | |
| 2637 } else if (list.parent is TopLevelVariableDeclaration) { | |
| 2638 TopLevelVariableDeclaration variableDeclaration = | |
| 2639 list.parent as TopLevelVariableDeclaration; | |
| 2640 _addAnnotations(annotationList, variableDeclaration.metadata); | |
| 2641 } | |
| 2642 } | |
| 2643 if (!annotationList.isEmpty) { | |
| 2644 (element as ElementImpl).metadata = annotationList; | |
| 2645 } | |
| 2646 } | |
| 2647 | |
| 2648 /** | |
| 2649 * Given a [node] that can have annotations associated with it and the | |
| 2650 * [element] to which that node has been resolved, create the annotations in | |
| 2651 * the element model representing the annotations on the node. | |
| 2652 */ | |
| 2653 void _setMetadataForParameter(Element element, NormalFormalParameter node) { | 2604 void _setMetadataForParameter(Element element, NormalFormalParameter node) { |
| 2654 if (element is! ElementImpl) { | 2605 if (element is! ElementImpl) { |
| 2655 return; | 2606 return; |
| 2656 } | 2607 } |
| 2657 List<ElementAnnotationImpl> annotationList = | 2608 List<ElementAnnotationImpl> annotationList = |
| 2658 new List<ElementAnnotationImpl>(); | 2609 new List<ElementAnnotationImpl>(); |
| 2659 _addAnnotations(annotationList, node.metadata); | 2610 _addAnnotations(annotationList, node.metadata); |
| 2660 if (!annotationList.isEmpty) { | 2611 if (!annotationList.isEmpty) { |
| 2661 (element as ElementImpl).metadata = annotationList; | 2612 (element as ElementImpl).metadata = annotationList; |
| 2662 } | 2613 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 2684 if (!isConditional && expression is Identifier) { | 2635 if (!isConditional && expression is Identifier) { |
| 2685 Element staticElement = expression.staticElement; | 2636 Element staticElement = expression.staticElement; |
| 2686 if (staticElement is ClassElementImpl) { | 2637 if (staticElement is ClassElementImpl) { |
| 2687 return staticElement; | 2638 return staticElement; |
| 2688 } | 2639 } |
| 2689 } | 2640 } |
| 2690 return null; | 2641 return null; |
| 2691 } | 2642 } |
| 2692 | 2643 |
| 2693 /** | 2644 /** |
| 2645 * Given a [node] that can have annotations associated with it and the | |
| 2646 * [element] to which that node has been resolved, create the annotations in | |
| 2647 * the element model representing the annotations on the node. | |
| 2648 */ | |
| 2649 static void setMetadata(Element element, AnnotatedNode node) { | |
| 2650 if (element is! ElementImpl) { | |
| 2651 return; | |
| 2652 } | |
| 2653 List<ElementAnnotationImpl> annotationList = | |
| 2654 new List<ElementAnnotationImpl>(); | |
|
Brian Wilkerson
2015/06/04 23:10:11
Why not "<ElementAnnotationImpl>[]"?
danrubel
2015/06/17 15:06:32
Done.
| |
| 2655 _addAnnotations(annotationList, node.metadata); | |
| 2656 if (node is VariableDeclaration && node.parent is VariableDeclarationList) { | |
| 2657 VariableDeclarationList list = node.parent as VariableDeclarationList; | |
| 2658 _addAnnotations(annotationList, list.metadata); | |
| 2659 if (list.parent is FieldDeclaration) { | |
| 2660 FieldDeclaration fieldDeclaration = list.parent as FieldDeclaration; | |
| 2661 _addAnnotations(annotationList, fieldDeclaration.metadata); | |
| 2662 } else if (list.parent is TopLevelVariableDeclaration) { | |
| 2663 TopLevelVariableDeclaration variableDeclaration = | |
| 2664 list.parent as TopLevelVariableDeclaration; | |
| 2665 _addAnnotations(annotationList, variableDeclaration.metadata); | |
| 2666 } | |
| 2667 } | |
| 2668 if (!annotationList.isEmpty) { | |
| 2669 (element as ElementImpl).metadata = annotationList; | |
| 2670 } | |
| 2671 } | |
| 2672 | |
| 2673 /** | |
| 2674 * Generate annotation elements for each of the annotations in the | |
| 2675 * [annotationList] and add them to the given list of [annotations]. | |
| 2676 */ | |
| 2677 static void _addAnnotations(List<ElementAnnotationImpl> annotationList, | |
| 2678 NodeList<Annotation> annotations) { | |
| 2679 int annotationCount = annotations.length; | |
| 2680 for (int i = 0; i < annotationCount; i++) { | |
| 2681 Annotation annotation = annotations[i]; | |
| 2682 Element resolvedElement = annotation.element; | |
| 2683 if (resolvedElement != null) { | |
| 2684 ElementAnnotationImpl elementAnnotation = | |
| 2685 new ElementAnnotationImpl(resolvedElement); | |
| 2686 annotation.elementAnnotation = elementAnnotation; | |
| 2687 annotationList.add(elementAnnotation); | |
| 2688 } | |
| 2689 } | |
| 2690 } | |
| 2691 | |
| 2692 /** | |
| 2694 * Return `true` if the given [identifier] is the return type of a constructor | 2693 * Return `true` if the given [identifier] is the return type of a constructor |
| 2695 * declaration. | 2694 * declaration. |
| 2696 */ | 2695 */ |
| 2697 static bool _isConstructorReturnType(SimpleIdentifier identifier) { | 2696 static bool _isConstructorReturnType(SimpleIdentifier identifier) { |
| 2698 AstNode parent = identifier.parent; | 2697 AstNode parent = identifier.parent; |
| 2699 if (parent is ConstructorDeclaration) { | 2698 if (parent is ConstructorDeclaration) { |
| 2700 return identical(parent.returnType, identifier); | 2699 return identical(parent.returnType, identifier); |
| 2701 } | 2700 } |
| 2702 return false; | 2701 return false; |
| 2703 } | 2702 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2792 | 2791 |
| 2793 @override | 2792 @override |
| 2794 Element get staticElement => null; | 2793 Element get staticElement => null; |
| 2795 | 2794 |
| 2796 @override | 2795 @override |
| 2797 accept(AstVisitor visitor) => null; | 2796 accept(AstVisitor visitor) => null; |
| 2798 | 2797 |
| 2799 @override | 2798 @override |
| 2800 void visitChildren(AstVisitor visitor) {} | 2799 void visitChildren(AstVisitor visitor) {} |
| 2801 } | 2800 } |
| OLD | NEW |