void complete() { CharSequence sourceCode = extractSourceCode(); try { JavaFileObject sourceFile = key.originatingElement != null ? getFiler().createSourceFile(key.toString(), key.originatingElement) : getFiler().createSourceFile(key.toString()); try (Writer writer = sourceFile.openWriter()) { writer.append(sourceCode); } } catch (FilerException ex) { if (identicalFileIsAlreadyGenerated(sourceCode)) { getMessager().printMessage(Kind.MANDATORY_WARNING, "Regenerated file with the same content: " + key); } else { getMessager().printMessage(Kind.MANDATORY_WARNING, String.format( "Generated source file name colission. Attempt to overwrite already generated file: %s, %s." + " If this happens when using @Value.Immutable on same-named nested classes in the same package," + " use can use @Value.Enclosing annotation to provide some sort of namespacing", key, ex)); } } catch (IOException ex) { throw Throwables.propagate(ex); } }
@Override public Invokable invoke(Invokation invokation, Object... parameters) { String packageName = parameters[0].toString(); String simpleName = parameters[1].toString(); Element originatingElement = (Element) parameters[2]; Invokable body = (Invokable) parameters[3]; ResourceKey key = new ResourceKey(packageName, simpleName, Delegates.unwrap(originatingElement)); SourceFile javaFile = getFiles().sourceFiles.get(key); body.invoke(new Invokation(javaFile.consumer)); javaFile.complete(); return null; } };
@Override public Invokable invoke(Invokation invokation, Object... parameters) { String interfaceName = parameters[0].toString(); Invokable body = (Invokable) parameters[1]; ResourceKey key = new ResourceKey("", META_INF_SERVICES + interfaceName); AppendServiceFile servicesFile = getFiles().appendResourceFiles.get(key); body.invoke(new Invokation(servicesFile.consumer)); return null; } };