Remove source annotations removing (not needed with KAPT3)
This commit is contained in:
+4
-8
@@ -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())
|
||||
|
||||
|
||||
+2
-4
@@ -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())
|
||||
|
||||
|
||||
+1
-12
@@ -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)
|
||||
|
||||
|
||||
+1
-2
@@ -25,7 +25,6 @@ import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.codegen.AbstractBytecodeTextTest
|
||||
import org.jetbrains.kotlin.codegen.CodegenTestUtil
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
|
||||
import org.jetbrains.kotlin.incremental.SourceRetentionAnnotationHandlerImpl
|
||||
import org.jetbrains.kotlin.java.model.elements.JeAnnotationMirror
|
||||
import org.jetbrains.kotlin.java.model.elements.JeMethodExecutableElement
|
||||
import org.jetbrains.kotlin.java.model.elements.JeTypeElement
|
||||
@@ -47,7 +46,7 @@ import javax.lang.model.element.*
|
||||
class AnnotationProcessingExtensionForTests(
|
||||
val processors: List<Processor>
|
||||
) : AbstractAnnotationProcessingExtension(createTempDir(), createTempDir(), listOf(), true,
|
||||
createIncrementalDataFile(), SourceRetentionAnnotationHandlerImpl()) {
|
||||
createIncrementalDataFile()) {
|
||||
override fun loadAnnotationProcessors() = processors
|
||||
|
||||
override val options: Map<String, String>
|
||||
|
||||
-9
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.annotation.processing.test.processor
|
||||
import org.intellij.lang.annotations.Language
|
||||
import org.jetbrains.kotlin.annotation.processing.impl.DisposableRef
|
||||
import org.jetbrains.kotlin.annotation.processing.impl.KotlinProcessingEnvironment
|
||||
import org.jetbrains.kotlin.incremental.SourceRetentionAnnotationHandlerImpl
|
||||
import org.jetbrains.kotlin.java.model.elements.*
|
||||
import org.jetbrains.kotlin.java.model.types.JeDeclaredType
|
||||
import org.jetbrains.kotlin.java.model.types.JeMethodExecutableTypeMirror
|
||||
@@ -255,14 +254,6 @@ class ProcessorTests : AbstractProcessorTest() {
|
||||
assertEquals(expectedText, text)
|
||||
}
|
||||
|
||||
fun testSourceRetention() {
|
||||
test("SourceRetention", "*") { set, roundEnv, env -> }
|
||||
val ext = getKapt2Extension()
|
||||
val annotationHandler = ext.sourceRetentionAnnotationHandler as SourceRetentionAnnotationHandlerImpl
|
||||
val annotations = annotationHandler.sourceRetentionAnnotations.sorted()
|
||||
assertEquals("Source1, Source2, Source3, Source4, Test5\$Source5", annotations.joinToString())
|
||||
}
|
||||
|
||||
fun testKotlinAnnotationDefaultValueFromBinary() = test("DefaultValueFromBinary", "*") { set, roundEnv, env ->
|
||||
fun check(expectedValue: Boolean, className: String) {
|
||||
val clazz = env.findClass(className)
|
||||
|
||||
Reference in New Issue
Block a user