Source:
private void writeStaticInjection(TypeElement type, List<Element> fields) throws IOException { String typeName = type.getQualifiedName().toString(); String adapterName = CodeGen.adapterName(type, STATIC_INJECTION_SUFFIX); JavaFileObject sourceFile = processingEnv.getFiler() .createSourceFile(adapterName, type); JavaWriter writer = new JavaWriter(sourceFile.openWriter()); writer.emitEndOfLineComment(ProcessorJavadocs.GENERATED_BY_DAGGER); writer.emitPackage(CodeGen.getPackage(type).getQualifiedName().toString()); writer.emitEmptyLine(); writer.emitImports(CodeGen.setOf( StaticInjection.class.getName(), Binding.class.getName(), Linker.class.getName())); writer.emitEmptyLine(); writer.emitJavadoc(ProcessorJavadocs.STATIC_INJECTION_TYPE, type.getSimpleName()); writer.beginType(adapterName, "class", PUBLIC | FINAL, StaticInjection.class.getSimpleName()); for (Element field : fields) { writer.emitField(JavaWriter.type(Binding.class, CodeGen.typeToString(field.asType())), fieldName(false, field), PRIVATE); } writer.emitEmptyLine(); writer.emitJavadoc(ProcessorJavadocs.ATTACH_METHOD); writer.emitAnnotation(Override.class); writer.beginMethod("void", "attach", PUBLIC, Linker.class.getName(), "linker"); for (Element field : fields) { writer.emitStatement( "%s = (%s) linker.requestBinding(%s, %s.class, %s.class.getClassLoader())", fieldName(false, field), writer.compressType(JavaWriter.type(Binding.class, typeToString(field.asType()))), JavaWriter.stringLiteral(GeneratorKeys.get((VariableElement) field)), typeName, adapterName); } writer.endMethod(); writer.emitEmptyLine(); writer.emitJavadoc(ProcessorJavadocs.STATIC_INJECT_METHOD); writer.emitAnnotation(Override.class); writer.beginMethod("void", "inject", PUBLIC); for (Element field : fields) { writer.emitStatement("%s.%s = %s.get()", writer.compressType(typeName), field.getSimpleName().toString(), fieldName(false, field)); } writer.endMethod(); writer.endType(); writer.close(); }

Target:
private void writeStaticInjection(TypeElement type, List<Element> fields) throws IOException { String typeName = type.getQualifiedName().toString(); String adapterName = CodeGen.adapterName(type, STATIC_INJECTION_SUFFIX); JavaFileObject sourceFile = processingEnv.getFiler() .createSourceFile(adapterName, type); JavaWriter writer = new JavaWriter(sourceFile.openWriter()); writer.emitEndOfLineComment(ProcessorJavadocs.GENERATED_BY_DAGGER); writer.emitPackage(CodeGen.getPackage(type).getQualifiedName().toString()); writer.emitEmptyLine(); writer.emitImports(CodeGen.setOf( StaticInjection.class.getName(), Binding.class.getName(), Linker.class.getName())); writer.emitEmptyLine(); writer.emitJavadoc(ProcessorJavadocs.STATIC_INJECTION_TYPE, type.getSimpleName()); writer.beginType(adapterName, "class", PUBLIC | FINAL, StaticInjection.class.getSimpleName()); for (Element field : fields) { writer.emitField(JavaWriter.type(Binding.class, CodeGen.typeToString(field.asType())), fieldName(false, field), PRIVATE); } writer.emitEmptyLine(); writer.emitJavadoc(ProcessorJavadocs.ATTACH_METHOD); writer.emitAnnotation(Override.class); writer.beginMethod("void", "attach", PUBLIC, Linker.class.getName(), "linker"); for (Element field : fields) { writer.emitStatement( "%s = (%s) linker.requestBinding(%s, %s.class, getClass().getClassLoader())", fieldName(false, field), writer.compressType(JavaWriter.type(Binding.class, typeToString(field.asType()))), JavaWriter.stringLiteral(GeneratorKeys.get((VariableElement) field)), typeName); } writer.endMethod(); writer.emitEmptyLine(); writer.emitJavadoc(ProcessorJavadocs.STATIC_INJECT_METHOD); writer.emitAnnotation(Override.class); writer.beginMethod("void", "inject", PUBLIC); for (Element field : fields) { writer.emitStatement("%s.%s = %s.get()", writer.compressType(typeName), field.getSimpleName().toString(), fieldName(false, field)); } writer.endMethod(); writer.endType(); writer.close(); }