| 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 748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 * If the AST structure has been resolved, and the function being invoked is | 759 * If the AST structure has been resolved, and the function being invoked is |
| 760 * known based on propagated type information, then return the parameter | 760 * known based on propagated type information, then return the parameter |
| 761 * element representing the parameter to which the value of the right operand | 761 * element representing the parameter to which the value of the right operand |
| 762 * will be bound. Otherwise, return `null`. | 762 * will be bound. Otherwise, return `null`. |
| 763 */ | 763 */ |
| 764 ParameterElement get _propagatedParameterElementForRightHandSide { | 764 ParameterElement get _propagatedParameterElementForRightHandSide { |
| 765 ExecutableElement executableElement = null; | 765 ExecutableElement executableElement = null; |
| 766 if (propagatedElement != null) { | 766 if (propagatedElement != null) { |
| 767 executableElement = propagatedElement; | 767 executableElement = propagatedElement; |
| 768 } else { | 768 } else { |
| 769 if (_leftHandSide is Identifier) { | 769 Expression left = _leftHandSide; |
| 770 Identifier identifier = _leftHandSide as Identifier; | 770 if (left is Identifier) { |
| 771 Element leftElement = identifier.propagatedElement; | 771 Element leftElement = left.propagatedElement; |
| 772 if (leftElement is ExecutableElement) { | 772 if (leftElement is ExecutableElement) { |
| 773 executableElement = leftElement; | 773 executableElement = leftElement; |
| 774 } | 774 } |
| 775 } else if (_leftHandSide is PropertyAccess) { | 775 } else if (left is PropertyAccess) { |
| 776 SimpleIdentifier identifier = | 776 Element leftElement = left.propertyName.propagatedElement; |
| 777 (_leftHandSide as PropertyAccess).propertyName; | |
| 778 Element leftElement = identifier.propagatedElement; | |
| 779 if (leftElement is ExecutableElement) { | 777 if (leftElement is ExecutableElement) { |
| 780 executableElement = leftElement; | 778 executableElement = leftElement; |
| 781 } | 779 } |
| 782 } | 780 } |
| 783 } | 781 } |
| 784 if (executableElement == null) { | 782 if (executableElement == null) { |
| 785 return null; | 783 return null; |
| 786 } | 784 } |
| 787 List<ParameterElement> parameters = executableElement.parameters; | 785 List<ParameterElement> parameters = executableElement.parameters; |
| 788 if (parameters.length < 1) { | 786 if (parameters.length < 1) { |
| 789 return null; | 787 return null; |
| 790 } | 788 } |
| 791 return parameters[0]; | 789 return parameters[0]; |
| 792 } | 790 } |
| 793 | 791 |
| 794 /** | 792 /** |
| 795 * If the AST structure has been resolved, and the function being invoked is | 793 * If the AST structure has been resolved, and the function being invoked is |
| 796 * known based on static type information, then return the parameter element | 794 * known based on static type information, then return the parameter element |
| 797 * representing the parameter to which the value of the right operand will be | 795 * representing the parameter to which the value of the right operand will be |
| 798 * bound. Otherwise, return `null`. | 796 * bound. Otherwise, return `null`. |
| 799 */ | 797 */ |
| 800 ParameterElement get _staticParameterElementForRightHandSide { | 798 ParameterElement get _staticParameterElementForRightHandSide { |
| 801 ExecutableElement executableElement = null; | 799 ExecutableElement executableElement = null; |
| 802 if (staticElement != null) { | 800 if (staticElement != null) { |
| 803 executableElement = staticElement; | 801 executableElement = staticElement; |
| 804 } else { | 802 } else { |
| 805 if (_leftHandSide is Identifier) { | 803 Expression left = _leftHandSide; |
| 806 Element leftElement = (_leftHandSide as Identifier).staticElement; | 804 if (left is Identifier) { |
| 805 Element leftElement = left.staticElement; |
| 807 if (leftElement is ExecutableElement) { | 806 if (leftElement is ExecutableElement) { |
| 808 executableElement = leftElement; | 807 executableElement = leftElement; |
| 809 } | 808 } |
| 810 } else if (_leftHandSide is PropertyAccess) { | 809 } else if (left is PropertyAccess) { |
| 811 Element leftElement = | 810 Element leftElement = left.propertyName.staticElement; |
| 812 (_leftHandSide as PropertyAccess).propertyName.staticElement; | |
| 813 if (leftElement is ExecutableElement) { | 811 if (leftElement is ExecutableElement) { |
| 814 executableElement = leftElement; | 812 executableElement = leftElement; |
| 815 } | 813 } |
| 816 } | 814 } |
| 817 } | 815 } |
| 818 if (executableElement == null) { | 816 if (executableElement == null) { |
| 819 return null; | 817 return null; |
| 820 } | 818 } |
| 821 List<ParameterElement> parameters = executableElement.parameters; | 819 List<ParameterElement> parameters = executableElement.parameters; |
| 822 if (parameters.length < 1) { | 820 if (parameters.length < 1) { |
| (...skipping 7405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8228 SimpleIdentifier get identifier => _identifier; | 8226 SimpleIdentifier get identifier => _identifier; |
| 8229 | 8227 |
| 8230 @override | 8228 @override |
| 8231 void set identifier(SimpleIdentifier identifier) { | 8229 void set identifier(SimpleIdentifier identifier) { |
| 8232 _identifier = _becomeParentOf(identifier); | 8230 _identifier = _becomeParentOf(identifier); |
| 8233 } | 8231 } |
| 8234 | 8232 |
| 8235 @override | 8233 @override |
| 8236 bool get isDeferred { | 8234 bool get isDeferred { |
| 8237 Element element = _prefix.staticElement; | 8235 Element element = _prefix.staticElement; |
| 8238 if (element is! PrefixElement) { | 8236 if (element is PrefixElement) { |
| 8239 return false; | 8237 List<ImportElement> imports = |
| 8238 element.enclosingElement.getImportsWithPrefix(element); |
| 8239 if (imports.length != 1) { |
| 8240 return false; |
| 8241 } |
| 8242 return imports[0].isDeferred; |
| 8240 } | 8243 } |
| 8241 PrefixElement prefixElement = element as PrefixElement; | 8244 return false; |
| 8242 List<ImportElement> imports = | |
| 8243 prefixElement.enclosingElement.getImportsWithPrefix(prefixElement); | |
| 8244 if (imports.length != 1) { | |
| 8245 return false; | |
| 8246 } | |
| 8247 return imports[0].isDeferred; | |
| 8248 } | 8245 } |
| 8249 | 8246 |
| 8250 @override | 8247 @override |
| 8251 String get name => "${_prefix.name}.${_identifier.name}"; | 8248 String get name => "${_prefix.name}.${_identifier.name}"; |
| 8252 | 8249 |
| 8253 @override | 8250 @override |
| 8254 int get precedence => 15; | 8251 int get precedence => 15; |
| 8255 | 8252 |
| 8256 @override | 8253 @override |
| 8257 SimpleIdentifier get prefix => _prefix; | 8254 SimpleIdentifier get prefix => _prefix; |
| (...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8950 @override | 8947 @override |
| 8951 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => | 8948 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 8952 visitor.visitSimpleIdentifier(this); | 8949 visitor.visitSimpleIdentifier(this); |
| 8953 | 8950 |
| 8954 @override | 8951 @override |
| 8955 bool inDeclarationContext() => false; | 8952 bool inDeclarationContext() => false; |
| 8956 | 8953 |
| 8957 @override | 8954 @override |
| 8958 bool inGetterContext() { | 8955 bool inGetterContext() { |
| 8959 // TODO(brianwilkerson) Convert this to a getter. | 8956 // TODO(brianwilkerson) Convert this to a getter. |
| 8960 AstNode parent = this.parent; | 8957 AstNode initialParent = this.parent; |
| 8958 AstNode parent = initialParent; |
| 8961 AstNode target = this; | 8959 AstNode target = this; |
| 8962 // skip prefix | 8960 // skip prefix |
| 8963 if (parent is PrefixedIdentifier) { | 8961 if (initialParent is PrefixedIdentifier) { |
| 8964 PrefixedIdentifier prefixed = parent as PrefixedIdentifier; | 8962 if (identical(initialParent.prefix, this)) { |
| 8965 if (identical(prefixed.prefix, this)) { | |
| 8966 return true; | 8963 return true; |
| 8967 } | 8964 } |
| 8968 parent = prefixed.parent; | 8965 parent = initialParent.parent; |
| 8969 target = prefixed; | 8966 target = initialParent; |
| 8970 } else if (parent is PropertyAccess) { | 8967 } else if (initialParent is PropertyAccess) { |
| 8971 PropertyAccess access = parent as PropertyAccess; | 8968 if (identical(initialParent.target, this)) { |
| 8972 if (identical(access.target, this)) { | |
| 8973 return true; | 8969 return true; |
| 8974 } | 8970 } |
| 8975 parent = access.parent; | 8971 parent = initialParent.parent; |
| 8976 target = access; | 8972 target = initialParent; |
| 8977 } | 8973 } |
| 8978 // skip label | 8974 // skip label |
| 8979 if (parent is Label) { | 8975 if (parent is Label) { |
| 8980 return false; | 8976 return false; |
| 8981 } | 8977 } |
| 8982 // analyze usage | 8978 // analyze usage |
| 8983 if (parent is AssignmentExpression) { | 8979 if (parent is AssignmentExpression) { |
| 8984 if (identical(parent.leftHandSide, target) && | 8980 if (identical(parent.leftHandSide, target) && |
| 8985 parent.operator.type == TokenType.EQ) { | 8981 parent.operator.type == TokenType.EQ) { |
| 8986 return false; | 8982 return false; |
| 8987 } | 8983 } |
| 8988 } | 8984 } |
| 8989 if (parent is ForEachStatement) { | 8985 if (parent is ForEachStatement) { |
| 8990 if (identical(parent.identifier, target)) { | 8986 if (identical(parent.identifier, target)) { |
| 8991 return false; | 8987 return false; |
| 8992 } | 8988 } |
| 8993 } | 8989 } |
| 8994 return true; | 8990 return true; |
| 8995 } | 8991 } |
| 8996 | 8992 |
| 8997 @override | 8993 @override |
| 8998 bool inSetterContext() { | 8994 bool inSetterContext() { |
| 8999 // TODO(brianwilkerson) Convert this to a getter. | 8995 // TODO(brianwilkerson) Convert this to a getter. |
| 9000 AstNode parent = this.parent; | 8996 AstNode initialParent = this.parent; |
| 8997 AstNode parent = initialParent; |
| 9001 AstNode target = this; | 8998 AstNode target = this; |
| 9002 // skip prefix | 8999 // skip prefix |
| 9003 if (parent is PrefixedIdentifier) { | 9000 if (initialParent is PrefixedIdentifier) { |
| 9004 PrefixedIdentifier prefixed = parent as PrefixedIdentifier; | |
| 9005 // if this is the prefix, then return false | 9001 // if this is the prefix, then return false |
| 9006 if (identical(prefixed.prefix, this)) { | 9002 if (identical(initialParent.prefix, this)) { |
| 9007 return false; | 9003 return false; |
| 9008 } | 9004 } |
| 9009 parent = prefixed.parent; | 9005 parent = initialParent.parent; |
| 9010 target = prefixed; | 9006 target = initialParent; |
| 9011 } else if (parent is PropertyAccess) { | 9007 } else if (initialParent is PropertyAccess) { |
| 9012 PropertyAccess access = parent as PropertyAccess; | 9008 if (identical(initialParent.target, this)) { |
| 9013 if (identical(access.target, this)) { | |
| 9014 return false; | 9009 return false; |
| 9015 } | 9010 } |
| 9016 parent = access.parent; | 9011 parent = initialParent.parent; |
| 9017 target = access; | 9012 target = initialParent; |
| 9018 } | 9013 } |
| 9019 // analyze usage | 9014 // analyze usage |
| 9020 if (parent is PrefixExpression) { | 9015 if (parent is PrefixExpression) { |
| 9021 return parent.operator.type.isIncrementOperator; | 9016 return parent.operator.type.isIncrementOperator; |
| 9022 } else if (parent is PostfixExpression) { | 9017 } else if (parent is PostfixExpression) { |
| 9023 return true; | 9018 return true; |
| 9024 } else if (parent is AssignmentExpression) { | 9019 } else if (parent is AssignmentExpression) { |
| 9025 return identical(parent.leftHandSide, target); | 9020 return identical(parent.leftHandSide, target); |
| 9026 } else if (parent is ForEachStatement) { | 9021 } else if (parent is ForEachStatement) { |
| 9027 return identical(parent.identifier, target); | 9022 return identical(parent.identifier, target); |
| (...skipping 1949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10977 | 10972 |
| 10978 @override | 10973 @override |
| 10979 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => | 10974 dynamic/*=E*/ accept/*<E>*/(AstVisitor/*<E>*/ visitor) => |
| 10980 visitor.visitYieldStatement(this); | 10975 visitor.visitYieldStatement(this); |
| 10981 | 10976 |
| 10982 @override | 10977 @override |
| 10983 void visitChildren(AstVisitor visitor) { | 10978 void visitChildren(AstVisitor visitor) { |
| 10984 _expression?.accept(visitor); | 10979 _expression?.accept(visitor); |
| 10985 } | 10980 } |
| 10986 } | 10981 } |
| OLD | NEW |