| 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.ast.ast; | 5 library analyzer.src.dart.ast.ast; |
| 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/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => | 62 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 63 visitor.visitAdjacentStrings(this); | 63 visitor.visitAdjacentStrings(this); |
| 64 | 64 |
| 65 @override | 65 @override |
| 66 void visitChildren(AstVisitor visitor) { | 66 void visitChildren(AstVisitor visitor) { |
| 67 _strings.accept(visitor); | 67 _strings.accept(visitor); |
| 68 } | 68 } |
| 69 | 69 |
| 70 @override | 70 @override |
| 71 void _appendStringValue(StringBuffer buffer) { | 71 void _appendStringValue(StringBuffer buffer) { |
| 72 for (StringLiteralImpl stringLiteral in strings) { | 72 int length = strings.length; |
| 73 for (int i = 0; i < length; i++) { |
| 74 StringLiteralImpl stringLiteral = strings[i]; |
| 73 stringLiteral._appendStringValue(buffer); | 75 stringLiteral._appendStringValue(buffer); |
| 74 } | 76 } |
| 75 } | 77 } |
| 76 } | 78 } |
| 77 | 79 |
| 78 /** | 80 /** |
| 79 * An AST node that can be annotated with both a documentation comment and a | 81 * An AST node that can be annotated with both a documentation comment and a |
| 80 * list of annotations. | 82 * list of annotations. |
| 81 */ | 83 */ |
| 82 abstract class AnnotatedNodeImpl extends AstNodeImpl implements AnnotatedNode { | 84 abstract class AnnotatedNodeImpl extends AstNodeImpl implements AnnotatedNode { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 } | 154 } |
| 153 return result; | 155 return result; |
| 154 } | 156 } |
| 155 | 157 |
| 156 @override | 158 @override |
| 157 void visitChildren(AstVisitor visitor) { | 159 void visitChildren(AstVisitor visitor) { |
| 158 if (_commentIsBeforeAnnotations()) { | 160 if (_commentIsBeforeAnnotations()) { |
| 159 _comment?.accept(visitor); | 161 _comment?.accept(visitor); |
| 160 _metadata.accept(visitor); | 162 _metadata.accept(visitor); |
| 161 } else { | 163 } else { |
| 162 for (AstNode child in sortedCommentAndAnnotations) { | 164 List<AstNode> children = sortedCommentAndAnnotations; |
| 163 child.accept(visitor); | 165 int length = children.length; |
| 166 for (int i = 0; i < length; i++) { |
| 167 children[i].accept(visitor); |
| 164 } | 168 } |
| 165 } | 169 } |
| 166 } | 170 } |
| 167 | 171 |
| 168 /** | 172 /** |
| 169 * Return `true` if there are no annotations before the comment. Note that a | 173 * Return `true` if there are no annotations before the comment. Note that a |
| 170 * result of `true` does not imply that there is a comment, nor that there are | 174 * result of `true` does not imply that there is a comment, nor that there are |
| 171 * annotations associated with this node. | 175 * annotations associated with this node. |
| 172 */ | 176 */ |
| 173 bool _commentIsBeforeAnnotations() { | 177 bool _commentIsBeforeAnnotations() { |
| (...skipping 1656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1830 void set withClause(WithClause withClause) { | 1834 void set withClause(WithClause withClause) { |
| 1831 _withClause = _becomeParentOf(withClause as AstNodeImpl); | 1835 _withClause = _becomeParentOf(withClause as AstNodeImpl); |
| 1832 } | 1836 } |
| 1833 | 1837 |
| 1834 @override | 1838 @override |
| 1835 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => | 1839 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 1836 visitor.visitClassDeclaration(this); | 1840 visitor.visitClassDeclaration(this); |
| 1837 | 1841 |
| 1838 @override | 1842 @override |
| 1839 ConstructorDeclaration getConstructor(String name) { | 1843 ConstructorDeclaration getConstructor(String name) { |
| 1840 for (ClassMember classMember in _members) { | 1844 int length = _members.length; |
| 1845 for (int i = 0; i < length; i++) { |
| 1846 ClassMember classMember = _members[i]; |
| 1841 if (classMember is ConstructorDeclaration) { | 1847 if (classMember is ConstructorDeclaration) { |
| 1842 ConstructorDeclaration constructor = classMember; | 1848 ConstructorDeclaration constructor = classMember; |
| 1843 SimpleIdentifier constructorName = constructor.name; | 1849 SimpleIdentifier constructorName = constructor.name; |
| 1844 if (name == null && constructorName == null) { | 1850 if (name == null && constructorName == null) { |
| 1845 return constructor; | 1851 return constructor; |
| 1846 } | 1852 } |
| 1847 if (constructorName != null && constructorName.name == name) { | 1853 if (constructorName != null && constructorName.name == name) { |
| 1848 return constructor; | 1854 return constructor; |
| 1849 } | 1855 } |
| 1850 } | 1856 } |
| 1851 } | 1857 } |
| 1852 return null; | 1858 return null; |
| 1853 } | 1859 } |
| 1854 | 1860 |
| 1855 @override | 1861 @override |
| 1856 VariableDeclaration getField(String name) { | 1862 VariableDeclaration getField(String name) { |
| 1857 for (ClassMember classMember in _members) { | 1863 int memberLength = _members.length; |
| 1864 for (int i = 0; i < memberLength; i++) { |
| 1865 ClassMember classMember = _members[i]; |
| 1858 if (classMember is FieldDeclaration) { | 1866 if (classMember is FieldDeclaration) { |
| 1859 FieldDeclaration fieldDeclaration = classMember; | 1867 FieldDeclaration fieldDeclaration = classMember; |
| 1860 NodeList<VariableDeclaration> fields = | 1868 NodeList<VariableDeclaration> fields = |
| 1861 fieldDeclaration.fields.variables; | 1869 fieldDeclaration.fields.variables; |
| 1862 for (VariableDeclaration field in fields) { | 1870 int fieldLength = fields.length; |
| 1871 for (int i = 0; i < fieldLength; i++) { |
| 1872 VariableDeclaration field = fields[i]; |
| 1863 SimpleIdentifier fieldName = field.name; | 1873 SimpleIdentifier fieldName = field.name; |
| 1864 if (fieldName != null && name == fieldName.name) { | 1874 if (fieldName != null && name == fieldName.name) { |
| 1865 return field; | 1875 return field; |
| 1866 } | 1876 } |
| 1867 } | 1877 } |
| 1868 } | 1878 } |
| 1869 } | 1879 } |
| 1870 return null; | 1880 return null; |
| 1871 } | 1881 } |
| 1872 | 1882 |
| 1873 @override | 1883 @override |
| 1874 MethodDeclaration getMethod(String name) { | 1884 MethodDeclaration getMethod(String name) { |
| 1875 for (ClassMember classMember in _members) { | 1885 int length = _members.length; |
| 1886 for (int i = 0; i < length; i++) { |
| 1887 ClassMember classMember = _members[i]; |
| 1876 if (classMember is MethodDeclaration) { | 1888 if (classMember is MethodDeclaration) { |
| 1877 MethodDeclaration method = classMember; | 1889 MethodDeclaration method = classMember; |
| 1878 SimpleIdentifier methodName = method.name; | 1890 SimpleIdentifier methodName = method.name; |
| 1879 if (methodName != null && name == methodName.name) { | 1891 if (methodName != null && name == methodName.name) { |
| 1880 return method; | 1892 return method; |
| 1881 } | 1893 } |
| 1882 } | 1894 } |
| 1883 } | 1895 } |
| 1884 return null; | 1896 return null; |
| 1885 } | 1897 } |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2419 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => | 2431 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 2420 visitor.visitCompilationUnit(this); | 2432 visitor.visitCompilationUnit(this); |
| 2421 | 2433 |
| 2422 @override | 2434 @override |
| 2423 void visitChildren(AstVisitor visitor) { | 2435 void visitChildren(AstVisitor visitor) { |
| 2424 _scriptTag?.accept(visitor); | 2436 _scriptTag?.accept(visitor); |
| 2425 if (_directivesAreBeforeDeclarations) { | 2437 if (_directivesAreBeforeDeclarations) { |
| 2426 _directives.accept(visitor); | 2438 _directives.accept(visitor); |
| 2427 _declarations.accept(visitor); | 2439 _declarations.accept(visitor); |
| 2428 } else { | 2440 } else { |
| 2429 for (AstNode child in sortedDirectivesAndDeclarations) { | 2441 int length = sortedDirectivesAndDeclarations.length; |
| 2442 for (int i = 0; i < length; i++) { |
| 2443 AstNode child = sortedDirectivesAndDeclarations[i]; |
| 2430 child.accept(visitor); | 2444 child.accept(visitor); |
| 2431 } | 2445 } |
| 2432 } | 2446 } |
| 2433 } | 2447 } |
| 2434 } | 2448 } |
| 2435 | 2449 |
| 2436 /** | 2450 /** |
| 2437 * A node that declares one or more names within the scope of a compilation | 2451 * A node that declares one or more names within the scope of a compilation |
| 2438 * unit. | 2452 * unit. |
| 2439 * | 2453 * |
| (...skipping 2224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4664 } | 4678 } |
| 4665 | 4679 |
| 4666 @override | 4680 @override |
| 4667 Token get beginToken => leftParenthesis; | 4681 Token get beginToken => leftParenthesis; |
| 4668 | 4682 |
| 4669 @override | 4683 @override |
| 4670 Iterable get childEntities { | 4684 Iterable get childEntities { |
| 4671 // TODO(paulberry): include commas. | 4685 // TODO(paulberry): include commas. |
| 4672 ChildEntities result = new ChildEntities()..add(leftParenthesis); | 4686 ChildEntities result = new ChildEntities()..add(leftParenthesis); |
| 4673 bool leftDelimiterNeeded = leftDelimiter != null; | 4687 bool leftDelimiterNeeded = leftDelimiter != null; |
| 4674 for (FormalParameter parameter in _parameters) { | 4688 int length = _parameters.length; |
| 4689 for (int i = 0; i < length; i++) { |
| 4690 FormalParameter parameter = _parameters[i]; |
| 4675 if (leftDelimiterNeeded && leftDelimiter.offset < parameter.offset) { | 4691 if (leftDelimiterNeeded && leftDelimiter.offset < parameter.offset) { |
| 4676 result.add(leftDelimiter); | 4692 result.add(leftDelimiter); |
| 4677 leftDelimiterNeeded = false; | 4693 leftDelimiterNeeded = false; |
| 4678 } | 4694 } |
| 4679 result.add(parameter); | 4695 result.add(parameter); |
| 4680 } | 4696 } |
| 4681 return result..add(rightDelimiter)..add(rightParenthesis); | 4697 return result..add(rightDelimiter)..add(rightParenthesis); |
| 4682 } | 4698 } |
| 4683 | 4699 |
| 4684 @override | 4700 @override |
| (...skipping 1984 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6669 @override | 6685 @override |
| 6670 NodeList<SimpleIdentifier> get components => _components; | 6686 NodeList<SimpleIdentifier> get components => _components; |
| 6671 | 6687 |
| 6672 @override | 6688 @override |
| 6673 Token get endToken => _components.endToken; | 6689 Token get endToken => _components.endToken; |
| 6674 | 6690 |
| 6675 @override | 6691 @override |
| 6676 String get name { | 6692 String get name { |
| 6677 StringBuffer buffer = new StringBuffer(); | 6693 StringBuffer buffer = new StringBuffer(); |
| 6678 bool needsPeriod = false; | 6694 bool needsPeriod = false; |
| 6679 for (SimpleIdentifier identifier in _components) { | 6695 int length = _components.length; |
| 6696 for (int i = 0; i < length; i++) { |
| 6697 SimpleIdentifier identifier = _components[i]; |
| 6680 if (needsPeriod) { | 6698 if (needsPeriod) { |
| 6681 buffer.write("."); | 6699 buffer.write("."); |
| 6682 } else { | 6700 } else { |
| 6683 needsPeriod = true; | 6701 needsPeriod = true; |
| 6684 } | 6702 } |
| 6685 buffer.write(identifier.name); | 6703 buffer.write(identifier.name); |
| 6686 } | 6704 } |
| 6687 return buffer.toString(); | 6705 return buffer.toString(); |
| 6688 } | 6706 } |
| 6689 | 6707 |
| (...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7665 } | 7683 } |
| 7666 | 7684 |
| 7667 @override | 7685 @override |
| 7668 void add(E node) { | 7686 void add(E node) { |
| 7669 insert(length, node); | 7687 insert(length, node); |
| 7670 } | 7688 } |
| 7671 | 7689 |
| 7672 @override | 7690 @override |
| 7673 bool addAll(Iterable<E> nodes) { | 7691 bool addAll(Iterable<E> nodes) { |
| 7674 if (nodes != null && !nodes.isEmpty) { | 7692 if (nodes != null && !nodes.isEmpty) { |
| 7675 _elements.addAll(nodes); | 7693 if (nodes is List<E>) { |
| 7676 for (E node in nodes) { | 7694 int length = nodes.length; |
| 7677 _owner._becomeParentOf(node as AstNodeImpl); | 7695 for (int i = 0; i < length; i++) { |
| 7696 E node = nodes[i]; |
| 7697 _elements.add(node); |
| 7698 _owner._becomeParentOf(node as AstNodeImpl); |
| 7699 } |
| 7700 } else { |
| 7701 for (E node in nodes) { |
| 7702 _elements.add(node); |
| 7703 _owner._becomeParentOf(node as AstNodeImpl); |
| 7704 } |
| 7678 } | 7705 } |
| 7679 return true; | 7706 return true; |
| 7680 } | 7707 } |
| 7681 return false; | 7708 return false; |
| 7682 } | 7709 } |
| 7683 | 7710 |
| 7684 @override | 7711 @override |
| 7685 void clear() { | 7712 void clear() { |
| 7686 _elements = <E>[]; | 7713 _elements = <E>[]; |
| 7687 } | 7714 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7806 @override | 7833 @override |
| 7807 void visitChildren(AstVisitor visitor) { | 7834 void visitChildren(AstVisitor visitor) { |
| 7808 // | 7835 // |
| 7809 // Note that subclasses are responsible for visiting the identifier because | 7836 // Note that subclasses are responsible for visiting the identifier because |
| 7810 // they often need to visit other nodes before visiting the identifier. | 7837 // they often need to visit other nodes before visiting the identifier. |
| 7811 // | 7838 // |
| 7812 if (_commentIsBeforeAnnotations()) { | 7839 if (_commentIsBeforeAnnotations()) { |
| 7813 _comment?.accept(visitor); | 7840 _comment?.accept(visitor); |
| 7814 _metadata.accept(visitor); | 7841 _metadata.accept(visitor); |
| 7815 } else { | 7842 } else { |
| 7816 for (AstNode child in sortedCommentAndAnnotations) { | 7843 List<AstNode> children = sortedCommentAndAnnotations; |
| 7817 child.accept(visitor); | 7844 int length = children.length; |
| 7845 for (int i = 0; i < length; i++) { |
| 7846 children[i].accept(visitor); |
| 7818 } | 7847 } |
| 7819 } | 7848 } |
| 7820 } | 7849 } |
| 7821 | 7850 |
| 7822 /** | 7851 /** |
| 7823 * Return `true` if the comment is lexically before any annotations. | 7852 * Return `true` if the comment is lexically before any annotations. |
| 7824 */ | 7853 */ |
| 7825 bool _commentIsBeforeAnnotations() { | 7854 bool _commentIsBeforeAnnotations() { |
| 7826 if (_comment == null || _metadata.isEmpty) { | 7855 if (_comment == null || _metadata.isEmpty) { |
| 7827 return true; | 7856 return true; |
| (...skipping 3175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11003 | 11032 |
| 11004 @override | 11033 @override |
| 11005 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => | 11034 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 11006 visitor.visitYieldStatement(this); | 11035 visitor.visitYieldStatement(this); |
| 11007 | 11036 |
| 11008 @override | 11037 @override |
| 11009 void visitChildren(AstVisitor visitor) { | 11038 void visitChildren(AstVisitor visitor) { |
| 11010 _expression?.accept(visitor); | 11039 _expression?.accept(visitor); |
| 11011 } | 11040 } |
| 11012 } | 11041 } |
| OLD | NEW |