Reviewers: rjrjr,

Description:
Allow @defs with multiple values


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

Affected files:
  M user/src/com/google/gwt/resources/rg/CssResourceGenerator.java
  M user/test/com/google/gwt/resources/client/CSSResourceTest.java
  M user/test/com/google/gwt/resources/client/deftest.css


Index: user/src/com/google/gwt/resources/rg/CssResourceGenerator.java
===================================================================
--- user/src/com/google/gwt/resources/rg/CssResourceGenerator.java (revision 10663) +++ user/src/com/google/gwt/resources/rg/CssResourceGenerator.java (working copy)
@@ -70,6 +70,7 @@
 import com.google.gwt.resources.ext.ResourceContext;
 import com.google.gwt.resources.ext.ResourceGeneratorUtil;
 import com.google.gwt.resources.ext.SupportsGeneratorResultCaching;
+import com.google.gwt.thirdparty.guava.common.base.Joiner;
 import com.google.gwt.user.rebind.SourceWriter;
 import com.google.gwt.user.rebind.StringSourceWriter;

@@ -896,6 +897,11 @@
         operableTypes);
   }

+  private boolean isReturnTypeString(JClassType classReturnType) {
+    return (classReturnType != null
+ && String.class.getName().equals(classReturnType.getQualifiedSourceName()));
+  }
+
   /**
* Check for the presence of the NotStrict annotation on the method. This will * also perform some limited sanity-checking for the now-deprecated Strict
@@ -1079,21 +1085,21 @@
       throw new UnableToCompleteException();
     }

-    // TODO: Allow returning an array of values
-    if (def.getValues().size() != 1) {
+    JClassType classReturnType = toImplement.getReturnType().isClass();
+
+ if (def.getValues().size() != 1 && !isReturnTypeString(classReturnType)) {
       logger.log(TreeLogger.ERROR, "@def rule " + name
-          + " must define exactly one value");
+ + " must define exactly one value or return type must be String");
       throw new UnableToCompleteException();
     }

-    NumberValue numberValue = def.getValues().get(0).isNumberValue();
-
     String returnExpr = "";
-    JClassType classReturnType = toImplement.getReturnType().isClass();
-    if (classReturnType != null
- && "java.lang.String".equals(classReturnType.getQualifiedSourceName())) { - returnExpr = "\"" + Generator.escape(def.getValues().get(0).toString())
-          + "\"";
+    if (isReturnTypeString(classReturnType)) {
+      List<String> returnValues = new ArrayList<String>();
+      for (Value val : def.getValues()) {
+        returnValues.add(Generator.escape(val.toString()));
+      }
+      returnExpr = "\"" + Joiner.on(" ").join(returnValues) + "\"";
     } else {
JPrimitiveType returnType = toImplement.getReturnType().isPrimitive();
       if (returnType == null) {
@@ -1102,6 +1108,7 @@
             + "@def accessors");
         throw new UnableToCompleteException();
       }
+      NumberValue numberValue = def.getValues().get(0).isNumberValue();
if (returnType == JPrimitiveType.INT || returnType == JPrimitiveType.LONG) {
         returnExpr = "" + Math.round(numberValue.getValue());
       } else if (returnType == JPrimitiveType.FLOAT) {
Index: user/test/com/google/gwt/resources/client/CSSResourceTest.java
===================================================================
--- user/test/com/google/gwt/resources/client/CSSResourceTest.java (revision 10663) +++ user/test/com/google/gwt/resources/client/CSSResourceTest.java (working copy)
@@ -60,6 +60,8 @@
     float rawFloat();

     int rawInt();
+
+    String multiValueBorderDef();
   }

   /**
@@ -362,6 +364,8 @@
     assertNotNull(defines.overrideIntClass());
     assertFalse("10px".equals(defines.overrideIntClass()));
     assertFalse("10".equals(defines.overrideIntClass()));
+
+ assertEquals("1px solid rgba(0,0,0,0.2)", defines.multiValueBorderDef());
   }

   public void testEnsureInjected() {
Index: user/test/com/google/gwt/resources/client/deftest.css
===================================================================
--- user/test/com/google/gwt/resources/client/deftest.css       (revision 10663)
+++ user/test/com/google/gwt/resources/client/deftest.css       (working copy)
@@ -27,6 +27,8 @@
  @def lengthString 100px;
  @def colorString #f00;

+ @def multiValueBorderDef 1px solid rgba(0,0,0,0.2);
+
/* Uncomment this, and you should get an error about a @def shadowing a name */
  /*
  .colorString {
@@ -41,5 +43,3 @@
  .overrideInt {
    width: 10px;
  }
-
-
\ No newline at end of file


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

Reply via email to