| Index: pkg/analyzer/lib/src/generated/constant.dart
|
| diff --git a/pkg/analyzer/lib/src/generated/constant.dart b/pkg/analyzer/lib/src/generated/constant.dart
|
| index 6aafe29f04a2986e1380ede8cf5b77cc0326f051..1a26cb164300fb16e6cda97872837bc5ee6d7bbe 100644
|
| --- a/pkg/analyzer/lib/src/generated/constant.dart
|
| +++ b/pkg/analyzer/lib/src/generated/constant.dart
|
| @@ -1314,19 +1314,6 @@ class ConstantVisitor extends UnifyingAstVisitor<DartObjectImpl> {
|
| */
|
| void beforeGetEvaluationResult(AstNode node) {}
|
|
|
| - /**
|
| - * Return `true` if the given [element] represents the `length` getter in
|
| - * class 'String'.
|
| - */
|
| - bool isStringLength(Element element) {
|
| - if (element is PropertyAccessorElement) {
|
| - if (element.isGetter && element.name == 'length') {
|
| - return element.enclosingElement == _typeProvider.stringType.element;
|
| - }
|
| - }
|
| - return false;
|
| - }
|
| -
|
| @override
|
| DartObjectImpl visitAdjacentStrings(AdjacentStrings node) {
|
| DartObjectImpl result = null;
|
| @@ -1600,17 +1587,16 @@ class ConstantVisitor extends UnifyingAstVisitor<DartObjectImpl> {
|
|
|
| @override
|
| DartObjectImpl visitPrefixedIdentifier(PrefixedIdentifier node) {
|
| + SimpleIdentifier prefixNode = node.prefix;
|
| + Element prefixElement = prefixNode.staticElement;
|
| // String.length
|
| - {
|
| - Element element = node.staticElement;
|
| - if (isStringLength(element)) {
|
| - DartObjectImpl prefixResult = node.prefix.accept(this);
|
| + if (prefixElement is! PrefixElement && prefixElement is! ClassElement) {
|
| + DartObjectImpl prefixResult = node.prefix.accept(this);
|
| + if (_isStringLength(prefixResult, node.identifier)) {
|
| return prefixResult.stringLength(_typeProvider);
|
| }
|
| }
|
| // importPrefix.CONST
|
| - SimpleIdentifier prefixNode = node.prefix;
|
| - Element prefixElement = prefixNode.staticElement;
|
| if (prefixElement is! PrefixElement) {
|
| DartObjectImpl prefixResult = prefixNode.accept(this);
|
| if (prefixResult == null) {
|
| @@ -1647,12 +1633,13 @@ class ConstantVisitor extends UnifyingAstVisitor<DartObjectImpl> {
|
|
|
| @override
|
| DartObjectImpl visitPropertyAccess(PropertyAccess node) {
|
| - Element element = node.propertyName.staticElement;
|
| - if (isStringLength(element)) {
|
| - DartObjectImpl prefixResult = node.realTarget.accept(this);
|
| - return prefixResult.stringLength(_typeProvider);
|
| + if (node.target != null) {
|
| + DartObjectImpl prefixResult = node.target.accept(this);
|
| + if (_isStringLength(prefixResult, node.propertyName)) {
|
| + return prefixResult.stringLength(_typeProvider);
|
| + }
|
| }
|
| - return _getConstantValue(node, element);
|
| + return _getConstantValue(node, node.propertyName.staticElement);
|
| }
|
|
|
| @override
|
| @@ -1743,6 +1730,18 @@ class ConstantVisitor extends UnifyingAstVisitor<DartObjectImpl> {
|
| }
|
|
|
| /**
|
| + * Return `true` if the given [targetResult] represents a string and the
|
| + * [identifier] is "length".
|
| + */
|
| + bool _isStringLength(
|
| + DartObjectImpl targetResult, SimpleIdentifier identifier) {
|
| + if (targetResult == null || targetResult.type != _typeProvider.stringType) {
|
| + return false;
|
| + }
|
| + return identifier.name == 'length';
|
| + }
|
| +
|
| + /**
|
| * Return the value of the given [expression], or a representation of 'null'
|
| * if the expression cannot be evaluated.
|
| */
|
|
|