| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library engine.ast; | 5 library engine.ast; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'element.dart'; | 9 import 'element.dart'; |
| 10 import 'engine.dart' show AnalysisEngine; | 10 import 'engine.dart' show AnalysisEngine; |
| (...skipping 2855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2866 */ | 2866 */ |
| 2867 static const List<AstNode> EMPTY_LIST = const <AstNode>[]; | 2867 static const List<AstNode> EMPTY_LIST = const <AstNode>[]; |
| 2868 | 2868 |
| 2869 /** | 2869 /** |
| 2870 * A comparator that can be used to sort AST nodes in lexical order. In other | 2870 * A comparator that can be used to sort AST nodes in lexical order. In other |
| 2871 * words, `compare` will return a negative value if the offset of the first | 2871 * words, `compare` will return a negative value if the offset of the first |
| 2872 * node is less than the offset of the second node, zero (0) if the nodes have | 2872 * node is less than the offset of the second node, zero (0) if the nodes have |
| 2873 * the same offset, and a positive value if the offset of the first node is | 2873 * the same offset, and a positive value if the offset of the first node is |
| 2874 * greater than the offset of the second node. | 2874 * greater than the offset of the second node. |
| 2875 */ | 2875 */ |
| 2876 static Comparator<AstNode> LEXICAL_ORDER = (AstNode first, AstNode second) => | 2876 static Comparator<AstNode> LEXICAL_ORDER = |
| 2877 first.offset - second.offset; | 2877 (AstNode first, AstNode second) => first.offset - second.offset; |
| 2878 | 2878 |
| 2879 /** | 2879 /** |
| 2880 * The parent of the node, or `null` if the node is the root of an AST | 2880 * The parent of the node, or `null` if the node is the root of an AST |
| 2881 * structure. | 2881 * structure. |
| 2882 */ | 2882 */ |
| 2883 AstNode _parent; | 2883 AstNode _parent; |
| 2884 | 2884 |
| 2885 /** | 2885 /** |
| 2886 * A table mapping the names of properties to their values, or `null` if this | 2886 * A table mapping the names of properties to their values, or `null` if this |
| 2887 * node does not have any properties associated with it. | 2887 * node does not have any properties associated with it. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2967 root = parent; | 2967 root = parent; |
| 2968 parent = root.parent; | 2968 parent = root.parent; |
| 2969 } | 2969 } |
| 2970 return root; | 2970 return root; |
| 2971 } | 2971 } |
| 2972 | 2972 |
| 2973 /** | 2973 /** |
| 2974 * Use the given [visitor] to visit this node. Return the value returned by | 2974 * Use the given [visitor] to visit this node. Return the value returned by |
| 2975 * the visitor as a result of visiting this node. | 2975 * the visitor as a result of visiting this node. |
| 2976 */ | 2976 */ |
| 2977 /* <E> E */ accept(AstVisitor /*<E>*/ visitor); | 2977 dynamic /*=E*/ accept /*<E>*/ (AstVisitor /*<E>*/ visitor); |
| 2978 | 2978 |
| 2979 /** | 2979 /** |
| 2980 * Return the most immediate ancestor of this node for which the [predicate] | 2980 * Return the most immediate ancestor of this node for which the [predicate] |
| 2981 * returns `true`, or `null` if there is no such ancestor. Note that this node | 2981 * returns `true`, or `null` if there is no such ancestor. Note that this node |
| 2982 * will never be returned. | 2982 * will never be returned. |
| 2983 */ | 2983 */ |
| 2984 AstNode getAncestor(Predicate<AstNode> predicate) { | 2984 AstNode getAncestor(Predicate<AstNode> predicate) { |
| 2985 // TODO(brianwilkerson) It is a bug that this method can return `this`. | 2985 // TODO(brianwilkerson) It is a bug that this method can return `this`. |
| 2986 AstNode node = this; | 2986 AstNode node = this; |
| 2987 while (node != null && !predicate(node)) { | 2987 while (node != null && !predicate(node)) { |
| (...skipping 3121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6109 /** | 6109 /** |
| 6110 * Set the name of the variable being declared to the given [identifier]. | 6110 * Set the name of the variable being declared to the given [identifier]. |
| 6111 */ | 6111 */ |
| 6112 void set identifier(SimpleIdentifier identifier) { | 6112 void set identifier(SimpleIdentifier identifier) { |
| 6113 _identifier = _becomeParentOf(identifier); | 6113 _identifier = _becomeParentOf(identifier); |
| 6114 } | 6114 } |
| 6115 | 6115 |
| 6116 /** | 6116 /** |
| 6117 * Return `true` if this variable was declared with the 'const' modifier. | 6117 * Return `true` if this variable was declared with the 'const' modifier. |
| 6118 */ | 6118 */ |
| 6119 bool get isConst => (keyword is KeywordToken) && | 6119 bool get isConst => |
| 6120 (keyword is KeywordToken) && |
| 6120 (keyword as KeywordToken).keyword == Keyword.CONST; | 6121 (keyword as KeywordToken).keyword == Keyword.CONST; |
| 6121 | 6122 |
| 6122 /** | 6123 /** |
| 6123 * Return `true` if this variable was declared with the 'final' modifier. | 6124 * Return `true` if this variable was declared with the 'final' modifier. |
| 6124 * Variables that are declared with the 'const' modifier will return `false` | 6125 * Variables that are declared with the 'const' modifier will return `false` |
| 6125 * even though they are implicitly final. | 6126 * even though they are implicitly final. |
| 6126 */ | 6127 */ |
| 6127 bool get isFinal => (keyword is KeywordToken) && | 6128 bool get isFinal => |
| 6129 (keyword is KeywordToken) && |
| 6128 (keyword as KeywordToken).keyword == Keyword.FINAL; | 6130 (keyword as KeywordToken).keyword == Keyword.FINAL; |
| 6129 | 6131 |
| 6130 /** | 6132 /** |
| 6131 * Return the name of the declared type of the parameter, or `null` if the | 6133 * Return the name of the declared type of the parameter, or `null` if the |
| 6132 * parameter does not have a declared type. | 6134 * parameter does not have a declared type. |
| 6133 */ | 6135 */ |
| 6134 TypeName get type => _type; | 6136 TypeName get type => _type; |
| 6135 | 6137 |
| 6136 /** | 6138 /** |
| 6137 * Set the name of the declared type of the parameter to the given [typeName]. | 6139 * Set the name of the declared type of the parameter to the given [typeName]. |
| (...skipping 1299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7437 | 7439 |
| 7438 @override | 7440 @override |
| 7439 Token get endToken { | 7441 Token get endToken { |
| 7440 if (_parameters != null) { | 7442 if (_parameters != null) { |
| 7441 return _parameters.endToken; | 7443 return _parameters.endToken; |
| 7442 } | 7444 } |
| 7443 return identifier.endToken; | 7445 return identifier.endToken; |
| 7444 } | 7446 } |
| 7445 | 7447 |
| 7446 @override | 7448 @override |
| 7447 bool get isConst => (keyword is KeywordToken) && | 7449 bool get isConst => |
| 7450 (keyword is KeywordToken) && |
| 7448 (keyword as KeywordToken).keyword == Keyword.CONST; | 7451 (keyword as KeywordToken).keyword == Keyword.CONST; |
| 7449 | 7452 |
| 7450 @override | 7453 @override |
| 7451 bool get isFinal => (keyword is KeywordToken) && | 7454 bool get isFinal => |
| 7455 (keyword is KeywordToken) && |
| 7452 (keyword as KeywordToken).keyword == Keyword.FINAL; | 7456 (keyword as KeywordToken).keyword == Keyword.FINAL; |
| 7453 | 7457 |
| 7454 /** | 7458 /** |
| 7455 * Return the parameters of the function-typed parameter, or `null` if this is | 7459 * Return the parameters of the function-typed parameter, or `null` if this is |
| 7456 * not a function-typed field formal parameter. | 7460 * not a function-typed field formal parameter. |
| 7457 */ | 7461 */ |
| 7458 FormalParameterList get parameters => _parameters; | 7462 FormalParameterList get parameters => _parameters; |
| 7459 | 7463 |
| 7460 /** | 7464 /** |
| 7461 * Set the parameters of the function-typed parameter to the given | 7465 * Set the parameters of the function-typed parameter to the given |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8155 * Set the function expression being wrapped to the given | 8159 * Set the function expression being wrapped to the given |
| 8156 * [functionExpression]. | 8160 * [functionExpression]. |
| 8157 */ | 8161 */ |
| 8158 void set functionExpression(FunctionExpression functionExpression) { | 8162 void set functionExpression(FunctionExpression functionExpression) { |
| 8159 _functionExpression = _becomeParentOf(functionExpression); | 8163 _functionExpression = _becomeParentOf(functionExpression); |
| 8160 } | 8164 } |
| 8161 | 8165 |
| 8162 /** | 8166 /** |
| 8163 * Return `true` if this function declares a getter. | 8167 * Return `true` if this function declares a getter. |
| 8164 */ | 8168 */ |
| 8165 bool get isGetter => propertyKeyword != null && | 8169 bool get isGetter => |
| 8170 propertyKeyword != null && |
| 8166 (propertyKeyword as KeywordToken).keyword == Keyword.GET; | 8171 (propertyKeyword as KeywordToken).keyword == Keyword.GET; |
| 8167 | 8172 |
| 8168 /** | 8173 /** |
| 8169 * Return `true` if this function declares a setter. | 8174 * Return `true` if this function declares a setter. |
| 8170 */ | 8175 */ |
| 8171 bool get isSetter => propertyKeyword != null && | 8176 bool get isSetter => |
| 8177 propertyKeyword != null && |
| 8172 (propertyKeyword as KeywordToken).keyword == Keyword.SET; | 8178 (propertyKeyword as KeywordToken).keyword == Keyword.SET; |
| 8173 | 8179 |
| 8174 /** | 8180 /** |
| 8175 * Return the return type of the function, or `null` if no return type was | 8181 * Return the return type of the function, or `null` if no return type was |
| 8176 * declared. | 8182 * declared. |
| 8177 */ | 8183 */ |
| 8178 TypeName get returnType => _returnType; | 8184 TypeName get returnType => _returnType; |
| 8179 | 8185 |
| 8180 /** | 8186 /** |
| 8181 * Set the return type of the function to the given [returnType]. | 8187 * Set the return type of the function to the given [returnType]. |
| (...skipping 2839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11021 _constructorName = _becomeParentOf(name); | 11027 _constructorName = _becomeParentOf(name); |
| 11022 } | 11028 } |
| 11023 | 11029 |
| 11024 @override | 11030 @override |
| 11025 Token get endToken => _argumentList.endToken; | 11031 Token get endToken => _argumentList.endToken; |
| 11026 | 11032 |
| 11027 /** | 11033 /** |
| 11028 * Return `true` if this creation expression is used to invoke a constant | 11034 * Return `true` if this creation expression is used to invoke a constant |
| 11029 * constructor. | 11035 * constructor. |
| 11030 */ | 11036 */ |
| 11031 bool get isConst => keyword is KeywordToken && | 11037 bool get isConst => |
| 11038 keyword is KeywordToken && |
| 11032 (keyword as KeywordToken).keyword == Keyword.CONST; | 11039 (keyword as KeywordToken).keyword == Keyword.CONST; |
| 11033 | 11040 |
| 11034 @override | 11041 @override |
| 11035 int get precedence => 16; | 11042 int get precedence => 16; |
| 11036 | 11043 |
| 11037 @override | 11044 @override |
| 11038 accept(AstVisitor visitor) => visitor.visitInstanceCreationExpression(this); | 11045 accept(AstVisitor visitor) => visitor.visitInstanceCreationExpression(this); |
| 11039 | 11046 |
| 11040 @override | 11047 @override |
| 11041 void visitChildren(AstVisitor visitor) { | 11048 void visitChildren(AstVisitor visitor) { |
| (...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11973 */ | 11980 */ |
| 11974 bool get isAbstract { | 11981 bool get isAbstract { |
| 11975 FunctionBody body = _body; | 11982 FunctionBody body = _body; |
| 11976 return externalKeyword == null && | 11983 return externalKeyword == null && |
| 11977 (body is EmptyFunctionBody && !body.semicolon.isSynthetic); | 11984 (body is EmptyFunctionBody && !body.semicolon.isSynthetic); |
| 11978 } | 11985 } |
| 11979 | 11986 |
| 11980 /** | 11987 /** |
| 11981 * Return `true` if this method declares a getter. | 11988 * Return `true` if this method declares a getter. |
| 11982 */ | 11989 */ |
| 11983 bool get isGetter => propertyKeyword != null && | 11990 bool get isGetter => |
| 11991 propertyKeyword != null && |
| 11984 (propertyKeyword as KeywordToken).keyword == Keyword.GET; | 11992 (propertyKeyword as KeywordToken).keyword == Keyword.GET; |
| 11985 | 11993 |
| 11986 /** | 11994 /** |
| 11987 * Return `true` if this method declares an operator. | 11995 * Return `true` if this method declares an operator. |
| 11988 */ | 11996 */ |
| 11989 bool get isOperator => operatorKeyword != null; | 11997 bool get isOperator => operatorKeyword != null; |
| 11990 | 11998 |
| 11991 /** | 11999 /** |
| 11992 * Return `true` if this method declares a setter. | 12000 * Return `true` if this method declares a setter. |
| 11993 */ | 12001 */ |
| 11994 bool get isSetter => propertyKeyword != null && | 12002 bool get isSetter => |
| 12003 propertyKeyword != null && |
| 11995 (propertyKeyword as KeywordToken).keyword == Keyword.SET; | 12004 (propertyKeyword as KeywordToken).keyword == Keyword.SET; |
| 11996 | 12005 |
| 11997 /** | 12006 /** |
| 11998 * Return `true` if this method is declared to be a static method. | 12007 * Return `true` if this method is declared to be a static method. |
| 11999 */ | 12008 */ |
| 12000 bool get isStatic => modifierKeyword != null && | 12009 bool get isStatic => |
| 12010 modifierKeyword != null && |
| 12001 (modifierKeyword as KeywordToken).keyword == Keyword.STATIC; | 12011 (modifierKeyword as KeywordToken).keyword == Keyword.STATIC; |
| 12002 | 12012 |
| 12003 /** | 12013 /** |
| 12004 * Return the name of the method. | 12014 * Return the name of the method. |
| 12005 */ | 12015 */ |
| 12006 SimpleIdentifier get name => _name; | 12016 SimpleIdentifier get name => _name; |
| 12007 | 12017 |
| 12008 /** | 12018 /** |
| 12009 * Set the name of the method to the given [identifier]. | 12019 * Set the name of the method to the given [identifier]. |
| 12010 */ | 12020 */ |
| (...skipping 4417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16428 } | 16438 } |
| 16429 | 16439 |
| 16430 @override | 16440 @override |
| 16431 Iterable get childEntities => | 16441 Iterable get childEntities => |
| 16432 super._childEntities..add(keyword)..add(_type)..add(identifier); | 16442 super._childEntities..add(keyword)..add(_type)..add(identifier); |
| 16433 | 16443 |
| 16434 @override | 16444 @override |
| 16435 Token get endToken => identifier.endToken; | 16445 Token get endToken => identifier.endToken; |
| 16436 | 16446 |
| 16437 @override | 16447 @override |
| 16438 bool get isConst => (keyword is KeywordToken) && | 16448 bool get isConst => |
| 16449 (keyword is KeywordToken) && |
| 16439 (keyword as KeywordToken).keyword == Keyword.CONST; | 16450 (keyword as KeywordToken).keyword == Keyword.CONST; |
| 16440 | 16451 |
| 16441 @override | 16452 @override |
| 16442 bool get isFinal => (keyword is KeywordToken) && | 16453 bool get isFinal => |
| 16454 (keyword is KeywordToken) && |
| 16443 (keyword as KeywordToken).keyword == Keyword.FINAL; | 16455 (keyword as KeywordToken).keyword == Keyword.FINAL; |
| 16444 | 16456 |
| 16445 /** | 16457 /** |
| 16446 * Return the name of the declared type of the parameter, or `null` if the | 16458 * Return the name of the declared type of the parameter, or `null` if the |
| 16447 * parameter does not have a declared type. | 16459 * parameter does not have a declared type. |
| 16448 */ | 16460 */ |
| 16449 TypeName get type => _type; | 16461 TypeName get type => _type; |
| 16450 | 16462 |
| 16451 /** | 16463 /** |
| 16452 * Set the name of the declared type of the parameter to the given [typeName]. | 16464 * Set the name of the declared type of the parameter to the given [typeName]. |
| (...skipping 3606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20059 } else if (_type != null) { | 20071 } else if (_type != null) { |
| 20060 return _type.beginToken; | 20072 return _type.beginToken; |
| 20061 } | 20073 } |
| 20062 return _variables.beginToken; | 20074 return _variables.beginToken; |
| 20063 } | 20075 } |
| 20064 | 20076 |
| 20065 /** | 20077 /** |
| 20066 * Return `true` if the variables in this list were declared with the 'const' | 20078 * Return `true` if the variables in this list were declared with the 'const' |
| 20067 * modifier. | 20079 * modifier. |
| 20068 */ | 20080 */ |
| 20069 bool get isConst => keyword is KeywordToken && | 20081 bool get isConst => |
| 20082 keyword is KeywordToken && |
| 20070 (keyword as KeywordToken).keyword == Keyword.CONST; | 20083 (keyword as KeywordToken).keyword == Keyword.CONST; |
| 20071 | 20084 |
| 20072 /** | 20085 /** |
| 20073 * Return `true` if the variables in this list were declared with the 'final' | 20086 * Return `true` if the variables in this list were declared with the 'final' |
| 20074 * modifier. Variables that are declared with the 'const' modifier will return | 20087 * modifier. Variables that are declared with the 'const' modifier will return |
| 20075 * `false` even though they are implicitly final. (In other words, this is a | 20088 * `false` even though they are implicitly final. (In other words, this is a |
| 20076 * syntactic check rather than a semantic check.) | 20089 * syntactic check rather than a semantic check.) |
| 20077 */ | 20090 */ |
| 20078 bool get isFinal => keyword is KeywordToken && | 20091 bool get isFinal => |
| 20092 keyword is KeywordToken && |
| 20079 (keyword as KeywordToken).keyword == Keyword.FINAL; | 20093 (keyword as KeywordToken).keyword == Keyword.FINAL; |
| 20080 | 20094 |
| 20081 /** | 20095 /** |
| 20082 * Return the type of the variables being declared, or `null` if no type was | 20096 * Return the type of the variables being declared, or `null` if no type was |
| 20083 * provided. | 20097 * provided. |
| 20084 */ | 20098 */ |
| 20085 TypeName get type => _type; | 20099 TypeName get type => _type; |
| 20086 | 20100 |
| 20087 /** | 20101 /** |
| 20088 * Set the type of the variables being declared to the given [typeName]. | 20102 * Set the type of the variables being declared to the given [typeName]. |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20377 } | 20391 } |
| 20378 | 20392 |
| 20379 @override | 20393 @override |
| 20380 accept(AstVisitor visitor) => visitor.visitYieldStatement(this); | 20394 accept(AstVisitor visitor) => visitor.visitYieldStatement(this); |
| 20381 | 20395 |
| 20382 @override | 20396 @override |
| 20383 void visitChildren(AstVisitor visitor) { | 20397 void visitChildren(AstVisitor visitor) { |
| 20384 _safelyVisitChild(_expression, visitor); | 20398 _safelyVisitChild(_expression, visitor); |
| 20385 } | 20399 } |
| 20386 } | 20400 } |
| OLD | NEW |