[KAPT4] Support -Xmetadata-version in Kapt for testing with external projects
This commit is contained in:
committed by
Space Team
parent
14bed668d4
commit
f2078caf64
@@ -86,23 +86,27 @@ private class Kapt4AnalysisHandlerExtension : FirAnalysisHandlerExtension() {
|
||||
logger.info(options.logString())
|
||||
}
|
||||
|
||||
var context: Kapt4ContextForStubGeneration? = null
|
||||
return try {
|
||||
KtAnalysisSessionProvider.getInstance(module.project).analyze(module) {
|
||||
context = Kapt4ContextForStubGeneration(options, withJdk = false, logger, this, psiFiles.filterIsInstance<KtFile>())
|
||||
Kapt4ContextForStubGeneration(
|
||||
options,
|
||||
false,
|
||||
logger,
|
||||
this,
|
||||
psiFiles.filterIsInstance<KtFile>(),
|
||||
configuration[CommonConfigurationKeys.METADATA_VERSION]
|
||||
).use { context ->
|
||||
if (options.mode.generateStubs)
|
||||
generateStubs(context)
|
||||
|
||||
if (options.mode.generateStubs)
|
||||
generateStubs(context!!)
|
||||
|
||||
if (options.mode.runAnnotationProcessing)
|
||||
runProcessors(context!!, options, logger)
|
||||
if (options.mode.runAnnotationProcessing)
|
||||
runProcessors(context, options, logger)
|
||||
}
|
||||
true
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
logger.exception(e)
|
||||
false
|
||||
} finally {
|
||||
context?.close()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.asJava.toLightClass
|
||||
import org.jetbrains.kotlin.base.kapt3.KaptOptions
|
||||
import org.jetbrains.kotlin.kapt3.base.KaptContext
|
||||
import org.jetbrains.kotlin.kapt3.base.util.KaptLogger
|
||||
import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
@@ -23,6 +24,7 @@ internal class Kapt4ContextForStubGeneration(
|
||||
logger: KaptLogger,
|
||||
val analysisSession: KtAnalysisSession,
|
||||
val files: List<KtFile>,
|
||||
val overriddenMetadataVersion: BinaryVersion? = null
|
||||
) : KaptContext(options, withJdk, logger) {
|
||||
val classes: Iterable<KtLightClass> = buildSet {
|
||||
files.flatMapTo(this) { file ->
|
||||
|
||||
@@ -276,7 +276,7 @@ internal class Kapt4StubGenerator {
|
||||
private fun convertMetadataAnnotation(metadata: Metadata): JCAnnotation {
|
||||
val argumentsWithNames = mutableMapOf<String, Any>()
|
||||
if (metadata.kind != 1) argumentsWithNames[KIND_FIELD_NAME] = metadata.kind
|
||||
argumentsWithNames[METADATA_VERSION_FIELD_NAME] = metadata.metadataVersion.toList()
|
||||
argumentsWithNames[METADATA_VERSION_FIELD_NAME] = (overriddenMetadataVersion?.toArray() ?: metadata.metadataVersion).toList()
|
||||
if (metadata.data1.isNotEmpty()) argumentsWithNames[METADATA_DATA_FIELD_NAME] = metadata.data1.toList()
|
||||
if (metadata.data2.isNotEmpty()) argumentsWithNames[METADATA_STRINGS_FIELD_NAME] = metadata.data2.toList()
|
||||
if (metadata.extraString.isNotEmpty()) argumentsWithNames[METADATA_EXTRA_STRING_FIELD_NAME] = metadata.extraString
|
||||
|
||||
Reference in New Issue
Block a user