Chromium Code Reviews| Index: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/constant/ConstantVisitor.java |
| diff --git a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/constant/ConstantVisitor.java b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/constant/ConstantVisitor.java |
| index 132a7149c39834e5c3bd9c5b471583f9f122298c..34c42b04e1985a6e0d0fdd1f241e881bdd5cf407 100644 |
| --- a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/constant/ConstantVisitor.java |
| +++ b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/constant/ConstantVisitor.java |
| @@ -394,10 +394,18 @@ public class ConstantVisitor extends UnifyingAstVisitor<EvaluationResultImpl> { |
| @Override |
| public EvaluationResultImpl visitPrefixedIdentifier(PrefixedIdentifier node) { |
| - // validate prefix |
| SimpleIdentifier prefixNode = node.getPrefix(); |
| Element prefixElement = prefixNode.getStaticElement(); |
| - if (!(prefixElement instanceof PrefixElement)) { |
| + if (prefixElement instanceof PropertyAccessorElement) { |
| + PropertyAccessorElement accessor = (PropertyAccessorElement) prefixElement; |
| + if (accessor.getName().equals("length")) { |
|
Paul Berry
2014/09/18 00:05:06
I'm confused. It seems to me that the case we nee
Brian Wilkerson
2014/09/18 20:29:26
No, I was. Reworked.
|
| + Element parent = accessor.getEnclosingElement(); |
| + if (parent instanceof ClassElement && ((ClassElement) parent).getName().equals("String")) { |
|
Paul Berry
2014/09/18 00:05:06
It's not sufficient to check whether the class's n
Brian Wilkerson
2014/09/18 20:29:26
Thanks! I forgot to come back to this.
|
| + EvaluationResultImpl target = node.getPrefix().accept(this); |
| + return target.stringLength(typeProvider, node); |
| + } |
| + } |
| + } else if (!(prefixElement instanceof PrefixElement)) { |
|
Paul Berry
2014/09/18 00:05:06
I'm not convinced that "else" is correct here. It
Brian Wilkerson
2014/09/18 20:29:26
I agree. Done.
|
| EvaluationResultImpl prefixResult = prefixNode.accept(this); |
| if (!(prefixResult instanceof ValidResult)) { |
| return error(node, null); |
| @@ -428,7 +436,18 @@ public class ConstantVisitor extends UnifyingAstVisitor<EvaluationResultImpl> { |
| @Override |
| public EvaluationResultImpl visitPropertyAccess(PropertyAccess node) { |
| - return getConstantValue(node, node.getPropertyName().getStaticElement()); |
| + Element element = node.getPropertyName().getStaticElement(); |
| + if (element instanceof PropertyAccessorElement) { |
| + PropertyAccessorElement accessor = (PropertyAccessorElement) element; |
| + if (accessor.getName().equals("length")) { |
| + Element parent = accessor.getEnclosingElement(); |
| + if (parent instanceof ClassElement && ((ClassElement) parent).getName().equals("String")) { |
|
Paul Berry
2014/09/18 00:05:07
As above, it's not sufficient to check whether the
Brian Wilkerson
2014/09/18 20:29:26
Done.
|
| + EvaluationResultImpl target = node.getRealTarget().accept(this); |
| + return target.stringLength(typeProvider, node); |
| + } |
| + } |
| + } |
| + return getConstantValue(node, element); |
| } |
| @Override |