This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
messager.printMessage(Diagnostic.Kind.ERROR, message, element); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String providerName = enclosing.getSimpleName().toString() + "Provider"; | |
PackageElement pkg = elementUtils.getPackageOf(enclosing); | |
String packageName = pkg.isUnnamed() ? "" : pkg.getQualifiedName().toString(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implementation 'com.squareup:javapoet:1.9.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TypeSpec.Builder classBuilder = TypeSpec.classBuilder(providerName) | |
.addModifiers(Modifier.PUBLIC, Modifier.FINAL); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MethodSpec.Builder provideFuncBuilder = MethodSpec.methodBuilder("provide") | |
.addModifiers(Modifier.PUBLIC, Modifier.STATIC) | |
.addParameter(ClassName.get(enclosing.asType()),"dependant"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
provideFuncBuilder.addParameter(ClassName.get(field.asType()), fieldName); | |
provideFuncBuilder.addStatement("dependant.$L = $L", fieldName, fieldName); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
classBuilder.addMethod(provideFuncBuilder.build()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JavaFile.builder(packageName, classBuilder.build()).build().writeTo(filer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
annotationProcessor project(':processor') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MainActivityProvider.provide(this, "John Smith"); |