use of org.graalvm.options.OptionCategory in project graal by oracle.
the class OptionProcessor method processElement.
private boolean processElement(Element element, AnnotationMirror elementAnnotation, OptionsInfo info) {
ProcessorContext context = ProcessorContext.getInstance();
if (!element.getModifiers().contains(Modifier.STATIC)) {
error(element, elementAnnotation, "Option field must be static");
return false;
}
if (element.getModifiers().contains(Modifier.PRIVATE)) {
error(element, elementAnnotation, "Option field cannot be private");
return false;
}
String[] groupPrefixStrings = null;
Option.Group prefix = info.type.getAnnotation(Option.Group.class);
if (prefix != null) {
groupPrefixStrings = prefix.value();
} else {
TypeMirror erasedTruffleType = context.getEnvironment().getTypeUtils().erasure(context.getType(TruffleLanguage.class));
if (context.getEnvironment().getTypeUtils().isAssignable(info.type.asType(), erasedTruffleType)) {
TruffleLanguage.Registration registration = info.type.getAnnotation(TruffleLanguage.Registration.class);
if (registration != null) {
groupPrefixStrings = new String[] { registration.id() };
if (groupPrefixStrings[0].isEmpty()) {
error(element, elementAnnotation, "%s must specify an id such that Truffle options can infer their prefix.", TruffleLanguage.Registration.class.getSimpleName());
return false;
}
}
} else if (context.getEnvironment().getTypeUtils().isAssignable(info.type.asType(), context.getType(TruffleInstrument.class))) {
TruffleInstrument.Registration registration = info.type.getAnnotation(TruffleInstrument.Registration.class);
if (registration != null) {
groupPrefixStrings = new String[] { registration.id() };
if (groupPrefixStrings[0].isEmpty()) {
error(element, elementAnnotation, "%s must specify an id such that Truffle options can infer their prefix.", TruffleInstrument.Registration.class.getSimpleName());
return false;
}
}
}
}
if (groupPrefixStrings == null || groupPrefixStrings.length == 0) {
groupPrefixStrings = new String[] { "" };
}
Option annotation = element.getAnnotation(Option.class);
assert annotation != null;
assert element instanceof VariableElement;
assert element.getKind() == ElementKind.FIELD;
VariableElement field = (VariableElement) element;
String fieldName = field.getSimpleName().toString();
Elements elements = processingEnv.getElementUtils();
Types types = processingEnv.getTypeUtils();
TypeMirror fieldType = field.asType();
if (fieldType.getKind() != TypeKind.DECLARED) {
error(element, elementAnnotation, "Option field must be of type " + OptionKey.class.getName());
return false;
}
TypeMirror optionKeyType = elements.getTypeElement(OptionKey.class.getName()).asType();
if (!types.isSubtype(fieldType, types.erasure(optionKeyType))) {
error(element, elementAnnotation, "Option field type %s is not a subclass of %s", fieldType, optionKeyType);
return false;
}
if (!field.getModifiers().contains(Modifier.STATIC)) {
error(element, elementAnnotation, "Option field must be static");
return false;
}
if (field.getModifiers().contains(Modifier.PRIVATE)) {
error(element, elementAnnotation, "Option field cannot be private");
return false;
}
String help = annotation.help();
if (help.length() != 0) {
char firstChar = help.charAt(0);
if (!Character.isUpperCase(firstChar)) {
error(element, elementAnnotation, "Option help text must start with upper case letter");
return false;
}
}
AnnotationValue value = ElementUtils.getAnnotationValue(elementAnnotation, "name", false);
String optionName;
if (value == null) {
optionName = fieldName;
} else {
optionName = annotation.name();
}
if (!optionName.isEmpty() && !Character.isUpperCase(optionName.charAt(0))) {
error(element, elementAnnotation, "Option names must start with capital letter");
return false;
}
boolean deprecated = annotation.deprecated();
OptionCategory category = annotation.category();
if (category == null) {
category = OptionCategory.DEBUG;
}
for (String group : groupPrefixStrings) {
String name;
if (group.isEmpty() && optionName.isEmpty()) {
error(element, elementAnnotation, "Both group and option name cannot be empty");
continue;
} else if (optionName.isEmpty()) {
name = group;
} else {
if (group.isEmpty()) {
name = optionName;
} else {
name = group + "." + optionName;
}
}
info.options.add(new OptionInfo(name, help, field, elementAnnotation, deprecated, category));
}
return true;
}
use of org.graalvm.options.OptionCategory in project graal by oracle.
the class Launcher method runPolyglotAction.
@SuppressWarnings("fallthrough")
final boolean runPolyglotAction() {
OptionCategory helpCategory = helpDebug ? OptionCategory.DEBUG : (helpExpert ? OptionCategory.EXPERT : OptionCategory.USER);
switch(versionAction) {
case PrintAndContinue:
printPolyglotVersions();
// fall through
case None:
break;
case PrintAndExit:
printPolyglotVersions();
return true;
}
boolean printDefaultHelp = help || ((helpExpert || helpDebug) && !helpTools && !helpLanguages);
if (printDefaultHelp) {
printHelp(helpCategory);
// @formatter:off
System.out.println();
System.out.println("Runtime Options:");
printOption("--polyglot", "Run with all other guest languages accessible.");
printOption("--native", "Run using the native launcher with limited Java access" + (this.getDefaultVMType() == VMType.Native ? " (default)" : "") + ".");
printOption("--native.[option]", "Pass options to the native image. To see available options, use '--native.help'.");
printOption("--jvm", "Run on the Java Virtual Machine with Java access" + (this.getDefaultVMType() == VMType.JVM ? " (default)" : "") + ".");
printOption("--jvm.[option]", "Pass options to the JVM; for example, '--jvm.classpath=myapp.jar'. To see available options. use '--jvm.help'.");
printOption("--help", "Print this help message.");
printOption("--help:languages", "Print options for all installed languages.");
printOption("--help:tools", "Print options for all installed tools.");
printOption("--help:expert", "Print additional options for experts.");
if (helpExpert || helpDebug) {
printOption("--help:debug", "Print additional options for debugging.");
}
printOption("--version:graalvm", "Print GraalVM version information and exit.");
printOption("--show-version:graalvm", "Print GraalVM version information and continue execution.");
// @formatter:on
List<PrintableOption> engineOptions = new ArrayList<>();
for (OptionDescriptor descriptor : getTempEngine().getOptions()) {
if (!descriptor.getName().startsWith("engine.") && !descriptor.getName().startsWith("compiler.")) {
continue;
}
if (descriptor.getCategory().ordinal() == helpCategory.ordinal()) {
engineOptions.add(asPrintableOption(descriptor));
}
}
if (!engineOptions.isEmpty()) {
printOptions(engineOptions, "Engine options:", 2);
}
}
if (helpLanguages) {
printLanguageOptions(getTempEngine(), helpCategory);
}
if (helpTools) {
printInstrumentOptions(getTempEngine(), helpCategory);
}
if (printDefaultHelp || helpLanguages || helpTools) {
System.out.println("\nSee http://www.graalvm.org for more information.");
return true;
}
return false;
}
Aggregations