mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Use Platform's findFiles as fallback, bug 260516.
This commit is contained in:
parent
4ae53aa136
commit
8d815b790d
6 changed files with 18 additions and 23 deletions
|
@ -43,8 +43,8 @@ import org.eclipse.cdt.internal.core.dom.rewrite.commenthandler.NodeCommentMap;
|
|||
import org.eclipse.cdt.internal.core.dom.rewrite.util.FileContentHelper;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.util.FileHelper;
|
||||
import org.eclipse.cdt.internal.core.parser.scanner.ILocationResolver;
|
||||
import org.eclipse.cdt.internal.core.resources.ResourceLookup;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.ltk.core.refactoring.Change;
|
||||
|
@ -230,13 +230,10 @@ public class ChangeGenerator extends CPPASTVisitor {
|
|||
targetLocation = getFileLocationOfEmptyTranslationUnit(modification.getTargetNode());
|
||||
String currentFile = targetLocation.getFileName();
|
||||
IPath implPath = new Path(currentFile);
|
||||
IFile[] relevantFiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(implPath);
|
||||
if (relevantFiles.length == 0) { // if not in workspace or local file system
|
||||
IFile relevantFile= ResourceLookup.selectFileForLocation(implPath, null);
|
||||
if (relevantFile == null) { // if not in workspace or local file system
|
||||
throw new UnhandledASTModificationException(modification);
|
||||
}
|
||||
// There may be multiple links to the same file, but since their contents are the
|
||||
// same, just use the first one.
|
||||
IFile relevantFile = relevantFiles[0];
|
||||
MultiTextEdit edit;
|
||||
if (changes.containsKey(relevantFile)) {
|
||||
edit = changes.get(relevantFile);
|
||||
|
|
|
@ -35,8 +35,8 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTTemplateDeclaration;
|
|||
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTWhileStatement;
|
||||
import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPASTExplicitTemplateInstantiation;
|
||||
import org.eclipse.cdt.internal.core.dom.rewrite.util.OffsetHelper;
|
||||
import org.eclipse.cdt.internal.core.resources.ResourceLookup;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
|
||||
|
@ -150,8 +150,7 @@ public class NodeCommenter {
|
|||
return true;
|
||||
}
|
||||
IPath path = new Path(node.getContainingFilename());
|
||||
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path);
|
||||
IFile file = files.length > 0 ? files[0] : null; // NPE thrown below, like original behavior
|
||||
IFile file = ResourceLookup.selectFileForLocation(path, null); // NPE thrown below, like original behavior
|
||||
|
||||
//XXX HSR Guido: Possible Performance Issue (File access)
|
||||
try {
|
||||
|
|
|
@ -18,6 +18,7 @@ import java.io.InputStream;
|
|||
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTNode;
|
||||
import org.eclipse.cdt.internal.core.resources.ResourceLookup;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ProjectScope;
|
||||
|
@ -36,8 +37,7 @@ public class FileHelper {
|
|||
|
||||
public static IFile getIFilefromIASTNode(IASTNode node) {
|
||||
IPath implPath = new Path(node.getContainingFilename());
|
||||
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(implPath);
|
||||
return files.length > 0 ? files[0] : null;
|
||||
return ResourceLookup.selectFileForLocation(implPath, null);
|
||||
}
|
||||
|
||||
public static boolean isFirstWithinSecondLocation(IASTFileLocation loc1, IASTFileLocation loc2){
|
||||
|
|
|
@ -14,7 +14,9 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
import org.eclipse.core.filesystem.URIUtil;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
|
@ -36,7 +38,8 @@ abstract class LocationAdapter<T> {
|
|||
|
||||
@Override
|
||||
public IFile[] platformsFindFilesForLocation(IPath location) {
|
||||
return ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(location);
|
||||
final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
|
||||
return root.findFilesForLocationURI(URIUtil.toURI(location.makeAbsolute()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -79,11 +79,11 @@ public class ResourceLookup {
|
|||
|
||||
/**
|
||||
* Uses {@link #findFilesForLocation(IPath)} and selects the most relevant file
|
||||
* from the result. Files form the first project, from cdt-projects and those on source
|
||||
* from the result. Files form the preferred project, from cdt-projects and those on source
|
||||
* roots are preferred, see {@link FileRelevance}.
|
||||
* @param location a path for the location of the files to search for.
|
||||
* @param preferredProject a project to be preferred over others, or <code>null</code>.
|
||||
* @return a file for the location in one of the given projects, or <code>null</code>.
|
||||
* @return a file for the location or <code>null</code>.
|
||||
*/
|
||||
public static IFile selectFileForLocation(IPath location, IProject preferredProject) {
|
||||
return selectFile(findFilesForLocation(location), preferredProject);
|
||||
|
|
|
@ -653,20 +653,16 @@ class ResourceLookupTree implements IResourceChangeListener, IResourceDeltaVisit
|
|||
synchronized (fLock) {
|
||||
initializeProjects(ResourcesPlugin.getWorkspace().getRoot().getProjects());
|
||||
Object obj= fNodeMap.get(hashCode(name.toCharArray()));
|
||||
if (obj == null) {
|
||||
if (fDefaultExtensions.isRelevant(name))
|
||||
return NO_FILES;
|
||||
} else {
|
||||
if (obj != null) {
|
||||
candidates= convert(obj);
|
||||
IFile[] result= extractMatchesForLocation(candidates, location, adapter);
|
||||
if (result.length > 0)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// fall back to platform functionality
|
||||
if (candidates == null) {
|
||||
return adapter.platformsFindFilesForLocation(location);
|
||||
}
|
||||
|
||||
return extractMatchesForLocation(candidates, location, adapter);
|
||||
return adapter.platformsFindFilesForLocation(location);
|
||||
}
|
||||
|
||||
private Node[] convert(Object obj) {
|
||||
|
|
Loading…
Add table
Reference in a new issue