-
public interface CodeGeneratorCodeGenerator creates and manages files.
Files created by CodeGenerator are considered in incremental processing. Kotlin and Java files will be compiled together with other source files in the module. Files created without using this API will not participate in incremental processing nor subsequent compilations.
-
-
Method Summary
Modifier and Type Method Description abstract OutputStreamcreateNewFile(Dependencies dependencies, String packageName, String fileName, String extensionName)Creates a file which is managed by CodeGeneratorSources of corresponding KSNodes which are obtained directly from Resolver need to be specified. abstract Unitassociate(List<KSFile> sources, String packageName, String fileName, String extensionName)Associate sources to an output file. abstract UnitassociateWithClasses(List<KSClassDeclaration> classes, String packageName, String fileName, String extensionName)Associate classes to an output file. abstract Collection<File>getGeneratedFile()-
-
Method Detail
-
createNewFile
abstract OutputStream createNewFile(Dependencies dependencies, String packageName, String fileName, String extensionName)
Creates a file which is managed by CodeGenerator
Sources of corresponding KSNodes which are obtained directly from Resolver need to be specified. Namely, the containing files of those KSNodes who are obtained from:
Instead of requiring processors to specify all source files which are relevant in generating the given output, KSP traces dependencies automatically and only needs to know those sources that only processors know what they are for. If a KSFile is indirectly obtained through other KSNodes, it hasn't to be specified for the given output, even if its contents contribute to the generation of the output.
For example, a processor generates an output
Oafter reading classAinA.ktand classBinB.kt, whereAextendsB. The processor gotAby Resolver.getSymbolsWithAnnotation and then gotBby KSClassDeclaration.superTypes fromA. Because the inclusion ofBis due toA,B.ktneedn't to be specified in dependencies forO. Note that specifyingB.ktin this case doesn't hurt, it is only unnecessary.- Parameters:
dependencies- are KSFiles from which this output is built.packageName- corresponds to the relative path of the generated file; using either '.'or '/' as separator.fileName- file nameextensionName- If "kt" or "java", this file will participate in subsequent compilation.
-
associate
abstract Unit associate(List<KSFile> sources, String packageName, String fileName, String extensionName)
Associate sources to an output file.
- Parameters:
sources- are KSFiles from which this output is built.packageName- corresponds to the relative path of the generated file; using either '.'or '/' as separator.fileName- file nameextensionName- If "kt" or "java", this file will participate in subsequent compilation.
-
associateWithClasses
abstract Unit associateWithClasses(List<KSClassDeclaration> classes, String packageName, String fileName, String extensionName)
Associate classes to an output file.
- Parameters:
classes- are KSClassDeclarations from which this output is built.packageName- corresponds to the relative path of the generated file; using either '.'or '/' as separator.fileName- file nameextensionName- If "kt" or "java", this file will participate in subsequent compilation.
-
getGeneratedFile
abstract Collection<File> getGeneratedFile()
-
-
-
-