KAPT: add tests for processed types, remove dead code, simplify logic
Add integration test which checks if only types can be reprocessed in an incremental round. Also, remove unused `invalidateTypesForFiles` method. Furthermore, clarify that types that are reprocessed (i.e types from .class files) are not necessarily aggregating types, but simply types that should be reprocessed. Test: KaptIncrementalWithIsolatingApt.testClasspathChangesCauseTypesToBeReprocessed
This commit is contained in:
committed by
Mikhael Bogdanov
parent
08a2b47c77
commit
11673bd09c
@@ -45,7 +45,7 @@ object Kapt {
|
||||
kaptContext.doAnnotationProcessing(
|
||||
javaSourceFiles,
|
||||
processors.processors,
|
||||
aggregatedTypes = collectAggregatedTypes(kaptContext.sourcesToReprocess)
|
||||
binaryTypesToReprocess = collectAggregatedTypes(kaptContext.sourcesToReprocess)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -14,7 +14,6 @@ import com.sun.tools.javac.processing.JavacProcessingEnvironment
|
||||
import com.sun.tools.javac.tree.JCTree
|
||||
import org.jetbrains.kotlin.base.kapt3.KaptFlag
|
||||
import org.jetbrains.kotlin.kapt3.base.incremental.*
|
||||
import org.jetbrains.kotlin.kapt3.base.javac.KaptJavaCompiler
|
||||
import org.jetbrains.kotlin.kapt3.base.util.KaptBaseError
|
||||
import org.jetbrains.kotlin.kapt3.base.util.KaptLogger
|
||||
import org.jetbrains.kotlin.kapt3.base.util.isJava9OrLater
|
||||
@@ -33,7 +32,7 @@ fun KaptContext.doAnnotationProcessing(
|
||||
javaSourceFiles: List<File>,
|
||||
processors: List<IncrementalProcessor>,
|
||||
additionalSources: JavacList<JCTree.JCCompilationUnit> = JavacList.nil(),
|
||||
aggregatedTypes: List<String> = emptyList()
|
||||
binaryTypesToReprocess: List<String> = emptyList()
|
||||
) {
|
||||
val processingEnvironment = JavacProcessingEnvironment.instance(context)
|
||||
|
||||
@@ -41,7 +40,7 @@ fun KaptContext.doAnnotationProcessing(
|
||||
|
||||
val compilerAfterAP: JavaCompiler
|
||||
try {
|
||||
if (javaSourceFiles.isEmpty() && aggregatedTypes.isEmpty() && additionalSources.isEmpty()) {
|
||||
if (javaSourceFiles.isEmpty() && binaryTypesToReprocess.isEmpty() && additionalSources.isEmpty()) {
|
||||
if (logger.isVerbose) {
|
||||
logger.info("Skipping annotation processing as all sources are up-to-date.")
|
||||
}
|
||||
@@ -57,6 +56,7 @@ fun KaptContext.doAnnotationProcessing(
|
||||
|
||||
if (logger.isVerbose) {
|
||||
logger.info("Processing java sources with annotation processors: ${javaSourceFiles.joinToString()}")
|
||||
logger.info("Processing types with annotation processors: ${binaryTypesToReprocess.joinToString()}")
|
||||
}
|
||||
val parsedJavaFiles = parseJavaFiles(javaSourceFiles)
|
||||
|
||||
@@ -74,7 +74,7 @@ fun KaptContext.doAnnotationProcessing(
|
||||
CompileState.PARSE, compiler.enterTrees(parsedJavaFiles + additionalSources)
|
||||
)
|
||||
|
||||
val additionalClassNames = JavacList.from(aggregatedTypes)
|
||||
val additionalClassNames = JavacList.from(binaryTypesToReprocess)
|
||||
if (isJava9OrLater()) {
|
||||
val processAnnotationsMethod =
|
||||
compiler.javaClass.getMethod("processAnnotations", JavacList::class.java, java.util.Collection::class.java)
|
||||
|
||||
@@ -93,8 +93,7 @@ class JavaClassCacheManager(val file: File) : Closeable {
|
||||
javaCache.invalidateDataForTypes(impactedTypes)
|
||||
aptCache.invalidateAggregating()
|
||||
// for isolating, invalidate both own types and classpath types
|
||||
aptCache.invalidateIsolatingForOriginTypes(impactedTypes)
|
||||
aptCache.invalidateIsolatingForOriginTypes(dirtyClasspathFqNames)
|
||||
aptCache.invalidateIsolatingForOriginTypes(impactedTypes + dirtyClasspathFqNames)
|
||||
}
|
||||
|
||||
return SourcesToReprocess.Incremental(sourcesToReprocess.toList(), impactedTypes, classNamesToReprocess)
|
||||
|
||||
-11
@@ -31,17 +31,6 @@ class JavaClassCache() : Serializable {
|
||||
sourceCache[sourceStructure.sourceFile] = sourceStructure
|
||||
}
|
||||
|
||||
/** Invalidates types for these files, and return the list of invalidated types.*/
|
||||
fun invalidateTypesForFiles(files: List<File>): Set<String> {
|
||||
val typesFromFiles = HashSet<String>()
|
||||
for (file in files) {
|
||||
sourceCache.remove(file.toURI())?.getDeclaredTypes()?.let {
|
||||
typesFromFiles.addAll(it)
|
||||
}
|
||||
}
|
||||
return typesFromFiles
|
||||
}
|
||||
|
||||
/** Returns all types defined in these files. */
|
||||
fun getTypesForFiles(files: Collection<File>): Set<String> {
|
||||
val typesFromFiles = HashSet<String>(files.size)
|
||||
|
||||
Reference in New Issue
Block a user