diff --git a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/javac/KaptJavaLog.kt b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/javac/KaptJavaLog.kt index 3085f66dfe7c4..965897c13dc4e 100644 --- a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/javac/KaptJavaLog.kt +++ b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/javac/KaptJavaLog.kt @@ -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() + 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) { diff --git a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt index 25db1dd6e889c..1512989a4696b 100644 --- a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt +++ b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt @@ -144,6 +144,8 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati private var done = false + private val treeMakerImportMethod = TreeMaker::class.java.declaredMethods.single { it.name == "Import" } + fun convert(): List { if (kaptContext.logger.isVerbose) { dumpDeclarationOrigins() @@ -315,13 +317,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 } } diff --git a/plugins/kapt4/src/org/jetbrains/kotlin/kapt4/Kapt4StubGenerator.kt b/plugins/kapt4/src/org/jetbrains/kotlin/kapt4/Kapt4StubGenerator.kt index 8da945165c37a..2c1dc68380e64 100644 --- a/plugins/kapt4/src/org/jetbrains/kotlin/kapt4/Kapt4StubGenerator.kt +++ b/plugins/kapt4/src/org/jetbrains/kotlin/kapt4/Kapt4StubGenerator.kt @@ -15,6 +15,7 @@ import com.sun.tools.javac.code.TypeTag import com.sun.tools.javac.parser.Tokens import com.sun.tools.javac.tree.JCTree import com.sun.tools.javac.tree.JCTree.* +import com.sun.tools.javac.tree.TreeMaker import kotlinx.kapt.KaptIgnored import org.jetbrains.kotlin.analysis.api.symbols.KtCallableSymbol import org.jetbrains.kotlin.analysis.api.symbols.KtClassOrObjectSymbol @@ -84,6 +85,8 @@ internal class Kapt4StubGenerator { private val JAVA_KEYWORDS = Tokens.TokenKind.values() .filter { JAVA_KEYWORD_FILTER_REGEX.matches(it.toString().orEmpty()) } .mapTo(hashSetOf(), Any::toString) + + private val treeMakerImportMethod = TreeMaker::class.java.declaredMethods.single { it.name == "Import" } } private val strictMode = options[KaptFlag.STRICT] @@ -260,13 +263,15 @@ internal class Kapt4StubGenerator { if (!isValidQualifiedName(importedFqName)) continue 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 } }