Community
Participate
Working Groups
Created attachment 116368 [details] Replace three calls to getFileForLocation() to findFilesForLocation() in rewriter Build ID: I20080617-2000 Steps To Reproduce: 1. Create an empty C++ project without a source directory 2. Create a new folder, click Advanced and click "Link to folder in folder in the file system", and specify a directory outside of the workspace. 3. In the project properties, select C/C++ General->Paths and Symbols, click on the Source Location tab, click Add Folder and select the previously linked directory. 4. Create a C++ source file in the linked directory. 5. Select an expression, then Refactor->Extract Function 6. Fill out the first wizard panel, then click either Next or Finish. More information: The problem is the use of IWorkspace.getFileForLocation() instead of IWorkspace.findFilesForLocation(). The former returns null if the path contains an Eclipse link, while the latter follows the link correctly. Here is the first exception, two others follow if you only fix this location: Root exception: org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.UnhandledASTModificationException: Tried to INSERT_BEFORE on org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDefinition@790ec1 with org.eclipse.cdt.internal.core.dom.parser.cpp.CPPASTFunctionDefinition@1b7d46f at org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator.synthTreatment(ChangeGenerator.java:237) at org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator.visit(ChangeGenerator.java:154) at org.eclipse.cdt.internal.core.dom.parser.ASTTranslationUnit.accept(ASTTranslationUnit.java:233) at org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator.generateChange(ChangeGenerator.java:115) at org.eclipse.cdt.internal.core.dom.rewrite.changegenerator.ChangeGenerator.generateChange(ChangeGenerator.java:107) at org.eclipse.cdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.rewriteAST(ASTRewriteAnalyzer.java:24) at org.eclipse.cdt.core.dom.rewrite.ASTRewrite.rewriteAST(ASTRewrite.java:177) at org.eclipse.cdt.internal.ui.refactoring.ModificationCollector.createFinalChange(ModificationCollector.java:64) at org.eclipse.cdt.internal.ui.refactoring.CRefactoring.createChange(CRefactoring.java:209) at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:124)
Upgrading severity since this bug blocks all C++ refactoring for all of our internal Eclipse users.
In your patch you've got the comment: // There may be multiple links to the same file, but since their contents are the // same, just use the first one. Is it really the case that the refactoring code doesn't use the context of the IFile -- i.e. if the file is linked in multiple projects, or there are overlapping projects in the workspace, does it matter if you return the IFile from a non CDT Project? FYI there is some new API in cdt.core: ResourceLookup.selectFileForLocation(IPath location, IProject preferredProject) which attempts to return the 'correct' IFile for a given external location.
(In reply to comment #2) > Is it really the case that the refactoring code doesn't use the context of the > IFile refactoring code does but the change generator code only deals with ASTNode and I found no way to get a IFile from a ASTNodeLocation. I've commited the patch to HEAD and 5.0
Thank you very much for resolving issue around so quickly!