This is an automated email from the ASF dual-hosted git repository.
mbien pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new 5d45c28aac `SourceUtils.findMatchingChild` should never return a folder
new aae13e97d6 Merge pull request #5739 from
jglick/SourceUtils.findMatchingChild
5d45c28aac is described below
commit 5d45c28aac066f568bcbb1dc5e0e800c47f9e601
Author: Jesse Glick <[email protected]>
AuthorDate: Wed Mar 29 11:30:34 2023 -0400
`SourceUtils.findMatchingChild` should never return a folder
---
.../src/org/netbeans/api/java/source/SourceUtils.java | 12 ++++++++----
.../src/org/netbeans/api/java/source/SourceUtilsTest.java | 9 +++++----
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git
a/java/java.source.base/src/org/netbeans/api/java/source/SourceUtils.java
b/java/java.source.base/src/org/netbeans/api/java/source/SourceUtils.java
index e58a6a257c..dfb02790c6 100644
--- a/java/java.source.base/src/org/netbeans/api/java/source/SourceUtils.java
+++ b/java/java.source.base/src/org/netbeans/api/java/source/SourceUtils.java
@@ -628,7 +628,9 @@ public class SourceUtils {
private static FileObject findMatchingChild(String sourceFileName,
Collection<FileObject> folders, boolean caseSensitive) {
final Match matchSet = caseSensitive ? new
CaseSensitiveMatch(sourceFileName) : new CaseInsensitiveMatch(sourceFileName);
for (FileObject folder : folders) {
- for (FileObject child : folder.getChildren()) {
+ FileObject[] children = folder.getChildren();
+ Arrays.sort(children,
Comparator.comparing(FileObject::getNameExt)); // for determinism
+ for (FileObject child : children) {
if (matchSet.apply(child)) {
return child;
}
@@ -684,6 +686,9 @@ public class SourceUtils {
}
final boolean apply(final FileObject fo) {
+ if (fo.isFolder()) {
+ return false;
+ }
if (fo.getNameExt().equals(name)) {
return true;
}
@@ -1127,9 +1132,8 @@ public class SourceUtils {
}
/**
- * Returns candidate filenames given a classname. The return value is
either
- * a String (top-level class, no $) or List<String> as the JLS permits
$ in
- * class names.
+ * Returns candidate filenames given a classname.
+ * @return a single name (top-level class, no $) or multiple as the JLS
permits $ in class names.
*/
private static List<String> getSourceFileNames(String classFileName) {
int index = classFileName.lastIndexOf('$');
diff --git
a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/SourceUtilsTest.java
b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/SourceUtilsTest.java
index 0a12ba30d8..90da3063a1 100644
---
a/java/java.source.base/test/unit/src/org/netbeans/api/java/source/SourceUtilsTest.java
+++
b/java/java.source.base/test/unit/src/org/netbeans/api/java/source/SourceUtilsTest.java
@@ -321,6 +321,7 @@ public class SourceUtilsTest extends ClassIndexTestCase {
FileObject srcInDefPkg = src.createData("Foo","java");
assertNotNull(srcInDefPkg);
FileObject sourceFile =
src.createFolder("org").createFolder("me").createData("Test", "java");
+ src.getFileObject("org/me").createFolder("Test"); //
https://github.com/apache/netbeans/issues/5738
assertNotNull(sourceFile);
ClasspathInfo cpInfo =
ClasspathInfo.create(ClassPathSupport.createClassPath(new FileObject[0]),
ClassPathSupport.createClassPath(new FileObject[0]),
ClassPathSupport.createClassPath(new FileObject[]{src}));
@@ -337,16 +338,16 @@ public class SourceUtilsTest extends ClassIndexTestCase {
ElementHandle<? extends Element> handle =
ElementHandle.createTypeElementHandle(ElementKind.CLASS, "org.me.Test");
assertNotNull (handle);
FileObject result = SourceUtils.getFile(handle, cpInfo);
- assertNotNull(result);
+ assertEquals(sourceFile, result);
handle = ElementHandle.createTypeElementHandle(ElementKind.CLASS,
"org.me.Test$Inner");
result = SourceUtils.getFile(handle,cpInfo);
- assertNotNull(result);
+ assertEquals(sourceFile, result);
handle = ElementHandle.createPackageElementHandle("org.me");
result = SourceUtils.getFile(handle,cpInfo);
- assertNotNull(result);
+ assertEquals(sourceFile.getParent(), result);
handle = ElementHandle.createTypeElementHandle(ElementKind.CLASS,
"Foo");
result = SourceUtils.getFile(handle,cpInfo);
- assertNotNull(result);
+ assertEquals(srcInDefPkg, result);
}
public void testGetMainClasses() throws Exception {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists