Thomas Broyer has submitted this change and it was merged.

Change subject: Cut circular dependency between c.g.g.core.linker and c.g.g.dev.js
......................................................................


Cut circular dependency between c.g.g.core.linker and c.g.g.dev.js

Change-Id: Id33cdf94725981c9c5779553444c1ac64659892c
---
M dev/core/src/com/google/gwt/core/linker/CrossSiteIframeLinker.java
M dev/core/src/com/google/gwt/core/linker/XSLinker.java
M dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java
M dev/core/src/com/google/gwt/util/tools/shared/StringUtils.java
R dev/core/test/com/google/gwt/util/tools/shared/JavaScriptStringTest.java
5 files changed, 144 insertions(+), 149 deletions(-)

Approvals:
  Leeroy Jenkins: Verified
  Thomas Broyer: Looks good to me, approved



diff --git a/dev/core/src/com/google/gwt/core/linker/CrossSiteIframeLinker.java b/dev/core/src/com/google/gwt/core/linker/CrossSiteIframeLinker.java
index c7f0128..3253174 100644
--- a/dev/core/src/com/google/gwt/core/linker/CrossSiteIframeLinker.java
+++ b/dev/core/src/com/google/gwt/core/linker/CrossSiteIframeLinker.java
@@ -33,12 +33,12 @@
 import com.google.gwt.core.ext.linker.impl.ResourceInjectionUtil;
 import com.google.gwt.core.ext.linker.impl.SelectionScriptLinker;
 import com.google.gwt.dev.About;
-import com.google.gwt.dev.js.JsToStringGenerationVisitor;
 import com.google.gwt.dev.util.DefaultTextOutput;
 import com.google.gwt.dev.util.TextOutput;
 import com.google.gwt.thirdparty.guava.common.base.Joiner;
 import com.google.gwt.thirdparty.guava.common.base.Splitter;
 import com.google.gwt.util.tools.Utility;
+import com.google.gwt.util.tools.shared.StringUtils;

 import java.io.IOException;
 import java.util.ArrayList;
@@ -584,7 +584,7 @@
     return String.format("$wnd.%s.runAsyncCallback%d(%s)\n",
         context.getModuleFunctionName(),
         fragment,
-        JsToStringGenerationVisitor.javaScriptString(js));
+        StringUtils.javaScriptString(js));
   }

   @Override
@@ -608,7 +608,7 @@
Iterable<String> chunks = Splitter.on(getScriptChunkSeparator(logger, context)).split(script);
       List<String> newChunks = new ArrayList<String>();
       for (String chunk : chunks) {
-        newChunks.add(JsToStringGenerationVisitor.javaScriptString(chunk));
+        newChunks.add(StringUtils.javaScriptString(chunk));
       }
       out.append(Joiner.on(",\n").join(newChunks));
       out.append("]);\n");
diff --git a/dev/core/src/com/google/gwt/core/linker/XSLinker.java b/dev/core/src/com/google/gwt/core/linker/XSLinker.java
index b6b2641..d379794 100644
--- a/dev/core/src/com/google/gwt/core/linker/XSLinker.java
+++ b/dev/core/src/com/google/gwt/core/linker/XSLinker.java
@@ -23,8 +23,8 @@
 import com.google.gwt.core.ext.linker.Shardable;
 import com.google.gwt.core.ext.linker.impl.SelectionScriptLinker;
 import com.google.gwt.dev.About;
-import com.google.gwt.dev.js.JsToStringGenerationVisitor;
 import com.google.gwt.dev.util.DefaultTextOutput;
+import com.google.gwt.util.tools.shared.StringUtils;

 /**
  * Generates a cross-site compatible bootstrap sequence.
@@ -88,7 +88,7 @@
     return String.format("%s.runAsyncCallback%d(%s)\n",
         context.getModuleFunctionName(),
         fragment,
-        JsToStringGenerationVisitor.javaScriptString(js));
+        StringUtils.javaScriptString(js));
   }

   private String getModulePrefix(LinkerContext context, String strongName,
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 55fab01..26c1bb8 100644
--- a/dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java
+++ b/dev/core/src/com/google/gwt/dev/js/JsToStringGenerationVisitor.java
@@ -73,6 +73,7 @@
 import com.google.gwt.dev.js.ast.JsWhile;
 import com.google.gwt.dev.util.TextOutput;
 import com.google.gwt.dev.util.collect.HashSet;
+import com.google.gwt.util.tools.shared.StringUtils;

 import java.util.ArrayList;
 import java.util.Iterator;
@@ -109,10 +110,6 @@
   private static final char[] CHARS_TRY = "try".toCharArray();
   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'};
-
   /**
* How many lines of code to print inside of a JsBlock when printing terse.
    */
@@ -125,135 +122,6 @@
    * surround those names with quotes in property initializers to be safe.
    */
private static final Pattern VALID_NAME_PATTERN = Pattern.compile("[a-zA-Z_$][\\w$]*");
-
-  /**
- * Generate JavaScript code that evaluates to the supplied string. Adapted - * from {@link com.google.gwt.dev.js.rhino.ScriptRuntime#escapeString(String)} - * . The difference is that we quote with either &quot; or &apos; depending on
-   * which one is used less inside the string.
-   */
-  public static String javaScriptString(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;
-      }
-    }
-
-    StringBuffer result = new StringBuffer(value.length() + 16);
-
-    char quoteChar = (quoteCount < aposCount) ? '"' : '\'';
-    result.append(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())
-        result.append(c);
-        continue;
-      }
-
-      int escape = -1;
-      switch (c) {
-        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 '"':
-          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
-        result.append('\\');
-        result.append((char) escape);
-      } else {
-        /*
-         * Emit characters from 0 to 31 that don't have a single character
-         * escape sequence in octal where possible. This saves one or two
-         * characters compared to the hexadecimal format '\xXX'.
-         *
- * These short octal sequences may only be used at the end of the string
-         * or where the following character is a non-digit. Otherwise, the
- * following character would be incorrectly interpreted as belonging to
-         * the sequence.
-         */
- if (c < ' ' && (i == n - 1 || chars[i + 1] < '0' || chars[i + 1]
'9')) {
-          result.append('\\');
-          if (c > 0x7) {
-            result.append((char) ('0' + (0x7 & (c >> 3))));
-          }
-          result.append((char) ('0' + (0x7 & c)));
-        } else {
-          int hexSize;
-          if (c < 256) {
-            // 2-digit hex
-            result.append("\\x");
-            hexSize = 2;
-          } else {
-            // Unicode.
-            result.append("\\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);
-            result.append(HEX_DIGITS[digit]);
-          }
-        }
-      }
-    }
-    result.append(quoteChar);
-    escapeClosingTags(result);
-    String resultString = result.toString();
-    return resultString;
-  }
-
-  /**
-   * Escapes any closing XML tags embedded in <code>str</code>, which could
- * potentially cause a parse failure in a browser, for example, embedding a
-   * closing <code>&lt;script&gt;</code> tag.
-   *
-   * @param str an unescaped literal; May be null
-   */
-  private static void escapeClosingTags(StringBuffer str) {
-    if (str == null) {
-      return;
-    }
-
-    int index = 0;
-
-    while ((index = str.indexOf("</", index)) != -1) {
-      str.insert(index + 1, '\\');
-    }
-  }

   protected boolean needSemi = true;
   /**
@@ -1416,7 +1284,7 @@
   }

   private void printStringLiteral(String value) {
-    String resultString = javaScriptString(value);
+    String resultString = StringUtils.javaScriptString(value);
     p.print(resultString);
   }
 }
diff --git a/dev/core/src/com/google/gwt/util/tools/shared/StringUtils.java b/dev/core/src/com/google/gwt/util/tools/shared/StringUtils.java
index c7ffb3b..c675e79 100644
--- a/dev/core/src/com/google/gwt/util/tools/shared/StringUtils.java
+++ b/dev/core/src/com/google/gwt/util/tools/shared/StringUtils.java
@@ -1,12 +1,12 @@
 /*
  * Copyright 2006 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
@@ -21,8 +21,7 @@
 public class StringUtils {

   public static char[] HEX_CHARS = new char[] {
-    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
-    'E', 'F'};
+      '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 
'E', 'F'};

   /**
    * A 4-digit hex result.
@@ -35,9 +34,119 @@
   }

   /**
+ * Generate JavaScript code that evaluates to the supplied string. Adapted + * from {@link com.google.gwt.dev.js.rhino.ScriptRuntime#escapeString(String)} + * . The difference is that we quote with either &quot; or &apos; depending on
+   * which one is used less inside the string.
+   */
+  public static String javaScriptString(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;
+      }
+    }
+
+    StringBuffer result = new StringBuffer(value.length() + 16);
+
+    char quoteChar = (quoteCount < aposCount) ? '"' : '\'';
+    result.append(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())
+        result.append(c);
+        continue;
+      }
+
+      int escape = -1;
+      switch (c) {
+        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 '"':
+          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
+        result.append('\\');
+        result.append((char) escape);
+      } else {
+        /*
+         * Emit characters from 0 to 31 that don't have a single character
+         * escape sequence in octal where possible. This saves one or two
+         * characters compared to the hexadecimal format '\xXX'.
+         *
+ * These short octal sequences may only be used at the end of the string
+         * or where the following character is a non-digit. Otherwise, the
+ * following character would be incorrectly interpreted as belonging to
+         * the sequence.
+         */
+ if (c < ' ' && (i == n - 1 || chars[i + 1] < '0' || chars[i + 1]
'9')) {
+          result.append('\\');
+          if (c > 0x7) {
+            result.append((char) ('0' + (0x7 & (c >> 3))));
+          }
+          result.append((char) ('0' + (0x7 & c)));
+        } else {
+          int hexSize;
+          if (c < 256) {
+            // 2-digit hex
+            result.append("\\x");
+            hexSize = 2;
+          } else {
+            // Unicode.
+            result.append("\\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);
+            result.append(HEX_CHARS[digit]);
+          }
+        }
+      }
+    }
+    result.append(quoteChar);
+    StringUtils.escapeClosingTags(result);
+    String resultString = result.toString();
+    return resultString;
+  }
+
+  /**
    * Returns a string representation of the byte array as a series of
    * hexadecimal characters.
-   *
+   *
    * @param bytes byte array to convert
    * @return a string representation of the byte array as a series of
    *         hexadecimal characters
@@ -51,4 +160,23 @@
     }
     return new String(hexString);
   }
+
+  /**
+   * Escapes any closing XML tags embedded in <code>str</code>, which could
+ * potentially cause a parse failure in a browser, for example, embedding a
+   * closing <code>&lt;script&gt;</code> tag.
+   *
+   * @param str an unescaped literal; May be null
+   */
+  private static void escapeClosingTags(StringBuffer str) {
+    if (str == null) {
+      return;
+    }
+
+    int index = 0;
+
+    while ((index = str.indexOf("</", index)) != -1) {
+      str.insert(index + 1, '\\');
+    }
+  }
 }
diff --git a/dev/core/test/com/google/gwt/dev/js/JavaScriptStringTest.java b/dev/core/test/com/google/gwt/util/tools/shared/JavaScriptStringTest.java
similarity index 78%
rename from dev/core/test/com/google/gwt/dev/js/JavaScriptStringTest.java
rename to dev/core/test/com/google/gwt/util/tools/shared/JavaScriptStringTest.java
index f91996f..0c92fe9 100644
--- a/dev/core/test/com/google/gwt/dev/js/JavaScriptStringTest.java
+++ b/dev/core/test/com/google/gwt/util/tools/shared/JavaScriptStringTest.java
@@ -1,8 +1,7 @@
 // Copyright 2010 Google Inc. All Rights Reserved.

-package com.google.gwt.dev.js;
+package com.google.gwt.util.tools.shared;

-import com.google.gwt.dev.js.JsToStringGenerationVisitor;
 import com.google.gwt.dev.js.rhino.TokenStream;

 import junit.framework.TestCase;
@@ -11,11 +10,11 @@
 import java.io.StringReader;

 /**
- * Tests {@link JsToStringGenerationVisitor#javaScriptString(String)}.
+ * Tests {@link StringUtils#javaScriptString(String)}.
  */
 public class JavaScriptStringTest extends TestCase {
   private void test(String original) throws IOException {
- String escaped = JsToStringGenerationVisitor.javaScriptString(original);
+    String escaped = StringUtils.javaScriptString(original);

     // Parse it back
     TokenStream tokenStream = new TokenStream(new StringReader(escaped),

--
To view, visit https://gwt-review.googlesource.com/1031
To unsubscribe, visit https://gwt-review.googlesource.com/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Id33cdf94725981c9c5779553444c1ac64659892c
Gerrit-PatchSet: 2
Gerrit-Project: gwt
Gerrit-Branch: master
Gerrit-Owner: Thomas Broyer <[email protected]>
Gerrit-Reviewer: Leeroy Jenkins <[email protected]>
Gerrit-Reviewer: Manuel Carrasco Moñino <[email protected]>
Gerrit-Reviewer: Matthew Dempsky <[email protected]>
Gerrit-Reviewer: Ray Cromwell <[email protected]>
Gerrit-Reviewer: Roberto Lublinerman <[email protected]>
Gerrit-Reviewer: Stephen Haberman <[email protected]>
Gerrit-Reviewer: Thomas Broyer <[email protected]>

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors
--- You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to