Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Unified Diff: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/constant/ConstantVisitor.java

Issue 581773002: Implement new constant expressions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..71d0f4c2bc9eeff0a9e2f39181c77c8684958335 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,7 +394,11 @@ public class ConstantVisitor extends UnifyingAstVisitor<EvaluationResultImpl> {
@Override
public EvaluationResultImpl visitPrefixedIdentifier(PrefixedIdentifier node) {
- // validate prefix
+ Element element = node.getStaticElement();
+ if (isStringLength(element)) {
+ EvaluationResultImpl target = node.getPrefix().accept(this);
+ return target.stringLength(typeProvider, node);
+ }
SimpleIdentifier prefixNode = node.getPrefix();
Element prefixElement = prefixNode.getStaticElement();
if (!(prefixElement instanceof PrefixElement)) {
@@ -428,7 +432,12 @@ public class ConstantVisitor extends UnifyingAstVisitor<EvaluationResultImpl> {
@Override
public EvaluationResultImpl visitPropertyAccess(PropertyAccess node) {
- return getConstantValue(node, node.getPropertyName().getStaticElement());
+ Element element = node.getPropertyName().getStaticElement();
+ if (isStringLength(element)) {
+ EvaluationResultImpl target = node.getRealTarget().accept(this);
+ return target.stringLength(typeProvider, node);
+ }
+ return getConstantValue(node, element);
}
@Override
@@ -566,6 +575,24 @@ public class ConstantVisitor extends UnifyingAstVisitor<EvaluationResultImpl> {
}
/**
+ * Return {@code true} if the given element represents the 'length' getter in class 'String'.
+ *
+ * @param element the element being tested.
+ * @return
+ */
+ private boolean isStringLength(Element element) {
+ if (!(element instanceof PropertyAccessorElement)) {
+ return false;
+ }
+ PropertyAccessorElement accessor = (PropertyAccessorElement) element;
+ if (!accessor.isGetter() || !accessor.getName().equals("length")) {
+ return false;
+ }
+ Element parent = accessor.getEnclosingElement();
+ return parent.equals(typeProvider.getStringType().getElement());
+ }
+
+ /**
* Return the union of the errors encoded in the given results.
*
* @param leftResult the first set of errors, or {@code null} if there was no previous collection

Powered by Google App Engine
This is Rietveld 408576698