diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java index e9a834ba427..5f447020e84 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/changegenerator/ChangeGenerator.java @@ -43,6 +43,7 @@ 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; @@ -230,10 +231,13 @@ public class ChangeGenerator extends CPPASTVisitor { targetLocation = getFileLocationOfEmptyTranslationUnit(modification.getTargetNode()); String currentFile = targetLocation.getFileName(); IPath implPath = new Path(currentFile); - IFile relevantFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(implPath); - if (relevantFile == null) { // if not in workspace + IFile[] relevantFiles = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(implPath); + if (relevantFiles.length == 0) { // 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); diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommenter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommenter.java index 3cae3e20ea0..4fdf8068f74 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommenter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/commenthandler/NodeCommenter.java @@ -150,7 +150,8 @@ public class NodeCommenter { return true; } IPath path = new Path(node.getContainingFilename()); - IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path); + IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path); + IFile file = files.length > 0 ? files[0] : null; // NPE thrown below, like original behavior //XXX HSR Guido: Possible Performance Issue (File access) try { diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileHelper.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileHelper.java index 6a64c399dbe..6bffa2e3f7d 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileHelper.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/rewrite/util/FileHelper.java @@ -36,7 +36,8 @@ public class FileHelper { public static IFile getIFilefromIASTNode(IASTNode node) { IPath implPath = new Path(node.getContainingFilename()); - return ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(implPath); + IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(implPath); + return files.length > 0 ? files[0] : null; } public static boolean isFirstWithinSecondLocation(IASTFileLocation loc1, IASTFileLocation loc2){