Bug 347501 - [qf] Create local variable quick fix should convert assignment statement into equals initializer
Summary: [qf] Create local variable quick fix should convert assignment statement into...
Status: NEW
Alias: None
Product: CDT
Classification: Tools
Component: cdt-editor (show other bugs)
Version: 8.0   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact: Jonah Graham CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-27 15:02 EDT by Sergey Prigogin CLA
Modified: 2020-09-04 15:17 EDT (History)
4 users (show)

See Also:


Attachments
fix (6.15 KB, patch)
2011-06-15 09:28 EDT, Tomasz Wesolowski CLA
no flags Details | Diff
fix + tests (8.57 KB, patch)
2011-07-18 18:27 EDT, Tomasz Wesolowski CLA
no flags Details | Diff
fix + tests (11.64 KB, patch)
2011-07-19 14:45 EDT, Tomasz Wesolowski CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sergey Prigogin CLA 2011-05-27 15:02:31 EDT
In the following code, position the cursor on x and select Create local variable from the quick fix menu.

void test() {
  x = 1;
}

The quick fix creates a declaration for x before the assignment statement:

void test() {
    int x;
  x = 1;
}

It should instead produce:

void test() {
  int x = 1;
}
Comment 1 Tomasz Wesolowski CLA 2011-06-15 09:28:19 EDT
Created attachment 198017 [details]
fix

This implements the feature for simple assignments.

One might notice that currently part of the generated declaration lands in the wrong place (the declspec is added line or a few lines before the initializer). I suspect this is another problem with ASTRewrite infrastructure.
Comment 2 Elena Laskavaia CLA 2011-07-15 21:17:45 EDT
can you please create a unit test too?
Comment 3 Tomasz Wesolowski CLA 2011-07-18 18:27:00 EDT
Created attachment 199868 [details]
fix + tests

The problem is that the issue with ASTRewrite I've mentioned (wrong output formatting) breaks the tests after this patch.
Comment 4 Sergey Prigogin CLA 2011-07-18 18:38:47 EDT
(In reply to comment #3)
> The problem is that the issue with ASTRewrite I've mentioned (wrong output
> formatting) breaks the tests after this patch.

The issues with ASTRewrite, invalid edits and lack of formatting, affect all refactorings. These issues should be solved independently from this bug.
Tomassz, you can modify the test to make it pass as long as the only difference is wrong formatting.
Comment 5 Tomasz Wesolowski CLA 2011-07-19 14:45:50 EDT
Created attachment 199933 [details]
fix + tests

OK, let's have it this way!

New patch. BTW- switched to command line from EGit, I hope I made the patch right :)
Comment 6 Nathan Ridge CLA 2015-12-15 21:33:50 EST
Tomasz, could you submit this patch to Gerrit so it can be committed? Thanks!