Don't consider a directory to be a package if there's a .java or .class file with the same name in its parent directory

#KT-12664 Fixed
This commit is contained in:
Dmitry Jemerov
2016-11-17 15:44:57 +01:00
parent 7dbcbeb794
commit 5a533a521b
7 changed files with 39 additions and 6 deletions
@@ -220,7 +220,7 @@ class JvmDependenciesIndexImpl(_roots: List<JavaRoot>): JvmDependenciesIndex {
}
}
else {
currentFile = currentFile.findChild(subPackageName) ?: return null
currentFile = currentFile.findChildPackage(subPackageName, pathRoot.type) ?: return null
}
val correspondingCacheIndex = pathIndex + 1
@@ -233,6 +233,21 @@ class JvmDependenciesIndexImpl(_roots: List<JavaRoot>): JvmDependenciesIndex {
return currentFile
}
private fun VirtualFile.findChildPackage(subPackageName: String, rootType: JavaRoot.RootType): VirtualFile? {
val childDirectory = findChild(subPackageName) ?: return null
// Resolve conflicts between files and packages with the same qualified name in favor of files
val fileExtension = when (rootType) {
JavaRoot.RootType.BINARY -> ".class"
JavaRoot.RootType.SOURCE -> ".java"
}
if (findChild(subPackageName + fileExtension)?.isDirectory == false) {
return null
}
return childDirectory
}
private fun cachesPath(path: List<String>): List<Cache> {
val caches = ArrayList<Cache>(path.size + 1)
caches.add(rootCache)
@@ -0,0 +1,7 @@
package test;
public class Foo {
public interface Bar {
}
}
@@ -0,0 +1,3 @@
import test.Foo.Bar
val f: Bar? = null
@@ -155,7 +155,7 @@ public class MockLibraryUtil {
}
}
private static File createJarFile(File contentDir, File dirToAdd, String sourcesPath, String jarName, boolean addSources) throws IOException {
public static File createJarFile(File contentDir, File dirToAdd, String sourcesPath, String jarName, boolean addSources) throws IOException {
File jarFile = new File(contentDir, jarName + ".jar");
ZipOutputStream zip = new ZipOutputStream(new FileOutputStream(jarFile));
@@ -40,10 +40,7 @@ import org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion;
import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.resolve.DescriptorUtils;
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
import org.jetbrains.kotlin.test.ConfigurationKind;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TestCaseWithTmpdir;
import org.jetbrains.kotlin.test.TestJdkKind;
import org.jetbrains.kotlin.test.*;
import org.jetbrains.kotlin.test.util.DescriptorValidator;
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator;
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
@@ -440,4 +437,14 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
new File(getTestDataDirectory(), "output.txt"), normalizeOutput(outputMain)
);
}
public void testInnerClassPackageConflict() throws Exception {
compileJava("library");
FileUtil.copy(new File(getTestDataDirectory(), "library/test/Foo/x.txt"),
new File(tmpdir, "library/test/Foo/x.txt"));
MockLibraryUtil.createJarFile(tmpdir, new File(tmpdir, "library"), null, "library", false);
File jarPath = new File(tmpdir, "library.jar");
Pair<String, ExitCode> output = compileKotlin("source.kt", tmpdir, jarPath);
KotlinTestUtils.assertEqualsToFile(new File(getTestDataDirectory(), "output.txt"), normalizeOutput(output));
}
}