Revision: 9603
Author: rj...@google.com
Date: Mon Jan 24 15:45:54 2011
Log: Public (t.bro...@gmail.com):
Addresses http://code.google.com/p/google-web-toolkit/issues/detail?id=5563
For GIN friendliness, make the PlaceHistoryMapperGenerator return null
when it encounters a concrete implementation. (Returning null from
a code generator results in a new Foo() call.)
http://gwt-code-reviews.appspot.com/1293801
Review by: robertvaw...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=9603
Modified:
/trunk/user/src/com/google/gwt/place/rebind/PlaceHistoryGeneratorContext.java
/trunk/user/src/com/google/gwt/place/rebind/PlaceHistoryMapperGenerator.java
/trunk/user/src/com/google/gwt/place/shared/PlaceHistoryMapper.java
/trunk/user/test/com/google/gwt/place/impl/PlaceHistoryMapperGeneratorTest.java
/trunk/user/test/com/google/gwt/place/rebind/PlaceHistoryGeneratorContextTest.java
=======================================
---
/trunk/user/src/com/google/gwt/place/rebind/PlaceHistoryGeneratorContext.java
Tue Oct 5 17:59:14 2010
+++
/trunk/user/src/com/google/gwt/place/rebind/PlaceHistoryGeneratorContext.java
Mon Jan 24 15:45:54 2011
@@ -38,6 +38,17 @@
import java.util.TreeMap;
class PlaceHistoryGeneratorContext {
+ /**
+ * Creates a {@link PlaceHistoryGeneratorContext} for the given
+ * {@link PlaceHistoryMapper} sub-interface.
+ *
+ * @return a {@link PlaceHistoryGeneratorContext}, or <code>null</code>
if the
+ * generator should not run (i.e. <code>interfaceName</code> is
not an
+ * interface)
+ * @throws UnableToCompleteException if the type denoted by
+ * <code>interfaceName</code> cannot be found in
+ * <code>typeOracle</code>
+ */
static PlaceHistoryGeneratorContext create(TreeLogger logger,
TypeOracle typeOracle, String interfaceName)
throws UnableToCompleteException {
@@ -57,9 +68,7 @@
}
if (interfaceType.isInterface() == null) {
- logger.log(TreeLogger.ERROR, interfaceType.getQualifiedSourceName()
- + " is not an interface.", null);
- throw new UnableToCompleteException();
+ return null;
}
factoryType = findFactoryType(placeHistoryMapperWithFactoryType,
=======================================
---
/trunk/user/src/com/google/gwt/place/rebind/PlaceHistoryMapperGenerator.java
Tue Oct 5 17:59:14 2010
+++
/trunk/user/src/com/google/gwt/place/rebind/PlaceHistoryMapperGenerator.java
Mon Jan 24 15:45:54 2011
@@ -32,11 +32,6 @@
import java.io.PrintWriter;
/**
- * <p>
- * <span style="color:red">Experimental API: This class is still under
rapid
- * development, and is very likely to be deleted. Use it at your own risk.
- * </span>
- * </p>
* Generates implementations of
* {@link com.google.gwt.place.shared.PlaceHistoryMapper
PlaceHistoryMapper}.
*/
@@ -50,6 +45,10 @@
context = PlaceHistoryGeneratorContext.create(logger,
generatorContext.getTypeOracle(), interfaceName);
+ if (context == null) {
+ return null;
+ }
+
PrintWriter out = generatorContext.tryCreate(logger,
context.packageName,
context.implName);
=======================================
--- /trunk/user/src/com/google/gwt/place/shared/PlaceHistoryMapper.java Thu
Oct 14 18:28:29 2010
+++ /trunk/user/src/com/google/gwt/place/shared/PlaceHistoryMapper.java Mon
Jan 24 15:45:54 2011
@@ -18,6 +18,10 @@
/**
* Maps {@link Place}s to/from tokens, used to configure a
* {@link PlaceHistoryHandler}.
+ * <p>
+ * You can annotate subinterfaces of PlaceHistoryMapper with
+ * {@link WithTokenizers} to have their implementation automatically
generated
+ * via a call to {@link com.google.gwt.core.client.GWT#create(Class)}.
*/
public interface PlaceHistoryMapper {
=======================================
---
/trunk/user/test/com/google/gwt/place/impl/PlaceHistoryMapperGeneratorTest.java
Tue Oct 5 18:38:29 2010
+++
/trunk/user/test/com/google/gwt/place/impl/PlaceHistoryMapperGeneratorTest.java
Mon Jan 24 15:45:54 2011
@@ -47,6 +47,19 @@
interface LocalWithFactory extends
PlaceHistoryMapperWithFactory<TokenizerFactory> {
};
+
+ /**
+ * The goal is only to test that the generator doesn't fail (but doesn't
+ * generate anything either).
+ */
+ static class LocalConcreteClass implements LocalNoFactory {
+ public Place getPlace(String token) {
+ return null;
+ }
+ public String getToken(Place place) {
+ return null;
+ }
+ }
@Override
public String getModuleName() {
@@ -86,6 +99,18 @@
doTest(subject, factory);
}
+
+ /**
+ * When asked to GWT.create a concrete implementation of
PlaceHistoryMapper,
+ * the generator politely instantiates it. This is to make life easier
+ * for GIN users. See
+ * http://code.google.com/p/google-web-toolkit/issues/detail?id=5563
+ */
+ public void testNotAnInterface() {
+ PlaceHistoryMapper subject = GWT.create(LocalConcreteClass.class);
+ assertNull(subject.getToken(null));
+ assertNull(subject.getPlace(null));
+ }
// CHECKSTYLE_OFF
private void doTest(AbstractPlaceHistoryMapper<?> subject,
=======================================
---
/trunk/user/test/com/google/gwt/place/rebind/PlaceHistoryGeneratorContextTest.java
Tue Oct 5 18:38:29 2010
+++
/trunk/user/test/com/google/gwt/place/rebind/PlaceHistoryGeneratorContextTest.java
Mon Jan 24 15:45:54 2011
@@ -89,6 +89,31 @@
rtn.addAll(Arrays.asList(resources));
return CompilationStateBuilder.buildFrom(createCompileLogger(),
rtn).getTypeOracle();
}
+
+ public void testCreateNotAnInterface() throws UnableToCompleteException {
+ MockJavaResource intf = new
MockJavaResource("my.MyPlaceHistoryMapper") {
+
+ @Override
+ protected CharSequence getContent() {
+ StringBuilder code = new StringBuilder();
+ code.append("package my;\n");
+ code.append("import
com.google.gwt.place.shared.PlaceHistoryMapper;\n");
+
+ code.append("public abstract class MyPlaceHistoryMapper implements
PlaceHistoryMapper {\n");
+ code.append("}\n");
+ return code;
+ }
+ };
+
+ TypeOracle typeOracle = createTypeOracle(intf);
+
+ UnitTestTreeLogger logger = new
UnitTestTreeLogger.Builder().createLogger();
+
+ PlaceHistoryGeneratorContext context =
PlaceHistoryGeneratorContext.create(
+ logger, typeOracle, intf.getTypeName());
+
+ assertNull(context);
+ }
public void testCreateNoFactory() throws UnableToCompleteException,
NotFoundException {
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors