# HG changeset patch # User Gilles Duboscq # Date 1431964780 -7200 # Node ID 4cc6793cda6909add70145c60ad4ea3911a5413e # Parent fe4a77bec5b7913d8d0167a05ed21a796bcd7969 Make OptionProcessor create options files diff -r fe4a77bec5b7 -r 4cc6793cda69 graal/com.oracle.graal.options.processor/src/com/oracle/graal/options/processor/OptionProcessor.java --- a/graal/com.oracle.graal.options.processor/src/com/oracle/graal/options/processor/OptionProcessor.java Thu May 07 16:59:34 2015 +0200 +++ b/graal/com.oracle.graal.options.processor/src/com/oracle/graal/options/processor/OptionProcessor.java Mon May 18 17:59:40 2015 +0200 @@ -211,6 +211,7 @@ try { createProviderFile(pkg, optionsClassName, originatingElements); + createOptionsFile(info, pkg, topDeclaringClass.toString(), originatingElements); } catch (IOException e) { processingEnv.getMessager().printMessage(Kind.ERROR, e.getMessage(), info.topDeclaringType); } @@ -224,6 +225,45 @@ writer.close(); } + private void createOptionsFile(OptionsInfo info, String pkg, String relativeName, Element... originatingElements) throws IOException { + String filename = "META-INF/options/" + pkg + "." + relativeName; + FileObject file = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", filename, originatingElements); + PrintWriter writer = new PrintWriter(new OutputStreamWriter(file.openOutputStream(), "UTF-8")); + for (OptionInfo option : info.options) { + String help = option.help; + if (help.indexOf('\t') >= 0 || help.indexOf('\r') >= 0 || help.indexOf('\n') >= 0) { + processingEnv.getMessager().printMessage(Kind.WARNING, "Option help should not contain '\\t', '\\r' or '\\n'", option.field); + help = help.replace('\t', ' ').replace('\n', ' ').replace('\r', ' '); + } + try { + char optionTypeToChar = optionTypeToChar(option); + writer.printf("%s\t%s\t%s%n", option.name, optionTypeToChar, help); + } catch (IllegalArgumentException iae) { + } + } + writer.close(); + } + + private char optionTypeToChar(OptionInfo option) { + switch (option.type) { + case "Boolean": + return 'z'; + case "Integer": + return 'i'; + case "Long": + return 'j'; + case "Float": + return 'f'; + case "Double": + return 'd'; + case "String": + return 's'; + default: + processingEnv.getMessager().printMessage(Kind.ERROR, "Unsoported option type: " + option.type, option.field); + throw new IllegalArgumentException(); + } + } + protected PrintWriter createSourceFile(String pkg, String relativeName, Filer filer, Element... originatingElements) { try { // Ensure Unix line endings to comply with Graal code style guide checked by Checkstyle