com.redhat.ceylon.common.JVMModuleUtil Maven / Gradle / Ivy
package com.redhat.ceylon.common;
import java.util.HashSet;
public class JVMModuleUtil {
/** Quote the given name by prefixing it with a dollar ($) */
public static String quote(String name) {
return "$"+name;
}
/** Removes dollar ($) prefix from the given name if it exists */
public static String unquote(String name) {
if (!name.isEmpty() && name.charAt(0) == '$') {
return name.substring(1);
}
return name;
}
private static final HashSet tokens;
private static final String[] tokensArray = new String[]{
"abstract",
"assert",
"boolean",
"break",
"byte",
"case",
"catch",
"char",
"class",
"const",
"continue",
"default",
"do",
"double",
"else",
"enum",
"extends",
"final",
"finally",
"float",
"for",
"goto",
"if",
"implements",
"import",
"instanceof",
"int",
"interface",
"long",
"native",
"new",
"package",
"private",
"protected",
"public",
"return",
"short",
"static",
"strictfp",
"super",
"switch",
"synchronized",
"this",
"throw",
"throws",
"transient",
"try",
"void",
"volatile",
"while",
"true",
"false",
"null",
};
static {
tokens = new HashSet();
for (String token : tokensArray) {
tokens.add(token);
}
}
/** Determines whether the given name is a Java keyword */
public static boolean isJavaKeyword(String name) {
return tokens.contains(name);
}
/** Determines whether the given name is a Java keyword */
public static boolean isJavaKeyword(String string, int start, int end) {
int length = end - start;
OUTER:
for(int i=0;i 0) {
firstChar = ceylonRunnableName.charAt(lastDot + 1);
String lastPart = ceylonRunnableName.substring(lastDot+1);
String pkgPart = ceylonRunnableName.substring(0, lastDot);
// only quote the package parts
ceylonRunnableName = JVMModuleUtil.quoteJavaKeywords(pkgPart) + "." + lastPart;
}
// if we have no package part, we don't need quoting
// we add _ to run class
return Character.isLowerCase(firstChar) ? ceylonRunnableName + "_" : ceylonRunnableName;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy