Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 53243

Summary: [Refactoring] Bad syntax should not fail local refactorings
Product: [Eclipse Project] JDT Reporter: Jason Yip <j.c.yip>
Component: UIAssignee: Markus Keller <markus.kell.r>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: frederic_fusier
Version: 3.0   
Target Milestone: 3.2 M6   
Hardware: PC   
OS: Windows 2000   
Whiteboard:
Bug Depends on: 42253    
Bug Blocks:    

Description Jason Yip CLA 2004-02-26 21:09:14 EST
Code looks like this:
----
System.out.println("blah");

for (int i=
----
Extract local variable for "blah" will fail because of the subsequent syntax 
error.  Non-existent types will not fail.  I would like Extract Local Variable 
to survive this kind of situation anyway since as far as I can tell, there is 
enough information in this context to determine what the extraction should do.  
Granted code is broken and it will stay broken, any duplicate "blah"s in the 
rest of the file should probably be ignored, etc. BUT I find myself attempting 
to do this sort of thing a lot and it's getting more and more annoying that 
Eclipse complains.
Comment 1 Martin Aeschlimann CLA 2004-02-27 05:30:51 EST
our AST is can't deal with incorrect syntax by design. I think there are plans
to improve error recovery; moving to jdt.core.
Comment 2 Philipe Mulet CLA 2004-03-04 18:31:26 EST
Not for 3.0
Comment 3 Philipe Mulet CLA 2004-07-22 12:07:05 EDT
dup
Comment 4 Philipe Mulet CLA 2004-07-22 12:07:17 EDT

*** This bug has been marked as a duplicate of 42253 ***
Comment 5 Frederic Fusier CLA 2006-02-15 11:20:18 EST
Reopen as there's still something preventing user to extract local variable.
Bug 42253 is fixed and I can see now 2 statements: ExpressionStatement and ForStatement. However, when I select "blah" and try to Refactor->Extract local variable... I get an "Extract Local variable" error dialog saying:
"The file contains syntax errors. To perform this operation you will need to fix the errors."
Comment 6 Frederic Fusier CLA 2006-02-15 11:20:50 EST
Back to JDT/UI to enable user to perform this operation...
Comment 7 Martin Aeschlimann CLA 2006-02-16 05:17:36 EST
BTW, it works if you use quick fix to extract the local.

But we should also update the refactoring to use the statement recovery AST.
Markus, can you make a pass on all of the 'local' refactoring (refactorings that just work on one file).
Comment 8 Markus Keller CLA 2006-02-27 12:50:08 EST
Fixed for all one-file-refactorings.