Skip to content

Commit

Permalink
Fix incremental recompilation of JvmMultifileClass with top level fun…
Browse files Browse the repository at this point in the history
…ction

See 53b584f and previous changes where this behavior was broken (this was
untested, however). Fixes EA-90065

(cherry picked from commit 7b2a80f)
  • Loading branch information
udalov committed Oct 19, 2016
1 parent 88f5269 commit 379239c
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor;
import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaPackageFragment;
import org.jetbrains.kotlin.load.kotlin.*;
import org.jetbrains.kotlin.load.kotlin.incremental.IncrementalPackageFragmentProvider.IncrementalMultifileClassPackageFragment;
import org.jetbrains.kotlin.name.ClassId;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.name.Name;
Expand Down Expand Up @@ -295,18 +296,27 @@ private static ContainingClassesInfo getPackageMemberContainingClassesInfo(@NotN
return new ContainingClassesInfo(FAKE_CLASS_ID_FOR_BUILTINS, FAKE_CLASS_ID_FOR_BUILTINS);
}

assert containingDeclaration instanceof LazyJavaPackageFragment :
"Unexpected package fragment for " + descriptor + ": " + containingDeclaration +
" (" + containingDeclaration.getClass().getSimpleName() + ")";
LazyJavaPackageFragment packageFragment = (LazyJavaPackageFragment) containingDeclaration;

Name implClassName = JvmFileClassUtil.getImplClassName(descriptor);
assert implClassName != null : "No implClassName for " + descriptor;
String implSimpleName = implClassName.asString();

String facadeSimpleName = packageFragment.getFacadeSimpleNameForPartSimpleName(implClassName.asString());
if (facadeSimpleName == null) return null;
String facadeSimpleName;

return ContainingClassesInfo.forPackageMember(packageFragment.getFqName(), facadeSimpleName, implClassName.asString());
if (containingDeclaration instanceof LazyJavaPackageFragment) {
facadeSimpleName = ((LazyJavaPackageFragment) containingDeclaration).getFacadeSimpleNameForPartSimpleName(implSimpleName);
if (facadeSimpleName == null) return null;
}
else if (containingDeclaration instanceof IncrementalMultifileClassPackageFragment) {
facadeSimpleName = ((IncrementalMultifileClassPackageFragment) containingDeclaration).getMultifileClassName().asString();
}
else {
throw new AssertionError("Unexpected package fragment for " + descriptor + ": " +
containingDeclaration + " (" + containingDeclaration.getClass().getSimpleName() + ")");
}

return ContainingClassesInfo.forPackageMember(
((PackageFragmentDescriptor) containingDeclaration).getFqName(), facadeSimpleName, implSimpleName
);
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ class IncrementalPackageFragmentProvider(
)
}

val multifileClassName: Name
get() = multifileClassFqName.shortName()

override fun getMemberScope() = memberScope()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,12 @@ public void testMoveFileWithoutChangingPackage() throws Exception {
doTest(fileName);
}

@TestMetadata("multifileClassAddTopLevelFunWithDefault")
public void testMultifileClassAddTopLevelFunWithDefault() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/multifileClassAddTopLevelFunWithDefault/");
doTest(fileName);
}

@TestMetadata("multifileClassFileAdded")
public void testMultifileClassFileAdded() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/multifileClassFileAdded/");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,12 @@ public void testMoveFileWithoutChangingPackage() throws Exception {
doTest(fileName);
}

@TestMetadata("multifileClassAddTopLevelFunWithDefault")
public void testMultifileClassAddTopLevelFunWithDefault() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/multifileClassAddTopLevelFunWithDefault/");
doTest(fileName);
}

@TestMetadata("multifileClassFileAdded")
public void testMultifileClassFileAdded() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/pureKotlin/multifileClassFileAdded/");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@file:[JvmName("Test") JvmMultifileClass]
package test

fun a() = "a"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@file:[JvmName("Test") JvmMultifileClass]
package test

fun b() = ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@file:[JvmName("Test") JvmMultifileClass]
package test

fun b() = ""
fun b(s: String = "") = s
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
================ Step #1 =================

Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/test/Test.class
out/production/module/test/Test__BKt.class
End of files
Compiling files:
src/b.kt
End of files
Exit code: ADDITIONAL_PASS_REQUIRED
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/test/Test.class
out/production/module/test/Test__AKt.class
out/production/module/usage/UsageKt.class
End of files
Compiling files:
src/a.kt
src/usage.kt
End of files
Exit code: OK
------------------------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
================ Step #1 =================

Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/test/Test.class
out/production/module/test/Test__BKt.class
End of files
Compiling files:
src/b.kt
End of files
Marked as dirty by Kotlin:
src/usage.kt
Exit code: ADDITIONAL_PASS_REQUIRED
------------------------------------------
Cleaning output files:
out/production/module/META-INF/module.kotlin_module
out/production/module/test/Test.class
out/production/module/test/Test__AKt.class
out/production/module/usage/UsageKt.class
End of files
Compiling files:
src/a.kt
src/usage.kt
End of files
Exit code: OK
------------------------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package usage

import test.*

fun usage() {
a()
b()
}

0 comments on commit 379239c

Please sign in to comment.