1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-29 11:55:40 +02:00

Use Platform's findFiles as fallback, bug 260516.

This commit is contained in:
Markus Schorn 2009-01-14 11:09:54 +00:00
parent 4ae53aa136
commit 8d815b790d
6 changed files with 18 additions and 23 deletions

View file

@ -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.FileContentHelper;
import org.eclipse.cdt.internal.core.dom.rewrite.util.FileHelper; 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.parser.scanner.ILocationResolver;
import org.eclipse.cdt.internal.core.resources.ResourceLookup;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import org.eclipse.ltk.core.refactoring.Change; import org.eclipse.ltk.core.refactoring.Change;
@ -230,13 +230,10 @@ public class ChangeGenerator extends CPPASTVisitor {
targetLocation = getFileLocationOfEmptyTranslationUnit(modification.getTargetNode()); targetLocation = getFileLocationOfEmptyTranslationUnit(modification.getTargetNode());
String currentFile = targetLocation.getFileName(); String currentFile = targetLocation.getFileName();
IPath implPath = new Path(currentFile); IPath implPath = new Path(currentFile);
IFile[] relevantFiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(implPath); IFile relevantFile= ResourceLookup.selectFileForLocation(implPath, null);
if (relevantFiles.length == 0) { // if not in workspace or local file system if (relevantFile == null) { // if not in workspace or local file system
throw new UnhandledASTModificationException(modification); 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; MultiTextEdit edit;
if (changes.containsKey(relevantFile)) { if (changes.containsKey(relevantFile)) {
edit = changes.get(relevantFile); edit = changes.get(relevantFile);

View file

@ -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.CPPASTWhileStatement;
import org.eclipse.cdt.internal.core.dom.parser.cpp.GPPASTExplicitTemplateInstantiation; 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.dom.rewrite.util.OffsetHelper;
import org.eclipse.cdt.internal.core.resources.ResourceLookup;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
@ -150,8 +150,7 @@ public class NodeCommenter {
return true; return true;
} }
IPath path = new Path(node.getContainingFilename()); IPath path = new Path(node.getContainingFilename());
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path); IFile file = ResourceLookup.selectFileForLocation(path, null); // NPE thrown below, like original behavior
IFile file = files.length > 0 ? files[0] : null; // NPE thrown below, like original behavior
//XXX HSR Guido: Possible Performance Issue (File access) //XXX HSR Guido: Possible Performance Issue (File access)
try { try {

View file

@ -18,6 +18,7 @@ import java.io.InputStream;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation; import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTNode; 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.IFile;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope; import org.eclipse.core.resources.ProjectScope;
@ -36,8 +37,7 @@ public class FileHelper {
public static IFile getIFilefromIASTNode(IASTNode node) { public static IFile getIFilefromIASTNode(IASTNode node) {
IPath implPath = new Path(node.getContainingFilename()); IPath implPath = new Path(node.getContainingFilename());
IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(implPath); return ResourceLookup.selectFileForLocation(implPath, null);
return files.length > 0 ? files[0] : null;
} }
public static boolean isFirstWithinSecondLocation(IASTFileLocation loc1, IASTFileLocation loc2){ public static boolean isFirstWithinSecondLocation(IASTFileLocation loc1, IASTFileLocation loc2){

View file

@ -14,7 +14,9 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import org.eclipse.core.filesystem.URIUtil;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
@ -36,7 +38,8 @@ abstract class LocationAdapter<T> {
@Override @Override
public IFile[] platformsFindFilesForLocation(IPath location) { 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 @Override

View file

@ -79,11 +79,11 @@ public class ResourceLookup {
/** /**
* Uses {@link #findFilesForLocation(IPath)} and selects the most relevant file * 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}. * roots are preferred, see {@link FileRelevance}.
* @param location a path for the location of the files to search for. * @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>. * @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) { public static IFile selectFileForLocation(IPath location, IProject preferredProject) {
return selectFile(findFilesForLocation(location), preferredProject); return selectFile(findFilesForLocation(location), preferredProject);

View file

@ -653,22 +653,18 @@ class ResourceLookupTree implements IResourceChangeListener, IResourceDeltaVisit
synchronized (fLock) { synchronized (fLock) {
initializeProjects(ResourcesPlugin.getWorkspace().getRoot().getProjects()); initializeProjects(ResourcesPlugin.getWorkspace().getRoot().getProjects());
Object obj= fNodeMap.get(hashCode(name.toCharArray())); Object obj= fNodeMap.get(hashCode(name.toCharArray()));
if (obj == null) { if (obj != null) {
if (fDefaultExtensions.isRelevant(name))
return NO_FILES;
} else {
candidates= convert(obj); candidates= convert(obj);
IFile[] result= extractMatchesForLocation(candidates, location, adapter);
if (result.length > 0)
return result;
} }
} }
// fall back to platform functionality // fall back to platform functionality
if (candidates == null) {
return adapter.platformsFindFilesForLocation(location); return adapter.platformsFindFilesForLocation(location);
} }
return extractMatchesForLocation(candidates, location, adapter);
}
private Node[] convert(Object obj) { private Node[] convert(Object obj) {
if (obj instanceof Node) if (obj instanceof Node)
return new Node[] {(Node) obj}; return new Node[] {(Node) obj};