mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
tolerate package directories with dots in the name (IDEA-123206)
This commit is contained in:
@@ -225,8 +225,8 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
}
|
||||
|
||||
public void testDirsByPackageName() throws IOException {
|
||||
checkPackage("", true, mySrcDir1, myTestSrc1, myResDir, myTestResDir, myFileLibSrc, myFileLibCls, mySrcDir2, myLibSrcDir, myLibClsDir);
|
||||
checkPackage("", false, mySrcDir1, myTestSrc1, myResDir, myTestResDir, myFileLibCls, mySrcDir2, myLibClsDir);
|
||||
checkPackage("", true, mySrcDir1, myTestSrc1, myResDir, myTestResDir, mySrcDir2, myLibSrcDir, myLibClsDir);
|
||||
checkPackage("", false, mySrcDir1, myTestSrc1, myResDir, myTestResDir, mySrcDir2, myLibClsDir);
|
||||
|
||||
checkPackage("pack1", true, myPack1Dir);
|
||||
checkPackage("pack1", false, myPack1Dir);
|
||||
@@ -257,6 +257,18 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
checkPackage("pack1", true, myPack1Dir, myModule3Dir);
|
||||
}
|
||||
|
||||
public void testPackageDirectoriesWithDots() throws IOException {
|
||||
VirtualFile fooBar = mySrcDir1.createChildDirectory(this, "foo.bar");
|
||||
VirtualFile goo1 = fooBar.createChildDirectory(this, "goo");
|
||||
VirtualFile foo = mySrcDir2.createChildDirectory(this, "foo");
|
||||
VirtualFile bar = foo.createChildDirectory(this, "bar");
|
||||
VirtualFile goo2 = bar.createChildDirectory(this, "goo");
|
||||
|
||||
checkPackage("foo", false, foo);
|
||||
checkPackage("foo.bar", false, bar, fooBar);
|
||||
checkPackage("foo.bar.goo", false, goo2, goo1);
|
||||
}
|
||||
|
||||
public void testCreateDir() throws Exception {
|
||||
String path = mySrcDir1.getPath().replace('/', File.separatorChar);
|
||||
assertTrue(new File(path + File.separatorChar + "dir1" + File.separatorChar + "dir2").mkdirs());
|
||||
@@ -957,6 +969,11 @@ public class DirectoryIndexTest extends IdeaTestCase {
|
||||
VirtualFile[] actualDirs = myIndex.getDirectoriesByPackageName(packageName, includeLibrarySources).toArray(VirtualFile.EMPTY_ARRAY);
|
||||
assertNotNull(actualDirs);
|
||||
assertOrderedEquals(actualDirs, expectedDirs);
|
||||
|
||||
for (VirtualFile dir : expectedDirs) {
|
||||
String actualName = myIndex.getPackageName(dir);
|
||||
assertEquals("Invalid package name for dir " + dir + ": " + packageName, packageName, actualName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -322,17 +322,27 @@ public class RootIndex extends DirectoryIndex {
|
||||
result = ContainerUtil.newSmartList();
|
||||
|
||||
if (StringUtil.isNotEmpty(packageName) && !StringUtil.startsWithChar(packageName, '.')) {
|
||||
String shortName = StringUtil.getShortName(packageName);
|
||||
for (VirtualFile parentDir : getDirectoriesByPackageName(StringUtil.getPackageName(packageName), true)) {
|
||||
VirtualFile child = parentDir.findChild(shortName);
|
||||
if (child != null && child.isDirectory() && getInfoForFile(child).isInProject()
|
||||
&& packageName.equals(getPackageName(child))) {
|
||||
result.add(child);
|
||||
int i = packageName.lastIndexOf('.');
|
||||
while (true) {
|
||||
String shortName = packageName.substring(i + 1);
|
||||
String parentPackage = i > 0 ? packageName.substring(0, i) : "";
|
||||
for (VirtualFile parentDir : getDirectoriesByPackageName(parentPackage, true)) {
|
||||
VirtualFile child = parentDir.findChild(shortName);
|
||||
if (child != null && child.isDirectory() && getInfoForFile(child).isInProject()
|
||||
&& packageName.equals(getPackageName(child))) {
|
||||
result.add(child);
|
||||
}
|
||||
}
|
||||
if (i < 0) break;
|
||||
i = packageName.lastIndexOf('.', i - 1);
|
||||
}
|
||||
}
|
||||
|
||||
result.addAll(myPackagePrefixRoots.get(packageName));
|
||||
for (VirtualFile file : myPackagePrefixRoots.get(packageName)) {
|
||||
if (file.isDirectory()) {
|
||||
result.add(file);
|
||||
}
|
||||
}
|
||||
|
||||
if (!result.isEmpty()) {
|
||||
myDirectoriesByPackageNameCache.put(packageName, result);
|
||||
|
||||
Reference in New Issue
Block a user