Reviewers: ,
Description:
Added a WithDelimiter Annotation to allow for custom delimiter for use
with the AbstractPlaceHistoryMapper.
Example useage:
@WithTokenizers(...)
@WithDelimiter(/)
public interface AppPlaceHistoryMapper extends PlaceHistoryMapper {}
http://code.google.com/p/google-web-toolkit/issues/detail?id=5899
Supports multiple character delimiter.
@WithDelimiter(::)
Please review this at http://gwt-code-reviews.appspot.com/1710803/
Affected files:
place/impl/AbstractPlaceHistoryMapper.java
place/rebind/PlaceHistoryGeneratorContext.java
place/rebind/PlaceHistoryMapperGenerator.java
place/shared/WithDelimiter.java
Index: place/impl/AbstractPlaceHistoryMapper.java
===
--- place/impl/AbstractPlaceHistoryMapper.java (revision 10971)
+++ place/impl/AbstractPlaceHistoryMapper.java (working copy)
@@ -31,31 +31,31 @@
* Return value for
* {@link AbstractPlaceHistoryMapper#getPrefixAndToken(Place)}.
*/
- public static class PrefixAndToken {
+ public class PrefixAndToken {
public final String prefix;
public final String token;
public PrefixAndToken(String prefix, String token) {
- assert prefix != null !prefix.contains(:);
+ assert prefix != null !prefix.contains(getDelimiter());
this.prefix = prefix;
this.token = token;
}
@Override
public String toString() {
- return (prefix.length() == 0) ? token : prefix + : + token;
+ return (prefix.length() == 0) ? token : prefix + getDelimiter() +
token;
}
}
protected F factory;
public Place getPlace(String token) {
-int colonAt = token.indexOf(':');
+int colonAt = token.indexOf(getDelimiter());
String initial;
String rest;
if (colonAt = 0) {
initial = token.substring(0, colonAt);
- rest = token.substring(colonAt + 1);
+ rest = token.substring(colonAt + getDelimiter().length());
} else {
initial = ;
rest = token;
@@ -79,6 +79,8 @@
this.factory = factory;
}
+ protected abstract String getDelimiter();
+
/**
* @param newPlace what needs tokenizing
* @return the token, or null
Index: place/rebind/PlaceHistoryGeneratorContext.java
===
--- place/rebind/PlaceHistoryGeneratorContext.java (revision 10971)
+++ place/rebind/PlaceHistoryGeneratorContext.java (working copy)
@@ -25,6 +25,7 @@
import com.google.gwt.place.shared.PlaceHistoryMapperWithFactory;
import com.google.gwt.place.shared.PlaceTokenizer;
import com.google.gwt.place.shared.Prefix;
+import com.google.gwt.place.shared.WithDelimiter;
import com.google.gwt.place.shared.WithTokenizers;
import java.util.ArrayList;
@@ -76,9 +77,11 @@
String implName = interfaceType.getName().replace(., _) + Impl;
+String delimiter = addDelimiter(interfaceType);
+
return new PlaceHistoryGeneratorContext(logger, typeOracle,
interfaceType,
factoryType, stringType, placeTokenizerType,
-interfaceType.getPackage().getName(), implName);
+interfaceType.getPackage().getName(), implName, delimiter);
}
private static JClassType findFactoryType(
@@ -118,6 +121,8 @@
final String packageName;
+ final String delimiter;
+
/**
* All tokenizers, either as a {@link JMethod} for factory getters or as
a
* {@link JClassType} for types that must be GWT.create()d, by prefix.
@@ -134,7 +139,7 @@
PlaceHistoryGeneratorContext(TreeLogger logger, TypeOracle typeOracle,
JClassType interfaceType, JClassType factoryType, JClassType
stringType,
- JClassType placeTokenizerType, String packageName, String implName) {
+ JClassType placeTokenizerType, String packageName, String implName,
String delimiter) {
this.logger = logger;
this.typeOracle = typeOracle;
this.interfaceType = interfaceType;
@@ -143,6 +148,7 @@
this.placeTokenizerType = placeTokenizerType;
this.packageName = packageName;
this.implName = implName;
+this.delimiter = delimiter;
}
public SetJClassType getPlaceTypes() throws UnableToCompleteException {
@@ -190,6 +196,15 @@
}
}
+ private static String addDelimiter(JClassType interfaceType) {
+
+WithDelimiter annotation =
interfaceType.getAnnotation(WithDelimiter.class);
+if (annotation == null) {
+ return :;
+}
+return annotation.value();
+ }
+
private void addPlaceTokenizer(Object tokenizerClassOrGetter, String
prefix,
JClassType tokenizerType) throws UnableToCompleteException {
if (prefix.contains(:)) {
@@ -220,6 +235,10 @@
placeTypes.put(placeType, prefix);
}
+ public String getDelimiter() {
+return delimiter;
+ }
+
private String getLogMessage(Object methodOrClass) {
if (methodOrClass instanceof JMethod) {
JMethod method = (JMethod) methodOrClass;
@@ -343,4 +362,4 @@
}
return rtn;
}