Fixed incremental compilation, when removing all callables from file.

This commit is contained in:
Evgeny Gerashchenko
2014-12-09 19:36:41 +03:00
parent d126a9711c
commit 4e702e34f0
10 changed files with 70 additions and 14 deletions
@@ -94,13 +94,18 @@ public class PackagePartClassUtils {
return ContainerUtil.filter(packageFiles, new Condition<JetFile>() {
@Override
public boolean value(JetFile packageFile) {
for (JetDeclaration declaration : packageFile.getDeclarations()) {
if (declaration instanceof JetProperty || declaration instanceof JetNamedFunction) {
return true;
}
}
return false;
return fileHasCallables(packageFile);
}
});
}
public static boolean fileHasCallables(@NotNull JetFile file) {
for (JetDeclaration declaration : file.getDeclarations()) {
if (declaration instanceof JetProperty || declaration instanceof JetNamedFunction) {
return true;
}
}
return false;
}
}
@@ -22,15 +22,20 @@ import org.jetbrains.jet.lang.resolve.name.FqName
import org.jetbrains.jet.lang.resolve.java.JvmClassName
import java.util.HashMap
import java.io.File
import org.jetbrains.jet.lang.resolve.kotlin.PackagePartClassUtils
public fun IncrementalCache.getPackagesWithRemovedFiles(sourceFilesToCompile: Collection<JetFile>): Collection<FqName> {
return getRemovedPackageParts(sourceFilesToCompile).map { it.getPackageFqName() }
}
public fun IncrementalCache.getRemovedPackageParts(sourceFilesToCompile: Collection<JetFile>): Collection<JvmClassName> {
val sourceFilesToFqName = HashMap<File, String>()
val sourceFilesToFqName = HashMap<File, String?>()
for (sourceFile in sourceFilesToCompile) {
sourceFilesToFqName[File(sourceFile.getVirtualFile()!!.getPath())] = sourceFile.getPackageFqName().asString()
sourceFilesToFqName[File(sourceFile.getVirtualFile()!!.getPath())] =
if (PackagePartClassUtils.fileHasCallables(sourceFile))
sourceFile.getPackageFqName().asString()
else
null
}
return getRemovedPackageParts(sourceFilesToFqName).map { JvmClassName.byInternalName(it) }
@@ -23,7 +23,10 @@ import java.util.HashMap
import java.io.File
public trait IncrementalCache {
public fun getRemovedPackageParts(sourceFilesToCompileAndFqNames: Map<File, String>): Collection<String>
public fun getRemovedPackageParts(
// null value means source file has no top-level callables (won't produce package part)
sourceFilesToCompileAndFqNames: Map<File, String?>
): Collection<String>
public fun getPackageData(fqName: String): ByteArray?
@@ -146,7 +146,7 @@ public class IncrementalCacheImpl(val baseDir: File): StorageOwner, IncrementalC
}
}
public override fun getRemovedPackageParts(sourceFilesToCompileAndFqNames: Map<File, String>): Collection<String> {
public override fun getRemovedPackageParts(sourceFilesToCompileAndFqNames: Map<File, String?>): Collection<String> {
return packagePartMap.getRemovedPackageParts(sourceFilesToCompileAndFqNames)
}
@@ -451,7 +451,7 @@ public class IncrementalCacheImpl(val baseDir: File): StorageOwner, IncrementalC
storage.remove(sourceFile.getAbsolutePath())
}
public fun getRemovedPackageParts(compiledSourceFilesToFqName: Map<File, String>): Collection<String> {
public fun getRemovedPackageParts(compiledSourceFilesToFqName: Map<File, String?>): Collection<String> {
val result = HashSet<String>()
storage.processKeysWithExistingMapping { key ->
@@ -463,9 +463,10 @@ public class IncrementalCacheImpl(val baseDir: File): StorageOwner, IncrementalC
}
else {
val previousPackageFqName = JvmClassName.byInternalName(packagePartClassName).getPackageFqName()
val currentPackageFqName = compiledSourceFilesToFqName[sourceFile]
if (currentPackageFqName != null && currentPackageFqName != previousPackageFqName.asString()) {
result.add(packagePartClassName)
if (sourceFile in compiledSourceFilesToFqName) {
if (compiledSourceFilesToFqName[sourceFile] != previousPackageFqName.asString()) {
result.add(packagePartClassName)
}
}
}
@@ -493,6 +493,12 @@ public class IncrementalJpsTestGenerated extends AbstractIncrementalJpsTest {
doTest(fileName);
}
@TestMetadata("onlyTopLevelFunctionInFileRemoved")
public void testOnlyTopLevelFunctionInFileRemoved() throws Exception {
String fileName = JetTestUtils.navigationMetadata("jps-plugin/testData/incremental/withJava/kotlinUsedInJava/onlyTopLevelFunctionInFileRemoved/");
doTest(fileName);
}
@TestMetadata("propertyRenamed")
public void testPropertyRenamed() throws Exception {
String fileName = JetTestUtils.navigationMetadata("jps-plugin/testData/incremental/withJava/kotlinUsedInJava/propertyRenamed/");
@@ -0,0 +1,5 @@
class Usage {
void usage() {
test.TestPackage.a();
}
}
@@ -0,0 +1,4 @@
package test
fun a() {
}
@@ -0,0 +1,4 @@
package test
fun b() {
}
@@ -0,0 +1,21 @@
Cleaning output files:
out/production/module/test/TestPackage$b$*.class
out/production/module/test/TestPackage.class
End of files
Compiling files:
src/b.kt
End of files
Compiling files:
src/Usage.java
End of files
Cleaning output files:
out/production/module/Usage.class
out/production/module/test/TestPackage$a$*.class
out/production/module/test/TestPackage.class
End of files
Compiling files:
src/a.kt
End of files
Compiling files:
src/Usage.java
End of files