Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: pkg/analyzer/lib/src/generated/ast.dart

Issue 137863002: Issue 8742. Preserve leading line comments during java2dart translation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Test for block-style comment translation. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.ast; 8 library engine.ast;
9 9
10 import 'dart:collection'; 10 import 'dart:collection';
(...skipping 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 * Otherwise, return `null`. 1033 * Otherwise, return `null`.
1034 * 1034 *
1035 * This method is only intended to be used by [Expression#getPropagatedParamet erElement]. 1035 * This method is only intended to be used by [Expression#getPropagatedParamet erElement].
1036 * 1036 *
1037 * @param expression the expression corresponding to the parameter to be retur ned 1037 * @param expression the expression corresponding to the parameter to be retur ned
1038 * @return the parameter element representing the parameter to which the value of the expression 1038 * @return the parameter element representing the parameter to which the value of the expression
1039 * will be bound 1039 * will be bound
1040 */ 1040 */
1041 ParameterElement getPropagatedParameterElementFor(Expression expression) { 1041 ParameterElement getPropagatedParameterElementFor(Expression expression) {
1042 if (_correspondingPropagatedParameters == null) { 1042 if (_correspondingPropagatedParameters == null) {
1043 // Either the AST structure has not been resolved or the invocation of whi ch this list is a
1044 // part could not be resolved.
1043 return null; 1045 return null;
1044 } 1046 }
1045 int index = _arguments.indexOf(expression); 1047 int index = _arguments.indexOf(expression);
1046 if (index < 0) { 1048 if (index < 0) {
1049 // The expression isn't a child of this node.
1047 return null; 1050 return null;
1048 } 1051 }
1049 return _correspondingPropagatedParameters[index]; 1052 return _correspondingPropagatedParameters[index];
1050 } 1053 }
1051 1054
1052 /** 1055 /**
1053 * If the given expression is a child of this list, and the AST structure has been resolved, and 1056 * If the given expression is a child of this list, and the AST structure has been resolved, and
1054 * the function being invoked is known based on static type information, and t he expression 1057 * the function being invoked is known based on static type information, and t he expression
1055 * corresponds to one of the parameters of the function being invoked, then re turn the parameter 1058 * corresponds to one of the parameters of the function being invoked, then re turn the parameter
1056 * element representing the parameter to which the value of the given expressi on will be bound. 1059 * element representing the parameter to which the value of the given expressi on will be bound.
1057 * Otherwise, return `null`. 1060 * Otherwise, return `null`.
1058 * 1061 *
1059 * This method is only intended to be used by [Expression#getStaticParameterEl ement]. 1062 * This method is only intended to be used by [Expression#getStaticParameterEl ement].
1060 * 1063 *
1061 * @param expression the expression corresponding to the parameter to be retur ned 1064 * @param expression the expression corresponding to the parameter to be retur ned
1062 * @return the parameter element representing the parameter to which the value of the expression 1065 * @return the parameter element representing the parameter to which the value of the expression
1063 * will be bound 1066 * will be bound
1064 */ 1067 */
1065 ParameterElement getStaticParameterElementFor(Expression expression) { 1068 ParameterElement getStaticParameterElementFor(Expression expression) {
1066 if (_correspondingStaticParameters == null) { 1069 if (_correspondingStaticParameters == null) {
1070 // Either the AST structure has not been resolved or the invocation of whi ch this list is a
1071 // part could not be resolved.
1067 return null; 1072 return null;
1068 } 1073 }
1069 int index = _arguments.indexOf(expression); 1074 int index = _arguments.indexOf(expression);
1070 if (index < 0) { 1075 if (index < 0) {
1076 // The expression isn't a child of this node.
1071 return null; 1077 return null;
1072 } 1078 }
1073 return _correspondingStaticParameters[index]; 1079 return _correspondingStaticParameters[index];
1074 } 1080 }
1075 } 1081 }
1076 1082
1077 /** 1083 /**
1078 * Instances of the class `AsExpression` represent an 'as' expression. 1084 * Instances of the class `AsExpression` represent an 'as' expression.
1079 * 1085 *
1080 * <pre> 1086 * <pre>
(...skipping 4566 matching lines...) Expand 10 before | Expand all | Expand 10 after
5647 } 5653 }
5648 5654
5649 accept(ASTVisitor visitor) => visitor.visitFunctionExpression(this); 5655 accept(ASTVisitor visitor) => visitor.visitFunctionExpression(this);
5650 5656
5651 Token get beginToken { 5657 Token get beginToken {
5652 if (_parameters != null) { 5658 if (_parameters != null) {
5653 return _parameters.beginToken; 5659 return _parameters.beginToken;
5654 } else if (_body != null) { 5660 } else if (_body != null) {
5655 return _body.beginToken; 5661 return _body.beginToken;
5656 } 5662 }
5663 // This should never be reached because external functions must be named, he nce either the body
5664 // or the name should be non-null.
5657 throw new IllegalStateException("Non-external functions must have a body"); 5665 throw new IllegalStateException("Non-external functions must have a body");
5658 } 5666 }
5659 5667
5660 /** 5668 /**
5661 * Return the body of the function, or `null` if this is an external function. 5669 * Return the body of the function, or `null` if this is an external function.
5662 * 5670 *
5663 * @return the body of the function 5671 * @return the body of the function
5664 */ 5672 */
5665 FunctionBody get body => _body; 5673 FunctionBody get body => _body;
5666 5674
5667 Token get endToken { 5675 Token get endToken {
5668 if (_body != null) { 5676 if (_body != null) {
5669 return _body.endToken; 5677 return _body.endToken;
5670 } else if (_parameters != null) { 5678 } else if (_parameters != null) {
5671 return _parameters.endToken; 5679 return _parameters.endToken;
5672 } 5680 }
5681 // This should never be reached because external functions must be named, he nce either the body
5682 // or the name should be non-null.
5673 throw new IllegalStateException("Non-external functions must have a body"); 5683 throw new IllegalStateException("Non-external functions must have a body");
5674 } 5684 }
5675 5685
5676 /** 5686 /**
5677 * Return the parameters associated with the function. 5687 * Return the parameters associated with the function.
5678 * 5688 *
5679 * @return the parameters associated with the function 5689 * @return the parameters associated with the function
5680 */ 5690 */
5681 FormalParameterList get parameters => _parameters; 5691 FormalParameterList get parameters => _parameters;
5682 5692
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
6359 * 6369 *
6360 * <pre> 6370 * <pre>
6361 * importDirective ::= 6371 * importDirective ::=
6362 * [Annotation] 'import' [StringLiteral] ('as' identifier)? [Combinator]* '; ' 6372 * [Annotation] 'import' [StringLiteral] ('as' identifier)? [Combinator]* '; '
6363 * </pre> 6373 * </pre>
6364 * 6374 *
6365 * @coverage dart.engine.ast 6375 * @coverage dart.engine.ast
6366 */ 6376 */
6367 class ImportDirective extends NamespaceDirective { 6377 class ImportDirective extends NamespaceDirective {
6368 static Comparator<ImportDirective> COMPARATOR = (ImportDirective import1, Impo rtDirective import2) { 6378 static Comparator<ImportDirective> COMPARATOR = (ImportDirective import1, Impo rtDirective import2) {
6379 //
6380 // uri
6381 //
6369 StringLiteral uri1 = import1.uri; 6382 StringLiteral uri1 = import1.uri;
6370 StringLiteral uri2 = import2.uri; 6383 StringLiteral uri2 = import2.uri;
6371 String uriStr1 = uri1.stringValue; 6384 String uriStr1 = uri1.stringValue;
6372 String uriStr2 = uri2.stringValue; 6385 String uriStr2 = uri2.stringValue;
6373 if (uriStr1 != null || uriStr2 != null) { 6386 if (uriStr1 != null || uriStr2 != null) {
6374 if (uriStr1 == null) { 6387 if (uriStr1 == null) {
6375 return -1; 6388 return -1;
6376 } else if (uriStr2 == null) { 6389 } else if (uriStr2 == null) {
6377 return 1; 6390 return 1;
6378 } else { 6391 } else {
6379 int compare = uriStr1.compareTo(uriStr2); 6392 int compare = uriStr1.compareTo(uriStr2);
6380 if (compare != 0) { 6393 if (compare != 0) {
6381 return compare; 6394 return compare;
6382 } 6395 }
6383 } 6396 }
6384 } 6397 }
6398 //
6399 // as
6400 //
6385 SimpleIdentifier prefix1 = import1.prefix; 6401 SimpleIdentifier prefix1 = import1.prefix;
6386 SimpleIdentifier prefix2 = import2.prefix; 6402 SimpleIdentifier prefix2 = import2.prefix;
6387 String prefixStr1 = prefix1 != null ? prefix1.name : null; 6403 String prefixStr1 = prefix1 != null ? prefix1.name : null;
6388 String prefixStr2 = prefix2 != null ? prefix2.name : null; 6404 String prefixStr2 = prefix2 != null ? prefix2.name : null;
6389 if (prefixStr1 != null || prefixStr2 != null) { 6405 if (prefixStr1 != null || prefixStr2 != null) {
6390 if (prefixStr1 == null) { 6406 if (prefixStr1 == null) {
6391 return -1; 6407 return -1;
6392 } else if (prefixStr2 == null) { 6408 } else if (prefixStr2 == null) {
6393 return 1; 6409 return 1;
6394 } else { 6410 } else {
6395 int compare = prefixStr1.compareTo(prefixStr2); 6411 int compare = prefixStr1.compareTo(prefixStr2);
6396 if (compare != 0) { 6412 if (compare != 0) {
6397 return compare; 6413 return compare;
6398 } 6414 }
6399 } 6415 }
6400 } 6416 }
6417 //
6418 // hides and shows
6419 //
6401 NodeList<Combinator> combinators1 = import1.combinators; 6420 NodeList<Combinator> combinators1 = import1.combinators;
6402 List<String> allHides1 = new List<String>(); 6421 List<String> allHides1 = new List<String>();
6403 List<String> allShows1 = new List<String>(); 6422 List<String> allShows1 = new List<String>();
6404 for (Combinator combinator in combinators1) { 6423 for (Combinator combinator in combinators1) {
6405 if (combinator is HideCombinator) { 6424 if (combinator is HideCombinator) {
6406 NodeList<SimpleIdentifier> hides = combinator.hiddenNames; 6425 NodeList<SimpleIdentifier> hides = combinator.hiddenNames;
6407 for (SimpleIdentifier simpleIdentifier in hides) { 6426 for (SimpleIdentifier simpleIdentifier in hides) {
6408 allHides1.add(simpleIdentifier.name); 6427 allHides1.add(simpleIdentifier.name);
6409 } 6428 }
6410 } else { 6429 } else {
(...skipping 12 matching lines...) Expand all
6423 for (SimpleIdentifier simpleIdentifier in hides) { 6442 for (SimpleIdentifier simpleIdentifier in hides) {
6424 allHides2.add(simpleIdentifier.name); 6443 allHides2.add(simpleIdentifier.name);
6425 } 6444 }
6426 } else { 6445 } else {
6427 NodeList<SimpleIdentifier> shows = (combinator as ShowCombinator).shownN ames; 6446 NodeList<SimpleIdentifier> shows = (combinator as ShowCombinator).shownN ames;
6428 for (SimpleIdentifier simpleIdentifier in shows) { 6447 for (SimpleIdentifier simpleIdentifier in shows) {
6429 allShows2.add(simpleIdentifier.name); 6448 allShows2.add(simpleIdentifier.name);
6430 } 6449 }
6431 } 6450 }
6432 } 6451 }
6452 // test lengths of combinator lists first
6433 if (allHides1.length != allHides2.length) { 6453 if (allHides1.length != allHides2.length) {
6434 return allHides1.length - allHides2.length; 6454 return allHides1.length - allHides2.length;
6435 } 6455 }
6436 if (allShows1.length != allShows2.length) { 6456 if (allShows1.length != allShows2.length) {
6437 return allShows1.length - allShows2.length; 6457 return allShows1.length - allShows2.length;
6438 } 6458 }
6459 // next ensure that the lists are equivalent
6439 if (!javaCollectionContainsAll(allHides1, allHides2)) { 6460 if (!javaCollectionContainsAll(allHides1, allHides2)) {
6440 return -1; 6461 return -1;
6441 } 6462 }
6442 if (!javaCollectionContainsAll(allShows1, allShows2)) { 6463 if (!javaCollectionContainsAll(allShows1, allShows2)) {
6443 return -1; 6464 return -1;
6444 } 6465 }
6445 return 0; 6466 return 0;
6446 }; 6467 };
6447 6468
6448 /** 6469 /**
(...skipping 2076 matching lines...) Expand 10 before | Expand all | Expand 10 after
8525 /** 8546 /**
8526 * Set the name of the parameter being declared to the given identifier. 8547 * Set the name of the parameter being declared to the given identifier.
8527 * 8548 *
8528 * @param identifier the name of the parameter being declared 8549 * @param identifier the name of the parameter being declared
8529 */ 8550 */
8530 void set identifier(SimpleIdentifier identifier) { 8551 void set identifier(SimpleIdentifier identifier) {
8531 this._identifier = becomeParentOf(identifier); 8552 this._identifier = becomeParentOf(identifier);
8532 } 8553 }
8533 8554
8534 void visitChildren(ASTVisitor visitor) { 8555 void visitChildren(ASTVisitor visitor) {
8556 //
8557 // Note that subclasses are responsible for visiting the identifier because they often need to
8558 // visit other nodes before visiting the identifier.
8559 //
8535 if (commentIsBeforeAnnotations()) { 8560 if (commentIsBeforeAnnotations()) {
8536 safelyVisitChild(_comment, visitor); 8561 safelyVisitChild(_comment, visitor);
8537 _metadata.accept(visitor); 8562 _metadata.accept(visitor);
8538 } else { 8563 } else {
8539 for (ASTNode child in sortedCommentAndAnnotations) { 8564 for (ASTNode child in sortedCommentAndAnnotations) {
8540 child.accept(visitor); 8565 child.accept(visitor);
8541 } 8566 }
8542 } 8567 }
8543 } 8568 }
8544 8569
(...skipping 1328 matching lines...) Expand 10 before | Expand all | Expand 10 after
9873 * 9898 *
9874 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor ar e 9899 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor ar e
9875 * they mutually exclusive. In other words, it is possible for both methods to return `true` 9900 * they mutually exclusive. In other words, it is possible for both methods to return `true`
9876 * when invoked on the same node. 9901 * when invoked on the same node.
9877 * 9902 *
9878 * @return `true` if this expression is in a context where a getter will be in voked 9903 * @return `true` if this expression is in a context where a getter will be in voked
9879 */ 9904 */
9880 bool inGetterContext() { 9905 bool inGetterContext() {
9881 ASTNode parent = this.parent; 9906 ASTNode parent = this.parent;
9882 ASTNode target = this; 9907 ASTNode target = this;
9908 // skip prefix
9883 if (parent is PrefixedIdentifier) { 9909 if (parent is PrefixedIdentifier) {
9884 PrefixedIdentifier prefixed = parent as PrefixedIdentifier; 9910 PrefixedIdentifier prefixed = parent as PrefixedIdentifier;
9885 if (identical(prefixed.prefix, this)) { 9911 if (identical(prefixed.prefix, this)) {
9886 return true; 9912 return true;
9887 } 9913 }
9888 parent = prefixed.parent; 9914 parent = prefixed.parent;
9889 target = prefixed; 9915 target = prefixed;
9890 } else if (parent is PropertyAccess) { 9916 } else if (parent is PropertyAccess) {
9891 PropertyAccess access = parent as PropertyAccess; 9917 PropertyAccess access = parent as PropertyAccess;
9892 if (identical(access.target, this)) { 9918 if (identical(access.target, this)) {
9893 return true; 9919 return true;
9894 } 9920 }
9895 parent = access.parent; 9921 parent = access.parent;
9896 target = access; 9922 target = access;
9897 } 9923 }
9924 // skip label
9898 if (parent is Label) { 9925 if (parent is Label) {
9899 return false; 9926 return false;
9900 } 9927 }
9928 // analyze usage
9901 if (parent is AssignmentExpression) { 9929 if (parent is AssignmentExpression) {
9902 AssignmentExpression expr = parent as AssignmentExpression; 9930 AssignmentExpression expr = parent as AssignmentExpression;
9903 if (identical(expr.leftHandSide, target) && identical(expr.operator.type, TokenType.EQ)) { 9931 if (identical(expr.leftHandSide, target) && identical(expr.operator.type, TokenType.EQ)) {
9904 return false; 9932 return false;
9905 } 9933 }
9906 } 9934 }
9907 return true; 9935 return true;
9908 } 9936 }
9909 9937
9910 /** 9938 /**
9911 * Return `true` if this expression is computing a left-hand value. 9939 * Return `true` if this expression is computing a left-hand value.
9912 * 9940 *
9913 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor ar e 9941 * Note that [inGetterContext] and [inSetterContext] are not opposites, nor ar e
9914 * they mutually exclusive. In other words, it is possible for both methods to return `true` 9942 * they mutually exclusive. In other words, it is possible for both methods to return `true`
9915 * when invoked on the same node. 9943 * when invoked on the same node.
9916 * 9944 *
9917 * @return `true` if this expression is in a context where a setter will be in voked 9945 * @return `true` if this expression is in a context where a setter will be in voked
9918 */ 9946 */
9919 bool inSetterContext() { 9947 bool inSetterContext() {
9920 ASTNode parent = this.parent; 9948 ASTNode parent = this.parent;
9921 ASTNode target = this; 9949 ASTNode target = this;
9950 // skip prefix
9922 if (parent is PrefixedIdentifier) { 9951 if (parent is PrefixedIdentifier) {
9923 PrefixedIdentifier prefixed = parent as PrefixedIdentifier; 9952 PrefixedIdentifier prefixed = parent as PrefixedIdentifier;
9953 // if this is the prefix, then return false
9924 if (identical(prefixed.prefix, this)) { 9954 if (identical(prefixed.prefix, this)) {
9925 return false; 9955 return false;
9926 } 9956 }
9927 parent = prefixed.parent; 9957 parent = prefixed.parent;
9928 target = prefixed; 9958 target = prefixed;
9929 } else if (parent is PropertyAccess) { 9959 } else if (parent is PropertyAccess) {
9930 PropertyAccess access = parent as PropertyAccess; 9960 PropertyAccess access = parent as PropertyAccess;
9931 if (identical(access.target, this)) { 9961 if (identical(access.target, this)) {
9932 return false; 9962 return false;
9933 } 9963 }
9934 parent = access.parent; 9964 parent = access.parent;
9935 target = access; 9965 target = access;
9936 } 9966 }
9967 // analyze usage
9937 if (parent is PrefixExpression) { 9968 if (parent is PrefixExpression) {
9938 return (parent as PrefixExpression).operator.type.isIncrementOperator; 9969 return (parent as PrefixExpression).operator.type.isIncrementOperator;
9939 } else if (parent is PostfixExpression) { 9970 } else if (parent is PostfixExpression) {
9940 return true; 9971 return true;
9941 } else if (parent is AssignmentExpression) { 9972 } else if (parent is AssignmentExpression) {
9942 return identical((parent as AssignmentExpression).leftHandSide, target); 9973 return identical((parent as AssignmentExpression).leftHandSide, target);
9943 } 9974 }
9944 return false; 9975 return false;
9945 } 9976 }
9946 9977
(...skipping 2052 matching lines...) Expand 10 before | Expand all | Expand 10 after
11999 Object leftOperand = node.leftOperand.accept(this); 12030 Object leftOperand = node.leftOperand.accept(this);
12000 if (identical(leftOperand, NOT_A_CONSTANT)) { 12031 if (identical(leftOperand, NOT_A_CONSTANT)) {
12001 return leftOperand; 12032 return leftOperand;
12002 } 12033 }
12003 Object rightOperand = node.rightOperand.accept(this); 12034 Object rightOperand = node.rightOperand.accept(this);
12004 if (identical(rightOperand, NOT_A_CONSTANT)) { 12035 if (identical(rightOperand, NOT_A_CONSTANT)) {
12005 return rightOperand; 12036 return rightOperand;
12006 } 12037 }
12007 while (true) { 12038 while (true) {
12008 if (node.operator.type == TokenType.AMPERSAND) { 12039 if (node.operator.type == TokenType.AMPERSAND) {
12040 // integer or {@code null}
12009 if (leftOperand is int && rightOperand is int) { 12041 if (leftOperand is int && rightOperand is int) {
12010 return leftOperand & rightOperand; 12042 return leftOperand & rightOperand;
12011 } 12043 }
12012 } else if (node.operator.type == TokenType.AMPERSAND_AMPERSAND) { 12044 } else if (node.operator.type == TokenType.AMPERSAND_AMPERSAND) {
12045 // boolean or {@code null}
12013 if (leftOperand is bool && rightOperand is bool) { 12046 if (leftOperand is bool && rightOperand is bool) {
12014 return leftOperand && rightOperand; 12047 return leftOperand && rightOperand;
12015 } 12048 }
12016 } else if (node.operator.type == TokenType.BANG_EQ) { 12049 } else if (node.operator.type == TokenType.BANG_EQ) {
12050 // numeric, string, boolean, or {@code null}
12017 if (leftOperand is bool && rightOperand is bool) { 12051 if (leftOperand is bool && rightOperand is bool) {
12018 return leftOperand != rightOperand; 12052 return leftOperand != rightOperand;
12019 } else if (leftOperand is int && rightOperand is int) { 12053 } else if (leftOperand is int && rightOperand is int) {
12020 return leftOperand != rightOperand; 12054 return leftOperand != rightOperand;
12021 } else if (leftOperand is double && rightOperand is double) { 12055 } else if (leftOperand is double && rightOperand is double) {
12022 return leftOperand != rightOperand; 12056 return leftOperand != rightOperand;
12023 } else if (leftOperand is String && rightOperand is String) { 12057 } else if (leftOperand is String && rightOperand is String) {
12024 return leftOperand != rightOperand; 12058 return leftOperand != rightOperand;
12025 } 12059 }
12026 } else if (node.operator.type == TokenType.BAR) { 12060 } else if (node.operator.type == TokenType.BAR) {
12061 // integer or {@code null}
12027 if (leftOperand is int && rightOperand is int) { 12062 if (leftOperand is int && rightOperand is int) {
12028 return leftOperand | rightOperand; 12063 return leftOperand | rightOperand;
12029 } 12064 }
12030 } else if (node.operator.type == TokenType.BAR_BAR) { 12065 } else if (node.operator.type == TokenType.BAR_BAR) {
12066 // boolean or {@code null}
12031 if (leftOperand is bool && rightOperand is bool) { 12067 if (leftOperand is bool && rightOperand is bool) {
12032 return leftOperand || rightOperand; 12068 return leftOperand || rightOperand;
12033 } 12069 }
12034 } else if (node.operator.type == TokenType.CARET) { 12070 } else if (node.operator.type == TokenType.CARET) {
12071 // integer or {@code null}
12035 if (leftOperand is int && rightOperand is int) { 12072 if (leftOperand is int && rightOperand is int) {
12036 return leftOperand ^ rightOperand; 12073 return leftOperand ^ rightOperand;
12037 } 12074 }
12038 } else if (node.operator.type == TokenType.EQ_EQ) { 12075 } else if (node.operator.type == TokenType.EQ_EQ) {
12076 // numeric, string, boolean, or {@code null}
12039 if (leftOperand is bool && rightOperand is bool) { 12077 if (leftOperand is bool && rightOperand is bool) {
12040 return identical(leftOperand, rightOperand); 12078 return identical(leftOperand, rightOperand);
12041 } else if (leftOperand is int && rightOperand is int) { 12079 } else if (leftOperand is int && rightOperand is int) {
12042 return leftOperand == rightOperand; 12080 return leftOperand == rightOperand;
12043 } else if (leftOperand is double && rightOperand is double) { 12081 } else if (leftOperand is double && rightOperand is double) {
12044 return leftOperand == rightOperand; 12082 return leftOperand == rightOperand;
12045 } else if (leftOperand is String && rightOperand is String) { 12083 } else if (leftOperand is String && rightOperand is String) {
12046 return leftOperand == rightOperand; 12084 return leftOperand == rightOperand;
12047 } 12085 }
12048 } else if (node.operator.type == TokenType.GT) { 12086 } else if (node.operator.type == TokenType.GT) {
12087 // numeric or {@code null}
12049 if (leftOperand is int && rightOperand is int) { 12088 if (leftOperand is int && rightOperand is int) {
12050 return leftOperand.compareTo(rightOperand) > 0; 12089 return leftOperand.compareTo(rightOperand) > 0;
12051 } else if (leftOperand is double && rightOperand is double) { 12090 } else if (leftOperand is double && rightOperand is double) {
12052 return leftOperand.compareTo(rightOperand) > 0; 12091 return leftOperand.compareTo(rightOperand) > 0;
12053 } 12092 }
12054 } else if (node.operator.type == TokenType.GT_EQ) { 12093 } else if (node.operator.type == TokenType.GT_EQ) {
12094 // numeric or {@code null}
12055 if (leftOperand is int && rightOperand is int) { 12095 if (leftOperand is int && rightOperand is int) {
12056 return leftOperand.compareTo(rightOperand) >= 0; 12096 return leftOperand.compareTo(rightOperand) >= 0;
12057 } else if (leftOperand is double && rightOperand is double) { 12097 } else if (leftOperand is double && rightOperand is double) {
12058 return leftOperand.compareTo(rightOperand) >= 0; 12098 return leftOperand.compareTo(rightOperand) >= 0;
12059 } 12099 }
12060 } else if (node.operator.type == TokenType.GT_GT) { 12100 } else if (node.operator.type == TokenType.GT_GT) {
12101 // integer or {@code null}
12061 if (leftOperand is int && rightOperand is int) { 12102 if (leftOperand is int && rightOperand is int) {
12062 return leftOperand >> rightOperand; 12103 return leftOperand >> rightOperand;
12063 } 12104 }
12064 } else if (node.operator.type == TokenType.LT) { 12105 } else if (node.operator.type == TokenType.LT) {
12106 // numeric or {@code null}
12065 if (leftOperand is int && rightOperand is int) { 12107 if (leftOperand is int && rightOperand is int) {
12066 return leftOperand.compareTo(rightOperand) < 0; 12108 return leftOperand.compareTo(rightOperand) < 0;
12067 } else if (leftOperand is double && rightOperand is double) { 12109 } else if (leftOperand is double && rightOperand is double) {
12068 return leftOperand.compareTo(rightOperand) < 0; 12110 return leftOperand.compareTo(rightOperand) < 0;
12069 } 12111 }
12070 } else if (node.operator.type == TokenType.LT_EQ) { 12112 } else if (node.operator.type == TokenType.LT_EQ) {
12113 // numeric or {@code null}
12071 if (leftOperand is int && rightOperand is int) { 12114 if (leftOperand is int && rightOperand is int) {
12072 return leftOperand.compareTo(rightOperand) <= 0; 12115 return leftOperand.compareTo(rightOperand) <= 0;
12073 } else if (leftOperand is double && rightOperand is double) { 12116 } else if (leftOperand is double && rightOperand is double) {
12074 return leftOperand.compareTo(rightOperand) <= 0; 12117 return leftOperand.compareTo(rightOperand) <= 0;
12075 } 12118 }
12076 } else if (node.operator.type == TokenType.LT_LT) { 12119 } else if (node.operator.type == TokenType.LT_LT) {
12120 // integer or {@code null}
12077 if (leftOperand is int && rightOperand is int) { 12121 if (leftOperand is int && rightOperand is int) {
12078 return leftOperand << rightOperand; 12122 return leftOperand << rightOperand;
12079 } 12123 }
12080 } else if (node.operator.type == TokenType.MINUS) { 12124 } else if (node.operator.type == TokenType.MINUS) {
12125 // numeric or {@code null}
12081 if (leftOperand is int && rightOperand is int) { 12126 if (leftOperand is int && rightOperand is int) {
12082 return leftOperand - rightOperand; 12127 return leftOperand - rightOperand;
12083 } else if (leftOperand is double && rightOperand is double) { 12128 } else if (leftOperand is double && rightOperand is double) {
12084 return leftOperand - rightOperand; 12129 return leftOperand - rightOperand;
12085 } 12130 }
12086 } else if (node.operator.type == TokenType.PERCENT) { 12131 } else if (node.operator.type == TokenType.PERCENT) {
12132 // numeric or {@code null}
12087 if (leftOperand is int && rightOperand is int) { 12133 if (leftOperand is int && rightOperand is int) {
12088 return leftOperand.remainder(rightOperand); 12134 return leftOperand.remainder(rightOperand);
12089 } else if (leftOperand is double && rightOperand is double) { 12135 } else if (leftOperand is double && rightOperand is double) {
12090 return leftOperand % rightOperand; 12136 return leftOperand % rightOperand;
12091 } 12137 }
12092 } else if (node.operator.type == TokenType.PLUS) { 12138 } else if (node.operator.type == TokenType.PLUS) {
12139 // numeric or {@code null}
12093 if (leftOperand is int && rightOperand is int) { 12140 if (leftOperand is int && rightOperand is int) {
12094 return leftOperand + rightOperand; 12141 return leftOperand + rightOperand;
12095 } else if (leftOperand is double && rightOperand is double) { 12142 } else if (leftOperand is double && rightOperand is double) {
12096 return leftOperand + rightOperand; 12143 return leftOperand + rightOperand;
12097 } 12144 }
12098 } else if (node.operator.type == TokenType.STAR) { 12145 } else if (node.operator.type == TokenType.STAR) {
12146 // numeric or {@code null}
12099 if (leftOperand is int && rightOperand is int) { 12147 if (leftOperand is int && rightOperand is int) {
12100 return leftOperand * rightOperand; 12148 return leftOperand * rightOperand;
12101 } else if (leftOperand is double && rightOperand is double) { 12149 } else if (leftOperand is double && rightOperand is double) {
12102 return leftOperand * rightOperand; 12150 return leftOperand * rightOperand;
12103 } 12151 }
12104 } else if (node.operator.type == TokenType.SLASH) { 12152 } else if (node.operator.type == TokenType.SLASH) {
12153 // numeric or {@code null}
12105 if (leftOperand is int && rightOperand is int) { 12154 if (leftOperand is int && rightOperand is int) {
12106 if (rightOperand != 0) { 12155 if (rightOperand != 0) {
12107 return leftOperand ~/ rightOperand; 12156 return leftOperand ~/ rightOperand;
12108 } else { 12157 } else {
12109 return leftOperand.toDouble() / rightOperand.toDouble(); 12158 return leftOperand.toDouble() / rightOperand.toDouble();
12110 } 12159 }
12111 } else if (leftOperand is double && rightOperand is double) { 12160 } else if (leftOperand is double && rightOperand is double) {
12112 return leftOperand / rightOperand; 12161 return leftOperand / rightOperand;
12113 } 12162 }
12114 } else if (node.operator.type == TokenType.TILDE_SLASH) { 12163 } else if (node.operator.type == TokenType.TILDE_SLASH) {
12164 // numeric or {@code null}
12115 if (leftOperand is int && rightOperand is int) { 12165 if (leftOperand is int && rightOperand is int) {
12116 if (rightOperand != 0) { 12166 if (rightOperand != 0) {
12117 return leftOperand ~/ rightOperand; 12167 return leftOperand ~/ rightOperand;
12118 } else { 12168 } else {
12119 return 0; 12169 return 0;
12120 } 12170 }
12121 } else if (leftOperand is double && rightOperand is double) { 12171 } else if (leftOperand is double && rightOperand is double) {
12122 return leftOperand ~/ rightOperand; 12172 return leftOperand ~/ rightOperand;
12123 } 12173 }
12124 } 12174 }
12125 break; 12175 break;
12126 } 12176 }
12177 // TODO(brianwilkerson) This doesn't handle numeric conversions.
12127 return visitExpression(node); 12178 return visitExpression(node);
12128 } 12179 }
12129 12180
12130 Object visitBooleanLiteral(BooleanLiteral node) => node.value ? true : false; 12181 Object visitBooleanLiteral(BooleanLiteral node) => node.value ? true : false;
12131 12182
12132 Object visitDoubleLiteral(DoubleLiteral node) => node.value; 12183 Object visitDoubleLiteral(DoubleLiteral node) => node.value;
12133 12184
12134 Object visitIntegerLiteral(IntegerLiteral node) => node.value; 12185 Object visitIntegerLiteral(IntegerLiteral node) => node.value;
12135 12186
12136 Object visitInterpolationExpression(InterpolationExpression node) { 12187 Object visitInterpolationExpression(InterpolationExpression node) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
12220 Object value = element.accept(this); 12271 Object value = element.accept(this);
12221 if (identical(value, NOT_A_CONSTANT)) { 12272 if (identical(value, NOT_A_CONSTANT)) {
12222 return value; 12273 return value;
12223 } 12274 }
12224 builder.append(value); 12275 builder.append(value);
12225 } 12276 }
12226 return builder.toString(); 12277 return builder.toString();
12227 } 12278 }
12228 12279
12229 Object visitSymbolLiteral(SymbolLiteral node) { 12280 Object visitSymbolLiteral(SymbolLiteral node) {
12281 // TODO(brianwilkerson) This isn't optimal because a Symbol is not a String.
12230 JavaStringBuilder builder = new JavaStringBuilder(); 12282 JavaStringBuilder builder = new JavaStringBuilder();
12231 for (Token component in node.components) { 12283 for (Token component in node.components) {
12232 if (builder.length > 0) { 12284 if (builder.length > 0) {
12233 builder.appendChar(0x2E); 12285 builder.appendChar(0x2E);
12234 } 12286 }
12235 builder.append(component.lexeme); 12287 builder.append(component.lexeme);
12236 } 12288 }
12237 return builder.toString(); 12289 return builder.toString();
12238 } 12290 }
12239 12291
12240 /** 12292 /**
12241 * Return the constant value of the static constant represented by the given e lement. 12293 * Return the constant value of the static constant represented by the given e lement.
12242 * 12294 *
12243 * @param element the element whose value is to be returned 12295 * @param element the element whose value is to be returned
12244 * @return the constant value of the static constant 12296 * @return the constant value of the static constant
12245 */ 12297 */
12246 Object getConstantValue(Element element) { 12298 Object getConstantValue(Element element) {
12299 // TODO(brianwilkerson) Implement this
12247 if (element is FieldElement) { 12300 if (element is FieldElement) {
12248 FieldElement field = element; 12301 FieldElement field = element;
12249 if (field.isStatic && field.isConst) { 12302 if (field.isStatic && field.isConst) {
12250 } 12303 }
12251 } 12304 }
12252 return NOT_A_CONSTANT; 12305 return NOT_A_CONSTANT;
12253 } 12306 }
12254 } 12307 }
12255 12308
12256 /** 12309 /**
(...skipping 15 matching lines...) Expand all
12272 } 12325 }
12273 12326
12274 /** 12327 /**
12275 * Locate the [Element] associated with the given [ASTNode] and offset. 12328 * Locate the [Element] associated with the given [ASTNode] and offset.
12276 * 12329 *
12277 * @param node the node (not `null`) 12330 * @param node the node (not `null`)
12278 * @param offset the offset relative to source 12331 * @param offset the offset relative to source
12279 * @return the associated element, or `null` if none is found 12332 * @return the associated element, or `null` if none is found
12280 */ 12333 */
12281 static Element locate2(ASTNode node, int offset) { 12334 static Element locate2(ASTNode node, int offset) {
12335 // try to get Element from node
12282 { 12336 {
12283 Element nodeElement = locate(node); 12337 Element nodeElement = locate(node);
12284 if (nodeElement != null) { 12338 if (nodeElement != null) {
12285 return nodeElement; 12339 return nodeElement;
12286 } 12340 }
12287 } 12341 }
12342 // try to get Angular specific Element
12288 { 12343 {
12289 Element element = null; 12344 Element element = null;
12290 if (element != null) { 12345 if (element != null) {
12291 return element; 12346 return element;
12292 } 12347 }
12293 } 12348 }
12349 // no Element
12294 return null; 12350 return null;
12295 } 12351 }
12296 } 12352 }
12297 12353
12298 /** 12354 /**
12299 * Visitor that maps nodes to elements. 12355 * Visitor that maps nodes to elements.
12300 */ 12356 */
12301 class ElementLocator_ElementMapper extends GeneralizingASTVisitor<Element> { 12357 class ElementLocator_ElementMapper extends GeneralizingASTVisitor<Element> {
12302 Element visitAssignmentExpression(AssignmentExpression node) => node.bestEleme nt; 12358 Element visitAssignmentExpression(AssignmentExpression node) => node.bestEleme nt;
12303 12359
12304 Element visitBinaryExpression(BinaryExpression node) => node.bestElement; 12360 Element visitBinaryExpression(BinaryExpression node) => node.bestElement;
12305 12361
12306 Element visitClassDeclaration(ClassDeclaration node) => node.element; 12362 Element visitClassDeclaration(ClassDeclaration node) => node.element;
12307 12363
12308 Element visitCompilationUnit(CompilationUnit node) => node.element; 12364 Element visitCompilationUnit(CompilationUnit node) => node.element;
12309 12365
12310 Element visitConstructorDeclaration(ConstructorDeclaration node) => node.eleme nt; 12366 Element visitConstructorDeclaration(ConstructorDeclaration node) => node.eleme nt;
12311 12367
12312 Element visitFunctionDeclaration(FunctionDeclaration node) => node.element; 12368 Element visitFunctionDeclaration(FunctionDeclaration node) => node.element;
12313 12369
12314 Element visitIdentifier(Identifier node) { 12370 Element visitIdentifier(Identifier node) {
12315 ASTNode parent = node.parent; 12371 ASTNode parent = node.parent;
12372 // Extra work to map Constructor Declarations to their associated Constructo r Elements
12316 if (parent is ConstructorDeclaration) { 12373 if (parent is ConstructorDeclaration) {
12317 ConstructorDeclaration decl = parent; 12374 ConstructorDeclaration decl = parent;
12318 Identifier returnType = decl.returnType; 12375 Identifier returnType = decl.returnType;
12319 if (identical(returnType, node)) { 12376 if (identical(returnType, node)) {
12320 SimpleIdentifier name = decl.name; 12377 SimpleIdentifier name = decl.name;
12321 if (name != null) { 12378 if (name != null) {
12322 return name.bestElement; 12379 return name.bestElement;
12323 } 12380 }
12324 Element element = node.bestElement; 12381 Element element = node.bestElement;
12325 if (element is ClassElement) { 12382 if (element is ClassElement) {
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
12727 return null; 12784 return null;
12728 } 12785 }
12729 if (start > _endOffset) { 12786 if (start > _endOffset) {
12730 return null; 12787 return null;
12731 } 12788 }
12732 try { 12789 try {
12733 node.visitChildren(this); 12790 node.visitChildren(this);
12734 } on NodeLocator_NodeFoundException catch (exception) { 12791 } on NodeLocator_NodeFoundException catch (exception) {
12735 throw exception; 12792 throw exception;
12736 } on JavaException catch (exception) { 12793 } on JavaException catch (exception) {
12794 // Ignore the exception and proceed in order to visit the rest of the stru cture.
12737 AnalysisEngine.instance.logger.logInformation2("Exception caught while tra versing an AST structure.", exception); 12795 AnalysisEngine.instance.logger.logInformation2("Exception caught while tra versing an AST structure.", exception);
12738 } 12796 }
12739 if (start <= _startOffset && _endOffset <= end) { 12797 if (start <= _startOffset && _endOffset <= end) {
12740 _foundNode = node; 12798 _foundNode = node;
12741 throw new NodeLocator_NodeFoundException(); 12799 throw new NodeLocator_NodeFoundException();
12742 } 12800 }
12743 return null; 12801 return null;
12744 } 12802 }
12745 } 12803 }
12746 12804
(...skipping 3215 matching lines...) Expand 10 before | Expand all | Expand 10 after
15962 16020
15963 ScriptTag visitScriptTag(ScriptTag node) => new ScriptTag(map(node.scriptTag)) ; 16021 ScriptTag visitScriptTag(ScriptTag node) => new ScriptTag(map(node.scriptTag)) ;
15964 16022
15965 ShowCombinator visitShowCombinator(ShowCombinator node) => new ShowCombinator( map(node.keyword), clone5(node.shownNames)); 16023 ShowCombinator visitShowCombinator(ShowCombinator node) => new ShowCombinator( map(node.keyword), clone5(node.shownNames));
15966 16024
15967 SimpleFormalParameter visitSimpleFormalParameter(SimpleFormalParameter node) = > new SimpleFormalParameter(clone4(node.documentationComment), clone5(node.metad ata), map(node.keyword), clone4(node.type), clone4(node.identifier)); 16025 SimpleFormalParameter visitSimpleFormalParameter(SimpleFormalParameter node) = > new SimpleFormalParameter(clone4(node.documentationComment), clone5(node.metad ata), map(node.keyword), clone4(node.type), clone4(node.identifier));
15968 16026
15969 SimpleIdentifier visitSimpleIdentifier(SimpleIdentifier node) { 16027 SimpleIdentifier visitSimpleIdentifier(SimpleIdentifier node) {
15970 Token mappedToken = map(node.token); 16028 Token mappedToken = map(node.token);
15971 if (mappedToken == null) { 16029 if (mappedToken == null) {
16030 // This only happens for SimpleIdentifiers created by the parser as part o f scanning
16031 // documentation comments (the tokens for those identifiers are not in the original token
16032 // stream and hence do not get copied). This extra check can be removed if the scanner is
16033 // changed to scan documentation comments for the parser.
15972 mappedToken = node.token; 16034 mappedToken = node.token;
15973 } 16035 }
15974 SimpleIdentifier copy = new SimpleIdentifier(mappedToken); 16036 SimpleIdentifier copy = new SimpleIdentifier(mappedToken);
15975 copy.auxiliaryElements = node.auxiliaryElements; 16037 copy.auxiliaryElements = node.auxiliaryElements;
15976 copy.propagatedElement = node.propagatedElement; 16038 copy.propagatedElement = node.propagatedElement;
15977 copy.propagatedType = node.propagatedType; 16039 copy.propagatedType = node.propagatedType;
15978 copy.staticElement = node.staticElement; 16040 copy.staticElement = node.staticElement;
15979 copy.staticType = node.staticType; 16041 copy.staticType = node.staticType;
15980 return copy; 16042 return copy;
15981 } 16043 }
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
16251 if (stmt is VariableDeclarationStatement) { 16313 if (stmt is VariableDeclarationStatement) {
16252 addVariables(stmt.variables.variables); 16314 addVariables(stmt.variables.variables);
16253 } else if (stmt is FunctionDeclarationStatement && !_referenceIsWithinLoca lFunction) { 16315 } else if (stmt is FunctionDeclarationStatement && !_referenceIsWithinLoca lFunction) {
16254 addToScope(stmt.functionDeclaration.name); 16316 addToScope(stmt.functionDeclaration.name);
16255 } 16317 }
16256 } 16318 }
16257 } 16319 }
16258 16320
16259 bool isInRange(ASTNode node) { 16321 bool isInRange(ASTNode node) {
16260 if (_position < 0) { 16322 if (_position < 0) {
16323 // if source position is not set then all nodes are in range
16261 return true; 16324 return true;
16262 } 16325 }
16263 return node.end < _position; 16326 return node.end < _position;
16264 } 16327 }
16265 } 16328 }
16266 /** 16329 /**
16267 * Instances of the class {@code NodeList} represent a list of AST nodes that ha ve a common parent. 16330 * Instances of the class {@code NodeList} represent a list of AST nodes that ha ve a common parent.
16268 */ 16331 */
16269 class NodeList<E extends ASTNode> extends Object with ListMixin<E> { 16332 class NodeList<E extends ASTNode> extends Object with ListMixin<E> {
16270 /** 16333 /**
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
16375 } 16438 }
16376 void operator[]=(int index, E node) { 16439 void operator[]=(int index, E node) {
16377 if (index < 0 || index >= _elements.length) { 16440 if (index < 0 || index >= _elements.length) {
16378 throw new RangeError("Index: ${index}, Size: ${_elements.length}"); 16441 throw new RangeError("Index: ${index}, Size: ${_elements.length}");
16379 } 16442 }
16380 owner.becomeParentOf(node); 16443 owner.becomeParentOf(node);
16381 _elements[index] = node; 16444 _elements[index] = node;
16382 } 16445 }
16383 int get length => _elements.length; 16446 int get length => _elements.length;
16384 } 16447 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698