| 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 analyzer.src.dart.element.builder; | 5 library analyzer.src.dart.element.builder; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/dart/ast/visitor.dart'; | 10 import 'package:analyzer/dart/ast/visitor.dart'; |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 ExportElementImpl exportElement = new ExportElementImpl(node.offset); | 169 ExportElementImpl exportElement = new ExportElementImpl(node.offset); |
| 170 exportElement.metadata = _getElementAnnotations(node.metadata); | 170 exportElement.metadata = _getElementAnnotations(node.metadata); |
| 171 StringLiteral uriLiteral = node.uri; | 171 StringLiteral uriLiteral = node.uri; |
| 172 if (uriLiteral != null) { | 172 if (uriLiteral != null) { |
| 173 exportElement.uriOffset = uriLiteral.offset; | 173 exportElement.uriOffset = uriLiteral.offset; |
| 174 exportElement.uriEnd = uriLiteral.end; | 174 exportElement.uriEnd = uriLiteral.end; |
| 175 } | 175 } |
| 176 exportElement.uri = node.uriContent; | 176 exportElement.uri = node.uriContent; |
| 177 exportElement.combinators = _buildCombinators(node); | 177 exportElement.combinators = _buildCombinators(node); |
| 178 exportElement.exportedLibrary = exportedLibrary; | 178 exportElement.exportedLibrary = exportedLibrary; |
| 179 _setDoc(exportElement, node); | 179 setElementDocumentationComment(exportElement, node); |
| 180 node.element = exportElement; | 180 node.element = exportElement; |
| 181 exports.add(exportElement); | 181 exports.add(exportElement); |
| 182 if (exportSourceKindMap[exportedSource] != SourceKind.LIBRARY) { | 182 if (exportSourceKindMap[exportedSource] != SourceKind.LIBRARY) { |
| 183 errors.add(new AnalysisError( | 183 errors.add(new AnalysisError( |
| 184 exportedSource, | 184 exportedSource, |
| 185 uriLiteral.offset, | 185 uriLiteral.offset, |
| 186 uriLiteral.length, | 186 uriLiteral.length, |
| 187 CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY, | 187 CompileTimeErrorCode.EXPORT_OF_NON_LIBRARY, |
| 188 [uriLiteral.toSource()])); | 188 [uriLiteral.toSource()])); |
| 189 } | 189 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 211 importElement.metadata = _getElementAnnotations(node.metadata); | 211 importElement.metadata = _getElementAnnotations(node.metadata); |
| 212 StringLiteral uriLiteral = node.uri; | 212 StringLiteral uriLiteral = node.uri; |
| 213 if (uriLiteral != null) { | 213 if (uriLiteral != null) { |
| 214 importElement.uriOffset = uriLiteral.offset; | 214 importElement.uriOffset = uriLiteral.offset; |
| 215 importElement.uriEnd = uriLiteral.end; | 215 importElement.uriEnd = uriLiteral.end; |
| 216 } | 216 } |
| 217 importElement.uri = uriContent; | 217 importElement.uri = uriContent; |
| 218 importElement.deferred = node.deferredKeyword != null; | 218 importElement.deferred = node.deferredKeyword != null; |
| 219 importElement.combinators = _buildCombinators(node); | 219 importElement.combinators = _buildCombinators(node); |
| 220 importElement.importedLibrary = importedLibrary; | 220 importElement.importedLibrary = importedLibrary; |
| 221 _setDoc(importElement, node); | 221 setElementDocumentationComment(importElement, node); |
| 222 SimpleIdentifier prefixNode = node.prefix; | 222 SimpleIdentifier prefixNode = node.prefix; |
| 223 if (prefixNode != null) { | 223 if (prefixNode != null) { |
| 224 importElement.prefixOffset = prefixNode.offset; | 224 importElement.prefixOffset = prefixNode.offset; |
| 225 String prefixName = prefixNode.name; | 225 String prefixName = prefixNode.name; |
| 226 PrefixElementImpl prefix = nameToPrefixMap[prefixName]; | 226 PrefixElementImpl prefix = nameToPrefixMap[prefixName]; |
| 227 if (prefix == null) { | 227 if (prefix == null) { |
| 228 prefix = new PrefixElementImpl.forNode(prefixNode); | 228 prefix = new PrefixElementImpl.forNode(prefixNode); |
| 229 nameToPrefixMap[prefixName] = prefix; | 229 nameToPrefixMap[prefixName] = prefix; |
| 230 } | 230 } |
| 231 importElement.prefix = prefix; | 231 importElement.prefix = prefix; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 */ | 265 */ |
| 266 List<ElementAnnotation> _getElementAnnotations( | 266 List<ElementAnnotation> _getElementAnnotations( |
| 267 NodeList<Annotation> metadata) { | 267 NodeList<Annotation> metadata) { |
| 268 if (metadata.isEmpty) { | 268 if (metadata.isEmpty) { |
| 269 return ElementAnnotation.EMPTY_LIST; | 269 return ElementAnnotation.EMPTY_LIST; |
| 270 } | 270 } |
| 271 return metadata.map((Annotation a) => a.elementAnnotation).toList(); | 271 return metadata.map((Annotation a) => a.elementAnnotation).toList(); |
| 272 } | 272 } |
| 273 | 273 |
| 274 /** | 274 /** |
| 275 * If the given [node] has a documentation comment, remember its content | |
| 276 * and range into the given [element]. | |
| 277 */ | |
| 278 void _setDoc(ElementImpl element, AnnotatedNode node) { | |
| 279 Comment comment = node.documentationComment; | |
| 280 if (comment != null && comment.isDocumentation) { | |
| 281 element.documentationComment = | |
| 282 comment.tokens.map((Token t) => t.lexeme).join('\n'); | |
| 283 element.setDocRange(comment.offset, comment.length); | |
| 284 } | |
| 285 } | |
| 286 | |
| 287 /** | |
| 288 * Build the element model representing the combinators declared by | 275 * Build the element model representing the combinators declared by |
| 289 * the given [directive]. | 276 * the given [directive]. |
| 290 */ | 277 */ |
| 291 static List<NamespaceCombinator> _buildCombinators( | 278 static List<NamespaceCombinator> _buildCombinators( |
| 292 NamespaceDirective directive) { | 279 NamespaceDirective directive) { |
| 293 _NamespaceCombinatorBuilder namespaceCombinatorBuilder = | 280 _NamespaceCombinatorBuilder namespaceCombinatorBuilder = |
| 294 new _NamespaceCombinatorBuilder(); | 281 new _NamespaceCombinatorBuilder(); |
| 295 for (Combinator combinator in directive.combinators) { | 282 for (Combinator combinator in directive.combinators) { |
| 296 combinator.accept(namespaceCombinatorBuilder); | 283 combinator.accept(namespaceCombinatorBuilder); |
| 297 } | 284 } |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 } | 395 } |
| 409 SimpleIdentifier className = node.name; | 396 SimpleIdentifier className = node.name; |
| 410 ClassElementImpl element = new ClassElementImpl.forNode(className); | 397 ClassElementImpl element = new ClassElementImpl.forNode(className); |
| 411 element.metadata = _createElementAnnotations(node.metadata); | 398 element.metadata = _createElementAnnotations(node.metadata); |
| 412 List<TypeParameterElement> typeParameters = holder.typeParameters; | 399 List<TypeParameterElement> typeParameters = holder.typeParameters; |
| 413 List<DartType> typeArguments = _createTypeParameterTypes(typeParameters); | 400 List<DartType> typeArguments = _createTypeParameterTypes(typeParameters); |
| 414 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl(element); | 401 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl(element); |
| 415 interfaceType.typeArguments = typeArguments; | 402 interfaceType.typeArguments = typeArguments; |
| 416 element.type = interfaceType; | 403 element.type = interfaceType; |
| 417 element.typeParameters = typeParameters; | 404 element.typeParameters = typeParameters; |
| 418 _setDoc(element, node); | 405 setElementDocumentationComment(element, node); |
| 419 element.abstract = node.isAbstract; | 406 element.abstract = node.isAbstract; |
| 420 element.accessors = holder.accessors; | 407 element.accessors = holder.accessors; |
| 421 List<ConstructorElement> constructors = holder.constructors; | 408 List<ConstructorElement> constructors = holder.constructors; |
| 422 if (constructors.isEmpty) { | 409 if (constructors.isEmpty) { |
| 423 constructors = _createDefaultConstructors(element); | 410 constructors = _createDefaultConstructors(element); |
| 424 } | 411 } |
| 425 element.constructors = constructors; | 412 element.constructors = constructors; |
| 426 element.fields = holder.fields; | 413 element.fields = holder.fields; |
| 427 element.methods = holder.methods; | 414 element.methods = holder.methods; |
| 428 // Function types must be initialized after the enclosing element has been | 415 // Function types must be initialized after the enclosing element has been |
| (...skipping 30 matching lines...) Expand all Loading... |
| 459 ClassElementImpl element = new ClassElementImpl.forNode(className); | 446 ClassElementImpl element = new ClassElementImpl.forNode(className); |
| 460 element.metadata = _createElementAnnotations(node.metadata); | 447 element.metadata = _createElementAnnotations(node.metadata); |
| 461 element.abstract = node.abstractKeyword != null; | 448 element.abstract = node.abstractKeyword != null; |
| 462 element.mixinApplication = true; | 449 element.mixinApplication = true; |
| 463 List<TypeParameterElement> typeParameters = holder.typeParameters; | 450 List<TypeParameterElement> typeParameters = holder.typeParameters; |
| 464 element.typeParameters = typeParameters; | 451 element.typeParameters = typeParameters; |
| 465 List<DartType> typeArguments = _createTypeParameterTypes(typeParameters); | 452 List<DartType> typeArguments = _createTypeParameterTypes(typeParameters); |
| 466 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl(element); | 453 InterfaceTypeImpl interfaceType = new InterfaceTypeImpl(element); |
| 467 interfaceType.typeArguments = typeArguments; | 454 interfaceType.typeArguments = typeArguments; |
| 468 element.type = interfaceType; | 455 element.type = interfaceType; |
| 469 _setDoc(element, node); | 456 setElementDocumentationComment(element, node); |
| 470 _currentHolder.addType(element); | 457 _currentHolder.addType(element); |
| 471 className.staticElement = element; | 458 className.staticElement = element; |
| 472 holder.validate(); | 459 holder.validate(); |
| 473 return null; | 460 return null; |
| 474 } | 461 } |
| 475 | 462 |
| 476 @override | 463 @override |
| 477 Object visitConstructorDeclaration(ConstructorDeclaration node) { | 464 Object visitConstructorDeclaration(ConstructorDeclaration node) { |
| 478 ElementHolder holder = new ElementHolder(); | 465 ElementHolder holder = new ElementHolder(); |
| 479 bool wasInFunction = _inFunction; | 466 bool wasInFunction = _inFunction; |
| 480 _inFunction = true; | 467 _inFunction = true; |
| 481 try { | 468 try { |
| 482 _visitChildren(holder, node); | 469 _visitChildren(holder, node); |
| 483 } finally { | 470 } finally { |
| 484 _inFunction = wasInFunction; | 471 _inFunction = wasInFunction; |
| 485 } | 472 } |
| 486 FunctionBody body = node.body; | 473 FunctionBody body = node.body; |
| 487 SimpleIdentifier constructorName = node.name; | 474 SimpleIdentifier constructorName = node.name; |
| 488 ConstructorElementImpl element = | 475 ConstructorElementImpl element = |
| 489 new ConstructorElementImpl.forNode(constructorName); | 476 new ConstructorElementImpl.forNode(constructorName); |
| 490 element.metadata = _createElementAnnotations(node.metadata); | 477 element.metadata = _createElementAnnotations(node.metadata); |
| 491 _setDoc(element, node); | 478 setElementDocumentationComment(element, node); |
| 492 if (node.externalKeyword != null) { | 479 if (node.externalKeyword != null) { |
| 493 element.external = true; | 480 element.external = true; |
| 494 } | 481 } |
| 495 if (node.factoryKeyword != null) { | 482 if (node.factoryKeyword != null) { |
| 496 element.factory = true; | 483 element.factory = true; |
| 497 } | 484 } |
| 498 element.functions = holder.functions; | 485 element.functions = holder.functions; |
| 499 element.labels = holder.labels; | 486 element.labels = holder.labels; |
| 500 element.localVariables = holder.localVariables; | 487 element.localVariables = holder.localVariables; |
| 501 element.parameters = holder.parameters; | 488 element.parameters = holder.parameters; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 holder.validate(); | 576 holder.validate(); |
| 590 return null; | 577 return null; |
| 591 } | 578 } |
| 592 | 579 |
| 593 @override | 580 @override |
| 594 Object visitEnumDeclaration(EnumDeclaration node) { | 581 Object visitEnumDeclaration(EnumDeclaration node) { |
| 595 SimpleIdentifier enumName = node.name; | 582 SimpleIdentifier enumName = node.name; |
| 596 ClassElementImpl enumElement = new ClassElementImpl.forNode(enumName); | 583 ClassElementImpl enumElement = new ClassElementImpl.forNode(enumName); |
| 597 enumElement.metadata = _createElementAnnotations(node.metadata); | 584 enumElement.metadata = _createElementAnnotations(node.metadata); |
| 598 enumElement.enum2 = true; | 585 enumElement.enum2 = true; |
| 599 _setDoc(enumElement, node); | 586 setElementDocumentationComment(enumElement, node); |
| 600 InterfaceTypeImpl enumType = new InterfaceTypeImpl(enumElement); | 587 InterfaceTypeImpl enumType = new InterfaceTypeImpl(enumElement); |
| 601 enumElement.type = enumType; | 588 enumElement.type = enumType; |
| 602 // The equivalent code for enums in the spec shows a single constructor, | 589 // The equivalent code for enums in the spec shows a single constructor, |
| 603 // but that constructor is not callable (since it is a compile-time error | 590 // but that constructor is not callable (since it is a compile-time error |
| 604 // to subclass, mix-in, implement, or explicitly instantiate an enum). So | 591 // to subclass, mix-in, implement, or explicitly instantiate an enum). So |
| 605 // we represent this as having no constructors. | 592 // we represent this as having no constructors. |
| 606 enumElement.constructors = ConstructorElement.EMPTY_LIST; | 593 enumElement.constructors = ConstructorElement.EMPTY_LIST; |
| 607 _currentHolder.addEnum(enumElement); | 594 _currentHolder.addEnum(enumElement); |
| 608 enumName.staticElement = enumElement; | 595 enumName.staticElement = enumElement; |
| 609 return super.visitEnumDeclaration(node); | 596 return super.visitEnumDeclaration(node); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 } finally { | 657 } finally { |
| 671 _inFunction = wasInFunction; | 658 _inFunction = wasInFunction; |
| 672 } | 659 } |
| 673 FunctionBody body = expression.body; | 660 FunctionBody body = expression.body; |
| 674 Token property = node.propertyKeyword; | 661 Token property = node.propertyKeyword; |
| 675 if (property == null || _inFunction) { | 662 if (property == null || _inFunction) { |
| 676 SimpleIdentifier functionName = node.name; | 663 SimpleIdentifier functionName = node.name; |
| 677 FunctionElementImpl element = | 664 FunctionElementImpl element = |
| 678 new FunctionElementImpl.forNode(functionName); | 665 new FunctionElementImpl.forNode(functionName); |
| 679 element.metadata = _createElementAnnotations(node.metadata); | 666 element.metadata = _createElementAnnotations(node.metadata); |
| 680 _setDoc(element, node); | 667 setElementDocumentationComment(element, node); |
| 681 if (node.externalKeyword != null) { | 668 if (node.externalKeyword != null) { |
| 682 element.external = true; | 669 element.external = true; |
| 683 } | 670 } |
| 684 element.functions = holder.functions; | 671 element.functions = holder.functions; |
| 685 element.labels = holder.labels; | 672 element.labels = holder.labels; |
| 686 element.localVariables = holder.localVariables; | 673 element.localVariables = holder.localVariables; |
| 687 element.parameters = holder.parameters; | 674 element.parameters = holder.parameters; |
| 688 element.typeParameters = holder.typeParameters; | 675 element.typeParameters = holder.typeParameters; |
| 689 if (body.isAsynchronous) { | 676 if (body.isAsynchronous) { |
| 690 element.asynchronous = true; | 677 element.asynchronous = true; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 716 if (variable == null) { | 703 if (variable == null) { |
| 717 variable = new TopLevelVariableElementImpl(node.name.name, -1); | 704 variable = new TopLevelVariableElementImpl(node.name.name, -1); |
| 718 variable.final2 = true; | 705 variable.final2 = true; |
| 719 variable.synthetic = true; | 706 variable.synthetic = true; |
| 720 _currentHolder.addTopLevelVariable(variable); | 707 _currentHolder.addTopLevelVariable(variable); |
| 721 } | 708 } |
| 722 if (node.isGetter) { | 709 if (node.isGetter) { |
| 723 PropertyAccessorElementImpl getter = | 710 PropertyAccessorElementImpl getter = |
| 724 new PropertyAccessorElementImpl.forNode(propertyNameNode); | 711 new PropertyAccessorElementImpl.forNode(propertyNameNode); |
| 725 getter.metadata = _createElementAnnotations(node.metadata); | 712 getter.metadata = _createElementAnnotations(node.metadata); |
| 726 _setDoc(getter, node); | 713 setElementDocumentationComment(getter, node); |
| 727 if (node.externalKeyword != null) { | 714 if (node.externalKeyword != null) { |
| 728 getter.external = true; | 715 getter.external = true; |
| 729 } | 716 } |
| 730 getter.functions = holder.functions; | 717 getter.functions = holder.functions; |
| 731 getter.labels = holder.labels; | 718 getter.labels = holder.labels; |
| 732 getter.localVariables = holder.localVariables; | 719 getter.localVariables = holder.localVariables; |
| 733 if (body.isAsynchronous) { | 720 if (body.isAsynchronous) { |
| 734 getter.asynchronous = true; | 721 getter.asynchronous = true; |
| 735 } | 722 } |
| 736 if (body.isGenerator) { | 723 if (body.isGenerator) { |
| 737 getter.generator = true; | 724 getter.generator = true; |
| 738 } | 725 } |
| 739 getter.variable = variable; | 726 getter.variable = variable; |
| 740 getter.getter = true; | 727 getter.getter = true; |
| 741 getter.static = true; | 728 getter.static = true; |
| 742 variable.getter = getter; | 729 variable.getter = getter; |
| 743 if (node.returnType == null) { | 730 if (node.returnType == null) { |
| 744 getter.hasImplicitReturnType = true; | 731 getter.hasImplicitReturnType = true; |
| 745 } | 732 } |
| 746 _currentHolder.addAccessor(getter); | 733 _currentHolder.addAccessor(getter); |
| 747 expression.element = getter; | 734 expression.element = getter; |
| 748 propertyNameNode.staticElement = getter; | 735 propertyNameNode.staticElement = getter; |
| 749 } else { | 736 } else { |
| 750 PropertyAccessorElementImpl setter = | 737 PropertyAccessorElementImpl setter = |
| 751 new PropertyAccessorElementImpl.forNode(propertyNameNode); | 738 new PropertyAccessorElementImpl.forNode(propertyNameNode); |
| 752 setter.metadata = _createElementAnnotations(node.metadata); | 739 setter.metadata = _createElementAnnotations(node.metadata); |
| 753 _setDoc(setter, node); | 740 setElementDocumentationComment(setter, node); |
| 754 if (node.externalKeyword != null) { | 741 if (node.externalKeyword != null) { |
| 755 setter.external = true; | 742 setter.external = true; |
| 756 } | 743 } |
| 757 setter.functions = holder.functions; | 744 setter.functions = holder.functions; |
| 758 setter.labels = holder.labels; | 745 setter.labels = holder.labels; |
| 759 setter.localVariables = holder.localVariables; | 746 setter.localVariables = holder.localVariables; |
| 760 setter.parameters = holder.parameters; | 747 setter.parameters = holder.parameters; |
| 761 if (body.isAsynchronous) { | 748 if (body.isAsynchronous) { |
| 762 setter.asynchronous = true; | 749 setter.asynchronous = true; |
| 763 } | 750 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 @override | 819 @override |
| 833 Object visitFunctionTypeAlias(FunctionTypeAlias node) { | 820 Object visitFunctionTypeAlias(FunctionTypeAlias node) { |
| 834 ElementHolder holder = new ElementHolder(); | 821 ElementHolder holder = new ElementHolder(); |
| 835 _visitChildren(holder, node); | 822 _visitChildren(holder, node); |
| 836 SimpleIdentifier aliasName = node.name; | 823 SimpleIdentifier aliasName = node.name; |
| 837 List<ParameterElement> parameters = holder.parameters; | 824 List<ParameterElement> parameters = holder.parameters; |
| 838 List<TypeParameterElement> typeParameters = holder.typeParameters; | 825 List<TypeParameterElement> typeParameters = holder.typeParameters; |
| 839 FunctionTypeAliasElementImpl element = | 826 FunctionTypeAliasElementImpl element = |
| 840 new FunctionTypeAliasElementImpl.forNode(aliasName); | 827 new FunctionTypeAliasElementImpl.forNode(aliasName); |
| 841 element.metadata = _createElementAnnotations(node.metadata); | 828 element.metadata = _createElementAnnotations(node.metadata); |
| 842 _setDoc(element, node); | 829 setElementDocumentationComment(element, node); |
| 843 element.parameters = parameters; | 830 element.parameters = parameters; |
| 844 element.typeParameters = typeParameters; | 831 element.typeParameters = typeParameters; |
| 845 _createTypeParameterTypes(typeParameters); | 832 _createTypeParameterTypes(typeParameters); |
| 846 element.type = new FunctionTypeImpl.forTypedef(element); | 833 element.type = new FunctionTypeImpl.forTypedef(element); |
| 847 _currentHolder.addTypeAlias(element); | 834 _currentHolder.addTypeAlias(element); |
| 848 aliasName.staticElement = element; | 835 aliasName.staticElement = element; |
| 849 holder.validate(); | 836 holder.validate(); |
| 850 return null; | 837 return null; |
| 851 } | 838 } |
| 852 | 839 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 if (property == null) { | 904 if (property == null) { |
| 918 SimpleIdentifier methodName = node.name; | 905 SimpleIdentifier methodName = node.name; |
| 919 String nameOfMethod = methodName.name; | 906 String nameOfMethod = methodName.name; |
| 920 if (nameOfMethod == TokenType.MINUS.lexeme && | 907 if (nameOfMethod == TokenType.MINUS.lexeme && |
| 921 node.parameters.parameters.length == 0) { | 908 node.parameters.parameters.length == 0) { |
| 922 nameOfMethod = "unary-"; | 909 nameOfMethod = "unary-"; |
| 923 } | 910 } |
| 924 MethodElementImpl element = | 911 MethodElementImpl element = |
| 925 new MethodElementImpl(nameOfMethod, methodName.offset); | 912 new MethodElementImpl(nameOfMethod, methodName.offset); |
| 926 element.metadata = _createElementAnnotations(node.metadata); | 913 element.metadata = _createElementAnnotations(node.metadata); |
| 927 _setDoc(element, node); | 914 setElementDocumentationComment(element, node); |
| 928 element.abstract = node.isAbstract; | 915 element.abstract = node.isAbstract; |
| 929 if (node.externalKeyword != null) { | 916 if (node.externalKeyword != null) { |
| 930 element.external = true; | 917 element.external = true; |
| 931 } | 918 } |
| 932 element.functions = holder.functions; | 919 element.functions = holder.functions; |
| 933 element.labels = holder.labels; | 920 element.labels = holder.labels; |
| 934 element.localVariables = holder.localVariables; | 921 element.localVariables = holder.localVariables; |
| 935 element.parameters = holder.parameters; | 922 element.parameters = holder.parameters; |
| 936 element.static = isStatic; | 923 element.static = isStatic; |
| 937 element.typeParameters = holder.typeParameters; | 924 element.typeParameters = holder.typeParameters; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 955 field = new FieldElementImpl(node.name.name, -1); | 942 field = new FieldElementImpl(node.name.name, -1); |
| 956 field.final2 = true; | 943 field.final2 = true; |
| 957 field.static = isStatic; | 944 field.static = isStatic; |
| 958 field.synthetic = true; | 945 field.synthetic = true; |
| 959 _currentHolder.addField(field); | 946 _currentHolder.addField(field); |
| 960 } | 947 } |
| 961 if (node.isGetter) { | 948 if (node.isGetter) { |
| 962 PropertyAccessorElementImpl getter = | 949 PropertyAccessorElementImpl getter = |
| 963 new PropertyAccessorElementImpl.forNode(propertyNameNode); | 950 new PropertyAccessorElementImpl.forNode(propertyNameNode); |
| 964 getter.metadata = _createElementAnnotations(node.metadata); | 951 getter.metadata = _createElementAnnotations(node.metadata); |
| 965 _setDoc(getter, node); | 952 setElementDocumentationComment(getter, node); |
| 966 if (node.externalKeyword != null) { | 953 if (node.externalKeyword != null) { |
| 967 getter.external = true; | 954 getter.external = true; |
| 968 } | 955 } |
| 969 getter.functions = holder.functions; | 956 getter.functions = holder.functions; |
| 970 getter.labels = holder.labels; | 957 getter.labels = holder.labels; |
| 971 getter.localVariables = holder.localVariables; | 958 getter.localVariables = holder.localVariables; |
| 972 if (body.isAsynchronous) { | 959 if (body.isAsynchronous) { |
| 973 getter.asynchronous = true; | 960 getter.asynchronous = true; |
| 974 } | 961 } |
| 975 if (body.isGenerator) { | 962 if (body.isGenerator) { |
| 976 getter.generator = true; | 963 getter.generator = true; |
| 977 } | 964 } |
| 978 getter.variable = field; | 965 getter.variable = field; |
| 979 getter.abstract = node.isAbstract; | 966 getter.abstract = node.isAbstract; |
| 980 getter.getter = true; | 967 getter.getter = true; |
| 981 getter.static = isStatic; | 968 getter.static = isStatic; |
| 982 field.getter = getter; | 969 field.getter = getter; |
| 983 if (node.returnType == null) { | 970 if (node.returnType == null) { |
| 984 getter.hasImplicitReturnType = true; | 971 getter.hasImplicitReturnType = true; |
| 985 } | 972 } |
| 986 _currentHolder.addAccessor(getter); | 973 _currentHolder.addAccessor(getter); |
| 987 propertyNameNode.staticElement = getter; | 974 propertyNameNode.staticElement = getter; |
| 988 } else { | 975 } else { |
| 989 PropertyAccessorElementImpl setter = | 976 PropertyAccessorElementImpl setter = |
| 990 new PropertyAccessorElementImpl.forNode(propertyNameNode); | 977 new PropertyAccessorElementImpl.forNode(propertyNameNode); |
| 991 setter.metadata = _createElementAnnotations(node.metadata); | 978 setter.metadata = _createElementAnnotations(node.metadata); |
| 992 _setDoc(setter, node); | 979 setElementDocumentationComment(setter, node); |
| 993 if (node.externalKeyword != null) { | 980 if (node.externalKeyword != null) { |
| 994 setter.external = true; | 981 setter.external = true; |
| 995 } | 982 } |
| 996 setter.functions = holder.functions; | 983 setter.functions = holder.functions; |
| 997 setter.labels = holder.labels; | 984 setter.labels = holder.labels; |
| 998 setter.localVariables = holder.localVariables; | 985 setter.localVariables = holder.localVariables; |
| 999 setter.parameters = holder.parameters; | 986 setter.parameters = holder.parameters; |
| 1000 if (body.isAsynchronous) { | 987 if (body.isAsynchronous) { |
| 1001 setter.asynchronous = true; | 988 setter.asynchronous = true; |
| 1002 } | 989 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 if (_inFieldContext) { | 1114 if (_inFieldContext) { |
| 1128 SimpleIdentifier fieldName = node.name; | 1115 SimpleIdentifier fieldName = node.name; |
| 1129 FieldElementImpl field; | 1116 FieldElementImpl field; |
| 1130 if ((isConst || isFinal) && hasInitializer) { | 1117 if ((isConst || isFinal) && hasInitializer) { |
| 1131 field = new ConstFieldElementImpl.forNode(fieldName); | 1118 field = new ConstFieldElementImpl.forNode(fieldName); |
| 1132 } else { | 1119 } else { |
| 1133 field = new FieldElementImpl.forNode(fieldName); | 1120 field = new FieldElementImpl.forNode(fieldName); |
| 1134 } | 1121 } |
| 1135 element = field; | 1122 element = field; |
| 1136 if (node.parent.parent is FieldDeclaration) { | 1123 if (node.parent.parent is FieldDeclaration) { |
| 1137 _setDoc(element, node.parent.parent); | 1124 setElementDocumentationComment(element, node.parent.parent); |
| 1138 } | 1125 } |
| 1139 if ((node.parent as VariableDeclarationList).type == null) { | 1126 if ((node.parent as VariableDeclarationList).type == null) { |
| 1140 field.hasImplicitType = true; | 1127 field.hasImplicitType = true; |
| 1141 } | 1128 } |
| 1142 _currentHolder.addField(field); | 1129 _currentHolder.addField(field); |
| 1143 fieldName.staticElement = field; | 1130 fieldName.staticElement = field; |
| 1144 } else if (_inFunction) { | 1131 } else if (_inFunction) { |
| 1145 SimpleIdentifier variableName = node.name; | 1132 SimpleIdentifier variableName = node.name; |
| 1146 LocalVariableElementImpl variable; | 1133 LocalVariableElementImpl variable; |
| 1147 if (isConst && hasInitializer) { | 1134 if (isConst && hasInitializer) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1162 } else { | 1149 } else { |
| 1163 SimpleIdentifier variableName = node.name; | 1150 SimpleIdentifier variableName = node.name; |
| 1164 TopLevelVariableElementImpl variable; | 1151 TopLevelVariableElementImpl variable; |
| 1165 if (isConst && hasInitializer) { | 1152 if (isConst && hasInitializer) { |
| 1166 variable = new ConstTopLevelVariableElementImpl.forNode(variableName); | 1153 variable = new ConstTopLevelVariableElementImpl.forNode(variableName); |
| 1167 } else { | 1154 } else { |
| 1168 variable = new TopLevelVariableElementImpl.forNode(variableName); | 1155 variable = new TopLevelVariableElementImpl.forNode(variableName); |
| 1169 } | 1156 } |
| 1170 element = variable; | 1157 element = variable; |
| 1171 if (node.parent.parent is TopLevelVariableDeclaration) { | 1158 if (node.parent.parent is TopLevelVariableDeclaration) { |
| 1172 _setDoc(element, node.parent.parent); | 1159 setElementDocumentationComment(element, node.parent.parent); |
| 1173 } | 1160 } |
| 1174 if ((node.parent as VariableDeclarationList).type == null) { | 1161 if ((node.parent as VariableDeclarationList).type == null) { |
| 1175 variable.hasImplicitType = true; | 1162 variable.hasImplicitType = true; |
| 1176 } | 1163 } |
| 1177 _currentHolder.addTopLevelVariable(variable); | 1164 _currentHolder.addTopLevelVariable(variable); |
| 1178 variableName.staticElement = element; | 1165 variableName.staticElement = element; |
| 1179 } | 1166 } |
| 1180 element.const3 = isConst; | 1167 element.const3 = isConst; |
| 1181 element.final2 = isFinal; | 1168 element.final2 = isFinal; |
| 1182 if (hasInitializer) { | 1169 if (hasInitializer) { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1333 return parent.body; | 1320 return parent.body; |
| 1334 } else if (parent is MethodDeclaration) { | 1321 } else if (parent is MethodDeclaration) { |
| 1335 return parent.body; | 1322 return parent.body; |
| 1336 } | 1323 } |
| 1337 parent = parent.parent; | 1324 parent = parent.parent; |
| 1338 } | 1325 } |
| 1339 return null; | 1326 return null; |
| 1340 } | 1327 } |
| 1341 | 1328 |
| 1342 /** | 1329 /** |
| 1343 * If the given [node] has a documentation comment, remember its content | |
| 1344 * and range into the given [element]. | |
| 1345 */ | |
| 1346 void _setDoc(ElementImpl element, AnnotatedNode node) { | |
| 1347 Comment comment = node.documentationComment; | |
| 1348 if (comment != null && comment.isDocumentation) { | |
| 1349 element.documentationComment = | |
| 1350 comment.tokens.map((Token t) => t.lexeme).join('\n'); | |
| 1351 element.setDocRange(comment.offset, comment.length); | |
| 1352 } | |
| 1353 } | |
| 1354 | |
| 1355 /** | |
| 1356 * Sets the visible source range for formal parameter. | 1330 * Sets the visible source range for formal parameter. |
| 1357 */ | 1331 */ |
| 1358 void _setParameterVisibleRange( | 1332 void _setParameterVisibleRange( |
| 1359 FormalParameter node, ParameterElementImpl element) { | 1333 FormalParameter node, ParameterElementImpl element) { |
| 1360 FunctionBody body = _getFunctionBody(node); | 1334 FunctionBody body = _getFunctionBody(node); |
| 1361 if (body != null) { | 1335 if (body != null) { |
| 1362 element.setVisibleRange(body.offset, body.length); | 1336 element.setVisibleRange(body.offset, body.length); |
| 1363 } | 1337 } |
| 1364 } | 1338 } |
| 1365 | 1339 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1451 return null; | 1425 return null; |
| 1452 } | 1426 } |
| 1453 | 1427 |
| 1454 /** | 1428 /** |
| 1455 * Return the lexical identifiers associated with the given [identifiers]. | 1429 * Return the lexical identifiers associated with the given [identifiers]. |
| 1456 */ | 1430 */ |
| 1457 static List<String> _getIdentifiers(NodeList<SimpleIdentifier> identifiers) { | 1431 static List<String> _getIdentifiers(NodeList<SimpleIdentifier> identifiers) { |
| 1458 return identifiers.map((identifier) => identifier.name).toList(); | 1432 return identifiers.map((identifier) => identifier.name).toList(); |
| 1459 } | 1433 } |
| 1460 } | 1434 } |
| OLD | NEW |