Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh with one depth when calling JDTUtils.getFileOrFolder() #1207

Merged
merged 2 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
package org.eclipse.jdt.ls.core.internal;

import static org.eclipse.core.resources.IResource.DEPTH_ONE;
import static org.eclipse.core.resources.IResource.DEPTH_ZERO;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -891,7 +890,7 @@ public static IResource getFileOrFolder(String uriString) {
return file;
}
try {
parent.refreshLocal(DEPTH_ZERO, null);
parent.refreshLocal(DEPTH_ONE, null);
} catch (CoreException e) {
// Ignore
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.commons.io.FileUtils;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
Expand Down Expand Up @@ -229,4 +230,22 @@ public void testIsFolder() throws Exception {
assertNotNull(JDTUtils.findFile(uriFile.toString()));
assertNotNull(JDTUtils.findFolder(uriFolder.toString()));
}

@Test
public void testGetFileOrFolder() throws Exception {
// For: https://github.com/eclipse/eclipse.jdt.ls/issues/1137
IProject project = WorkspaceHelper.getProject(ProjectsManager.DEFAULT_PROJECT_NAME);

File parentFolder = new File(project.getLocation().toString(), "/src/org/eclipse");
IResource parent = JDTUtils.getFileOrFolder(parentFolder.toURI().toString());
assertTrue(parent instanceof IFolder);
final int originalMemberNum = ((IFolder) parent).members().length;

File newPackage = new File(project.getLocation().toString(), "/src/org/eclipse/testGetFileOrFolder");
newPackage.mkdirs();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will the new package be cleaned up after the test done?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


IResource resource = JDTUtils.getFileOrFolder(newPackage.toURI().toString());
assertTrue(resource instanceof IFolder);
assertEquals("The parent package should be aware of the newly created child package", ((IFolder) parent).members().length, originalMemberNum + 1);
}
}