Mercurial > hg > graal-jvmci-8
comparison 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 |
comparison
equal
deleted
inserted
replaced
21561:ce2113326bc8 | 21562:47bebae7454f |
---|---|
209 out.println("}"); | 209 out.println("}"); |
210 } | 210 } |
211 | 211 |
212 try { | 212 try { |
213 createProviderFile(pkg, optionsClassName, originatingElements); | 213 createProviderFile(pkg, optionsClassName, originatingElements); |
214 createOptionsFile(info, pkg, topDeclaringClass.toString(), originatingElements); | |
214 } catch (IOException e) { | 215 } catch (IOException e) { |
215 processingEnv.getMessager().printMessage(Kind.ERROR, e.getMessage(), info.topDeclaringType); | 216 processingEnv.getMessager().printMessage(Kind.ERROR, e.getMessage(), info.topDeclaringType); |
216 } | 217 } |
217 } | 218 } |
218 | 219 |
220 String filename = "META-INF/providers/" + pkg + "." + providerClassName; | 221 String filename = "META-INF/providers/" + pkg + "." + providerClassName; |
221 FileObject file = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", filename, originatingElements); | 222 FileObject file = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", filename, originatingElements); |
222 PrintWriter writer = new PrintWriter(new OutputStreamWriter(file.openOutputStream(), "UTF-8")); | 223 PrintWriter writer = new PrintWriter(new OutputStreamWriter(file.openOutputStream(), "UTF-8")); |
223 writer.println(Options.class.getName()); | 224 writer.println(Options.class.getName()); |
224 writer.close(); | 225 writer.close(); |
226 } | |
227 | |
228 private void createOptionsFile(OptionsInfo info, String pkg, String relativeName, Element... originatingElements) throws IOException { | |
229 String filename = "META-INF/options/" + pkg + "." + relativeName; | |
230 FileObject file = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", filename, originatingElements); | |
231 PrintWriter writer = new PrintWriter(new OutputStreamWriter(file.openOutputStream(), "UTF-8")); | |
232 Types types = processingEnv.getTypeUtils(); | |
233 for (OptionInfo option : info.options) { | |
234 String help = option.help; | |
235 if (help.indexOf('\t') >= 0 || help.indexOf('\r') >= 0 || help.indexOf('\n') >= 0) { | |
236 processingEnv.getMessager().printMessage(Kind.WARNING, "Option help should not contain '\\t', '\\r' or '\\n'", option.field); | |
237 help = help.replace('\t', ' ').replace('\n', ' ').replace('\r', ' '); | |
238 } | |
239 try { | |
240 char optionTypeToChar = optionTypeToChar(option); | |
241 String fqDeclaringClass = className(types.erasure(option.field.getEnclosingElement().asType())); | |
242 String fqFieldType = className(types.erasure(option.field.asType())); | |
243 writer.printf("%s\t%s\t%s\t%s\t%s%n", option.name, optionTypeToChar, help, fqDeclaringClass, fqFieldType); | |
244 } catch (IllegalArgumentException iae) { | |
245 } | |
246 } | |
247 writer.close(); | |
248 } | |
249 | |
250 private String className(TypeMirror t) { | |
251 DeclaredType dt = (DeclaredType) t; | |
252 return processingEnv.getElementUtils().getBinaryName((TypeElement) dt.asElement()).toString(); | |
253 } | |
254 | |
255 private char optionTypeToChar(OptionInfo option) { | |
256 switch (option.type) { | |
257 case "Boolean": | |
258 return 'z'; | |
259 case "Integer": | |
260 return 'i'; | |
261 case "Long": | |
262 return 'j'; | |
263 case "Float": | |
264 return 'f'; | |
265 case "Double": | |
266 return 'd'; | |
267 case "String": | |
268 return 's'; | |
269 default: | |
270 processingEnv.getMessager().printMessage(Kind.ERROR, "Unsoported option type: " + option.type, option.field); | |
271 throw new IllegalArgumentException(); | |
272 } | |
225 } | 273 } |
226 | 274 |
227 protected PrintWriter createSourceFile(String pkg, String relativeName, Filer filer, Element... originatingElements) { | 275 protected PrintWriter createSourceFile(String pkg, String relativeName, Filer filer, Element... originatingElements) { |
228 try { | 276 try { |
229 // Ensure Unix line endings to comply with code style guide checked by Checkstyle | 277 // Ensure Unix line endings to comply with code style guide checked by Checkstyle |