Bug 252511 - UnhandedASTModificationException when refactoring source files in linked directories
Summary: UnhandedASTModificationException when refactoring source files in linked dire...
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-core (show other bugs)
Version: 6.0   Edit
Hardware: All All
: P3 critical (vote)
Target Milestone: 5.0.2   Edit
Assignee: Emanuel Graf CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2008-10-28 18:23 EDT by Tom Ball CLA
Modified: 2010-05-28 12:55 EDT (History)
4 users (show)

See Also:


Attachments
Replace three calls to getFileForLocation() to findFilesForLocation() in rewriter (3.53 KB, patch)
2008-10-28 18:23 EDT, Tom Ball CLA
cdtdoug: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Ball CLA 2008-10-28 18:23:00 EDT
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)
Comment 1 Tom Ball CLA 2008-10-28 18:25:35 EDT
Upgrading severity since this bug blocks all C++ refactoring for all of our internal Eclipse users.
Comment 2 James Blackburn CLA 2008-10-28 18:34:36 EDT
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.
Comment 3 Emanuel Graf CLA 2008-10-29 08:12:45 EDT
(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
Comment 4 Tom Ball CLA 2008-10-29 10:21:54 EDT
Thank you very much for resolving issue around so quickly!