Skip to content

Commit

Permalink
Move turbine's fork of SourceCodeEscapers to a new package
Browse files Browse the repository at this point in the history
to avoid one version conflicts, as reported in
bazelbuild/bazel#23592

PiperOrigin-RevId: 673420893
  • Loading branch information
cushon authored and Javac Team committed Sep 11, 2024
1 parent e1ea3c5 commit 9298332
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.
*
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

@com.google.errorprone.annotations.CheckReturnValue
@org.jspecify.annotations.NullMarked
package com.google.common.escape;
package com.google.turbine.escape;
2 changes: 1 addition & 1 deletion java/com/google/turbine/model/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion javatests/com/google/turbine/parse/JavacLexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion javatests/com/google/turbine/parse/LexerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9298332

Please sign in to comment.