Mercurial > hg > graal-jvmci-8
changeset 21517:4cc6793cda69
Make OptionProcessor create options files
author | Gilles Duboscq <gilles.m.duboscq@oracle.com> |
---|---|
date | Mon, 18 May 2015 17:59:40 +0200 |
parents | fe4a77bec5b7 |
children | c2e58b2a2a76 |
files | graal/com.oracle.graal.options.processor/src/com/oracle/graal/options/processor/OptionProcessor.java |
diffstat | 1 files changed, 40 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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