KAPT: Use reflection to access code, changed in JDK 21
#KT-57389 Fixed
This commit is contained in:
committed by
Space Team
parent
4f7c96ae43
commit
37417f7919
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.kapt3.base.javac
|
||||
|
||||
import com.sun.tools.javac.tree.JCTree
|
||||
import com.sun.tools.javac.tree.JCTree.JCImport
|
||||
import com.sun.tools.javac.util.*
|
||||
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType
|
||||
import org.jetbrains.kotlin.kapt3.base.KaptContext
|
||||
@@ -55,6 +56,8 @@ class KaptJavaLog(
|
||||
|
||||
private val _reportedDiagnostics = mutableListOf<JCDiagnostic>()
|
||||
|
||||
private val jcImportQualidField = JCImport::class.java.declaredFields.single { it.name == "qualid" }
|
||||
|
||||
override fun flush(kind: WriterKind?) {
|
||||
super.flush(kind)
|
||||
|
||||
@@ -197,7 +200,7 @@ class KaptJavaLog(
|
||||
val visitor = object : JCTree.Visitor() {
|
||||
override fun visitImport(that: JCTree.JCImport) {
|
||||
super.visitImport(that)
|
||||
if (!found) that.qualid.accept(this)
|
||||
if (!found) (jcImportQualidField.get(that) as JCTree).accept(this)
|
||||
}
|
||||
|
||||
override fun visitSelect(that: JCTree.JCFieldAccess) {
|
||||
|
||||
+6
-2
@@ -142,6 +142,8 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
|
||||
|
||||
private var done = false
|
||||
|
||||
private val treeMakerImportMethod = TreeMaker::class.java.declaredMethods.single { it.name == "Import" }
|
||||
|
||||
fun convert(): List<KaptStub> {
|
||||
if (kaptContext.logger.isVerbose) {
|
||||
dumpDeclarationOrigins()
|
||||
@@ -313,13 +315,15 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
|
||||
val importedExpr = treeMaker.FqName(importedFqName.asString())
|
||||
|
||||
imports += if (importDirective.isAllUnder) {
|
||||
treeMaker.Import(treeMaker.Select(importedExpr, treeMaker.nameTable.names.asterisk), false)
|
||||
treeMakerImportMethod.invoke(
|
||||
treeMaker, treeMaker.Select(importedExpr, treeMaker.nameTable.names.asterisk), false
|
||||
) as JCImport
|
||||
} else {
|
||||
if (!importedShortNames.add(importedFqName.shortName().asString())) {
|
||||
continue
|
||||
}
|
||||
|
||||
treeMaker.Import(importedExpr, false)
|
||||
treeMakerImportMethod.invoke(treeMaker, importedExpr, false) as JCImport
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user