From 929833252187c2e4db68b581b053e6c8604fd6b8 Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Wed, 11 Sep 2024 09:22:14 -0700 Subject: [PATCH] Move turbine's fork of SourceCodeEscapers to a new package to avoid one version conflicts, as reported in https://github.com/bazelbuild/bazel/pull/23592 PiperOrigin-RevId: 673420893 --- .../escape/SourceCodeEscapers.java | 14 ++++++++------ .../{common => turbine}/escape/package-info.java | 2 +- java/com/google/turbine/model/Const.java | 2 +- javatests/com/google/turbine/parse/JavacLexer.java | 2 +- javatests/com/google/turbine/parse/LexerTest.java | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) rename java/com/google/{common => turbine}/escape/SourceCodeEscapers.java (89%) rename java/com/google/{common => turbine}/escape/package-info.java (95%) diff --git a/java/com/google/common/escape/SourceCodeEscapers.java b/java/com/google/turbine/escape/SourceCodeEscapers.java similarity index 89% rename from java/com/google/common/escape/SourceCodeEscapers.java rename to java/com/google/turbine/escape/SourceCodeEscapers.java index c0f9d6bb..1c3466d7 100644 --- a/java/com/google/common/escape/SourceCodeEscapers.java +++ b/java/com/google/turbine/escape/SourceCodeEscapers.java @@ -14,8 +14,10 @@ * limitations under the License. */ -package com.google.common.escape; +package com.google.turbine.escape; +import com.google.common.escape.ArrayBasedCharEscaper; +import com.google.common.escape.CharEscaper; import java.util.HashMap; import java.util.Map; @@ -39,7 +41,7 @@ private SourceCodeEscapers() {} private static final char[] HEX_DIGITS = "0123456789abcdef".toCharArray(); /** - * Returns an {@link Escaper} instance that escapes special characters in a string so it can + * Returns an {@link CharEscaper} instance that escapes special characters in a string so it can * safely be included in either a Java character literal or string literal. This is the preferred * way to escape Java characters for use in String or character literals. * @@ -83,16 +85,16 @@ protected char[] escapeUnsafe(char c) { // Helper for common case of escaping a single char. private static char[] asUnicodeHexEscape(char c) { - // Equivalent to String.format("\\u%04x", (int)c); + // Equivalent to String.format("\\u%04x", (int) c); char[] r = new char[6]; r[0] = '\\'; r[1] = 'u'; r[5] = HEX_DIGITS[c & 0xF]; - c >>>= 4; + c = (char) (c >>> 4); r[4] = HEX_DIGITS[c & 0xF]; - c >>>= 4; + c = (char) (c >>> 4); r[3] = HEX_DIGITS[c & 0xF]; - c >>>= 4; + c = (char) (c >>> 4); r[2] = HEX_DIGITS[c & 0xF]; return r; } diff --git a/java/com/google/common/escape/package-info.java b/java/com/google/turbine/escape/package-info.java similarity index 95% rename from java/com/google/common/escape/package-info.java rename to java/com/google/turbine/escape/package-info.java index f48c52ee..4797b68a 100644 --- a/java/com/google/common/escape/package-info.java +++ b/java/com/google/turbine/escape/package-info.java @@ -16,4 +16,4 @@ @com.google.errorprone.annotations.CheckReturnValue @org.jspecify.annotations.NullMarked -package com.google.common.escape; +package com.google.turbine.escape; diff --git a/java/com/google/turbine/model/Const.java b/java/com/google/turbine/model/Const.java index 739b0f37..40431c6c 100644 --- a/java/com/google/turbine/model/Const.java +++ b/java/com/google/turbine/model/Const.java @@ -18,7 +18,7 @@ import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; -import com.google.common.escape.SourceCodeEscapers; +import com.google.turbine.escape.SourceCodeEscapers; import javax.lang.model.element.AnnotationValue; import javax.lang.model.element.AnnotationValueVisitor; import org.jspecify.annotations.Nullable; diff --git a/javatests/com/google/turbine/parse/JavacLexer.java b/javatests/com/google/turbine/parse/JavacLexer.java index 3fcdedfd..6c323c2f 100644 --- a/javatests/com/google/turbine/parse/JavacLexer.java +++ b/javatests/com/google/turbine/parse/JavacLexer.java @@ -18,7 +18,7 @@ import com.google.common.base.Function; import com.google.common.collect.Lists; -import com.google.common.escape.SourceCodeEscapers; +import com.google.turbine.escape.SourceCodeEscapers; import com.sun.tools.javac.parser.Scanner; import com.sun.tools.javac.parser.ScannerFactory; import com.sun.tools.javac.parser.Tokens; diff --git a/javatests/com/google/turbine/parse/LexerTest.java b/javatests/com/google/turbine/parse/LexerTest.java index e0f0f613..f4293fee 100644 --- a/javatests/com/google/turbine/parse/LexerTest.java +++ b/javatests/com/google/turbine/parse/LexerTest.java @@ -19,9 +19,9 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assume.assumeTrue; -import com.google.common.escape.SourceCodeEscapers; import com.google.common.truth.Expect; import com.google.turbine.diag.SourceFile; +import com.google.turbine.escape.SourceCodeEscapers; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List;