Reviewers: zundel, jbrosenberg,

Message:
Turns out the target GWT field is not always fully baked, as it was in
GenerateJavaAST.  Using JDT to get the compile-time constant is the
right appraoch.


http://gwt-code-reviews.appspot.com/1449818/diff/1/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
File dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
(right):

http://gwt-code-reviews.appspot.com/1449818/diff/1/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java#newcode258
dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java:258:
processField(x, info, JField.NULL_FIELD, ctx);
This line is why I hoisted the constant handling up to the call site
(below) instead changing the signature to pass in the FieldBinding.



Please review this at http://gwt-code-reviews.appspot.com/1449818/

Affected files:
  M dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java


Index: dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java b/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java index 32971878c729bdc9077ba55538a147e295816c37..59d63bfae5cd6d80da339183d2981995198c7441 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
@@ -236,6 +236,7 @@ public class GwtAstBuilder {
* Resolves local references to function parameters, and JSNI references.
      */
     private class JsniResolver extends JsModVisitor {
+ private final GenerateJavaScriptLiterals generator = new GenerateJavaScriptLiterals();
       private final JsniMethodBody nativeMethodBody;

       private JsniResolver(JsniMethodBody nativeMethodBody) {
@@ -260,8 +261,23 @@ public class GwtAstBuilder {
             JType type = typeMap.get((TypeBinding) binding);
             processClassLiteral(x, info, type, ctx);
           } else if (binding instanceof FieldBinding) {
-            JField field = typeMap.get((FieldBinding) binding);
-            processField(x, info, field, ctx);
+            FieldBinding fieldBinding = (FieldBinding) binding;
+            /*
+             * We must replace any compile-time constants with the constant
+             * value of the field.
+             */
+            if (fieldBinding.constant() != Constant.NotAConstant) {
+              assert !ctx.isLvalue();
+ JExpression constant = getConstant(info, fieldBinding.constant());
+              generator.accept(constant);
+              JsExpression result = generator.pop();
+              assert (result != null);
+              ctx.replaceMe(result);
+            } else {
+              // Normal: create a jsniRef.
+              JField field = typeMap.get(fieldBinding);
+              processField(x, info, field, ctx);
+            }
           } else {
             JMethod method = typeMap.get((MethodBinding) binding);
             processMethod(x, info, method);
@@ -276,25 +292,6 @@ public class GwtAstBuilder {
       }

private void processField(JsNameRef nameRef, SourceInfo info, JField field, JsContext ctx) {
-        /*
- * We must replace any compile-time constants with the constant value of
-         * the field.
-         */
-        if (field.isCompileTimeConstant()) {
-          assert !ctx.isLvalue();
-          JLiteral initializer = field.getConstInitializer();
-          JType type = initializer.getType();
- if (type instanceof JPrimitiveType || initializer instanceof JStringLiteral) { - GenerateJavaScriptLiterals generator = new GenerateJavaScriptLiterals();
-            generator.accept(initializer);
-            JsExpression result = generator.peek();
-            assert (result != null);
-            ctx.replaceMe(result);
-            return;
-          }
-        }
-
-        // Normal: create a jsniRef.
         JsniFieldRef fieldRef =
new JsniFieldRef(info, nameRef.getIdent(), field, curClass.type, ctx.isLvalue());
         nativeMethodBody.addJsniRef(fieldRef);


--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to