| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Google Web Toolkit
Revision: 3593
Author: scottb@google.com
Date: 28 Aug 2008 20:03:51
Changes:Merging releases/1.5 into trunk
svn merge -r3556:3587 https://google-web-toolkit.googlecode.com/svn/releases/1.5 .
Files:| ... | ...@@ -63,7 +63,7 @@ | |
| 63 | 63 | assertEquals("testClass", cssClass); |
| 64 | 64 | DOM.removeElementAttribute(div, "class"); |
| 65 | 65 | cssClass = DOM.getElementAttribute(div, "class"); |
| 66 | assertNull(cssClass); | |
| 66 | assertEquals("", cssClass); | |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
| ... | ...@@ -1,5 +1,5 @@ | |
| 1 | 1 | /* |
| 2 | * Copyright 2007 Google Inc. | |
| 2 | * Copyright 2008 Google Inc. | |
| 3 | 3 | * |
| 4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | 5 | * use this file except in compliance with the License. You may obtain a copy of |
| ... | ...@@ -25,7 +25,7 @@ | |
| 25 | 25 | * junit tests due to it's code generation. |
| 26 | 26 | */ |
| 27 | 27 | public class I18NSyncTest_ extends TestCase { |
| 28 | static final File CLIENT_SOURCE_DIR = new File("../../gwt-user/src/test/java"); | |
| 28 | static final File CLIENT_SOURCE_DIR = new File("../../user/test"); | |
| 29 | 29 | static final String CLIENT_SOURCE_PACKAGE = "com.google.gwt.i18n.client.gen."; |
| 30 | 30 | |
| 31 | 31 | /** |
| ... | ...@@ -10,7 +10,7 @@ | |
| 10 | 10 | <property.ensure name="gwt.dev.jar" location="${gwt.build.lib}/gwt-dev-linux.jar" /> |
| 11 | 11 | |
| 12 | 12 | <property name="USER_PKGS" |
| 13 | value="com.google.gwt.core.client;com.google.gwt.core.ext;com.google.gwt.core.ext.linker;com.google.gwt.core.ext.typeinfo;com.google.gwt.dom.client;com.google.gwt.i18n.client;com.google.gwt.i18n.rebind.format;com.google.gwt.i18n.rebind.keygen;com.google.gwt.json.client;com.google.gwt.junit.client;com.google.gwt.benchmarks.client;com.google.gwt.user.client;com.google.gwt.user.client.rpc;com.google.gwt.user.client.ui;com.google.gwt.user.server.rpc;com.google.gwt.xml.client;com.google.gwt.http.client" /> | |
| 13 | value="com.google.gwt.core.client;com.google.gwt.core.ext;com.google.gwt.core.ext.linker;com.google.gwt.core.ext.typeinfo;com.google.gwt.dom.client;com.google.gwt.i18n.client;com.google.gwt.i18n.rebind.format;com.google.gwt.i18n.rebind.keygen;com.google.gwt.json.client;com.google.gwt.junit.client;com.google.gwt.benchmarks.client;com.google.gwt.user.client;com.google.gwt.user.client.rpc;com.google.gwt.user.client.ui;com.google.gwt.user.server.rpc;com.google.gwt.xml.client;com.google.gwt.http.client;com.google.gwt.animation.client" /> | |
| 14 | 14 | <property name="LANG_PKGS" value="java.lang;java.lang.annotation;java.util;java.io;java.sql" /> |
| 15 | 15 | |
| 16 | 16 | <!-- Individual classes to include when we don't want to |
| ... | ...@@ -77,6 +77,7 @@ | |
| 77 | 77 | <echo>Building javadoc</echo> |
| 78 | 78 | <java classpathref="DOC_PATH" classname="com.google.doctool.custom.GWTJavaDoclet" fork="yes" failonerror="true"> |
| 79 | 79 | <arg value="-quiet" /> |
| 80 | <arg value="-notimestamp" /> | |
| 80 | 81 | <arg value="-source" /> |
| 81 | 82 | <arg value="1.5" /> |
| 82 | 83 | <arg value="-windowtitle" /> |
| ... | ...@@ -1,32 +0,0 @@ | |
| 1 | <!-- --> | |
| 2 | <!-- Copyright 2008 Google Inc. --> | |
| 3 | <!-- Licensed under the Apache License, Version 2.0 (the "License"); you --> | |
| 4 | <!-- may not use this file except in compliance with the License. You may --> | |
| 5 | <!-- may obtain a copy of the License at --> | |
| 6 | <!-- --> | |
| 7 | <!-- http://www.apache.org/licenses/LICENSE-2.0 --> | |
| 8 | <!-- --> | |
| 9 | <!-- Unless required by applicable law or agreed to in writing, software --> | |
| 10 | <!-- distributed under the License is distributed on an "AS IS" BASIS, --> | |
| 11 | <!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or --> | |
| 12 | <!-- implied. License for the specific language governing permissions and --> | |
| 13 | <!-- limitations under the License. --> | |
| 14 | ||
| 15 | <!-- Deferred binding rules for browser selection. --> | |
| 16 | <!-- --> | |
| 17 | <!-- This module is typically inherited via com.google.gwt.user.User --> | |
| 18 | <!-- --> | |
| 19 | <module> | |
| 20 | <inherits name="com.google.gwt.core.Core" /> | |
| 21 | <inherits name="com.google.gwt.user.UserAgent" /> | |
| 22 | ||
| 23 | <!-- Mozilla has a different implementation because of support for ARIA --> | |
| 24 | <replace-with | |
| 25 | class="com.google.gwt.user.client.ui.impl.AccessibilityImplMozilla"> | |
| 26 | <when-type-is | |
| 27 | class="com.google.gwt.user.client.ui.impl.AccessibilityImpl" /> | |
| 28 | <any> | |
| 29 | <when-property-is name="user.agent" value="gecko1_8" /> | |
| 30 | </any> | |
| 31 | </replace-with> | |
| 32 | </module> |
| ... | ...@@ -56,7 +56,7 @@ | |
| 56 | 56 | * does not have a specified or default value |
| 57 | 57 | */ |
| 58 | 58 | public final native String getAttribute(String name) /*-{ |
| 59 | return this.getAttribute(name); | |
| 59 | return this.getAttribute(name) || ''; | |
| 60 | 60 | }-*/; |
| 61 | 61 | |
| 62 | 62 | /** |
| ... | ...@@ -1,5 +1,5 @@ | |
| 1 | 1 | /* |
| 2 | * Copyright 2007 Google Inc. | |
| 2 | * Copyright 2008 Google Inc. | |
| 3 | 3 | * |
| 4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | 5 | * use this file except in compliance with the License. You may obtain a copy of |
| ... | ...@@ -18,7 +18,6 @@ | |
| 18 | 18 | import com.google.gwt.dev.util.Util; |
| 19 | 19 | import com.google.gwt.dev.util.log.PrintWriterTreeLogger; |
| 20 | 20 | import com.google.gwt.i18n.client.Localizable; |
| 21 | import com.google.gwt.i18n.tools.I18NSync; | |
| 22 | 21 | import com.google.gwt.user.rebind.ClassSourceFileComposerFactory; |
| 23 | 22 | import com.google.gwt.user.rebind.SourceWriter; |
| 24 | 23 | |
| ... | ...@@ -134,7 +133,7 @@ | |
| 134 | 133 | * @param defaultValue default value |
| 135 | 134 | */ |
| 136 | 135 | public void genSimpleMethodDecl(String key, String defaultValue) { |
| 137 | genMethodDecl("String", defaultValue, key, key); | |
| 136 | genMethodDecl("String", defaultValue, key); | |
| 138 | 137 | } |
| 139 | 138 | |
| 140 | 139 | /** |
| ... | ...@@ -145,6 +144,11 @@ | |
| 145 | 144 | protected abstract void genMethodArgs(String defaultValue); |
| 146 | 145 | |
| 147 | 146 | /** |
| 147 | * Create an annotation to hold the default value. | |
| 148 | */ | |
| 149 | protected abstract void genValueAnnotation(String defaultValue); | |
| 150 | ||
| 151 | /** | |
| 148 | 152 | * Returns the javaDocComment for the class. |
| 149 | 153 | * |
| 150 | 154 | * @param path path of class |
| ... | ...@@ -187,20 +191,20 @@ | |
| 187 | 191 | key = formatter.format(key); |
| 188 | 192 | } |
| 189 | 193 | if (Util.isValidJavaIdent(key) == false) { |
| 190 | System.err.println("Warning: " + key | |
| 191 | + " is not a legitimate method name. " + sourceFile | |
| 192 | + " will have compiler errors"); | |
| 194 | // TODO(jat): we could synthesize legal method names and add an | |
| 195 | // @Key annotation to keep the matching key name. | |
| 196 | throw new IllegalArgumentException(key | |
| 197 | + " is not a legitimate method name."); | |
| 193 | 198 | } |
| 194 | 199 | return key; |
| 195 | 200 | } |
| 196 | 201 | |
| 197 | private void genMethodDecl(String type, String defaultValue, String key, | |
| 198 | String typeArg) { | |
| 202 | private void genMethodDecl(String type, String defaultValue, String key) { | |
| 199 | 203 | composer.beginJavaDocComment(); |
| 200 | 204 | composer.println("Translated \"" + defaultValue + "\".\n"); |
| 201 | 205 | composer.println("@return translated \"" + defaultValue + "\""); |
| 202 | composer.print(I18NSync.ID + typeArg); | |
| 203 | 206 | composer.endJavaDocComment(); |
| 207 | genValueAnnotation(defaultValue); | |
| 204 | 208 | key = formatKey(key); |
| 205 | 209 | composer.print(type + " " + key); |
| 206 | 210 | composer.print("("); |
| ... | ...@@ -214,6 +218,7 @@ | |
| 214 | 218 | ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory( |
| 215 | 219 | packageName, className); |
| 216 | 220 | factory.makeInterface(); |
| 221 | // TODO(jat): need a way to add an @GeneratedFrom annotation. | |
| 217 | 222 | factory.setJavaDocCommentForClass(javaDocComment(resourceBundle.getCanonicalPath().replace( |
| 218 | 223 | File.separatorChar, '/'))); |
| 219 | 224 | factory.addImplementedInterface(interfaceClass.getName()); |
| ... | ...@@ -1,5 +1,5 @@ | |
| 1 | 1 | /* |
| 2 | * Copyright 2007 Google Inc. | |
| 2 | * Copyright 2008 Google Inc. | |
| 3 | 3 | * |
| 4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | 5 | * use this file except in compliance with the License. You may obtain a copy of |
| ... | ...@@ -16,11 +16,14 @@ | |
| 16 | 16 | package com.google.gwt.i18n.rebind; |
| 17 | 17 | |
| 18 | 18 | import com.google.gwt.i18n.client.Messages; |
| 19 | import com.google.gwt.i18n.rebind.MessageFormatParser.ArgumentChunk; | |
| 20 | import com.google.gwt.i18n.rebind.MessageFormatParser.TemplateChunk; | |
| 19 | 21 | |
| 20 | 22 | import java.io.File; |
| 21 | 23 | import java.io.IOException; |
| 22 | import java.text.MessageFormat; | |
| 23 | 24 | import java.text.ParseException; |
| 25 | import java.util.HashSet; | |
| 26 | import java.util.Set; | |
| 24 | 27 | |
| 25 | 28 | /** |
| 26 | 29 | * Creates a MessagesInterface from a Resource file. |
| ... | ...@@ -29,34 +32,22 @@ | |
| 29 | 32 | AbstractLocalizableInterfaceCreator { |
| 30 | 33 | |
| 31 | 34 | /** |
| 32 | * Calculates the number of arguments <code>MessageFormat</code> expects to | |
| 33 | * see in a template. | |
| 35 | * Searches for MessageFormat-style args in the template string and returns | |
| 36 | * a set of argument indices seen. | |
| 34 | 37 | * |
| 35 | 38 | * @param template template to parse |
| 36 | * @return number of args | |
| 37 | * @throws ParseException | |
| 39 | * @return set of argument indices seen | |
| 40 | * @throws ParseException if the template is incorrect. | |
| 38 | 41 | */ |
| 39 | public static int numberOfMessageArgs(String template) throws ParseException { | |
| 40 | /* | |
| 41 | * As parse, unlike format, cannot deal with single quotes, we have to remove | |
| 42 | * them. First, we remove doubled quotes (which go into the output as single | |
| 43 | * quotes. Then, we remove any quoted strings. | |
| 44 | * | |
| 45 | * If sub-formats are supported in the future, this code will | |
| 46 | * have to change. | |
| 47 | */ | |
| 48 | // strip doubled single-quotes | |
| 49 | template = template.replace("''", ""); | |
| 50 | ||
| 51 | // delete quoted sections | |
| 52 | template = template.replaceAll("'[^']+'", ""); | |
| 53 | ||
| 54 | if (template.length() == 0) { | |
| 55 | // special case empty strings since MessageFormat.parse chokes on them. | |
| 56 | return 0; | |
| 42 | private static Set<Integer> numberOfMessageArgs(String template) | |
| 43 | throws ParseException { | |
| 44 | Set<Integer> seenArgs = new HashSet<Integer>(); | |
| 45 | for (TemplateChunk chunk : MessageFormatParser.parse(template)) { | |
| 46 | if (chunk instanceof ArgumentChunk) { | |
| 47 | seenArgs.add(((ArgumentChunk) chunk).getArgumentNumber()); | |
| 48 | } | |
| 57 | 49 | } |
| 58 | int numArgs = new MessageFormat(template).parse(template).length; | |
| 59 | return numArgs; | |
| 50 | return seenArgs; | |
| 60 | 51 | } |
| 61 | 52 | |
| 62 | 53 | /** |
| ... | ...@@ -77,11 +68,20 @@ | |
| 77 | 68 | @Override |
| 78 | 69 | protected void genMethodArgs(String defaultValue) { |
| 79 | 70 | try { |
| 80 | int numArgs = numberOfMessageArgs(defaultValue); | |
| 81 | for (int i = 0; i < numArgs; i++) { | |
| 71 | Set<Integer> seenArgs = numberOfMessageArgs(defaultValue); | |
| 72 | int maxArgSeen = -1; | |
| 73 | for (int arg : seenArgs) { | |
| 74 | if (arg > maxArgSeen) { | |
| 75 | maxArgSeen = arg; | |
| 76 | } | |
| 77 | } | |
| 78 | for (int i = 0; i <= maxArgSeen; i++) { | |
| 82 | 79 | if (i > 0) { |
| 83 | 80 | composer.print(", "); |
| 84 | 81 | } |
| 82 | if (!seenArgs.contains(i)) { | |
| 83 | composer.print("@Optional "); | |
| 84 | } | |
| 85 | 85 | composer.print("String arg" + i); |
| 86 | 86 | } |
| 87 | 87 | } catch (ParseException e) { |
| ... | ...@@ -91,8 +91,14 @@ | |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | @Override |
| 94 | protected void genValueAnnotation(String defaultValue) { | |
| 95 | composer.println("@DefaultMessage(\"" + defaultValue.replace("\"", "\\\"") | |
| 96 | + "\")"); | |
| 97 | } | |
| 98 | ||
| 99 | @Override | |
| 94 | 100 | protected String javaDocComment(String path) { |
| 95 | return "Interface to represent the messages contained in resource bundle:\n\t" | |
| 101 | return "Interface to represent the messages contained in resource bundle:\n\t" | |
| 96 | 102 | + path + "'."; |
| 97 | 103 | } |
| 98 | 104 | } |
| ... | ...@@ -0,0 +1,255 @@ | |
| 1 | /* | |
| 2 | * Copyright 2008 Google Inc. | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not | |
| 5 | * use this file except in compliance with the License. You may obtain a copy of | |
| 6 | * the License at | |
| 7 | * | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | |
| 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | |
| 13 | * License for the specific language governing permissions and limitations under | |
| 14 | * the License. | |
| 15 | */ | |
| 16 | package com.google.gwt.i18n.rebind; | |
| 17 | ||
| 18 | import java.text.ParseException; | |
| 19 | import java.util.ArrayList; | |
| 20 | import java.util.List; | |
| 21 | import java.util.regex.Matcher; | |
| 22 | import java.util.regex.Pattern; | |
| 23 | ||
| 24 | /** | |
| 25 | * Helper class for parsing MessageFormat-style format strings. | |
| 26 | */ | |
| 27 | public class MessageFormatParser { | |
| 28 | ||
| 29 | /** | |
| 30 | * Represents an argument in a template string. | |
| 31 | */ | |
| 32 | public static class ArgumentChunk extends TemplateChunk { | |
| 33 | ||
| 34 | private int argNumber; | |
| 35 | private String format; | |
| 36 | private String subFormat; | |
| 37 | ||
| 38 | public ArgumentChunk(int argNumber, String format, String subformat) { | |
| 39 | this.argNumber = argNumber; | |
| 40 | this.format = format; | |
| 41 | this.subFormat = subformat; | |
| 42 | } | |
| 43 | ||
| 44 | public int getArgumentNumber() { | |
| 45 | return argNumber; | |
| 46 | } | |
| 47 | ||
| 48 | public String getFormat() { | |
| 49 | return format; | |
| 50 | } | |
| 51 | ||
| 52 | @Override | |
| 53 | public String getString() { | |
| 54 | StringBuilder buf = new StringBuilder(); | |
| 55 | buf.append('{'); | |
| 56 | buf.append(argNumber); | |
| 57 | if (format != null || subFormat != null) { | |
| 58 | buf.append(','); | |
| 59 | } | |
| 60 | if (format != null) { | |
| 61 | buf.append(format); | |
| 62 | } | |
| 63 | if (subFormat != null) { | |
| 64 | buf.append(','); | |
| 65 | buf.append(subFormat); | |
| 66 | } | |
| 67 | buf.append('}'); | |
| 68 | return buf.toString(); | |
| 69 | } | |
| 70 | ||
| 71 | public String getSubFormat() { | |
| 72 | return subFormat; | |
| 73 | } | |
| 74 | ||
| 75 | @Override | |
| 76 | public String toString() { | |
| 77 | return "Argument: #=" + argNumber + ", format=" + format + ", subformat=" | |
| 78 | + subFormat; | |
| 79 | } | |
| 80 | } | |
| 81 | ||
| 82 | /** | |
| 83 | * Represents a literal string portion of a template string. | |
| 84 | */ | |
| 85 | public static class StringChunk extends TemplateChunk { | |
| 86 | ||
| 87 | private StringBuilder buf = new StringBuilder(); | |
| 88 | ||
| 89 | public StringChunk() { | |
| 90 | } | |
| 91 | ||
| 92 | public StringChunk(String str) { | |
| 93 | buf.append(str); | |
| 94 | } | |
| 95 | ||
| 96 | public void append(String str) { | |
| 97 | buf.append(str); | |
| 98 | } | |
| 99 | ||
| 100 | @Override | |
| 101 | public String getString() { | |
| 102 | return buf.toString(); | |
| 103 | } | |
| 104 | ||
| 105 | @Override | |
| 106 | public boolean isLiteral() { | |
| 107 | return true; | |
| 108 | } | |
| 109 | ||
| 110 | @Override | |
| 111 | public String toString() { | |
| 112 | return "StringLiteral: \"" + buf.toString() + "\""; | |
| 113 | } | |
| 114 | } | |
| 115 | ||
| 116 | /** | |
| 117 | * Represents a parsed chunk of a template. | |
| 118 | */ | |
| 119 | public static class TemplateChunk { | |
| 120 | ||
| 121 | /** | |
| 122 | * @return the string as this chunk would be represented in a MessageFormat | |
| 123 | * template. Note that this is distinct from toString in that the latter | |
| 124 | * is intend for human consumption. | |
| 125 | */ | |
| 126 | public String getString() { | |
| 127 | return toString(); | |
| 128 | } | |
| 129 | ||
| 130 | public boolean isLiteral() { | |
| 131 | return false; | |
| 132 | } | |
| 133 | } | |
| 134 | ||
| 135 | /** | |
| 136 | * Pattern to find MessageFormat argument references, including format and | |
| 137 | * subformat pieces, if present. | |
| 138 | */ | |
| 139 | private static final Pattern argPattern = Pattern.compile( | |
| 140 | "\\{(\\d+)(,(\\w+)(,([^\\}]+))?)?\\}"); | |
| 141 | ||
| 142 | /** | |
| 143 | * Generate a MessageFormat-style string representing the supplied components, | |
| 144 | * properly quoting any special characters in string literal portions. | |
| 145 | * | |
| 146 | * Note that additional quoting may be required depending on how it will be | |
| 147 | * used, such as backslash-escaping double quotes if it will be used in a | |
| 148 | * generated string constant. | |
| 149 | * | |
| 150 | * @param parts list of TemplateChunks to assemble | |
| 151 | * @return assembled/quoted string | |
| 152 | */ | |
| 153 | public static String assemble(Iterable<TemplateChunk> parts) { | |
| 154 | StringBuilder buf = new StringBuilder(); | |
| 155 | for (TemplateChunk part : parts) { | |
| 156 | String str = part.getString(); | |
| 157 | if (part.isLiteral()) { | |
| 158 | // quote MessageFormat special characters | |
| 159 | str = str.replace("'", "''"); | |
| 160 | str = str.replace("{", "'{'").replace("}", "'}'"); | |
| 161 | } | |
| 162 | buf.append(str); | |
| 163 | } | |
| 164 | return buf.toString(); | |
| 165 | } | |
| 166 | ||
| 167 | public static List<TemplateChunk> parse(String template) throws ParseException { | |
| 168 | Matcher match = argPattern.matcher(template); | |
| 169 | int curPos = 0; | |
| 170 | boolean inQuote = false; | |
| 171 | int templateLen = template.length(); | |
| 172 | ArrayList<TemplateChunk> chunks = new ArrayList<TemplateChunk>(); | |
| 173 | TemplateChunk curChunk = null; | |
| 174 | while (curPos < templateLen) { | |
| 175 | char ch = template.charAt(curPos++); | |
| 176 | switch (ch) { | |
| 177 | case '\'': | |
| 178 | if (curPos < templateLen && template.charAt(curPos) == '\'') { | |
| 179 | curChunk = appendString(chunks, curChunk, "'"); | |
| 180 | ++curPos; | |
| 181 | break; | |
| 182 | } | |
| 183 | inQuote = !inQuote; | |
| 184 | break; | |
| 185 | ||
| 186 | case '{': | |
| 187 | if (inQuote) { | |
| 188 | curChunk = appendString(chunks, curChunk, "{"); | |
| 189 | break; | |
| 190 | } | |
| 191 | if (match.find(curPos - 1) && match.start() == curPos - 1) { | |
| 192 | // match group 1 is the argument number (zero-based) | |
| 193 | // match group 3 is the format name or null if none | |
| 194 | // match group 5 is the subformat string or null if none | |
| 195 | int argNumber = Integer.valueOf(match.group(1)); | |
| 196 | curPos = match.end(); | |
| 197 | String format = match.group(3); | |
| 198 | String subformat = match.group(5); | |
| 199 | if (curChunk != null) { | |
| 200 | chunks.add(curChunk); | |
| 201 | } | |
| 202 | chunks.add(new ArgumentChunk(argNumber, format, subformat)); | |
| 203 | curChunk = null; | |
| 204 | } else { | |
| 205 | throw new ParseException( | |
| 206 | "Invalid message format - { not start of valid argument" | |
| 207 | + template, curPos); | |
| 208 | } | |
| 209 | break; | |
| 210 | ||
| 211 | case '\n': | |
| 212 | curChunk = appendString(chunks, curChunk, "\\n"); | |
| 213 | break; | |
| 214 | ||
| 215 | case '\r': | |
| 216 | curChunk = appendString(chunks, curChunk, "\\r"); | |
| 217 | break; | |
| 218 | ||
| 219 | case '\\': | |
| 220 | curChunk = appendString(chunks, curChunk, "\\\\"); | |
| 221 | break; | |
| 222 | ||
| 223 | case '"': | |
| 224 | curChunk = appendString(chunks, curChunk, "\\\""); | |
| 225 | break; | |
| 226 | ||
| 227 | default: | |
| 228 | curChunk = appendString(chunks, curChunk, String.valueOf(ch)); | |
| 229 | break; | |
| 230 | } | |
| 231 | } | |
| 232 | if (inQuote) { | |
| 233 | throw new ParseException("Unterminated single quote: " + template, | |
| 234 | template.length()); | |
| 235 | } | |
| 236 | if (curChunk != null) { | |
| 237 | chunks.add(curChunk); | |
| 238 | } | |
| 239 | return chunks; | |
| 240 | } | |
| 241 | ||
| 242 | private static TemplateChunk appendString(ArrayList<TemplateChunk> chunks, | |
| 243 | TemplateChunk curChunk, String string) { | |
| 244 | if (curChunk != null && !curChunk.isLiteral()) { | |
| 245 | chunks.add(curChunk); | |
| 246 | curChunk = null; | |
| 247 | } | |
| 248 | if (curChunk == null) { | |
| 249 | curChunk = new StringChunk(string); | |
| 250 | } else { | |
| 251 | ((StringChunk) curChunk).append(string); | |
| 252 | } | |
| 253 | return curChunk; | |
| 254 | } | |
| 255 | } |
| ... | ...@@ -1,5 +1,5 @@ | |
| 1 | 1 | /* |
| 2 | * Copyright 2007 Google Inc. | |
| 2 | * Copyright 2008 Google Inc. | |
| 3 | 3 | * |
| 4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | 5 | * use this file except in compliance with the License. You may obtain a copy of |
| ... | ...@@ -49,6 +49,12 @@ | |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | @Override |
| 52 | protected void genValueAnnotation(String defaultValue) { | |
| 53 | composer.println("@DefaultStringValue(\"" + defaultValue.replace("\"", "\\\"") | |
| 54 | + "\")"); | |
| 55 | } | |
| 56 | ||
| 57 | @Override | |
| 52 | 58 | protected String javaDocComment(String path) { |
| 53 | 59 | return "Interface to represent the constants contained in resource bundle:\n\t'" |
| 54 | 60 | + path + "'."; |
| ... | ...@@ -15,33 +15,33 @@ | |
| 15 | 15 | */ |
| 16 | 16 | package com.google.gwt.user.client.ui; |
| 17 | 17 | |
| 18 | import com.google.gwt.core.client.GWT; | |
| 19 | import com.google.gwt.user.client.ui.impl.AccessibilityImpl; | |
| 20 | 18 | import com.google.gwt.user.client.Element; |
| 21 | 19 | |
| 22 | 20 | /** |
| 23 | * Allows ARIA attributes to be added to widgets so that they can be | |
| 24 | * identified by assistive technologies. FireFox 3 is the only browser that | |
| 25 | * currently supports this feature. However, in the future, a new version of | |
| 26 | * FireVox will be created that will support this implementation and work with | |
| 27 | * FireFox 2. | |
| 21 | * <p>Allows ARIA attributes to be added to widgets so that they can be | |
| 22 | * identified by assistive technologies. Firefox 3, Firefox 2 (via FireVox), | |
| 23 | * and Opera 9.5 are the only released browsers that currently support this | |
| 24 | * feature, but in the near future it will be available in Safari and Internet | |
| 25 | * Explorer 8. Individual screen reader applications may also support ARIA, to | |
| 26 | * varying extents.</p> | |
| 28 | 27 | * |
| 29 | * A 'role' describes the role a widget plays in a page: i.e. a checkbox widget | |
| 30 | * is assigned a "checkbox" role. | |
| 28 | * <p>A 'role' describes the role a widget plays in a page: i.e. a checkbox | |
| 29 | * widget is assigned a "checkbox" role.</p> | |
| 31 | 30 | * |
| 32 | * A 'state' describes the current state of the widget. For example, a checkbox | |
| 33 | * widget has the state "checked", which is given a value of "true" or "false" | |
| 34 | * depending on whether it is currently checked or unchecked. | |
| 31 | * <p>A 'state' describes the current state of the widget. For example, a | |
| 32 | * checkbox widget has the state "checked", which is given a value of "true" or | |
| 33 | * "false" depending on whether it is currently checked or unchecked.</p> | |
| 35 | 34 | * |
| 36 | * See {@see <a href="http://developer.mozilla.org/en/docs/Accessible_DHTML">http://developer.mozilla.org/en/docs/Accessible_DHTML</a>} | |
| 37 | * for more information. | |
| 35 | * <p>See <a href="http://developer.mozilla.org/en/docs/Accessible_DHTML">the | |
| 36 | * MDC page on Accessible DHTML</a> for more information.</p> | |
| 38 | 37 | * |
| 39 | * Note that this API is package protected. At this time, the ARIA specification is still | |
| 40 | * in flux, which means that this API is subject to change. Once we are fairly confident | |
| 41 | * that this API will remain stable, we will make it public. | |
| 38 | * <p>Note that although this API is public, the ARIA specification is still | |
| 39 | * somewhat in flux. As a result, this API is subject to change as the | |
| 40 | * specification stabilizes; we will do our best to keep the community | |
| 41 | * updated on changes.</p> | |
| 42 | 42 | */ |
| 43 | 43 | |
| 44 | final class Accessibility { | |
| 44 | public final class Accessibility { | |
| 45 | 45 | |
| 46 | 46 | public static final String ROLE_TREE = "tree"; |
| 47 | 47 | public static final String ROLE_TREEITEM = "treeitem"; |
| ... | ...@@ -59,8 +59,8 @@ | |
| 59 | 59 | public static final String STATE_EXPANDED = "aria-expanded"; |
| 60 | 60 | public static final String STATE_LEVEL = "aria-level"; |
| 61 | 61 | public static final String STATE_HASPOPUP = "aria-haspopup"; |
| 62 | ||
| 63 | private static AccessibilityImpl impl = (AccessibilityImpl) GWT.create(AccessibilityImpl.class); | |
| 62 | ||
| 63 | private static final String ATTR_NAME_ROLE = "role"; | |
| 64 | 64 | |
| 65 | 65 | /** |
| 66 | 66 | * Requests the string value of the role with the specified namespace. |
| ... | ...@@ -69,7 +69,7 @@ | |
| 69 | 69 | * @return the value of the role, or an empty string if none exists |
| 70 | 70 | */ |
| 71 | 71 | public static String getRole(Element elem) { |
| 72 | return impl.getRole(elem); | |
| 72 | return elem.getAttribute(ATTR_NAME_ROLE); | |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
| ... | ...@@ -80,7 +80,7 @@ | |
| 80 | 80 | * @return the value of the state, or an empty string if none exists |
| 81 | 81 | */ |
| 82 | 82 | public static String getState(Element elem, String stateName) { |
| 83 | return impl.getState(elem, stateName); | |
| 83 | return elem.getAttribute(stateName); | |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
| ... | ...@@ -90,7 +90,7 @@ | |
| 90 | 90 | * @param stateName the name of the state to remove |
| 91 | 91 | */ |
| 92 | 92 | public static void removeState(Element elem, String stateName) { |
| 93 | impl.removeState(elem, stateName); | |
| 93 | elem.removeAttribute(stateName); | |
| 94 | 94 | } |
| 95 | 95 | /** |
| 96 | 96 | * Assigns the specified element the specified role and value for that role. |
| ... | ...@@ -99,7 +99,7 @@ | |
| 99 | 99 | * @param roleName the name of the role |
| 100 | 100 | */ |
| 101 | 101 | public static void setRole(Element elem, String roleName) { |
| 102 | impl.setRole(elem, roleName); | |
| 102 | elem.setAttribute(ATTR_NAME_ROLE, roleName); | |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
| ... | ...@@ -110,7 +110,7 @@ | |
| 110 | 110 | * @param stateValue the value of the state |
| 111 | 111 | */ |
| 112 | 112 | public static void setState(Element elem, String stateName, String stateValue) { |
| 113 | impl.setState(elem, stateName, stateValue); | |
| 113 | elem.setAttribute(stateName, stateValue); | |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | private Accessibility() { |
| ... | ...@@ -30,6 +30,7 @@ | |
| 30 | 30 | import com.google.gwt.i18n.client.NumberParse_en_Test; |
| 31 | 31 | import com.google.gwt.i18n.client.NumberParse_fr_Test; |
| 32 | 32 | import com.google.gwt.i18n.rebind.AbstractResourceTest; |
| 33 | import com.google.gwt.i18n.rebind.MessageFormatParserTest; | |
| 33 | 34 | import com.google.gwt.junit.tools.GWTTestSuite; |
| 34 | 35 | |
| 35 | 36 | import junit.framework.Test; |
| ... | ...@@ -53,6 +54,7 @@ | |
| 53 | 54 | suite.addTestSuite(I18N2Test.class); |
| 54 | 55 | suite.addTestSuite(LocaleInfo_ar_Test.class); |
| 55 | 56 | suite.addTestSuite(LocaleInfoTest.class); |
| 57 | suite.addTestSuite(MessageFormatParserTest.class); | |
| 56 | 58 | suite.addTestSuite(NumberFormat_ar_Test.class); |
| 57 | 59 | suite.addTestSuite(NumberFormat_en_Test.class); |
| 58 | 60 | suite.addTestSuite(NumberFormat_fr_Test.class); |
| ... | ...@@ -270,4 +270,26 @@ | |
| 270 | 270 | assertNull(eLabel.getParent()); |
| 271 | 271 | assertFalse(childTree.getChildWidgets().containsKey(eLabel.getParent())); |
| 272 | 272 | } |
| 273 | ||
| 274 | /** | |
| 275 | * Tests setImageBase() which, though deprecated, should still work. | |
| 276 | */ | |
| 277 | public void testSetImageBase() { | |
| 278 | Tree t = new Tree(); | |
| 279 | TreeItem parent = new TreeItem("parent"); | |
| 280 | parent.addItem("child"); | |
| 281 | t.addItem(parent); | |
| 282 | RootPanel.get().add(t); | |
| 283 | ||
| 284 | // This was throwing UnsupportedOperationException at one point (just | |
| 285 | // before the 1.5 release), because of additions to ImagePrototype. If | |
| 286 | // that were to creep back in, we'd see an exception. | |
| 287 | t.setImageBase(""); | |
| 288 | ||
| 289 | // Make sure the parent open/close image actually got created (there's | |
| 290 | // no actual public image file to back this up, but it won't matter from | |
| 291 | // the standpoint of this test). | |
| 292 | String parentSrc = DOM.getImgSrc(parent.getImageElement()); | |
| 293 | assertTrue(parentSrc.endsWith("tree_closed.gif")); | |
| 294 | } | |
| 273 | 295 | } |
| ... | ...@@ -376,10 +376,10 @@ | |
| 376 | 376 | TreeLogger.ERROR, |
| 377 | 377 | "Not enough arguments (" |
| 378 | 378 | + numArgs |
| 379 | + ") passed to external.gwtOnLoad(), expected (3); " | |
| 380 | + "your hosted mode bootstrap file may be out of date; " | |
| 381 | + "if you are using -noserver try recompiling and redeploying " | |
| 382 | + "your app"); | |
| 379 | + ") passed to external.gwtOnLoad(), expected (3); " | |
| 380 | + "your hosted mode bootstrap file may be out of date; " | |
| 381 | + "if you are using -noserver try recompiling and redeploying " | |
| 382 | + "your app"); | |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
| ... | ...@@ -415,7 +415,7 @@ | |
| 415 | 415 | + "\"; your hosted mode bootstrap file may be out of date; " |
| 416 | 416 | + "if you are using -noserver try recompiling and redeploying " |
| 417 | 417 | + "your app"); |
| 418 | return false; | |
| 418 | return false; | |
| 419 | 419 | } |
| 420 | 420 | return true; |
| 421 | 421 | } |
| ... | ...@@ -573,15 +573,8 @@ | |
| 573 | 573 | evt.doit = true; |
| 574 | 574 | break; |
| 575 | 575 | } else { |
| 576 | String msg = "Cannot find file '" + file.getAbsolutePath() | |
| 577 | + "'"; | |
| 578 | TreeLogger branch = logger.branch(TreeLogger.ERROR, msg, null); | |
| 579 | if ("gwt-hosted.html".equalsIgnoreCase(file.getName())) { | |
| 580 | branch.log( | |
| 581 | TreeLogger.ERROR, | |
| 582 | "If you want to open compiled output within this hosted browser, add '?gwt.hybrid' to the end of the URL", | |
| 583 | null); | |
| 584 | } | |
| 576 | logger.log(TreeLogger.ERROR, "Cannot find file '" | |
| 577 | + file.getAbsolutePath() + "'"); | |
| 585 | 578 | } |
| 586 | 579 | file = file.getParentFile(); |
| 587 | 580 | } |
| ... | ...@@ -18,7 +18,7 @@ | |
| 18 | 18 | import com.google.gwt.core.ext.TreeLogger; |
| 19 | 19 | import com.google.gwt.core.ext.UnableToCompleteException; |
| 20 | 20 | import com.google.gwt.dev.javac.CompilationState; |
| 21 | import com.google.gwt.dev.javac.CompilationUnit; | |
| 21 | import com.google.gwt.dev.javac.CompiledClass; | |
| 22 | 22 | import com.google.gwt.dev.javac.JdtCompiler.CompilationUnitAdapter; |
| 23 | 23 | import com.google.gwt.dev.jdt.FindDeferredBindingSitesVisitor.DeferredBindingSite; |
| 24 | 24 | import com.google.gwt.dev.util.Empty; |
| ... | ...@@ -54,23 +54,17 @@ | |
| 54 | 54 | throws UnableToCompleteException { |
| 55 | 55 | |
| 56 | 56 | // Build the initial set of compilation units. |
| 57 | Map<String, CompilationUnit> unitMap = compilationState.getCompilationUnitMap(); | |
| 57 | Map<String, CompiledClass> classMapBySource = compilationState.getClassFileMapBySource(); | |
| 58 | 58 | ICompilationUnit[] icus = new ICompilationUnit[seedTypeNames.length]; |
| 59 | 59 | for (int i = 0; i < seedTypeNames.length; i++) { |
| 60 | 60 | String seedTypeName = seedTypeNames[i]; |
| 61 | CompilationUnit unit = unitMap.get(seedTypeName); | |
| 62 | while (unit == null) { | |
| 63 | int pos = seedTypeName.lastIndexOf('.'); | |
| 64 | if (pos < 0) { | |
| 65 | logger.log(TreeLogger.ERROR, | |
| 66 | "Unable to find compilation unit for type '" + seedTypeNames[i] | |
| 67 | + "'"); | |
| 68 |