Fix conflict between constant and style class name. In GWT-CSS, a constant and a style class can share the same name if in the interface there is a method for the constant that doesn't return String and another method for the style class using the @ClassName annotation. Change-Id: I7406e053d121d6e821322bd50428f58feedba9ba (cherry picked from commit 139e7f0002ad8a7b193864682fe85fc462dd9606)
diff --git a/user/src/com/google/gwt/resources/rg/GssResourceGenerator.java b/user/src/com/google/gwt/resources/rg/GssResourceGenerator.java index 32dafb0..6e63538 100644 --- a/user/src/com/google/gwt/resources/rg/GssResourceGenerator.java +++ b/user/src/com/google/gwt/resources/rg/GssResourceGenerator.java
@@ -736,7 +736,8 @@ ConversionResult result = convertToGss(concatenatedCss, logger); String gss = result.gss; - sourceCodes.add(new SourceCode("[auto-converted gss files]", gss)); + String name = "[auto-converted gss files from : " + resources + "]"; + sourceCodes.add(new SourceCode(name, gss)); constantNameMappingBuilder.putAll(result.defNameMapping); } else { @@ -858,12 +859,6 @@ Map<String, String> substitutionMap, SourceWriter sw) throws UnableToCompleteException { - if (!isReturnTypeString(userMethod.getReturnType().isClass())) { - logger.log(Type.ERROR, "The return type of the method [" + userMethod.getName() + "] must " + - "be java.lang.String."); - throw new UnableToCompleteException(); - } - if (userMethod.getParameters().length > 0) { logger.log(Type.ERROR, "The method [" + userMethod.getName() + "] shouldn't contain any " + "parameters"); @@ -981,8 +976,10 @@ throws UnableToCompleteException { String className = getClassName(userMethod); + // method to access style class ? - if (substitutionMap.containsKey(className)) { + if (substitutionMap.containsKey(className) && + isReturnTypeString(userMethod.getReturnType().isClass())) { return writeClassMethod(logger, userMethod, substitutionMap, sw); } @@ -1007,11 +1004,19 @@ return writeDefMethod(definitionNode, logger, userMethod, sw); } + if (substitutionMap.containsKey(className)) { + // method matched a class name but not a constant and the return type is not a string + logger.log(Type.ERROR, "The return type of the method [" + userMethod.getName() + "] must " + + "be java.lang.String."); + throw new UnableToCompleteException(); + } + // the method doesn't match a style class nor a constant logger.log(Type.ERROR, "The following method [" + userMethod.getName() + "()] doesn't match a constant" + " nor a style class. You could fix that by adding ." + className + " {}" ); + return false; }
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 66c7b2f..91aaeaf 100644 --- a/user/test/com/google/gwt/resources/client/gss/GssResourceTest.java +++ b/user/test/com/google/gwt/resources/client/gss/GssResourceTest.java
@@ -113,6 +113,9 @@ assertEquals("black", res().cssWithConstant().CONSTANT_THREE()); assertNotSame("white", res().cssWithConstant().conflictConstantClass()); + + assertEquals(15, res().cssWithConstant().overrideConstantInt()); + assertNotSame("15px", res().cssWithConstant().overrideConstantIntClass()); } public void testNotStrict() {
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 ec13ecb..bbe3a4f 100644 --- a/user/test/com/google/gwt/resources/client/gss/TestResources.java +++ b/user/test/com/google/gwt/resources/client/gss/TestResources.java
@@ -124,6 +124,11 @@ String className1(); String conflictConstantClass(); + + int overrideConstantInt(); + + @ClassName("overrideConstantInt") + String overrideConstantIntClass(); } /**
diff --git a/user/test/com/google/gwt/resources/client/gss/cssWithConstant.gss b/user/test/com/google/gwt/resources/client/gss/cssWithConstant.gss index 8ad9216..396eca5 100644 --- a/user/test/com/google/gwt/resources/client/gss/cssWithConstant.gss +++ b/user/test/com/google/gwt/resources/client/gss/cssWithConstant.gss
@@ -2,6 +2,7 @@ @def CONSTANT_TWO 5px; @def CONSTANT_THREE black; @def CONFLICT_CONSTANT_CLASS white; +@def OVERRIDE_CONSTANT_INT 15px; .className1 { padding-right: CONSTANT_ONE; @@ -12,3 +13,7 @@ .conflictConstantClass{ color: CONFLICT_CONSTANT_CLASS; } + +.overrideConstantInt { + width: 15px; +}