Skip to content

Commit

Permalink
Make it possible to report folder changes to jdt.ls (not only file ch…
Browse files Browse the repository at this point in the history
…anges)

Related Issue: eclipse-che/che#10115

Signed-off-by: Victor Rubezhny <[email protected]>
  • Loading branch information
vrubezhny committed Aug 15, 2018
1 parent 604829f commit 6daf588
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -601,10 +601,33 @@ private static boolean isJavaIdentifierOrPeriod(char ch) {
return Character.isJavaIdentifierPart(ch) || ch == '.';
}

public static boolean isFolder(String uriString) {
IFile fakeFile = findFile(uriString); // This may return IFile even when uriString really describes a IContainer
IContainer parent = fakeFile == null ? null : fakeFile.getParent();
if (parent == null) {
return false;
}
String name = fakeFile.getName();
try {
for (IResource member : parent.members()) {
if (name.equals(member.getName())) {
return (member instanceof IFolder);
}
}
} catch (CoreException e) {
// Ignore
}
return false;
}

public static IFile findFile(String uriString) {
return (IFile) findResource(toURI(uriString), ResourcesPlugin.getWorkspace().getRoot()::findFilesForLocationURI);
}

public static IContainer findFolder(String uriString) {
return (IContainer) findResource(toURI(uriString), ResourcesPlugin.getWorkspace().getRoot()::findContainersForLocationURI);
}

public static IResource findResource(URI uri, Function<URI, IResource[]> resourceFinder) {
if (uri == null || !"file".equals(uri.getScheme())) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public void fileChanged(String uriString, CHANGE_TYPE changeType) {
if (uriString == null) {
return;
}
IResource resource = JDTUtils.findFile(uriString);
IResource resource = JDTUtils.isFolder(uriString) ? JDTUtils.findFolder(uriString) : JDTUtils.findFile(uriString);
if (resource == null) {
return;
}
Expand Down

0 comments on commit 6daf588

Please sign in to comment.