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

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

Issue 270813004: Evaluate constant instance creation expressions in ConstantValueComputer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 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/ConstantFinder.java
diff --git a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/constant/ConstantFinder.java b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/constant/ConstantFinder.java
index aacb0c544751199ec38ec6f951e2b553f4123040..ad94ef69ea8d858ee9dbfbc5f47ad1b879b77c97 100644
--- a/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/constant/ConstantFinder.java
+++ b/editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/internal/constant/ConstantFinder.java
@@ -13,12 +13,16 @@
*/
package com.google.dart.engine.internal.constant;
+import com.google.dart.engine.ast.ConstructorDeclaration;
import com.google.dart.engine.ast.Expression;
+import com.google.dart.engine.ast.InstanceCreationExpression;
import com.google.dart.engine.ast.VariableDeclaration;
import com.google.dart.engine.ast.visitor.RecursiveAstVisitor;
+import com.google.dart.engine.element.ConstructorElement;
import com.google.dart.engine.element.VariableElement;
import java.util.HashMap;
+import java.util.HashSet;
/**
* Instances of the class {@code ConstantFinder} are used to traverse the AST structures of all of
@@ -32,6 +36,16 @@ public class ConstantFinder extends RecursiveAstVisitor<Void> {
private HashMap<VariableElement, VariableDeclaration> variableMap = new HashMap<VariableElement, VariableDeclaration>();
/**
+ * A table mapping constant constructors to the declarations of those constructors.
+ */
+ private HashMap<ConstructorElement, ConstructorDeclaration> constructorMap = new HashMap<ConstructorElement, ConstructorDeclaration>();
+
+ /**
+ * A collection of constant constructor invocations.
+ */
+ private HashSet<InstanceCreationExpression> constructorInvocations = new HashSet<InstanceCreationExpression>();
Brian Wilkerson 2014/05/08 22:12:49 I don't think there's any reason for this to be a
Paul Berry 2014/05/08 23:12:46 Good point. I've changed it to an ArrayList.
+
+ /**
* Initialize a newly created constant finder.
*/
public ConstantFinder() {
@@ -39,6 +53,20 @@ public class ConstantFinder extends RecursiveAstVisitor<Void> {
}
/**
+ * Return a collection of constant constructor invocations.
+ */
+ public HashSet<InstanceCreationExpression> getConstructorInvocations() {
+ return constructorInvocations;
+ }
+
+ /**
+ * Return a table mapping constant constructors to the declarations of those constructors.
+ */
+ public HashMap<ConstructorElement, ConstructorDeclaration> getConstructorMap() {
+ return constructorMap;
+ }
+
+ /**
* Return a table mapping constant variable elements to the declarations of those variables.
*
* @return a table mapping constant variable elements to the declarations of those variables
@@ -48,6 +76,27 @@ public class ConstantFinder extends RecursiveAstVisitor<Void> {
}
@Override
+ public Void visitConstructorDeclaration(ConstructorDeclaration node) {
+ super.visitConstructorDeclaration(node);
+ if (node.getConstKeyword() != null) {
+ ConstructorElement element = node.getElement();
+ if (element != null) {
+ constructorMap.put(element, node);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Void visitInstanceCreationExpression(InstanceCreationExpression node) {
+ super.visitInstanceCreationExpression(node);
+ if (node.isConst()) {
+ constructorInvocations.add(node);
+ }
+ return null;
+ }
+
+ @Override
public Void visitVariableDeclaration(VariableDeclaration node) {
super.visitVariableDeclaration(node);
Expression initializer = node.getInitializer();

Powered by Google App Engine
This is Rietveld 408576698