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 5036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5047 | 5047 |
5048 /** | 5048 /** |
5049 * The invocation of a function resulting from evaluating an expression. | 5049 * The invocation of a function resulting from evaluating an expression. |
5050 * Invocations of methods and other forms of functions are represented by | 5050 * Invocations of methods and other forms of functions are represented by |
5051 * [MethodInvocation] nodes. Invocations of getters and setters are represented | 5051 * [MethodInvocation] nodes. Invocations of getters and setters are represented |
5052 * by either [PrefixedIdentifier] or [PropertyAccess] nodes. | 5052 * by either [PrefixedIdentifier] or [PropertyAccess] nodes. |
5053 * | 5053 * |
5054 * > functionExpressionInvocation ::= | 5054 * > functionExpressionInvocation ::= |
5055 * > [Expression] [TypeArgumentList]? [ArgumentList] | 5055 * > [Expression] [TypeArgumentList]? [ArgumentList] |
5056 */ | 5056 */ |
5057 class FunctionExpressionInvocationImpl extends ExpressionImpl | 5057 class FunctionExpressionInvocationImpl extends InvocationExpressionImpl |
5058 implements FunctionExpressionInvocation { | 5058 implements FunctionExpressionInvocation { |
5059 /** | 5059 /** |
5060 * The expression producing the function being invoked. | 5060 * The expression producing the function being invoked. |
5061 */ | 5061 */ |
5062 Expression _function; | 5062 Expression _function; |
5063 | 5063 |
5064 /** | 5064 /** |
5065 * The type arguments to be applied to the method being invoked, or `null` if | |
5066 * no type arguments were provided. | |
5067 */ | |
5068 TypeArgumentList _typeArguments; | |
5069 | |
5070 /** | |
5071 * The list of arguments to the function. | |
5072 */ | |
5073 ArgumentList _argumentList; | |
5074 | |
5075 /** | |
5076 * The element associated with the function being invoked based on static type | 5065 * The element associated with the function being invoked based on static type |
5077 * information, or `null` if the AST structure has not been resolved or the | 5066 * information, or `null` if the AST structure has not been resolved or the |
5078 * function could not be resolved. | 5067 * function could not be resolved. |
5079 */ | 5068 */ |
5080 ExecutableElement staticElement; | 5069 ExecutableElement staticElement; |
5081 | 5070 |
5082 /** | 5071 /** |
5083 * The function type of the method invocation, or `null` if the AST | |
5084 * structure has not been resolved, or if the invoke could not be resolved. | |
5085 * | |
5086 * This will usually be a [FunctionType], but it can also be an | |
5087 * [InterfaceType] with a `call` method, `dynamic`, `Function`, or a `@proxy` | |
5088 * interface type that implements `Function`. | |
5089 */ | |
5090 DartType staticInvokeType; | |
5091 | |
5092 /** | |
5093 * The element associated with the function being invoked based on propagated | 5072 * The element associated with the function being invoked based on propagated |
5094 * type information, or `null` if the AST structure has not been resolved or | 5073 * type information, or `null` if the AST structure has not been resolved or |
5095 * the function could not be resolved. | 5074 * the function could not be resolved. |
5096 */ | 5075 */ |
5097 ExecutableElement propagatedElement; | 5076 ExecutableElement propagatedElement; |
5098 | 5077 |
5099 /** | 5078 /** |
5100 * Like [staticInvokeType], but reflects propagated type information. | |
5101 */ | |
5102 DartType propagatedInvokeType; | |
5103 | |
5104 /** | |
5105 * Initialize a newly created function expression invocation. | 5079 * Initialize a newly created function expression invocation. |
5106 */ | 5080 */ |
5107 FunctionExpressionInvocationImpl(Expression function, | 5081 FunctionExpressionInvocationImpl(Expression function, |
5108 TypeArgumentList typeArguments, ArgumentList argumentList) { | 5082 TypeArgumentList typeArguments, ArgumentList argumentList) |
| 5083 : super(typeArguments, argumentList) { |
5109 _function = _becomeParentOf(function); | 5084 _function = _becomeParentOf(function); |
5110 _typeArguments = _becomeParentOf(typeArguments); | |
5111 _argumentList = _becomeParentOf(argumentList); | |
5112 } | 5085 } |
5113 | 5086 |
5114 @override | 5087 @override |
5115 ArgumentList get argumentList => _argumentList; | |
5116 | |
5117 @override | |
5118 void set argumentList(ArgumentList argumentList) { | |
5119 _argumentList = _becomeParentOf(argumentList); | |
5120 } | |
5121 | |
5122 @override | |
5123 Token get beginToken => _function.beginToken; | 5088 Token get beginToken => _function.beginToken; |
5124 | 5089 |
5125 @override | 5090 @override |
5126 ExecutableElement get bestElement { | 5091 ExecutableElement get bestElement { |
5127 ExecutableElement element = propagatedElement; | 5092 ExecutableElement element = propagatedElement; |
5128 if (element == null) { | 5093 if (element == null) { |
5129 element = staticElement; | 5094 element = staticElement; |
5130 } | 5095 } |
5131 return element; | 5096 return element; |
5132 } | 5097 } |
(...skipping 10 matching lines...) Expand all Loading... |
5143 | 5108 |
5144 @override | 5109 @override |
5145 void set function(Expression expression) { | 5110 void set function(Expression expression) { |
5146 _function = _becomeParentOf(expression); | 5111 _function = _becomeParentOf(expression); |
5147 } | 5112 } |
5148 | 5113 |
5149 @override | 5114 @override |
5150 int get precedence => 15; | 5115 int get precedence => 15; |
5151 | 5116 |
5152 @override | 5117 @override |
5153 TypeArgumentList get typeArguments => _typeArguments; | |
5154 | |
5155 @override | |
5156 void set typeArguments(TypeArgumentList typeArguments) { | |
5157 _typeArguments = _becomeParentOf(typeArguments); | |
5158 } | |
5159 | |
5160 @override | |
5161 accept(AstVisitor visitor) => visitor.visitFunctionExpressionInvocation(this); | 5118 accept(AstVisitor visitor) => visitor.visitFunctionExpressionInvocation(this); |
5162 | 5119 |
5163 @override | 5120 @override |
5164 void visitChildren(AstVisitor visitor) { | 5121 void visitChildren(AstVisitor visitor) { |
5165 _safelyVisitChild(_function, visitor); | 5122 _safelyVisitChild(_function, visitor); |
5166 _safelyVisitChild(_typeArguments, visitor); | 5123 _safelyVisitChild(_typeArguments, visitor); |
5167 _safelyVisitChild(_argumentList, visitor); | 5124 _safelyVisitChild(_argumentList, visitor); |
5168 } | 5125 } |
5169 } | 5126 } |
5170 | 5127 |
(...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6160 Token get endToken => contents; | 6117 Token get endToken => contents; |
6161 | 6118 |
6162 @override | 6119 @override |
6163 accept(AstVisitor visitor) => visitor.visitInterpolationString(this); | 6120 accept(AstVisitor visitor) => visitor.visitInterpolationString(this); |
6164 | 6121 |
6165 @override | 6122 @override |
6166 void visitChildren(AstVisitor visitor) {} | 6123 void visitChildren(AstVisitor visitor) {} |
6167 } | 6124 } |
6168 | 6125 |
6169 /** | 6126 /** |
| 6127 * Common base class for [FunctionExpressionInvocationImpl] and |
| 6128 * [MethodInvocationImpl]. |
| 6129 */ |
| 6130 abstract class InvocationExpressionImpl extends ExpressionImpl |
| 6131 implements InvocationExpression { |
| 6132 /** |
| 6133 * The type arguments to be applied to the method being invoked, or `null` if |
| 6134 * no type arguments were provided. |
| 6135 */ |
| 6136 TypeArgumentList _typeArguments; |
| 6137 |
| 6138 /** |
| 6139 * The list of arguments to the function. |
| 6140 */ |
| 6141 ArgumentList _argumentList; |
| 6142 |
| 6143 @override |
| 6144 DartType propagatedInvokeType; |
| 6145 |
| 6146 @override |
| 6147 DartType staticInvokeType; |
| 6148 |
| 6149 /** |
| 6150 * Initialize a newly created invocation. |
| 6151 */ |
| 6152 InvocationExpressionImpl( |
| 6153 TypeArgumentList typeArguments, ArgumentList argumentList) { |
| 6154 _typeArguments = _becomeParentOf(typeArguments); |
| 6155 _argumentList = _becomeParentOf(argumentList); |
| 6156 } |
| 6157 |
| 6158 @override |
| 6159 ArgumentList get argumentList => _argumentList; |
| 6160 |
| 6161 @override |
| 6162 void set argumentList(ArgumentList argumentList) { |
| 6163 _argumentList = _becomeParentOf(argumentList); |
| 6164 } |
| 6165 |
| 6166 @override |
| 6167 TypeArgumentList get typeArguments => _typeArguments; |
| 6168 |
| 6169 @override |
| 6170 void set typeArguments(TypeArgumentList typeArguments) { |
| 6171 _typeArguments = _becomeParentOf(typeArguments); |
| 6172 } |
| 6173 } |
| 6174 |
| 6175 /** |
6170 * An is expression. | 6176 * An is expression. |
6171 * | 6177 * |
6172 * > isExpression ::= | 6178 * > isExpression ::= |
6173 * > [Expression] 'is' '!'? [TypeName] | 6179 * > [Expression] 'is' '!'? [TypeName] |
6174 */ | 6180 */ |
6175 class IsExpressionImpl extends ExpressionImpl implements IsExpression { | 6181 class IsExpressionImpl extends ExpressionImpl implements IsExpression { |
6176 /** | 6182 /** |
6177 * The expression used to compute the value whose type is being tested. | 6183 * The expression used to compute the value whose type is being tested. |
6178 */ | 6184 */ |
6179 Expression _expression; | 6185 Expression _expression; |
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6952 | 6958 |
6953 /** | 6959 /** |
6954 * The invocation of either a function or a method. Invocations of functions | 6960 * The invocation of either a function or a method. Invocations of functions |
6955 * resulting from evaluating an expression are represented by | 6961 * resulting from evaluating an expression are represented by |
6956 * [FunctionExpressionInvocation] nodes. Invocations of getters and setters are | 6962 * [FunctionExpressionInvocation] nodes. Invocations of getters and setters are |
6957 * represented by either [PrefixedIdentifier] or [PropertyAccess] nodes. | 6963 * represented by either [PrefixedIdentifier] or [PropertyAccess] nodes. |
6958 * | 6964 * |
6959 * > methodInvocation ::= | 6965 * > methodInvocation ::= |
6960 * > ([Expression] '.')? [SimpleIdentifier] [TypeArgumentList]? [ArgumentLis
t] | 6966 * > ([Expression] '.')? [SimpleIdentifier] [TypeArgumentList]? [ArgumentLis
t] |
6961 */ | 6967 */ |
6962 class MethodInvocationImpl extends ExpressionImpl implements MethodInvocation { | 6968 class MethodInvocationImpl extends InvocationExpressionImpl |
| 6969 implements MethodInvocation { |
6963 /** | 6970 /** |
6964 * The expression producing the object on which the method is defined, or | 6971 * The expression producing the object on which the method is defined, or |
6965 * `null` if there is no target (that is, the target is implicitly `this`). | 6972 * `null` if there is no target (that is, the target is implicitly `this`). |
6966 */ | 6973 */ |
6967 Expression _target; | 6974 Expression _target; |
6968 | 6975 |
6969 /** | 6976 /** |
6970 * The operator that separates the target from the method name, or `null` | 6977 * The operator that separates the target from the method name, or `null` |
6971 * if there is no target. In an ordinary method invocation this will be a | 6978 * if there is no target. In an ordinary method invocation this will be a |
6972 * period ('.'). In a cascade section this will be the cascade operator | 6979 * period ('.'). In a cascade section this will be the cascade operator |
6973 * ('..'). | 6980 * ('..'). |
6974 */ | 6981 */ |
6975 Token operator; | 6982 Token operator; |
6976 | 6983 |
6977 /** | 6984 /** |
6978 * The name of the method being invoked. | 6985 * The name of the method being invoked. |
6979 */ | 6986 */ |
6980 SimpleIdentifier _methodName; | 6987 SimpleIdentifier _methodName; |
6981 | 6988 |
6982 /** | 6989 /** |
6983 * The type arguments to be applied to the method being invoked, or `null` if | |
6984 * no type arguments were provided. | |
6985 */ | |
6986 TypeArgumentList _typeArguments; | |
6987 | |
6988 /** | |
6989 * The list of arguments to the method. | |
6990 */ | |
6991 ArgumentList _argumentList; | |
6992 | |
6993 /** | |
6994 * The function type of the method invocation, or `null` if the AST | |
6995 * structure has not been resolved, or if the invoke could not be resolved. | |
6996 * | |
6997 * This will usually be a [FunctionType], but it can also be an | |
6998 * [InterfaceType] with a `call` method, `dynamic`, `Function`, or a `@proxy` | |
6999 * interface type that implements `Function`. | |
7000 */ | |
7001 DartType staticInvokeType; | |
7002 | |
7003 /** | |
7004 * Like [staticInvokeType], but reflects propagated type information. | |
7005 */ | |
7006 DartType propagatedInvokeType; | |
7007 | |
7008 /** | |
7009 * Initialize a newly created method invocation. The [target] and [operator] | 6990 * Initialize a newly created method invocation. The [target] and [operator] |
7010 * can be `null` if there is no target. | 6991 * can be `null` if there is no target. |
7011 */ | 6992 */ |
7012 MethodInvocationImpl( | 6993 MethodInvocationImpl( |
7013 Expression target, | 6994 Expression target, |
7014 this.operator, | 6995 this.operator, |
7015 SimpleIdentifier methodName, | 6996 SimpleIdentifier methodName, |
7016 TypeArgumentList typeArguments, | 6997 TypeArgumentList typeArguments, |
7017 ArgumentList argumentList) { | 6998 ArgumentList argumentList) |
| 6999 : super(typeArguments, argumentList) { |
7018 _target = _becomeParentOf(target); | 7000 _target = _becomeParentOf(target); |
7019 _methodName = _becomeParentOf(methodName); | 7001 _methodName = _becomeParentOf(methodName); |
7020 _typeArguments = _becomeParentOf(typeArguments); | |
7021 _argumentList = _becomeParentOf(argumentList); | |
7022 } | 7002 } |
7023 | 7003 |
7024 @override | 7004 @override |
7025 ArgumentList get argumentList => _argumentList; | |
7026 | |
7027 @override | |
7028 void set argumentList(ArgumentList argumentList) { | |
7029 _argumentList = _becomeParentOf(argumentList); | |
7030 } | |
7031 | |
7032 @override | |
7033 Token get beginToken { | 7005 Token get beginToken { |
7034 if (_target != null) { | 7006 if (_target != null) { |
7035 return _target.beginToken; | 7007 return _target.beginToken; |
7036 } else if (operator != null) { | 7008 } else if (operator != null) { |
7037 return operator; | 7009 return operator; |
7038 } | 7010 } |
7039 return _methodName.beginToken; | 7011 return _methodName.beginToken; |
7040 } | 7012 } |
7041 | 7013 |
7042 @override | 7014 @override |
7043 Iterable get childEntities => new ChildEntities() | 7015 Iterable get childEntities => new ChildEntities() |
7044 ..add(_target) | 7016 ..add(_target) |
7045 ..add(operator) | 7017 ..add(operator) |
7046 ..add(_methodName) | 7018 ..add(_methodName) |
7047 ..add(_argumentList); | 7019 ..add(_argumentList); |
7048 | 7020 |
7049 @override | 7021 @override |
7050 Token get endToken => _argumentList.endToken; | 7022 Token get endToken => _argumentList.endToken; |
7051 | 7023 |
7052 @override | 7024 @override |
| 7025 Expression get function => methodName; |
| 7026 |
| 7027 @override |
7053 bool get isCascaded => | 7028 bool get isCascaded => |
7054 operator != null && operator.type == TokenType.PERIOD_PERIOD; | 7029 operator != null && operator.type == TokenType.PERIOD_PERIOD; |
7055 | 7030 |
7056 @override | 7031 @override |
7057 SimpleIdentifier get methodName => _methodName; | 7032 SimpleIdentifier get methodName => _methodName; |
7058 | 7033 |
7059 @override | 7034 @override |
7060 void set methodName(SimpleIdentifier identifier) { | 7035 void set methodName(SimpleIdentifier identifier) { |
7061 _methodName = _becomeParentOf(identifier); | 7036 _methodName = _becomeParentOf(identifier); |
7062 } | 7037 } |
(...skipping 18 matching lines...) Expand all Loading... |
7081 | 7056 |
7082 @override | 7057 @override |
7083 Expression get target => _target; | 7058 Expression get target => _target; |
7084 | 7059 |
7085 @override | 7060 @override |
7086 void set target(Expression expression) { | 7061 void set target(Expression expression) { |
7087 _target = _becomeParentOf(expression); | 7062 _target = _becomeParentOf(expression); |
7088 } | 7063 } |
7089 | 7064 |
7090 @override | 7065 @override |
7091 TypeArgumentList get typeArguments => _typeArguments; | |
7092 | |
7093 @override | |
7094 void set typeArguments(TypeArgumentList typeArguments) { | |
7095 _typeArguments = _becomeParentOf(typeArguments); | |
7096 } | |
7097 | |
7098 @override | |
7099 accept(AstVisitor visitor) => visitor.visitMethodInvocation(this); | 7066 accept(AstVisitor visitor) => visitor.visitMethodInvocation(this); |
7100 | 7067 |
7101 @override | 7068 @override |
7102 void visitChildren(AstVisitor visitor) { | 7069 void visitChildren(AstVisitor visitor) { |
7103 _safelyVisitChild(_target, visitor); | 7070 _safelyVisitChild(_target, visitor); |
7104 _safelyVisitChild(_methodName, visitor); | 7071 _safelyVisitChild(_methodName, visitor); |
7105 _safelyVisitChild(_typeArguments, visitor); | 7072 _safelyVisitChild(_typeArguments, visitor); |
7106 _safelyVisitChild(_argumentList, visitor); | 7073 _safelyVisitChild(_argumentList, visitor); |
7107 } | 7074 } |
7108 } | 7075 } |
(...skipping 3739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10848 } | 10815 } |
10849 | 10816 |
10850 @override | 10817 @override |
10851 accept(AstVisitor visitor) => visitor.visitYieldStatement(this); | 10818 accept(AstVisitor visitor) => visitor.visitYieldStatement(this); |
10852 | 10819 |
10853 @override | 10820 @override |
10854 void visitChildren(AstVisitor visitor) { | 10821 void visitChildren(AstVisitor visitor) { |
10855 _safelyVisitChild(_expression, visitor); | 10822 _safelyVisitChild(_expression, visitor); |
10856 } | 10823 } |
10857 } | 10824 } |
OLD | NEW |