ordercheck passes.
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@38 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/js/JsKeywords.java b/dev/core/src/com/google/gwt/dev/js/JsKeywords.java
index 14aee37..2cae6d1 100644
--- a/dev/core/src/com/google/gwt/dev/js/JsKeywords.java
+++ b/dev/core/src/com/google/gwt/dev/js/JsKeywords.java
@@ -25,39 +25,46 @@
public class JsKeywords {
private static TreeSet sJavaScriptKeywords = new TreeSet(
- CharArrayComparator.INSTANCE);
+ CharArrayComparator.INSTANCE);
static {
initJavaScriptKeywords();
}
- private JsKeywords() {
+ public static boolean isKeyword(char[] s) {
+ return sJavaScriptKeywords.contains(s);
}
private static synchronized void initJavaScriptKeywords() {
- String[] keywords = new String[]{
- // These are current keywords
- //
- "break", "delete", "function", "return", "typeof", "case", "do", "if",
- "switch", "var", "catch", "else", "in", "this", "void", "continue",
- "false", "instanceof", "throw", "while", "debugger", "finally", "new",
- "true", "with", "default", "for", "null", "try",
+ String[] keywords = new String[] {
+ // These are current keywords
+ //
+ "break", "delete", "function", "return", "typeof", "case", "do", "if",
+ "switch", "var", "catch", "else", "in", "this", "void", "continue",
+ "false", "instanceof", "throw", "while", "debugger",
+ "finally",
+ "new",
+ "true",
+ "with",
+ "default",
+ "for",
+ "null",
+ "try",
- // These are future keywords
- //
- "abstract", "double", "goto", "native", "static", "boolean", "enum",
- "implements", "package", "super", "byte", "export", "import", "private",
- "synchronized", "char", "extends", "int", "protected", "throws", "class",
- "final", "interface", "public", "transient", "const", "float", "long",
- "short", "volatile"};
+ // These are future keywords
+ //
+ "abstract", "double", "goto", "native", "static", "boolean", "enum",
+ "implements", "package", "super", "byte", "export", "import",
+ "private", "synchronized", "char", "extends", "int", "protected",
+ "throws", "class", "final", "interface", "public", "transient",
+ "const", "float", "long", "short", "volatile"};
for (int i = 0; i < keywords.length; i++) {
sJavaScriptKeywords.add(keywords[i].toCharArray());
}
}
- public static boolean isKeyword(char[] s) {
- return sJavaScriptKeywords.contains(s);
+ private JsKeywords() {
}
}
diff --git a/dev/core/src/com/google/gwt/dev/js/JsParser.java b/dev/core/src/com/google/gwt/dev/js/JsParser.java
index de51d87..6a8f3ff 100644
--- a/dev/core/src/com/google/gwt/dev/js/JsParser.java
+++ b/dev/core/src/com/google/gwt/dev/js/JsParser.java
@@ -75,20 +75,22 @@
public class JsParser {
+ private final Stack scopeStack = new Stack();
+
public JsParser() {
// Create a custom error handler so that we can throw our own exceptions.
//
Context.enter().setErrorReporter(new ErrorReporter() {
public void error(String msg, String loc, int ln, String src, int col) {
throw new UncheckedJsParserException(new JsParserException(msg, ln,
- src, col));
+ src, col));
}
public EvaluatorException runtimeError(String msg, String loc, int ln,
String src, int col) {
// Never called, but just in case.
throw new UncheckedJsParserException(new JsParserException(msg, ln,
- src, col));
+ src, col));
}
public void warning(String msg, String loc, int ln, String src, int col) {
@@ -304,7 +306,7 @@
default:
int tokenType = node.getType();
throw new JsParserException("Unexpected top-level token type: "
- + tokenType);
+ + tokenType);
}
}
@@ -378,7 +380,7 @@
default:
throw new JsParserException("Unknown assignment operator variant: "
- + asgNode.getIntDatum());
+ + asgNode.getIntDatum());
}
}
@@ -470,7 +472,8 @@
toDelete.setExpr((JsArrayAccess) to);
} else {
throw createParserException(
- "'delete' can only operate on property names and array elements", from);
+ "'delete' can only operate on property names and array elements",
+ from);
}
return toDelete;
}
@@ -535,7 +538,7 @@
default:
throw new JsParserException("Unknown equality operator variant: "
- + eqNode.getIntDatum());
+ + eqNode.getIntDatum());
}
}
@@ -650,7 +653,7 @@
String fromParamName = fromParamNode.getString();
// should this be unique? I think not since you can have dup args.
JsName paramName = toFn.getScope().getOrCreateObfuscatableName(
- fromParamName);
+ fromParamName);
toFn.getParameters().add(new JsParameter(paramName));
fromParamNode = fromParamNode.getNext();
}
@@ -690,8 +693,7 @@
//
Object obj = getPropNode.getProp(Node.SPECIAL_PROP_PROP);
assert (obj instanceof String);
- toNameRef = getScope().getOrCreateUnobfuscatableName((String) obj)
- .makeRef();
+ toNameRef = getScope().getOrCreateUnobfuscatableName((String) obj).makeRef();
}
toNameRef.setQualifier(toQualifier);
@@ -737,7 +739,7 @@
return mapPostfixOperation(op, node);
default:
throw new JsParserException("Unknown prefix/postfix variant: "
- + node.getIntDatum());
+ + node.getIntDatum());
}
}
@@ -812,12 +814,12 @@
Node fromValueExpr = fromPropInit;
if (fromValueExpr == null) {
throw createParserException("Expected an init expression for: "
- + toLabelExpr, objLitNode);
+ + toLabelExpr, objLitNode);
}
JsExpression toValueExpr = mapExpression(fromValueExpr);
JsPropertyInitializer toPropInit = new JsPropertyInitializer(toLabelExpr,
- toValueExpr);
+ toValueExpr);
toLit.getPropertyInitializers().add(toPropInit);
// Begin the next property initializer, if there is one.
@@ -911,7 +913,7 @@
default:
throw new JsParserException("Unknown relational operator variant: "
- + relNode.getIntDatum());
+ + relNode.getIntDatum());
}
}
@@ -965,7 +967,7 @@
default:
throw new JsParserException("Unknown equality operator variant: "
- + shiftNode.getIntDatum());
+ + shiftNode.getIntDatum());
}
}
@@ -1083,7 +1085,7 @@
//
Node fromCatchVarName = fromCatchNode.getFirstChild();
JsName name = getScope().getOrCreateObfuscatableName(
- fromCatchVarName.getString());
+ fromCatchVarName.getString());
JsCatch catchBlock = new JsCatch(name);
// Pre-advance to the next catch block, if any.
@@ -1149,7 +1151,7 @@
default:
throw new JsParserException("Unknown unary operator variant: "
- + unOp.getIntDatum());
+ + unOp.getIntDatum());
}
}
@@ -1186,7 +1188,7 @@
// called.
//
throw createParserException("Internal error: unexpected token 'with'",
- withNode);
+ withNode);
}
private void popScope() {
@@ -1196,6 +1198,4 @@
private void pushScope(JsScope scope) {
scopeStack.push(scope);
}
-
- private final Stack scopeStack = new Stack();
}
diff --git a/dev/core/src/com/google/gwt/dev/js/JsParserException.java b/dev/core/src/com/google/gwt/dev/js/JsParserException.java
index 532ba1c..fd7a7bc 100644
--- a/dev/core/src/com/google/gwt/dev/js/JsParserException.java
+++ b/dev/core/src/com/google/gwt/dev/js/JsParserException.java
@@ -21,6 +21,12 @@
public class JsParserException extends Exception {
public static class SourceDetail {
+ private final int line;
+
+ private final int lineOffset;
+
+ private final String lineSource;
+
public SourceDetail(int line, String lineSource, int lineOffset) {
this.line = line;
this.lineSource = lineSource;
@@ -38,12 +44,10 @@
public String getLineSource() {
return lineSource;
}
-
- private final int line;
- private final int lineOffset;
- private final String lineSource;
}
+ private final SourceDetail sourceDetail;
+
public JsParserException(String msg) {
super(msg);
sourceDetail = null;
@@ -65,16 +69,6 @@
sourceDetail = null;
}
- /**
- * Provides additional source detail in some cases.
- *
- * @return additional detail regarding the error, or <code>null</code> if no
- * additional detail is available
- */
- public SourceDetail getSourceDetail() {
- return sourceDetail;
- }
-
public String getDescription() {
StringBuffer sb = new StringBuffer();
@@ -98,5 +92,13 @@
return sb.toString();
}
- private final SourceDetail sourceDetail;
+ /**
+ * Provides additional source detail in some cases.
+ *
+ * @return additional detail regarding the error, or <code>null</code> if no
+ * additional detail is available
+ */
+ public SourceDetail getSourceDetail() {
+ return sourceDetail;
+ }
}
diff --git a/dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java b/dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java
index 1ff7269..e00c8e4 100644
--- a/dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java
+++ b/dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java
@@ -94,6 +94,16 @@
private static final char[] CHARS_VAR = "var".toCharArray();
private static final char[] CHARS_WHILE = "while".toCharArray();
+ private static final char[] HEX_DIGITS = {
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
+ 'E', 'F'};
+
+ protected boolean needSemi = true;
+
+ private final NamingStrategy namer;
+
+ private final TextOutput p;
+
public JsToStringGenerationVisitor(TextOutput out, NamingStrategy namer) {
this.p = out;
this.namer = namer;
@@ -160,7 +170,7 @@
* (sic).
*/
if (stmt instanceof JsExprStmt
- && ((JsExprStmt) stmt).getExpression() instanceof JsFunction) {
+ && ((JsExprStmt) stmt).getExpression() instanceof JsFunction) {
_newline();
} else {
_semi();
@@ -654,101 +664,6 @@
return false;
}
- private static final char[] HEX_DIGITS = {
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E',
- 'F'};
-
- /**
- * Adapted from
- * {@link com.google.javascript.jscomp.rhino.ScriptRuntime#escapeString(String)}.
- * The difference is that we quote with either " or ' depending on
- * which one is used less inside the string.
- */
- private void printStringLiteral(String value) {
- char[] chars = value.toCharArray();
- final int n = chars.length;
- int quoteCount = 0;
- int aposCount = 0;
- for (int i = 0; i < n; ++i) {
- switch (chars[i]) {
- case '"':
- ++quoteCount;
- break;
- case '\'':
- ++aposCount;
- break;
- }
- }
-
- char quoteChar = (quoteCount < aposCount) ? '"' : '\'';
- p.print(quoteChar);
- for (int i = 0; i < n; ++i) {
- char c = chars[i];
-
- if (' ' <= c && c <= '~' && c != quoteChar && c != '\\') {
- // an ordinary print character (like C isprint())
- p.print(c);
- continue;
- }
-
- int escape = -1;
- switch (c) {
- case 0:
- escape = '0';
- break;
- case '\b':
- escape = 'b';
- break;
- case '\f':
- escape = 'f';
- break;
- case '\n':
- escape = 'n';
- break;
- case '\r':
- escape = 'r';
- break;
- case '\t':
- escape = 't';
- break;
- case 0xb:
- escape = 'v';
- break; // Java lacks \v.
- case '"':
- escape = '"';
- break; // only reach here if == quoteChar
- case '\'':
- escape = '\'';
- break; // only reach here if == quoteChar
- case '\\':
- escape = '\\';
- break;
- }
- if (escape >= 0) {
- // an \escaped sort of character
- p.print('\\');
- p.print((char) escape);
- } else {
- int hexSize;
- if (c < 256) {
- // 2-digit hex
- p.print("\\x");
- hexSize = 2;
- } else {
- // Unicode.
- p.print("\\u");
- hexSize = 4;
- }
- // append hexadecimal form of ch left-padded with 0
- for (int shift = (hexSize - 1) * 4; shift >= 0; shift -= 4) {
- int digit = 0xf & (c >> shift);
- p.print(HEX_DIGITS[digit]);
- }
- }
- }
- p.print(quoteChar);
- }
-
public boolean visit(JsSwitch x) {
_switch();
_spaceOpt();
@@ -825,6 +740,14 @@
return false;
}
+ protected void _newline() {
+ p.newline();
+ }
+
+ protected void _newlineOpt() {
+ p.newlineOpt();
+ }
+
private void _assignment() {
p.print('=');
}
@@ -953,14 +876,6 @@
p.print(CHARS_NEW);
}
- protected void _newlineOpt() {
- p.newlineOpt();
- }
-
- protected void _newline() {
- p.newline();
- }
-
private void _null() {
p.print(CHARS_NULL);
}
@@ -983,7 +898,7 @@
private boolean _parenPopIfCommaExpr(JsExpression x) {
boolean doPop = x instanceof JsBinaryOperation
- && ((JsBinaryOperation) x).getOperator() == JsBinaryOperator.COMMA;
+ && ((JsBinaryOperation) x).getOperator() == JsBinaryOperator.COMMA;
if (doPop) {
_rparen();
}
@@ -1023,7 +938,7 @@
private boolean _parenPushIfCommaExpr(JsExpression x) {
boolean doPush = x instanceof JsBinaryOperation
- && ((JsBinaryOperation) x).getOperator() == JsBinaryOperator.COMMA;
+ && ((JsBinaryOperation) x).getOperator() == JsBinaryOperator.COMMA;
if (doPush) {
_lparen();
}
@@ -1130,7 +1045,94 @@
p.indentOut();
}
- private final NamingStrategy namer;
- private final TextOutput p;
- protected boolean needSemi = true;
+ /**
+ * Adapted from
+ * {@link com.google.javascript.jscomp.rhino.ScriptRuntime#escapeString(String)}.
+ * The difference is that we quote with either " or ' depending on
+ * which one is used less inside the string.
+ */
+ private void printStringLiteral(String value) {
+ char[] chars = value.toCharArray();
+ final int n = chars.length;
+ int quoteCount = 0;
+ int aposCount = 0;
+ for (int i = 0; i < n; ++i) {
+ switch (chars[i]) {
+ case '"':
+ ++quoteCount;
+ break;
+ case '\'':
+ ++aposCount;
+ break;
+ }
+ }
+
+ char quoteChar = (quoteCount < aposCount) ? '"' : '\'';
+ p.print(quoteChar);
+ for (int i = 0; i < n; ++i) {
+ char c = chars[i];
+
+ if (' ' <= c && c <= '~' && c != quoteChar && c != '\\') {
+ // an ordinary print character (like C isprint())
+ p.print(c);
+ continue;
+ }
+
+ int escape = -1;
+ switch (c) {
+ case 0:
+ escape = '0';
+ break;
+ case '\b':
+ escape = 'b';
+ break;
+ case '\f':
+ escape = 'f';
+ break;
+ case '\n':
+ escape = 'n';
+ break;
+ case '\r':
+ escape = 'r';
+ break;
+ case '\t':
+ escape = 't';
+ break;
+ case 0xb:
+ escape = 'v';
+ break; // Java lacks \v.
+ case '"':
+ escape = '"';
+ break; // only reach here if == quoteChar
+ case '\'':
+ escape = '\'';
+ break; // only reach here if == quoteChar
+ case '\\':
+ escape = '\\';
+ break;
+ }
+ if (escape >= 0) {
+ // an \escaped sort of character
+ p.print('\\');
+ p.print((char) escape);
+ } else {
+ int hexSize;
+ if (c < 256) {
+ // 2-digit hex
+ p.print("\\x");
+ hexSize = 2;
+ } else {
+ // Unicode.
+ p.print("\\u");
+ hexSize = 4;
+ }
+ // append hexadecimal form of ch left-padded with 0
+ for (int shift = (hexSize - 1) * 4; shift >= 0; shift -= 4) {
+ int digit = 0xf & (c >> shift);
+ p.print(HEX_DIGITS[digit]);
+ }
+ }
+ }
+ p.print(quoteChar);
+ }
}
diff --git a/dev/core/src/com/google/gwt/dev/js/NamingStrategy.java b/dev/core/src/com/google/gwt/dev/js/NamingStrategy.java
index e57fd06..ee78100 100644
--- a/dev/core/src/com/google/gwt/dev/js/NamingStrategy.java
+++ b/dev/core/src/com/google/gwt/dev/js/NamingStrategy.java
@@ -28,6 +28,12 @@
private class RootScopeHandler {
+ private final JsScope rootScope;
+
+ private final Map/* <JsObfuscatableName, String> */resultByName = new IdentityHashMap();
+
+ private final Map/* <JsScope, Map<String, JsName>> */nameByResultByScope = new IdentityHashMap();
+
public RootScopeHandler(JsScope rootScope) {
this.rootScope = rootScope;
}
@@ -45,8 +51,7 @@
// check for conflicts!
if (!conflicts(result, scope)) {
resultByName.put(name, result);
- Map/* <String, JsName> */nameByResult = (Map) nameByResultByScope
- .get(scope);
+ Map/* <String, JsName> */nameByResult = (Map) nameByResultByScope.get(scope);
if (nameByResult == null) {
nameByResult = new HashMap();
nameByResultByScope.put(scope, nameByResult);
@@ -62,6 +67,19 @@
return result;
}
+ private boolean childConflicts(String result, JsScope scope) {
+ for (int i = 0; i < scope.getChildren().size(); i++) {
+ JsScope child = (JsScope) scope.getChildren().get(i);
+ if (scopeConflicts(result, child)) {
+ return true;
+ }
+ if (childConflicts(result, child)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
private boolean conflicts(String result, JsScope scope) {
if (JsKeywords.isKeyword(result.toCharArray())) {
return true;
@@ -78,28 +96,6 @@
return childConflicts(result, scope);
}
- private boolean scopeConflicts(String result, JsScope scope) {
- Map/* <String, JsName> */nameByResult = (Map) nameByResultByScope
- .get(scope);
- if (nameByResult != null) {
- return nameByResult.containsKey(result);
- }
- return false;
- }
-
- private boolean childConflicts(String result, JsScope scope) {
- for (int i = 0; i < scope.getChildren().size(); i++) {
- JsScope child = (JsScope) scope.getChildren().get(i);
- if (scopeConflicts(result, child)) {
- return true;
- }
- if (childConflicts(result, child)) {
- return true;
- }
- }
- return false;
- }
-
private boolean parentConflicts(String result, JsScope scope) {
JsScope parent = scope.getParent();
if (parent == null) {
@@ -111,11 +107,17 @@
return parentConflicts(result, parent);
}
- private final JsScope rootScope;
- private final Map/* <JsObfuscatableName, String> */resultByName = new IdentityHashMap();
- private final Map/* <JsScope, Map<String, JsName>> */nameByResultByScope = new IdentityHashMap();
+ private boolean scopeConflicts(String result, JsScope scope) {
+ Map/* <String, JsName> */nameByResult = (Map) nameByResultByScope.get(scope);
+ if (nameByResult != null) {
+ return nameByResult.containsKey(result);
+ }
+ return false;
+ }
}
+ private final Map/* <JsScope, RootScopeHandler> */handlersByScope = new IdentityHashMap();
+
public final String getIdent(JsName name) {
if (name instanceof JsUnobfuscatableName) {
return name.getIdent();
@@ -142,6 +144,4 @@
}
return handler;
}
-
- private final Map/* <JsScope, RootScopeHandler> */handlersByScope = new IdentityHashMap();
}
diff --git a/dev/core/src/com/google/gwt/dev/js/ObfuscatedNamingStrategy.java b/dev/core/src/com/google/gwt/dev/js/ObfuscatedNamingStrategy.java
index cc50215..ebcae5d 100644
--- a/dev/core/src/com/google/gwt/dev/js/ObfuscatedNamingStrategy.java
+++ b/dev/core/src/com/google/gwt/dev/js/ObfuscatedNamingStrategy.java
@@ -20,12 +20,14 @@
public class ObfuscatedNamingStrategy extends NamingStrategy {
- private static final char[] sBase64Chars = new char[]{
- 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
- 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D',
- 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
- 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', '$', '_'};
+ private static final char[] sBase64Chars = new char[] {
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B',
+ 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
+ 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3',
+ '4', '5', '6', '7', '8', '9', '$', '_'};
+
+ private int nextId = 0;
// @Override
protected String getBaseIdent(JsObfuscatableName name) {
@@ -54,6 +56,4 @@
return result;
}
- private int nextId = 0;
-
}
diff --git a/dev/core/src/com/google/gwt/dev/js/UncheckedJsParserException.java b/dev/core/src/com/google/gwt/dev/js/UncheckedJsParserException.java
index 500accf..3aa374b 100644
--- a/dev/core/src/com/google/gwt/dev/js/UncheckedJsParserException.java
+++ b/dev/core/src/com/google/gwt/dev/js/UncheckedJsParserException.java
@@ -15,9 +15,11 @@
*/
package com.google.gwt.dev.js;
-// An unchecked wrapper exception to interop with Rhino.
+// An unchecked wrapper exception to interop with Rhino.
class UncheckedJsParserException extends RuntimeException {
+ private final JsParserException parserException;
+
public UncheckedJsParserException(JsParserException parserException) {
this.parserException = parserException;
}
@@ -25,6 +27,4 @@
public JsParserException getParserException() {
return parserException;
}
-
- private final JsParserException parserException;
}