Diagnostic.Kind.ERROR, "Problem with Filer: " + filerEx.getMessage() );
@Override public OutputStream openBinary(JPackage pkg, String fileName) throws IOException { String qualifiedClassName = toQualifiedClassName(pkg, fileName); LOGGER.debug("Generating class: {}", qualifiedClassName); Element[] classOriginatingElements = originatingElements.getClassOriginatingElements(qualifiedClassName); try { JavaFileObject sourceFile; if (classOriginatingElements.length == 0) { LOGGER.info("Generating class with no originating element: {}", qualifiedClassName); } sourceFile = filer.createSourceFile(qualifiedClassName, classOriginatingElements); return sourceFile.openOutputStream(); } catch (FilerException e) { LOGGER.error("Could not generate source file for {} due to error: {}", qualifiedClassName, e.getMessage()); /* * This exception is expected, when some files are created twice. We cannot * delete existing files, unless using a dirty hack. Files a created twice when * the same file is created from different annotation rounds. Happens when * renaming classes, and for Background executor. It also probably means I * didn't fully understand how annotation processing works. If anyone can point * me out... */ return VOID_OUTPUT_STREAM; } }
processingEnv.getMessager().printMessage( Kind.WARNING, "Error producing Builder: " + e.getMessage(), type, findAnnotationMirror(type, "org.inferred.freebuilder.FreeBuilder").get());
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (abortProcessing.get() == Boolean.TRUE) { // Another instance of AutoDelegateProcessor is running in the current processing environment. return false; } Set<String> generatedTypes = new HashSet<>(); for (Element annotatedElement : roundEnv.getElementsAnnotatedWith(AutoDelegate.class)) { try { validateAnnotatedElement(annotatedElement); TypeElement typeElement = (TypeElement) annotatedElement; TypeToExtend typeToExtend = createTypeToExtend(typeElement); if (generatedTypes.contains(typeToExtend.getCanonicalName())) { continue; } generatedTypes.add(typeToExtend.getCanonicalName()); generateCode(typeToExtend); } catch (FilerException e) { // Happens when same file is written twice. warn(annotatedElement, e.getMessage()); } catch (ProcessingException e) { error(e.getElement(), e.getMessage()); } catch (IOException | RuntimeException e) { error(annotatedElement, e.getMessage()); } } return false; }
public String filePath(Location location, TypeElement element) { try { String qualifiedName = element.asType().toString(); String fileName = qualifiedName.replace(".", FILE_SEPARATOR); Filer filer = environment.getFiler(); FileObject file = filer.getResource(location, "", fileName + ".java"); return file.toUri().getPath(); } catch (FilerException e) { // this is clearly very weak... String message = e.getMessage(); return message.substring(message.indexOf(FILE_SEPARATOR)); } catch (IOException e) { throw new UncheckedIOException(e); } }
public String filePath(Location location, TypeElement element) { try { String qualifiedName = element.asType().toString(); String fileName = qualifiedName.replace(".", FILE_SEPARATOR); Filer filer = environment.getFiler(); FileObject file = filer.getResource(location, "", fileName + ".java"); return file.toUri().getPath(); } catch (FilerException e) { // this is clearly very weak... String message = e.getMessage(); return message.substring(message.indexOf(FILE_SEPARATOR)); } catch (IOException e) { throw new UncheckedIOException(e); } }
public String filePath(Location location, TypeElement element) { try { String qualifiedName = element.asType().toString(); String fileName = qualifiedName.replace(".", FILE_SEPARATOR); Filer filer = environment.getFiler(); FileObject file = filer.getResource(location, "", fileName + ".java"); return file.toUri().getPath(); } catch (FilerException e) { // this is clearly very weak... String message = e.getMessage(); return message.substring(message.indexOf(FILE_SEPARATOR)); } catch (IOException e) { throw new UncheckedIOException(e); } }
@Override public void init(ProcessingEnvironment pe) { super.init(pe); messager = pe.getMessager(); filer = pe.getFiler(); if (filer == null) messager.printMessage(Kind.ERROR, "No filer!"); // create the batch.xml try { if (logger.isLoggable(Level.FINE)) { logger.fine("Overwriting " + BATCHXML); } resourceFile = filer.createResource(StandardLocation.CLASS_OUTPUT, "", BATCHXML, (Element[]) null); if (logger.isLoggable(Level.FINE)) { logger.fine("Successfully overwrote " + BATCHXML); } } catch (FilerException e) { if (logger.isLoggable(Level.SEVERE)) { logger.severe("Cannot create " + BATCHXML + " :" + e.getMessage()); } throw new IllegalStateException(e); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public OutputStream openBinary(JPackage pkg, String fileName) throws IOException { String qualifiedClassName = toQualifiedClassName(pkg, fileName); message.printMessage(Kind.NOTE, "Generating source file: " + qualifiedClassName); Element originatingElement = originatingElementsByGeneratedClassQualifiedName.get(qualifiedClassName); try { JavaFileObject sourceFile; if (originatingElement != null) { sourceFile = filer.createSourceFile(qualifiedClassName, originatingElement); } else { message.printMessage(Kind.NOTE, "Generating class with no originating element: " + qualifiedClassName); sourceFile = filer.createSourceFile(qualifiedClassName); } return sourceFile.openOutputStream(); } catch (FilerException e) { message.printMessage(Kind.NOTE, "Could not generate source file for " + qualifiedClassName + ", message: " + e.getMessage()); /* * This exception is expected, when some files are created twice. We * cannot delete existing files, unless using a dirty hack. Files a * created twice when the same file is created from different * annotation rounds. Happens when renaming classes, and for * Background executor. It also probably means I didn't fully * understand how annotation processing works. If anyone can point * me out... */ return VOID_OUTPUT_STREAM; } }
public void writeXSD(Model m) throws IOException { try { for (MainInfo main : m.getMains()) { List<Element> sources = new ArrayList<Element>(); sources.add(main.getElement()); sources.addAll(main.getInterceptorElements()); FileObject o = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, main.getAnnotation().outputPackage(), main.getAnnotation().outputName(), sources.toArray(new Element[0])); BufferedWriter bw = new BufferedWriter(o.openWriter()); try { assembleXSD(bw, m, main); } finally { bw.close(); } } } catch (FilerException e) { if (e.getMessage().contains("Source file already created")) return; throw e; } }
Diagnostic.Kind.ERROR, "Problem with Filer: " + filerEx.getMessage() );
processingEnv.getMessager().printMessage( Kind.WARNING, "Error producing Builder: " + e.getMessage(), type, findAnnotationMirror(type, "org.inferred.freebuilder.FreeBuilder").get());
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (abortProcessing.get() == Boolean.TRUE) { // Another instance of AutoDelegateProcessor is running in the current processing environment. return false; } Set<String> generatedTypes = new HashSet<>(); for (Element annotatedElement : roundEnv.getElementsAnnotatedWith(AutoDelegate.class)) { try { validateAnnotatedElement(annotatedElement); TypeElement typeElement = (TypeElement) annotatedElement; TypeToExtend typeToExtend = createTypeToExtend(typeElement); if (generatedTypes.contains(typeToExtend.getCanonicalName())) { continue; } generatedTypes.add(typeToExtend.getCanonicalName()); generateCode(typeToExtend); } catch (FilerException e) { // Happens when same file is written twice. warn(annotatedElement, e.getMessage()); } catch (ProcessingException e) { error(e.getElement(), e.getMessage()); } catch (IOException | RuntimeException e) { error(annotatedElement, e.getMessage()); } } return false; }
@Override public OutputStream openBinary(JPackage pkg, String fileName) throws IOException { String qualifiedClassName = toQualifiedClassName(pkg, fileName); LOGGER.debug("Generating class: {}", qualifiedClassName); Element[] classOriginatingElements = originatingElements.getClassOriginatingElements(qualifiedClassName); try { JavaFileObject sourceFile; if (classOriginatingElements.length == 0) { LOGGER.info("Generating class with no originating element: {}", qualifiedClassName); } sourceFile = filer.createSourceFile(qualifiedClassName, classOriginatingElements); return sourceFile.openOutputStream(); } catch (FilerException e) { LOGGER.error("Could not generate source file for {} due to error: {}", qualifiedClassName, e.getMessage()); /* * This exception is expected, when some files are created twice. We cannot * delete existing files, unless using a dirty hack. Files a created twice when * the same file is created from different annotation rounds. Happens when * renaming classes, and for Background executor. It also probably means I * didn't fully understand how annotation processing works. If anyone can point * me out... */ return VOID_OUTPUT_STREAM; } }
if (e.getMessage().contains("Source file already created")) return; throw e;
if (e.getMessage().contains("Source file already created")) return; throw e;
if (e.getMessage().contains("Source file already created")) return; throw e;
if (e.getMessage().contains("Source file already created")) return; throw e;
System.err.println(ex.getMessage()); // propably duplicate ?