Remove source annotations removing (not needed with KAPT3)

This commit is contained in:
Alexey Tsvetkov
2016-12-13 13:46:30 +03:00
parent 190c038ad8
commit 4fdca24db4
21 changed files with 14 additions and 398 deletions
@@ -34,7 +34,6 @@ 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.psi.KtFile
@@ -56,11 +55,10 @@ class ClasspathBasedAnnotationProcessingExtension(
classesOutputDir: File,
javaSourceRoots: List<File>,
verboseOutput: Boolean,
incrementalDataFile: File?,
sourceRetentionAnnotationHandler: SourceRetentionAnnotationHandler?
) : AbstractAnnotationProcessingExtension(generatedSourcesOutputDir,
incrementalDataFile: File?
) : AbstractAnnotationProcessingExtension(generatedSourcesOutputDir,
classesOutputDir, javaSourceRoots, verboseOutput,
incrementalDataFile, sourceRetentionAnnotationHandler) {
incrementalDataFile) {
override fun loadAnnotationProcessors(): List<Processor> {
val classLoader = URLClassLoader(annotationProcessingClasspath.map { it.toURI().toURL() }.toTypedArray())
return ServiceLoader.load(Processor::class.java, classLoader).toList()
@@ -72,8 +70,7 @@ abstract class AbstractAnnotationProcessingExtension(
val classesOutputDir: File,
val javaSourceRoots: List<File>,
val verboseOutput: Boolean,
val incrementalDataFile: File? = null,
val sourceRetentionAnnotationHandler: SourceRetentionAnnotationHandler? = null
val incrementalDataFile: File? = null
) : AnalysisHandlerExtension {
private companion object {
val LINE_SEPARATOR = System.getProperty("line.separator") ?: "\n"
@@ -201,7 +198,6 @@ abstract class AbstractAnnotationProcessingExtension(
}
val firstRoundAnnotations = RoundAnnotations(
sourceRetentionAnnotationHandler,
bindingContext(),
createTypeMapper())
@@ -141,12 +141,10 @@ class AnnotationProcessingComponentRegistrar : ComponentRegistrar {
// Annotations with the "SOURCE" retention will be written to class files
project.putUserData(IS_KAPT2_ENABLED_KEY, true)
val sourceRetentionAnnotationHandler = configuration[JVMConfigurationKeys.SOURCE_RETENTION_ANNOTATION_HANDLER]
val annotationProcessingExtension = ClasspathBasedAnnotationProcessingExtension(
classpath, apOptions, generatedOutputDirFile, classesOutputDir, javaRoots, verboseOutput,
incrementalDataFile, sourceRetentionAnnotationHandler)
incrementalDataFile)
project.registerService(JeElementRegistry::class.java, JeElementRegistry())
@@ -22,14 +22,12 @@ import org.jetbrains.kotlin.asJava.elements.KtLightAnnotation
import org.jetbrains.kotlin.asJava.findFacadeClass
import org.jetbrains.kotlin.asJava.toLightClass
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
import org.jetbrains.kotlin.incremental.components.SourceRetentionAnnotationHandler
import org.jetbrains.kotlin.java.model.internal.getAnnotationsWithInherited
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.BindingContext
internal class RoundAnnotations(
val sourceRetentionAnnotationHandler: SourceRetentionAnnotationHandler?,
val bindingContext: BindingContext,
val typeMapper: KotlinTypeMapper
) {
@@ -51,7 +49,7 @@ internal class RoundAnnotations(
val analyzedClasses: Set<String>
get() = mutableAnalyzedClasses
fun copy() = RoundAnnotations(sourceRetentionAnnotationHandler, bindingContext, typeMapper)
fun copy() = RoundAnnotations(bindingContext, typeMapper)
fun analyzeFiles(files: Collection<KtFile>) = files.forEach { analyzeFile(it) }
@@ -102,15 +100,6 @@ internal class RoundAnnotations(
for (annotation in declaration.getAnnotationsWithInherited()) {
val fqName = annotation.qualifiedName ?: continue
val ktLightAnnotation = annotation as? KtLightAnnotation
if (ktLightAnnotation != null && sourceRetentionAnnotationHandler != null && ktLightAnnotation.hasSourceRetention) {
val type = bindingContext[BindingContext.ANNOTATION, ktLightAnnotation.kotlinOrigin]?.type
if (type != null) {
val internalName = typeMapper.mapType(type).internalName
sourceRetentionAnnotationHandler.register(internalName)
}
}
if (BLACKLISTED_ANNOTATATIONS.any { fqName.startsWith(it) }) continue
mutableAnnotationsMap.getOrPut(fqName, { mutableListOf() }).add(declaration)