diff --git a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/ProcessorLoader.kt b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/ProcessorLoader.kt index 83c3fac2c0d..4a6948580b9 100644 --- a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/ProcessorLoader.kt +++ b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/ProcessorLoader.kt @@ -64,10 +64,15 @@ open class ProcessorLoader(private val options: KaptOptions, private val logger: val processorsInfo: Map = getIncrementalProcessorsFromClasspath(processorNames, classpath) val nonIncremental = processorNames.filter { !processorsInfo.containsKey(it) } - return if (nonIncremental.isNotEmpty()) { - processors.map { IncrementalProcessor(it, DeclaredProcType.NON_INCREMENTAL) } - } else { - processors.map { IncrementalProcessor(it, processorsInfo.getValue(it.javaClass.name)) } + return processors.map { + val procType = processorsInfo[it.javaClass.name]?.let { + if (nonIncremental.isEmpty()) { + it + } else { + DeclaredProcType.INCREMENTAL_BUT_OTHER_APS_ARE_NOT + } + } ?: DeclaredProcType.NON_INCREMENTAL + IncrementalProcessor(it, procType) } } diff --git a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/annotationProcessing.kt b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/annotationProcessing.kt index 0d6c3a15d05..87ccacec835 100644 --- a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/annotationProcessing.kt +++ b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/annotationProcessing.kt @@ -13,7 +13,9 @@ import com.sun.tools.javac.processing.JavacFiler 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.incremental.GeneratedTypesTaskListener +import org.jetbrains.kotlin.kapt3.base.incremental.IncrementalProcessor +import org.jetbrains.kotlin.kapt3.base.incremental.MentionedTypesTaskListener import org.jetbrains.kotlin.kapt3.base.util.KaptBaseError import org.jetbrains.kotlin.kapt3.base.util.isJava9OrLater import org.jetbrains.kotlin.kapt3.base.util.measureTimeMillisWithResult @@ -51,7 +53,7 @@ fun KaptContext.doAnnotationProcessing( val parsedJavaFiles = parseJavaFiles(javaSourceFiles) val sourcesStructureListener = cacheManager?.let { - if (processors.any { it.kind == DeclaredProcType.NON_INCREMENTAL }) return@let null + if (processors.any { it.isUnableToRunIncrementally() }) return@let null val recordTypesListener = MentionedTypesTaskListener(cacheManager.javaCache, processingEnvironment.elementUtils, Trees.instance(processingEnvironment)) compiler.getTaskListeners().add(recordTypesListener) @@ -89,13 +91,15 @@ fun KaptContext.doAnnotationProcessing( logger.info("Analyzing sources structure took ${it.time}[ms].") } } - if (cacheManager != null && processors.any { it.getRuntimeType() == RuntimeProcType.NON_INCREMENTAL }) { - val nonIncremental = - processors.filter { it.getRuntimeType() == RuntimeProcType.NON_INCREMENTAL }.map { it.processorName } - logger.warn( - "Incremental annotation processing requested, but support is disabled because the following " + - "processors are not incremental: ${nonIncremental.joinToString()}." - ) + if (cacheManager != null) { + val missingIncrementalSupport = processors.filter { it.isMissingIncrementalSupport() } + if (missingIncrementalSupport.isNotEmpty()) { + val nonIncremental = missingIncrementalSupport.map { "${it.processorName} (${it.incrementalSupportType})" } + logger.warn( + "Incremental annotation processing requested, but support is disabled because the following " + + "processors are not incremental: ${nonIncremental.joinToString()}." + ) + } } val log = compilerAfterAP.log diff --git a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/incremental/incrementalProcessors.kt b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/incremental/incrementalProcessors.kt index a158f9be8ce..f418495b9fc 100644 --- a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/incremental/incrementalProcessors.kt +++ b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/incremental/incrementalProcessors.kt @@ -19,14 +19,15 @@ import javax.tools.JavaFileObject private val ALLOWED_RUNTIME_TYPES = setOf(RuntimeProcType.AGGREGATING.name, RuntimeProcType.ISOLATING.name) -class IncrementalProcessor(private val processor: Processor, val kind: DeclaredProcType) : Processor by processor { +class IncrementalProcessor(private val processor: Processor, private val kind: DeclaredProcType) : Processor by processor { private var dependencyCollector = lazy { createDependencyCollector() } val processorName: String = processor.javaClass.name + val incrementalSupportType: String = kind.name override fun init(processingEnv: ProcessingEnvironment) { - if (kind == DeclaredProcType.NON_INCREMENTAL) { + if (!kind.canRunIncrementally) { processor.init(processingEnv) } else { val originalFiler = processingEnv.filer @@ -58,6 +59,12 @@ class IncrementalProcessor(private val processor: Processor, val kind: DeclaredP return AnnotationProcessorDependencyCollector(type) } + fun isMissingIncrementalSupport(): Boolean { + if (kind == DeclaredProcType.NON_INCREMENTAL) return true + + return kind == DeclaredProcType.DYNAMIC && getRuntimeType() == RuntimeProcType.NON_INCREMENTAL + } + fun isUnableToRunIncrementally() = !kind.canRunIncrementally fun getGeneratedToSources() = dependencyCollector.value.getGeneratedToSources() fun getRuntimeType(): RuntimeProcType = dependencyCollector.value.getRuntimeType() } @@ -137,19 +144,23 @@ private fun getSrcFiles(elements: Array): Set { }.toSet() } -enum class DeclaredProcType { - AGGREGATING { +enum class DeclaredProcType(val canRunIncrementally: Boolean) { + AGGREGATING(true) { override fun toRuntimeType() = RuntimeProcType.AGGREGATING }, - ISOLATING { + ISOLATING(true) { override fun toRuntimeType() = RuntimeProcType.ISOLATING }, - DYNAMIC { + DYNAMIC(true) { override fun toRuntimeType() = throw IllegalStateException("This should not be used") }, - NON_INCREMENTAL { + NON_INCREMENTAL(false) { override fun toRuntimeType() = RuntimeProcType.NON_INCREMENTAL - }; + }, + INCREMENTAL_BUT_OTHER_APS_ARE_NOT(false) { + override fun toRuntimeType() = RuntimeProcType.NON_INCREMENTAL + }, + ; abstract fun toRuntimeType(): RuntimeProcType }