Remove source annotations when copy class with kapt2

Writing source annotations enables incremental compilation for kapt2.
However they are not needed in bytecode, so we remove them when
copying classes.

# Conflicts:
#	compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt
#	compiler/frontend.java/src/org/jetbrains/kotlin/config/JVMConfigurationKeys.java
This commit is contained in:
Alexey Tsvetkov
2016-09-06 15:55:03 +03:00
parent 5534350fd6
commit 6ebb50751c
25 changed files with 377 additions and 78 deletions
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
import org.jetbrains.kotlin.config.APPEND_JAVA_SOURCE_ROOTS_HANDLER_KEY
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.fileClasses.NoResolveFileClassesProvider
import org.jetbrains.kotlin.incremental.components.SourceRetentionAnnotationHandler
import org.jetbrains.kotlin.java.model.elements.JeTypeElement
import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
@@ -51,10 +52,10 @@ class ClasspathBasedAnnotationProcessingExtension(
javaSourceRoots: List<File>,
verboseOutput: Boolean,
incrementalDataFile: File?,
incrementalCompilationComponents: IncrementalCompilationComponents?
sourceRetentionAnnotationHandler: SourceRetentionAnnotationHandler?
) : AbstractAnnotationProcessingExtension(generatedSourcesOutputDir,
classesOutputDir, javaSourceRoots, verboseOutput,
incrementalDataFile, incrementalCompilationComponents) {
incrementalDataFile, sourceRetentionAnnotationHandler) {
override fun loadAnnotationProcessors(): List<Processor> {
val classLoader = URLClassLoader(annotationProcessingClasspath.map { it.toURI().toURL() }.toTypedArray())
return ServiceLoader.load(Processor::class.java, classLoader).toList()
@@ -67,7 +68,7 @@ abstract class AbstractAnnotationProcessingExtension(
val javaSourceRoots: List<File>,
val verboseOutput: Boolean,
val incrementalDataFile: File? = null,
val incrementalCompilationComponents: IncrementalCompilationComponents? = null
val sourceRetentionAnnotationHandler: SourceRetentionAnnotationHandler? = null
) : AnalysisCompletedHandlerExtension {
private companion object {
val LINE_SEPARATOR = System.getProperty("line.separator") ?: "\n"
@@ -170,7 +171,7 @@ abstract class AbstractAnnotationProcessingExtension(
}
val firstRoundAnnotations = RoundAnnotations(
incrementalCompilationComponents?.getSourceRetentionAnnotationHandler(),
sourceRetentionAnnotationHandler,
bindingContext,
createTypeMapper())
@@ -122,11 +122,11 @@ class AnnotationProcessingComponentRegistrar : ComponentRegistrar {
// Annotations with the "SOURCE" retention will be written to class files
project.putUserData(IS_KAPT2_ENABLED_KEY, true)
val incrementalCompilationComponents = configuration[JVMConfigurationKeys.INCREMENTAL_COMPILATION_COMPONENTS]
val sourceRetentionAnnotationHandler = configuration[JVMConfigurationKeys.SOURCE_RETENTION_ANNOTATION_HANDLER]
val annotationProcessingExtension = ClasspathBasedAnnotationProcessingExtension(
classpath, generatedOutputDirFile, classesOutputDir, javaRoots, verboseOutput,
incrementalDataFile, incrementalCompilationComponents)
incrementalDataFile, sourceRetentionAnnotationHandler)
AnalysisCompletedHandlerExtension.registerExtension(project, annotationProcessingExtension)
}