Revision: 8372
Author: [email protected]
Date: Fri Jul  9 08:37:26 2010
Log: Allows Linkers to mark themselves as shardable by including a
private field with a certain name. Most linkers should use the
@Shardable annotation, but that doesn't work for linkers that
need to also compile against older versions of GWT.

Review at http://gwt-code-reviews.appspot.com/678802

Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=8372

Added:
 /trunk/user/test/com/google/gwt/core/ext/LinkerUnitTest.java
Modified:
 /trunk/dev/core/src/com/google/gwt/core/ext/Linker.java

=======================================
--- /dev/null
+++ /trunk/user/test/com/google/gwt/core/ext/LinkerUnitTest.java Fri Jul 9 08:37:26 2010
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.core.ext;
+
+import com.google.gwt.core.ext.linker.Shardable;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit tests for the {...@link Linker} class itself.
+ */
+public class LinkerUnitTest extends TestCase {
+  public void testIsShardable() {
+    {
+      // Non-shardable by default
+      class TestLinker extends Linker {
+        @Override
+        public String getDescription() {
+          return "Test Linker";
+        }
+      }
+      assertFalse(new TestLinker().isShardable());
+    }
+
+    {
+      // Annotating as shardable
+      @Shardable
+      class TestLinker extends Linker {
+        @Override
+        public String getDescription() {
+          return "Test Linker";
+        }
+      }
+      assertTrue(new TestLinker().isShardable());
+    }
+
+    {
+      // Using a private field to indicate shardability
+      class TestLinker extends Linker {
+        private boolean gwtIsShardable;
+
+        @Override
+        public String getDescription() {
+          return "Test Linker";
+        }
+      }
+      assertTrue(new TestLinker().isShardable());
+    }
+  }
+}
=======================================
--- /trunk/dev/core/src/com/google/gwt/core/ext/Linker.java Fri Mar 19 08:12:41 2010 +++ /trunk/dev/core/src/com/google/gwt/core/ext/Linker.java Fri Jul 9 08:37:26 2010
@@ -55,10 +55,26 @@
   public abstract String getDescription();

   /**
-   * Check whether this class has the {...@link Shardable} annotation.
+   * Check whether this class is considered a shardable linker. A linker is
+ * shardable if it either implements the {...@link Shardable} annotation or it + * has a field named <code>gwtIsShardable</code>. If such a field is present, + * it doesn't matter what value the field holds. The latter mechanism is only + * intended to support linkers that must compile against older versions of
+   * GWT.
    */
   public final boolean isShardable() {
-    return getClass().isAnnotationPresent(Shardable.class);
+    if (getClass().isAnnotationPresent(Shardable.class)) {
+      return true;
+    }
+
+    try {
+      getClass().getDeclaredField("gwtIsShardable");
+      return true;
+    } catch (NoSuchFieldException e) {
+      // The field does not exist; fall through
+    }
+
+    return false;
   }

   /**

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

Reply via email to