public final class JavaEscapeHelper
extends java.lang.Object
JavaEscapeHelper class provides various methods which can be used to generate valid Java identifiers or package / class
names, especially when generating them from a transcompiler.| Modifier and Type | Method and Description |
|---|---|
static @NotNull java.lang.String |
escapeChar(char ch)
Escapes the provided character so that it's a valid Java identifier character.
|
static @NotNull java.lang.String |
getJavaIdentifier(@NotNull java.lang.String identifier)
Converts the given identifier to a legal Java identifier.
|
static boolean |
isJavaKeyword(@NotNull java.lang.String key)
Test whether the argument is a Java keyword, according to the
Java Language Specification.
|
static boolean |
isJavaLiteral(@NotNull java.lang.String key)
Test whether the argument is a Java literal, according to the
Java Language Specification..
|
static boolean |
isSpecialIdentifier(@NotNull java.lang.String key)
Test whether the argument is a special identifier, according to the
Java Language Specification.
|
static @NotNull java.lang.String |
makeJavaPackage(@NotNull java.lang.String path)
Converts the given
path to a Java package or fully-qualified class name, depending on the path's value. |
static char |
unescape(@NotNull java.lang.String escapeSequence)
Returns the original character that was escaped, given an
escapeSequence. |
static @NotNull java.lang.String |
unescapeAll(@NotNull java.lang.String input)
Provided a string which could contain escape sequences generated through
escapeChar(char), this method will unescape all
such sequences. |
@NotNull
public static @NotNull java.lang.String getJavaIdentifier(@NotNull
@NotNull java.lang.String identifier)
identifier - the identifier to convert@NotNull public static @NotNull java.lang.String escapeChar(char ch)
(__[0-9a-f]{4}__) pattern, by using the
character's decimal code and converting it to hexadecimal.ch - the character to escapepublic static char unescape(@NotNull
@NotNull java.lang.String escapeSequence)
escapeSequence. The escapeSequence has to match the
(__[0-9a-f]{4}__) pattern.escapeSequence - the escaped stringjava.lang.IllegalArgumentException - if the escaped string does not match the (__[0-9a-f]{4}__) pattern@NotNull
public static @NotNull java.lang.String unescapeAll(@NotNull
@NotNull java.lang.String input)
escapeChar(char), this method will unescape all
such sequences.input - a string containing escaped charactersescapeChar(char) replaced by the original character@NotNull
public static @NotNull java.lang.String makeJavaPackage(@NotNull
@NotNull java.lang.String path)
path to a Java package or fully-qualified class name, depending on the path's value.path - the path to convertpublic static boolean isJavaKeyword(@NotNull
@NotNull java.lang.String key)
key - the String to testtrue if the String is a Java keyword, false otherwisepublic static boolean isJavaLiteral(@NotNull
@NotNull java.lang.String key)
key - the String to testtrue if the String is a Java literal, false otherwisepublic static boolean isSpecialIdentifier(@NotNull
@NotNull java.lang.String key)
key - the String to testtrue if the String is a Java special identifier, false otherwiseCopyright © 2022 The Apache Software Foundation. All rights reserved.