Revision: 6343 Author: [email protected] Date: Sat Oct 10 13:50:11 2009 Log: Switch CssResource to strict-by-default mode.
Patch by: bobv Review by: rjrjr http://code.google.com/p/google-web-toolkit/source/detail?r=6343 Modified: /trunk/user/src/com/google/gwt/resources/Resources.gwt.xml /trunk/user/src/com/google/gwt/resources/client/CssResource.java /trunk/user/src/com/google/gwt/resources/css/ast/CssExternalSelectors.java /trunk/user/src/com/google/gwt/resources/rg/CssResourceGenerator.java /trunk/user/src/com/google/gwt/uibinder/rebind/BundleWriter.java /trunk/user/src/com/google/gwt/uibinder/sample/client/DomBasedUi.java /trunk/user/src/com/google/gwt/uibinder/sample/client/WidgetBasedUiExternalResources.java /trunk/user/test/com/google/gwt/resources/client/CSSResourceTest.java /trunk/user/test/com/google/gwt/uibinder/sample/client/UiBinderTest.java ======================================= --- /trunk/user/src/com/google/gwt/resources/Resources.gwt.xml Tue Sep 29 13:58:28 2009 +++ /trunk/user/src/com/google/gwt/resources/Resources.gwt.xml Sat Oct 10 13:50:11 2009 @@ -84,12 +84,6 @@ <define-configuration-property name="CssResource.mergeEnabled" is-multi-valued="false" /> <set-configuration-property name="CssResource.mergeEnabled" value="true" /> - <!-- This forces all CssResource accessor functions to have the @Strict --> - <!-- annotation. This is intended primarily for application developers and --> - <!-- the library test code. --> - <define-configuration-property name="CssResource.strictAccessors" is-multi-valued="false" /> - <set-configuration-property name="CssResource.strictAccessors" value="false" /> - <!-- This allows the developer to use shorter obfuscated class names. --> <!-- Is is valid to extend this property to use a custom name. --> <define-configuration-property name="CssResource.obfuscationPrefix" is-multi-valued="false" /> ======================================= --- /trunk/user/src/com/google/gwt/resources/client/CssResource.java Tue Sep 29 13:58:28 2009 +++ /trunk/user/src/com/google/gwt/resources/client/CssResource.java Sat Oct 10 13:50:11 2009 @@ -50,8 +50,8 @@ * <li>{...@code @eval NAME Java-expression; .myClass background: NAME;} Define a * constant based on a Java expression.</li> * <li>{...@code @external class-name, class-name, ...;} Disable obfuscation for - * specific class selectors and exclude those class selectors from - * {...@link Strict} requirements.</li> + * specific class selectors and exclude those class selectors from strictness + * requirements.</li> * <li><code>{...@literal @if} [!]property list of values {ruleBlock}</code> Include or * exclude CSS rules based on the value of a deferred-binding property. Also * {...@code @elif} and {...@code @else} follow the same pattern.<br/> @@ -92,6 +92,51 @@ * </li> * </ul> * + * <p> + * Any class selectors that do not correspond with a String accessor method in + * the return type will trigger a compilation error. This ensures that the + * CssResource does not contribute any unobfuscated class selectors into the + * global CSS namespace. Strict mode can be disabled by annotating the + * ClientBundle method declaration with {...@link NotStrict}, however this is only + * recommended for interacting with legacy CSS. + * + * <p> + * Given these interfaces: + * + * <pre> + * interface MyCss extends CssResource { + * String someClass(); + * } + * + * interface MyBundle extends ClientBundle { + * {...@literal @Source("my.css")} + * MyCss css(); + * } + * </pre> + * + * the source CSS will fail to compile if it does not contain exactly the one + * class selector defined in the MyCss type. + * <p> + * The {...@code @external} at-rule can be used in strict mode to indicate that + * certain class selectors are exempt from the strict semantics. Class selectors + * marked as external will not be obfuscated and are not required to have string + * accessor functions. Consider the following example in conjunction with the + * above <code>MyCss</code> interface: + * + * <pre> + * {...@literal @external} .foo, .bar; + * .foo .someClass .bar { .... } + * </pre> + * + * The resulting CSS would look like: + * + * <pre> + * .foo .A1234 .bar { .... } + * </pre> + * + * If a <code>String foo()</code> method were defined in <code>MyCss</code>, it + * would return the string value "<code>foo</code>". + * * @see <a href="http://code.google.com/p/google-web-toolkit/wiki/CssResource" * >CssResource design doc</a> */ @@ -183,6 +228,14 @@ * method in the return type or an {...@code @external} declaration should not * trigger a compilation error. This annotation is not recommended for new * code. + * + * <pre> + * interface Resources extends ClientBundle { + * {...@literal @NotStrict} + * {...@literal @Source}("legacy.css") + * CssResource css(); + * } + * </pre> */ @Documented @Target(ElementType.METHOD) @@ -234,52 +287,11 @@ } /** - * The presence of this annotation on a CssResource accessor method indicates - * that any class selectors that do not correspond with a String accessor - * method in the return type should trigger a compilation error. In the - * default case, any unobfuscatable class selectors will be emitted as-is. - * This annotation ensures that the CssResource does not contribute any - * unobfuscated class selectors into the global CSS namespace and is - * recommended as the default behavior for CssResources. - * <p> - * Given these interfaces: + * This annotation is a no-op. * - * <pre> - * interface MyCss extends CssResource { - * String someClass(); - * } - * - * interface MyBundle extends ClientBundle { - * {...@literal @Source("my.css")} - * {...@literal @Strict} - * MyCss css(); - * } - * </pre> - * - * the source CSS will fail to compile if it does not contain exactly the one - * class selector defined in the MyCss type. - * <p> - * The {...@code @external} at-rule can be used in strict mode to indicate that - * certain class selectors are exempt from the strict semantics. Class - * selectors marked as external will not be obfuscated and are not required to - * have string accessor functions. Consider the following example in - * conjunction with the above <code>MyCss</code> interface: - * - * <pre> - * {...@literal @external} .foo, .bar; - * .foo .someClass .bar { .... } - * </pre> - * - * The resulting CSS would look like: - * - * <pre> - * .foo .A1234 .bar { .... } - * </pre> - * - * If a <code>String foo()</code> method were defined in <code>MyCss</code>, - * it would return the string value "<code>foo</code>". + * @deprecated Strict mode is now the default behavior for CssResource */ - @Documented + @Deprecated @Target(ElementType.METHOD) public @interface Strict { } ======================================= --- /trunk/user/src/com/google/gwt/resources/css/ast/CssExternalSelectors.java Wed May 20 16:14:31 2009 +++ /trunk/user/src/com/google/gwt/resources/css/ast/CssExternalSelectors.java Sat Oct 10 13:50:11 2009 @@ -22,8 +22,6 @@ * An AST node that allows the developer to indicate that certain class * selectors appearing in the stylesheet should be considered external and not * subject to obfuscation requirements. - * - * @see CssResource.Strict */ public class CssExternalSelectors extends CssNode { ======================================= --- /trunk/user/src/com/google/gwt/resources/rg/CssResourceGenerator.java Tue Sep 29 13:58:28 2009 +++ /trunk/user/src/com/google/gwt/resources/rg/CssResourceGenerator.java Sat Oct 10 13:50:11 2009 @@ -713,54 +713,27 @@ computeObfuscatedNames(logger, classPrefix, cssResourceSubtypes); } + /** + * Check for the presence of the NotStrict annotation on the method. This will + * also perform some limited sanity-checking for the now-deprecated Strict + * annotation. + */ + @SuppressWarnings("deprecation") private boolean isStrict(TreeLogger logger, ResourceContext context, JMethod method) { Strict strictAnnotation = method.getAnnotation(Strict.class); NotStrict nonStrictAnnotation = method.getAnnotation(NotStrict.class); - boolean strict = false; + boolean strict = true; if (strictAnnotation != null && nonStrictAnnotation != null) { // Both annotations logger.log(TreeLogger.WARN, "Contradictory annotations " + Strict.class.getName() + " and " + NotStrict.class.getName() + " applied to the CssResource accessor method; assuming strict"); - strict = true; - - } else if (strictAnnotation == null && nonStrictAnnotation == null) { - // Neither annotation - - /* - * Fall back to using the to-be-deprecated strictAccessor property. - */ - try { - PropertyOracle propertyOracle = context.getGeneratorContext().getPropertyOracle(); - ConfigurationProperty prop = propertyOracle.getConfigurationProperty("CssResource.strictAccessors"); - String propertyValue = prop.getValues().get(0); - if (Boolean.valueOf(propertyValue)) { - logger.log(TreeLogger.WARN, - "CssResource.strictAccessors is true, but " + method.getName() - + "() is missing the @Strict annotation."); - strict = true; - } - } catch (BadPropertyValueException e) { - // Ignore - } - - if (!strict) { - // This is a temporary warning during the transitional phase - logger.log(TreeLogger.WARN, "Accessor does not specify " - + Strict.class.getName() + " or " + NotStrict.class.getName() - + ". The default behavior will change from non-strict " - + "to strict in a future revision."); - } } else if (nonStrictAnnotation != null) { // Only the non-strict annotation strict = false; - - } else if (strictAnnotation != null) { - // Only the strict annotation - strict = true; } return strict; ======================================= --- /trunk/user/src/com/google/gwt/uibinder/rebind/BundleWriter.java Fri Oct 9 22:09:58 2009 +++ /trunk/user/src/com/google/gwt/uibinder/rebind/BundleWriter.java Sat Oct 10 13:50:11 2009 @@ -20,7 +20,6 @@ import com.google.gwt.core.ext.typeinfo.TypeOracle; import com.google.gwt.resources.client.ClientBundle; import com.google.gwt.resources.client.ImageResource; -import com.google.gwt.resources.client.CssResource.Strict; import com.google.gwt.resources.client.ImageResource.ImageOptions; import com.google.gwt.resources.client.ImageResource.RepeatStyle; import com.google.gwt.uibinder.rebind.model.ImplicitClientBundle; @@ -38,7 +37,6 @@ private final TypeOracle oracle; private final JClassType clientBundleType; - private final JClassType strictAnnotationType; private final JClassType imageOptionType; private final JClassType imageResourceType; private final JClassType repeatStyleType; @@ -53,7 +51,6 @@ this.oracle = oracle; clientBundleType = oracle.findType(ClientBundle.class.getName()); - strictAnnotationType = oracle.findType(Strict.class.getCanonicalName()); imageOptionType = oracle.findType(ImageOptions.class.getCanonicalName()); imageResourceType = oracle.findType(ImageResource.class.getCanonicalName()); repeatStyleType = oracle.findType(RepeatStyle.class.getCanonicalName()); @@ -79,7 +76,6 @@ writer.write("import %s;", imageResourceType.getQualifiedSourceName()); writer.write("import %s;", imageOptionType.getQualifiedSourceName()); writer.write("import %s;", clientBundleType.getQualifiedSourceName()); - writer.write("import %s;", strictAnnotationType.getQualifiedSourceName()); writer.newline(); // Open interface @@ -89,7 +85,7 @@ // Write css methods for (ImplicitCssResource css : bundleClass.getCssMethods()) { - writer.write("@Strict @Source(\"%s\")", css.getSource()); + writer.write("@Source(\"%s\")", css.getSource()); writer.write("%s %s();", css.getClassName(), css.getName()); writer.newline(); } ======================================= --- /trunk/user/src/com/google/gwt/uibinder/sample/client/DomBasedUi.java Thu Sep 3 16:03:13 2009 +++ /trunk/user/src/com/google/gwt/uibinder/sample/client/DomBasedUi.java Sat Oct 10 13:50:11 2009 @@ -21,7 +21,6 @@ import com.google.gwt.dom.client.StyleInjector; import com.google.gwt.resources.client.ClientBundle; import com.google.gwt.resources.client.CssResource; -import com.google.gwt.resources.client.CssResource.Strict; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; @@ -34,7 +33,6 @@ * Resources for this template. */ public interface Resources extends ClientBundle { - @Strict @Source("DomBasedUi.css") Style style(); } ======================================= --- /trunk/user/src/com/google/gwt/uibinder/sample/client/WidgetBasedUiExternalResources.java Thu Sep 3 16:03:13 2009 +++ /trunk/user/src/com/google/gwt/uibinder/sample/client/WidgetBasedUiExternalResources.java Sat Oct 10 13:50:11 2009 @@ -17,7 +17,6 @@ import com.google.gwt.resources.client.ClientBundle; import com.google.gwt.resources.client.CssResource; -import com.google.gwt.resources.client.CssResource.Strict; /** * Sample external resources used by {...@link WidgetBasedUi}, to test @@ -34,6 +33,5 @@ } @Source("WidgetBasedUiExternal.css") - @Strict MyCss style(); } ======================================= --- /trunk/user/test/com/google/gwt/resources/client/CSSResourceTest.java Tue Sep 29 13:58:28 2009 +++ /trunk/user/test/com/google/gwt/resources/client/CSSResourceTest.java Sat Oct 10 13:50:11 2009 @@ -21,7 +21,6 @@ import com.google.gwt.resources.client.CssResource.ImportedWithPrefix; import com.google.gwt.resources.client.CssResource.NotStrict; import com.google.gwt.resources.client.CssResource.Shared; -import com.google.gwt.resources.client.CssResource.Strict; /** * Contains various full-stack tests of the CssResource system. @@ -37,7 +36,6 @@ interface ConcatenatedResources extends ClientBundle { @Source(value = {"concatenatedA.css", "concatenatedB.css"}) - @Strict CssResource css(); } @@ -112,11 +110,9 @@ Resources INSTANCE = GWT.create(Resources.class); @Source("siblingTestA.css") - @Strict MyCssResourceA a(); @Source("siblingTestB.css") - @Strict MyCssResourceB b(); @Source("test.css") @@ -127,16 +123,13 @@ DataResource dataMethod(); // Test default extensions - @Strict CssWithDefines deftest(); @Source("unrelatedDescendants.css") @Import(value = {MyCssResourceA.class, MyCssResourceB.class}) - @Strict HasDescendants descendants(); // Make sure an empty, no-op CssResource works - @Strict CssResource empty(); @Source("16x16.png") @@ -157,11 +150,9 @@ interface SiblingResources extends ClientBundle { @Source("siblingTestA.css") - @Strict MyCssResourceA a(); @Source("siblingTestB.css") - @Strict MyCssResourceB b(); } ======================================= --- /trunk/user/test/com/google/gwt/uibinder/sample/client/UiBinderTest.java Fri Oct 9 22:09:58 2009 +++ /trunk/user/test/com/google/gwt/uibinder/sample/client/UiBinderTest.java Sat Oct 10 13:50:11 2009 @@ -25,6 +25,7 @@ import com.google.gwt.junit.Platform; import com.google.gwt.junit.client.GWTTestCase; import com.google.gwt.resources.client.ClientBundle; +import com.google.gwt.resources.client.CssResource.NotStrict; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.ui.DisclosurePanel; import com.google.gwt.user.client.ui.DockPanel; @@ -238,7 +239,8 @@ interface Bundle extends ClientBundle { @Source("WidgetBasedUi.css") - public WidgetBasedUi.Style style(); + @NotStrict + WidgetBasedUi.Style style(); } public void testNoOverrideInheritedSharedCssClasses() { --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---
