Mercurial > hg > graal-jvmci-8
diff graal/com.oracle.jvmci.options.processor/src/com/oracle/jvmci/options/processor/OptionProcessor.java @ 21562:47bebae7454f
Merge.
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 28 May 2015 21:58:33 +0200 |
parents | graal/com.oracle.graal.options.processor/src/com/oracle/graal/options/processor/OptionProcessor.java@cecb4e39521c graal/com.oracle.graal.options.processor/src/com/oracle/graal/options/processor/OptionProcessor.java@d563baeca9df |
children |
line wrap: on
line diff
--- a/graal/com.oracle.jvmci.options.processor/src/com/oracle/jvmci/options/processor/OptionProcessor.java Thu May 28 17:13:22 2015 +0200 +++ b/graal/com.oracle.jvmci.options.processor/src/com/oracle/jvmci/options/processor/OptionProcessor.java Thu May 28 21:58:33 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,53 @@ 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")); + Types types = processingEnv.getTypeUtils(); + 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); + String fqDeclaringClass = className(types.erasure(option.field.getEnclosingElement().asType())); + String fqFieldType = className(types.erasure(option.field.asType())); + writer.printf("%s\t%s\t%s\t%s\t%s%n", option.name, optionTypeToChar, help, fqDeclaringClass, fqFieldType); + } catch (IllegalArgumentException iae) { + } + } + writer.close(); + } + + private String className(TypeMirror t) { + DeclaredType dt = (DeclaredType) t; + return processingEnv.getElementUtils().getBinaryName((TypeElement) dt.asElement()).toString(); + } + + 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 code style guide checked by Checkstyle