Fix searching serialized classes package contains multiple fragments

This commit is contained in:
Alexey Tsvetkov
2017-07-20 11:21:02 +03:00
parent b54414d628
commit 1c4ada2008
12 changed files with 98 additions and 11 deletions
@@ -296,6 +296,12 @@ public class IncrementalJsCompilerRunnerTestGenerated extends AbstractIncrementa
doTest(fileName);
}
@TestMetadata("functionReferencingClass")
public void testFunctionReferencingClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/functionReferencingClass/");
doTest(fileName);
}
@TestMetadata("independentClasses")
public void testIndependentClasses() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/independentClasses/");
@@ -296,6 +296,12 @@ public class IncrementalJvmCompilerRunnerTestGenerated extends AbstractIncrement
doTest(fileName);
}
@TestMetadata("functionReferencingClass")
public void testFunctionReferencingClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/functionReferencingClass/");
doTest(fileName);
}
@TestMetadata("independentClasses")
public void testIndependentClasses() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/independentClasses/");
@@ -55,13 +55,8 @@ class ClassDeserializer(private val components: DeserializationComponents) {
}
else {
val fragments = components.packageFragmentProvider.getPackageFragments(classId.packageFqName)
assert(fragments.size == 1) { "There should be exactly one package: $fragments, class id is $classId" }
val fragment = fragments.single()
if (fragment is DeserializedPackageFragment) {
// Similarly, verify that the containing package has information about this class
if (!fragment.hasTopLevelClass(classId.shortClassName)) return null
}
val fragment = fragments.firstOrNull { it !is DeserializedPackageFragment || it.hasTopLevelClass(classId.shortClassName) }
?: return null
components.createContext(
fragment, nameResolver,
@@ -22,9 +22,12 @@ import org.jetbrains.kotlin.serialization.ClassDataWithSource
class DeserializedClassDataFinder(private val packageFragmentProvider: PackageFragmentProvider) : ClassDataFinder {
override fun findClassData(classId: ClassId): ClassDataWithSource? {
val packageFragment =
packageFragmentProvider.getPackageFragments(classId.packageFqName).singleOrNull()
as? DeserializedPackageFragment ?: return null
return packageFragment.classDataFinder.findClassData(classId)
val packageFragments = packageFragmentProvider.getPackageFragments(classId.packageFqName)
for (fragment in packageFragments) {
if (fragment !is DeserializedPackageFragment) continue
fragment.classDataFinder.findClassData(classId)?.let { return it }
}
return null
}
}
@@ -467,6 +467,12 @@ public class IncrementalJpsTestGenerated extends AbstractIncrementalJpsTest {
doTest(fileName);
}
@TestMetadata("functionReferencingClass")
public void testFunctionReferencingClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/functionReferencingClass/");
doTest(fileName);
}
@TestMetadata("independentClasses")
public void testIndependentClasses() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/independentClasses/");
@@ -0,0 +1 @@
class A(val x: Int)
@@ -0,0 +1,11 @@
================ Step #1 =================
Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/UseAKt.class
End of files
Compiling files:
src/useA.kt
End of files
Exit code: OK
------------------------------------------
@@ -0,0 +1 @@
fun useA(a: A) { a.x }
@@ -3497,6 +3497,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
doTest(fileName);
}
@TestMetadata("classReferencingClass.kt")
public void testClassReferencingClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/incremental/classReferencingClass.kt");
doTest(fileName);
}
@TestMetadata("coroutines.kt")
public void testCoroutines() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/incremental/coroutines.kt");
@@ -3515,6 +3521,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest {
doTest(fileName);
}
@TestMetadata("functionReferencingClass.kt")
public void testFunctionReferencingClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/incremental/functionReferencingClass.kt");
doTest(fileName);
}
@TestMetadata("inline.kt")
public void testInline() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("js/js.translator/testData/box/incremental/inline.kt");
@@ -0,0 +1,25 @@
// EXPECTED_REACHABLE_NODES: 1002
// FILE: A.kt
open class A {
open fun f(): Int = 1
}
// FILE: B.kt
// RECOMPILE
class B : A() {
override fun f(): Int = super.f() + 2
}
// FILE: box.kt
fun box(): String {
val af = A().f()
if (af != 1) return "fail: result of 'A().f()' is '$af', but '1' was expected"
val bf = B().f()
if (bf != 3) return "fail: result of 'B().f()' is '$bf', but '3' was expected"
return "OK"
}
@@ -0,0 +1,21 @@
// EXPECTED_REACHABLE_NODES: 995
// FILE: A.kt
open class A {
open fun f(): Int = 1
}
// FILE: useA.kt
// RECOMPILE
fun useA(a: A): Int = a.f()
fun useList(xs: List<Int>) {}
// FILE: box.kt
fun box(): String {
val result = useA(A())
if (result != 1) return "fail: result of 'useA(A())' is '$result', but '1' was expected"
return "OK"
}