Add a LocaleInfo object which priovides access to various information about
the current locale and the set of available locales. Also included are
handwritten implementations of CLDR data which currently only provide isRTL(),
but can later be expanded to provide access to most data provided in CLDR.
Patch by: jat
Review by: scottb, bbavar, shanjian, bjung, rdayal
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1732 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/core/ext/PropertyOracle.java b/dev/core/src/com/google/gwt/core/ext/PropertyOracle.java
index 35dda73..8f07ad4 100644
--- a/dev/core/src/com/google/gwt/core/ext/PropertyOracle.java
+++ b/dev/core/src/com/google/gwt/core/ext/PropertyOracle.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006 Google Inc.
+ * Copyright 2008 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
@@ -31,4 +31,16 @@
*/
String getPropertyValue(TreeLogger logger, String propertyName)
throws BadPropertyValueException;
+
+ /**
+ * Attempts to get a named deferred binding property and returns the list of
+ * possible values. Throws <code>BadPropertyValueException</code> if the
+ * property is undefined.
+ *
+ * @param logger the current logger
+ * @param propertyName the name of the property
+ * @return the possible values for the property
+ */
+ String[] getPropertyValueSet(TreeLogger logger, String propertyName)
+ throws BadPropertyValueException;
}
diff --git a/dev/core/src/com/google/gwt/dev/cfg/StaticPropertyOracle.java b/dev/core/src/com/google/gwt/dev/cfg/StaticPropertyOracle.java
index c34b1de..6e760e4 100644
--- a/dev/core/src/com/google/gwt/dev/cfg/StaticPropertyOracle.java
+++ b/dev/core/src/com/google/gwt/dev/cfg/StaticPropertyOracle.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2006 Google Inc.
+ * Copyright 2008 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
@@ -56,6 +56,20 @@
throw new BadPropertyValueException(propertyName);
}
+ public String[] getPropertyValueSet(TreeLogger logger, String propertyName)
+ throws BadPropertyValueException {
+ for (int i = 0; i < currentProps.length; i++) {
+ Property prop = currentProps[i];
+ if (prop.getName().equals(propertyName)) {
+ return prop.getKnownValues();
+ }
+ }
+
+ // Didn't find it.
+ //
+ throw new BadPropertyValueException(propertyName);
+ }
+
public void setPropertyValues(Property[] props, String[] values) {
currentProps = props;
currentValues = values;
diff --git a/dev/core/src/com/google/gwt/dev/shell/ModuleSpacePropertyOracle.java b/dev/core/src/com/google/gwt/dev/shell/ModuleSpacePropertyOracle.java
index 91003b4..940bf9e 100644
--- a/dev/core/src/com/google/gwt/dev/shell/ModuleSpacePropertyOracle.java
+++ b/dev/core/src/com/google/gwt/dev/shell/ModuleSpacePropertyOracle.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2007 Google Inc.
+ * Copyright 2008 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
@@ -46,16 +46,7 @@
*/
public String getPropertyValue(TreeLogger logger, String propertyName)
throws BadPropertyValueException {
- if (propertyName == null) {
- throw new NullPointerException("propertyName");
- }
-
- Property prop = props.find(propertyName);
- if (prop == null) {
- // Don't know this property; that's not good.
- //
- throw new BadPropertyValueException(propertyName);
- }
+ Property prop = getProperty(propertyName);
// Check if this property has already been queried for; if so, return
// the same answer. This is necessary to match web mode behavior since
@@ -72,6 +63,15 @@
}
/**
+ * Returns the list of possible values for a property.
+ */
+ public String[] getPropertyValueSet(TreeLogger logger, String propertyName)
+ throws BadPropertyValueException {
+ Property prop = getProperty(propertyName);
+ return prop.getKnownValues();
+ }
+
+ /**
* Returns the value of the specified property.
*
* @throws BadPropertyValueException if the property value could not be
@@ -114,4 +114,24 @@
throw new BadPropertyValueException(propertyName, value);
}
}
+
+ /**
+ * Returns a Property given its name, handling error conditions.
+ *
+ * @throws BadPropertyValueException
+ */
+ private Property getProperty(String propertyName)
+ throws BadPropertyValueException {
+ if (propertyName == null) {
+ throw new NullPointerException("propertyName");
+ }
+
+ Property prop = props.find(propertyName);
+ if (prop == null) {
+ // Don't know this property; that's not good.
+ //
+ throw new BadPropertyValueException(propertyName);
+ }
+ return prop;
+ }
}
diff --git a/dev/core/test/com/google/gwt/dev/shell/StandardGeneratorContextTest.java b/dev/core/test/com/google/gwt/dev/shell/StandardGeneratorContextTest.java
index e3ee325..bbfa58b 100644
--- a/dev/core/test/com/google/gwt/dev/shell/StandardGeneratorContextTest.java
+++ b/dev/core/test/com/google/gwt/dev/shell/StandardGeneratorContextTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2007 Google Inc.
+ * Copyright 2008 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
@@ -50,6 +50,11 @@
throws BadPropertyValueException {
return "";
}
+
+ public String[] getPropertyValueSet(TreeLogger logger, String propertyName)
+ throws BadPropertyValueException {
+ return new String[] {};
+ }
}
private static class MockPublicOracle implements PublicOracle {
@@ -289,6 +294,7 @@
mockCacheManager.invalidateVolatileFiles();
}
+ @Override
protected void tearDown() throws Exception {
for (int i = toDelete.size() - 1; i >= 0; --i) {
File f = toDelete.get(i);
diff --git a/user/src/com/google/gwt/i18n/I18N.gwt.xml b/user/src/com/google/gwt/i18n/I18N.gwt.xml
index f07c9da..dc968f1 100644
--- a/user/src/com/google/gwt/i18n/I18N.gwt.xml
+++ b/user/src/com/google/gwt/i18n/I18N.gwt.xml
@@ -1,5 +1,5 @@
<!-- -->
-<!-- Copyright 2007 Google Inc. -->
+<!-- Copyright 2008 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 -->
<!-- may obtain a copy of the License at -->
@@ -69,4 +69,7 @@
<generate-with class="com.google.gwt.i18n.rebind.LocalizableGenerator">
<when-type-assignable class="com.google.gwt.i18n.client.Localizable" />
</generate-with>
+ <generate-with class="com.google.gwt.i18n.rebind.LocaleInfoGenerator">
+ <when-type-is class="com.google.gwt.i18n.client.impl.LocaleInfoImpl" />
+ </generate-with>
</module>
diff --git a/user/src/com/google/gwt/i18n/client/LocaleInfo.java b/user/src/com/google/gwt/i18n/client/LocaleInfo.java
new file mode 100644
index 0000000..f60140c
--- /dev/null
+++ b/user/src/com/google/gwt/i18n/client/LocaleInfo.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright 2008 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.i18n.client;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.i18n.client.impl.CldrImpl;
+import com.google.gwt.i18n.client.impl.LocaleInfoImpl;
+
+/**
+ * Provides access to the currently-running locale and the list of available
+ * locales.
+ */
+public class LocaleInfo {
+
+ /**
+ * Currently we only support getting the currently running locale, so this
+ * is a static. In the future, we would need a hash map from locale names
+ * to LocaleInfo instances.
+ */
+ private static LocaleInfo instance = new LocaleInfo(
+ (LocaleInfoImpl) GWT.create(LocaleInfoImpl.class),
+ (CldrImpl) GWT.create(CldrImpl.class));
+
+ /**
+ * @return an array of available locales
+ */
+ public static String[] getAvailableLocaleNames() {
+ /*
+ * The set of all locales is constant across all permutations, so this
+ * is static. Ideally, the set of available locales would be generated
+ * by a different GWT.create but that would slow the compilation process
+ * unnecessarily.
+ *
+ * This is static, and accesses infoImpl this way, with an eye towards
+ * when we implement static LocaleInfo getLocale(String localeName) as
+ * you might want to get the list of available locales in order to create
+ * instances of each of them.
+ */
+ return instance.infoImpl.getAvailableLocaleNames();
+ }
+
+ /**
+ * @return a LocaleInfo instance for the current locale.
+ *
+ * In the future, we could make additional static methods which returned
+ * a LocaleInfo instance for a specific locale (from the set of those
+ * the app was compiled with), accessed via a method like:
+ * <pre>
+ * public static LocaleInfo getLocale(String localeName)
+ * </pre>
+ */
+ public static LocaleInfo getCurrentLocale() {
+ return instance;
+ }
+
+ private final LocaleInfoImpl infoImpl;
+
+ private final CldrImpl cldrImpl;
+
+ /**
+ * Constructor to be used by subclasses, such as mock classes for testing.
+ * Any such subclass should override all methods.
+ */
+ protected LocaleInfo() {
+ infoImpl = null;
+ cldrImpl = null;
+ }
+
+ /**
+ * Create a LocaleInfo instance, passing in the implementation classes.
+ *
+ * @param impl LocaleInfoImpl instance to use
+ * @param cldr CldrImpl instance to use
+ */
+ private LocaleInfo(LocaleInfoImpl impl, CldrImpl cldr) {
+ this.infoImpl = impl;
+ this.cldrImpl = cldr;
+ }
+
+ /**
+ * @return the name of this locale, such as "default, "en_US", etc.
+ */
+ public String getLocaleName() {
+ return infoImpl.getLocaleName();
+ }
+
+ /**
+ * @return true if this locale is right-to-left instead of left-to-right.
+ */
+ public boolean isRTL() {
+ return cldrImpl.isRTL();
+ }
+}
diff --git a/user/src/com/google/gwt/i18n/client/cldr/CldrImpl_ar.java b/user/src/com/google/gwt/i18n/client/cldr/CldrImpl_ar.java
new file mode 100644
index 0000000..ef36dd6
--- /dev/null
+++ b/user/src/com/google/gwt/i18n/client/cldr/CldrImpl_ar.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2008 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.i18n.client.cldr;
+
+import com.google.gwt.i18n.client.impl.CldrImpl;
+
+/**
+ * Placeholder for generated file.
+ */
+public class CldrImpl_ar extends CldrImpl {
+
+ public boolean isRTL() {
+ return true;
+ }
+}
diff --git a/user/src/com/google/gwt/i18n/client/cldr/CldrImpl_fa.java b/user/src/com/google/gwt/i18n/client/cldr/CldrImpl_fa.java
new file mode 100644
index 0000000..a370fb6
--- /dev/null
+++ b/user/src/com/google/gwt/i18n/client/cldr/CldrImpl_fa.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2008 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.i18n.client.cldr;
+
+import com.google.gwt.i18n.client.impl.CldrImpl;
+
+/**
+ * Placeholder for generated file.
+ */
+public class CldrImpl_fa extends CldrImpl {
+
+ public boolean isRTL() {
+ return true;
+ }
+}
diff --git a/user/src/com/google/gwt/i18n/client/cldr/CldrImpl_he.java b/user/src/com/google/gwt/i18n/client/cldr/CldrImpl_he.java
new file mode 100644
index 0000000..eaca740
--- /dev/null
+++ b/user/src/com/google/gwt/i18n/client/cldr/CldrImpl_he.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2008 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.i18n.client.cldr;
+
+import com.google.gwt.i18n.client.impl.CldrImpl;
+
+/**
+ * Placeholder for generated file.
+ */
+public class CldrImpl_he extends CldrImpl {
+
+ public boolean isRTL() {
+ return true;
+ }
+}
diff --git a/user/src/com/google/gwt/i18n/client/cldr/CldrImpl_ps.java b/user/src/com/google/gwt/i18n/client/cldr/CldrImpl_ps.java
new file mode 100644
index 0000000..3c2953d
--- /dev/null
+++ b/user/src/com/google/gwt/i18n/client/cldr/CldrImpl_ps.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2008 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.i18n.client.cldr;
+
+import com.google.gwt.i18n.client.impl.CldrImpl;
+
+/**
+ * Placeholder for generated file.
+ */
+public class CldrImpl_ps extends CldrImpl {
+
+ public boolean isRTL() {
+ return true;
+ }
+}
diff --git a/user/src/com/google/gwt/i18n/client/cldr/CldrImpl_ur.java b/user/src/com/google/gwt/i18n/client/cldr/CldrImpl_ur.java
new file mode 100644
index 0000000..e050454
--- /dev/null
+++ b/user/src/com/google/gwt/i18n/client/cldr/CldrImpl_ur.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2008 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.i18n.client.cldr;
+
+import com.google.gwt.i18n.client.impl.CldrImpl;
+
+/**
+ * Placeholder for generated file.
+ */
+public class CldrImpl_ur extends CldrImpl {
+
+ public boolean isRTL() {
+ return true;
+ }
+}
diff --git a/user/src/com/google/gwt/i18n/client/impl/CldrImpl.java b/user/src/com/google/gwt/i18n/client/impl/CldrImpl.java
new file mode 100644
index 0000000..c30a088
--- /dev/null
+++ b/user/src/com/google/gwt/i18n/client/impl/CldrImpl.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2008 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.i18n.client.impl;
+
+import com.google.gwt.i18n.client.Localizable;
+
+/**
+ * Implementation detail of LocaleInfo -- not a public API and subject to
+ * change.
+ *
+ * Locale data from CLDR.
+ *
+ * Subclasses of this are currently hand-written, but will eventually be
+ * generated directly from the CLDR data and make available most of the
+ * information present in CLDR.
+ */
+public class CldrImpl implements Localizable {
+ /*
+ * This class is separate from LocaleInfoImpl because it will be generated
+ * from CLDR data rather than at compile time by a generator.
+ */
+
+ /**
+ * @return true if the current locale is right-to-left rather than
+ * left-to-right.
+ *
+ * Most languages are left-to-right, so the default is false.
+ */
+ public boolean isRTL() {
+ return false;
+ }
+}
diff --git a/user/src/com/google/gwt/i18n/client/impl/LocaleInfoImpl.java b/user/src/com/google/gwt/i18n/client/impl/LocaleInfoImpl.java
new file mode 100644
index 0000000..6520bdd
--- /dev/null
+++ b/user/src/com/google/gwt/i18n/client/impl/LocaleInfoImpl.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2008 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.i18n.client.impl;
+
+/**
+ * Implementation detail of LocaleInfo -- not a public API and subject to
+ * change.
+ *
+ * Generated interface for locale information.
+ *
+ * @see com.google.gwt.i18n.client.LocaleInfo
+ */
+public interface LocaleInfoImpl {
+
+ /**
+ * @return an array of available locale names
+ */
+ String[] getAvailableLocaleNames();
+
+ /**
+ * @return the current locale name, such as "default, "en_US", etc.
+ */
+ String getLocaleName();
+}
diff --git a/user/src/com/google/gwt/i18n/rebind/LocaleInfoGenerator.java b/user/src/com/google/gwt/i18n/rebind/LocaleInfoGenerator.java
new file mode 100644
index 0000000..7791659
--- /dev/null
+++ b/user/src/com/google/gwt/i18n/rebind/LocaleInfoGenerator.java
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2008 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.i18n.rebind;
+
+import com.google.gwt.core.ext.BadPropertyValueException;
+import com.google.gwt.core.ext.Generator;
+import com.google.gwt.core.ext.GeneratorContext;
+import com.google.gwt.core.ext.PropertyOracle;
+import com.google.gwt.core.ext.TreeLogger;
+import com.google.gwt.core.ext.UnableToCompleteException;
+import com.google.gwt.core.ext.typeinfo.JClassType;
+import com.google.gwt.core.ext.typeinfo.NotFoundException;
+import com.google.gwt.core.ext.typeinfo.TypeOracle;
+import com.google.gwt.i18n.client.impl.LocaleInfoImpl;
+import com.google.gwt.user.rebind.ClassSourceFileComposerFactory;
+import com.google.gwt.user.rebind.SourceWriter;
+
+import java.io.PrintWriter;
+
+/**
+ * Generator used to generate an implementation of the LocaleInfoImpl class,
+ * which is used by the LocaleInfo class.
+ */
+public class LocaleInfoGenerator extends Generator {
+
+ /**
+ * The token representing the locale property controlling Localization.
+ */
+ private static final String PROP_LOCALE = "locale";
+
+ /**
+ * Generate an implementation for the given type.
+ *
+ * @param logger error logger
+ * @param context generator context
+ * @param typeName target type name
+ * @return generated class name
+ * @throws UnableToCompleteException
+ */
+ @Override
+ public final String generate(TreeLogger logger, GeneratorContext context,
+ String typeName) throws UnableToCompleteException {
+ TypeOracle typeOracle = context.getTypeOracle();
+ // Get the current locale and interface type.
+ PropertyOracle propertyOracle = context.getPropertyOracle();
+ String locale;
+ try {
+ locale = propertyOracle.getPropertyValue(logger, PROP_LOCALE);
+ } catch (BadPropertyValueException e) {
+ logger.log(TreeLogger.ERROR, "Could not parse specified locale", e);
+ throw new UnableToCompleteException();
+ }
+
+ JClassType targetClass;
+ try {
+ targetClass = typeOracle.getType(typeName);
+ } catch (NotFoundException e) {
+ logger.log(TreeLogger.ERROR, "No such type", e);
+ throw new UnableToCompleteException();
+ }
+ assert (LocaleInfoImpl.class.getName().equals(targetClass.getQualifiedSourceName()));
+
+ String packageName = targetClass.getPackage().getName();
+ String className = targetClass.getName().replace('.', '_') + "_";
+ if (!locale.equals("default")) {
+ className += locale;
+ }
+
+ PrintWriter pw = context.tryCreate(logger, packageName, className);
+ if (pw != null) {
+ ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(
+ packageName, className);
+ factory.addImplementedInterface(targetClass.getQualifiedSourceName());
+ SourceWriter writer = factory.createSourceWriter(context, pw);
+ writer.println("private static final String[] availableLocales = new String[] {");
+ try {
+ for (String propval : propertyOracle.getPropertyValueSet(logger,
+ PROP_LOCALE)) {
+ writer.println(" \"" + propval.replaceAll("\"", "\\\"") + "\",");
+ }
+ } catch (BadPropertyValueException e) {
+ logger.log(TreeLogger.ERROR,
+ "No locale property defined -- did you inherit the I18N module?", e);
+ throw new UnableToCompleteException();
+ }
+ writer.println("};");
+ writer.println();
+ writer.println("public String getLocaleName() {");
+ writer.println(" return \"" + locale + "\";");
+ writer.println("}");
+ writer.println();
+ writer.println("public String[] getAvailableLocaleNames() {");
+ writer.println(" return availableLocales;");
+ writer.println("}");
+ writer.commit(logger);
+ }
+ return packageName + "." + className;
+ }
+}
diff --git a/user/test/com/google/gwt/i18n/I18NTest_ar.gwt.xml b/user/test/com/google/gwt/i18n/I18NTest_ar.gwt.xml
new file mode 100644
index 0000000..e00f9d8
--- /dev/null
+++ b/user/test/com/google/gwt/i18n/I18NTest_ar.gwt.xml
@@ -0,0 +1,23 @@
+<!-- -->
+<!-- Copyright 2008 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 -->
+<!-- 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. License for the specific language governing permissions and -->
+<!-- limitations under the License. -->
+
+<module>
+ <!-- Inherit the JUnit support -->
+ <inherits name='com.google.gwt.junit.JUnit'/>
+ <inherits name = 'com.google.gwt.i18n.I18N'/>
+ <!-- Include client-side source for the test cases -->
+ <source path="client"/>
+ <extend-property name="locale" values="ar"/>
+ <set-property name = "locale" value = "ar"/>
+</module>
diff --git a/user/test/com/google/gwt/i18n/client/LocaleInfoTest.java b/user/test/com/google/gwt/i18n/client/LocaleInfoTest.java
new file mode 100644
index 0000000..443df93
--- /dev/null
+++ b/user/test/com/google/gwt/i18n/client/LocaleInfoTest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2008 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.i18n.client;
+
+import com.google.gwt.junit.client.GWTTestCase;
+
+/**
+ * Tests the LocaleInfo class and the associated generator.
+ */
+public class LocaleInfoTest extends GWTTestCase {
+
+ public String getModuleName() {
+ return "com.google.gwt.i18n.I18NTest";
+ }
+
+ public void testCurrentLocale() {
+ String locale = LocaleInfo.getCurrentLocale().getLocaleName();
+ assertEquals("piglatin_UK_win", locale);
+ }
+
+ public void testAvailableLocales() {
+ String[] locales = LocaleInfo.getAvailableLocaleNames();
+ assertArrayEquals(new String[] {
+ "default", "piglatin", "piglatin_UK", "piglatin_UK_win"}, locales);
+ }
+
+ public void testRTL() {
+ boolean isRTL = LocaleInfo.getCurrentLocale().isRTL();
+ assertFalse(isRTL);
+ }
+
+ private void assertArrayEquals(String[] expected, String[] actual) {
+ assertEquals(expected.length, actual.length);
+ for (int i = 0; i < actual.length; i++) {
+ assertEquals(expected[i], actual[i]);
+ }
+ }
+}
diff --git a/user/test/com/google/gwt/i18n/client/LocaleInfo_ar_Test.java b/user/test/com/google/gwt/i18n/client/LocaleInfo_ar_Test.java
new file mode 100644
index 0000000..d2df01a
--- /dev/null
+++ b/user/test/com/google/gwt/i18n/client/LocaleInfo_ar_Test.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2008 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.i18n.client;
+
+import com.google.gwt.junit.client.GWTTestCase;
+
+/**
+ * Tests the LocaleInfo class and the associated generator.
+ */
+public class LocaleInfo_ar_Test extends GWTTestCase {
+
+ public String getModuleName() {
+ return "com.google.gwt.i18n.I18NTest_ar";
+ }
+
+ public void testCurrentLocale() {
+ String locale = LocaleInfo.getCurrentLocale().getLocaleName();
+ assertEquals("ar", locale);
+ }
+
+ public void testAvailableLocales() {
+ String[] locales = LocaleInfo.getAvailableLocaleNames();
+ assertArrayEquals(new String[] {"ar", "default"}, locales);
+ }
+
+ public void testRTL() {
+ boolean isRTL = LocaleInfo.getCurrentLocale().isRTL();
+ assertTrue(isRTL);
+ }
+
+ private void assertArrayEquals(String[] expected, String[] actual) {
+ assertEquals(expected.length, actual.length);
+ for (int i = 0; i < actual.length; i++) {
+ assertEquals(expected[i], actual[i]);
+ }
+ }
+}
diff --git a/user/test/com/google/gwt/user/rebind/rpc/SerializableTypeOracleBuilderTest.java b/user/test/com/google/gwt/user/rebind/rpc/SerializableTypeOracleBuilderTest.java
index 97b1bbf..7d6ba5c 100644
--- a/user/test/com/google/gwt/user/rebind/rpc/SerializableTypeOracleBuilderTest.java
+++ b/user/test/com/google/gwt/user/rebind/rpc/SerializableTypeOracleBuilderTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2007 Google Inc.
+ * Copyright 2008 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
@@ -82,6 +82,10 @@
// Could mock "gwt.enforceRPCTypeVersioning" etc here
return "";
}
+
+ public String[] getPropertyValueSet(TreeLogger logger, String propertyName) {
+ return new String[] {};
+ }
}
/**
@@ -112,15 +116,12 @@
}
private static void sort(TypeInfo[] typeInfos) {
- Arrays.sort(typeInfos, new Comparator() {
- public int compare(Object o1, Object o2) {
- if (o1 == o2) {
+ Arrays.sort(typeInfos, new Comparator<TypeInfo>() {
+ public int compare(TypeInfo ti1, TypeInfo ti2) {
+ if (ti1 == ti2) {
return 0;
}
- TypeInfo ti1 = (TypeInfo) o1;
- TypeInfo ti2 = (TypeInfo) o2;
-
return ti1.sourceName.compareTo(ti2.sourceName);
}
});