Fix constant reference in GSS.
Fix issue occurring when a constant definition made reference to
another constant and the CssResource interface contains a method
to refer to the numerical value of this constant.
bug: Issue 9199
Change-Id: I589c6bca0a91b98463d1f82ec90dcf0661a0abfd
diff --git a/user/src/com/google/gwt/resources/rg/GssResourceGenerator.java b/user/src/com/google/gwt/resources/rg/GssResourceGenerator.java
index 2b85ab0..a789edb 100644
--- a/user/src/com/google/gwt/resources/rg/GssResourceGenerator.java
+++ b/user/src/com/google/gwt/resources/rg/GssResourceGenerator.java
@@ -64,6 +64,7 @@
import com.google.gwt.thirdparty.common.css.SourceCode;
import com.google.gwt.thirdparty.common.css.SourceCodeLocation;
import com.google.gwt.thirdparty.common.css.SubstitutionMap;
+import com.google.gwt.thirdparty.common.css.compiler.ast.CssCompositeValueNode;
import com.google.gwt.thirdparty.common.css.compiler.ast.CssDefinitionNode;
import com.google.gwt.thirdparty.common.css.compiler.ast.CssNumericNode;
import com.google.gwt.thirdparty.common.css.compiler.ast.CssTree;
@@ -1274,6 +1275,16 @@
return false;
}
CssValueNode valueNode = params.get(0);
+
+ // when a constant refers to another constant, closure-stylesheet wrap the CssNumericNode in
+ // a CssCompositeValueNode. Unwrap it.
+ if (valueNode instanceof CssCompositeValueNode) {
+ CssCompositeValueNode toUnwrap = (CssCompositeValueNode) valueNode;
+ if (toUnwrap.getValues().size() == 1) {
+ valueNode = toUnwrap.getValues().get(0);
+ }
+ }
+
if (!(valueNode instanceof CssNumericNode)) {
logger.log(TreeLogger.ERROR, "The value of the constant defined by @" + name + " is not a" +
" numeric");
diff --git a/user/test/com/google/gwt/resources/client/gss/GssResourceTest.java b/user/test/com/google/gwt/resources/client/gss/GssResourceTest.java
index f988bf7..74f7bd6 100644
--- a/user/test/com/google/gwt/resources/client/gss/GssResourceTest.java
+++ b/user/test/com/google/gwt/resources/client/gss/GssResourceTest.java
@@ -186,6 +186,7 @@
assertEquals("#012345", res().constants().mycolor1());
assertEquals(10, res().constants().margin());
assertEquals(120, res().constants().width());
+ assertEquals(1, res().constants().bar());
assertEquals("div{width:120px}", res().constants().getText());
}
diff --git a/user/test/com/google/gwt/resources/client/gss/TestResources.java b/user/test/com/google/gwt/resources/client/gss/TestResources.java
index 9cd6418..a1b89fc 100644
--- a/user/test/com/google/gwt/resources/client/gss/TestResources.java
+++ b/user/test/com/google/gwt/resources/client/gss/TestResources.java
@@ -177,6 +177,8 @@
String padding2();
int width();
+
+ int bar();
}
/**
diff --git a/user/test/com/google/gwt/resources/client/gss/constants.gss b/user/test/com/google/gwt/resources/client/gss/constants.gss
index f9111c2..ff7951a 100644
--- a/user/test/com/google/gwt/resources/client/gss/constants.gss
+++ b/user/test/com/google/gwt/resources/client/gss/constants.gss
@@ -17,6 +17,9 @@
@def WIDTH add(MARGIN, PADDING, 100px);
+@def FOO 1px;
+@def BAR FOO;
+
div {
width: WIDTH;
}