Kapt+JVM_IR: do not require KtFile for each generated class
In particular, JVM IR doesn't provide KtFile for a multifile facade in JvmDeclarationOrigin (JVM backend provides KtFile of a random multifile part). This led to multifile classes being completely ignored in the JVM_IR version of kapt. Now they are generated correctly and the changed test passes, but there's a _ir.txt expectation file because the order of 'foo' and 'bar' is different (which is not a problem).
This commit is contained in:
+7
-4
@@ -52,6 +52,7 @@ import org.jetbrains.kotlin.psi.*
|
|||||||
import org.jetbrains.kotlin.resolve.ArrayFqNames
|
import org.jetbrains.kotlin.resolve.ArrayFqNames
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.DelegatingBindingTrace
|
import org.jetbrains.kotlin.resolve.DelegatingBindingTrace
|
||||||
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.DefaultValueArgument
|
import org.jetbrains.kotlin.resolve.calls.model.DefaultValueArgument
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument
|
||||||
import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall
|
||||||
@@ -64,9 +65,9 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassOrAny
|
|||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isCompanionObject
|
import org.jetbrains.kotlin.resolve.descriptorUtil.isCompanionObject
|
||||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin
|
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin
|
||||||
import org.jetbrains.kotlin.resolve.source.getPsi
|
import org.jetbrains.kotlin.resolve.source.getPsi
|
||||||
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.error.ErrorTypeKind
|
import org.jetbrains.kotlin.types.error.ErrorTypeKind
|
||||||
import org.jetbrains.kotlin.types.error.ErrorUtils
|
import org.jetbrains.kotlin.types.error.ErrorUtils
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
|
||||||
import org.jetbrains.kotlin.types.isError
|
import org.jetbrains.kotlin.types.isError
|
||||||
import org.jetbrains.kotlin.types.typeUtil.isEnum
|
import org.jetbrains.kotlin.types.typeUtil.isEnum
|
||||||
import org.jetbrains.org.objectweb.asm.Opcodes
|
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||||
@@ -206,7 +207,6 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
|
|||||||
|
|
||||||
private fun convertTopLevelClass(clazz: ClassNode): KaptStub? {
|
private fun convertTopLevelClass(clazz: ClassNode): KaptStub? {
|
||||||
val origin = kaptContext.origins[clazz] ?: return null
|
val origin = kaptContext.origins[clazz] ?: return null
|
||||||
val ktFile = origin.element?.containingFile as? KtFile ?: return null
|
|
||||||
val descriptor = origin.descriptor ?: return null
|
val descriptor = origin.descriptor ?: return null
|
||||||
|
|
||||||
// Nested classes will be processed during the outer classes conversion
|
// Nested classes will be processed during the outer classes conversion
|
||||||
@@ -214,14 +214,17 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati
|
|||||||
|
|
||||||
val lineMappings = KaptLineMappingCollector(kaptContext)
|
val lineMappings = KaptLineMappingCollector(kaptContext)
|
||||||
|
|
||||||
val packageName = ktFile.packageFqName.asString()
|
val packageName = DescriptorUtils.getParentOfType(descriptor, PackageFragmentDescriptor::class.java, false)?.fqName?.asString()
|
||||||
|
?: return null
|
||||||
|
|
||||||
val packageClause = if (packageName.isEmpty()) null else treeMaker.FqName(packageName)
|
val packageClause = if (packageName.isEmpty()) null else treeMaker.FqName(packageName)
|
||||||
|
|
||||||
val classDeclaration = convertClass(clazz, lineMappings, packageName, true) ?: return null
|
val classDeclaration = convertClass(clazz, lineMappings, packageName, true) ?: return null
|
||||||
|
|
||||||
classDeclaration.mods.annotations = classDeclaration.mods.annotations
|
classDeclaration.mods.annotations = classDeclaration.mods.annotations
|
||||||
|
|
||||||
val imports = if (correctErrorTypes) convertImports(ktFile, classDeclaration) else JavacList.nil()
|
val ktFile = origin.element?.containingFile as? KtFile
|
||||||
|
val imports = if (ktFile != null && correctErrorTypes) convertImports(ktFile, classDeclaration) else JavacList.nil()
|
||||||
|
|
||||||
val classes = JavacList.of<JCTree>(classDeclaration)
|
val classes = JavacList.of<JCTree>(classDeclaration)
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND: JVM_IR
|
|
||||||
// WITH_STDLIB
|
// WITH_STDLIB
|
||||||
|
|
||||||
// FILE: a.kt
|
// FILE: a.kt
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package test;
|
||||||
|
|
||||||
|
@kotlin.Metadata()
|
||||||
|
public final class M1 {
|
||||||
|
|
||||||
|
public M1() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final void bar() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final void foo() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
|
||||||
|
package test;
|
||||||
|
|
||||||
|
@kotlin.Metadata()
|
||||||
|
public final class M2 {
|
||||||
|
|
||||||
|
public M2() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final void baz() {
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user