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

Bug 319196

Summary: Quick fixes for creating a variable
Product: [Tools] CDT Reporter: Tomasz Wesolowski <kosashi>
Component: cdt-codanAssignee: Elena Laskavaia <elaskavaia.cdt>
Status: RESOLVED FIXED QA Contact: Elena Laskavaia <elaskavaia.cdt>
Severity: enhancement    
Priority: P3 CC: cdtdoug, malaperle
Version: 7.0   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Bug Depends on: 309760    
Bug Blocks:    
Attachments:
Description Flags
CxxAstUtils updated
elaskavaia.cdt: iplog+
Fixes
none
updated AbstractCodanCMarkerResolution
elaskavaia.cdt: iplog+
Fixes
elaskavaia.cdt: iplog+
Additional fix for type inference
none
mylyn/context/zip none

Description Tomasz Wesolowski CLA 2010-07-07 18:05:40 EDT
Build Identifier: 

This includes fixes for creating a local variable, a parameter or a field.

Reproducible: Always
Comment 1 Tomasz Wesolowski CLA 2010-07-07 18:06:39 EDT
Created attachment 173719 [details]
CxxAstUtils updated

Extended type inference in CxxAstUtils, used by fixes
Comment 2 Tomasz Wesolowski CLA 2010-07-07 18:07:16 EDT
Created attachment 173720 [details]
Fixes

QuickFixCreateField
QuickFixCreateLocalVariable
QuickFixCreateParameter
Comment 3 Marc-André Laperle CLA 2010-07-09 00:24:52 EDT
Hi Tomasz, I applied the latest patch from bug 309760 and the two patches from this bug, but getIndexFromMarker seems to be missing. Did I forget something?
Comment 4 Tomasz Wesolowski CLA 2010-07-14 05:14:46 EDT
Created attachment 174269 [details]
updated AbstractCodanCMarkerResolution

Actually I did forget something while splitting the previous (big) patch from bug 309760 into smaller ones. Here's the missing part.
Comment 5 Tomasz Wesolowski CLA 2010-07-20 12:20:42 EDT
Created attachment 174766 [details]
Fixes

More strict applicability test
Comment 6 CDT Genie CLA 2010-07-20 20:23:03 EDT
*** cdt cvs genie on behalf of elaskavaia ***
Bug 319196 - updated utils with more useful methods (contributed by Tomasz Wesolowski)

[*] CxxAstUtils.java 1.5 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java?root=Tools_Project&r1=1.4&r2=1.5
Comment 7 Elena Laskavaia CLA 2010-07-20 22:31:25 EDT
For patch#2 updated AbstractCodanCMarkerResolution I did not add methods for getArtuments - they are specific to a problem not to quick fix.

I modified code for quick fixed - extracted an abstract class to lock the index,
also for next time please do not leave e.printStackTrace() in the code - replace with eclipse logging.

Applied to trunk. Also added test you sent me by e-mail. For bugs in these and extra tests please open another bug.
Comment 8 CDT Genie CLA 2010-07-20 23:23:08 EDT
*** cdt cvs genie on behalf of elaskavaia ***
Bug 319196 updated to add common method

[*] AbstractCodanCMarkerResolution.java 1.4 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/AbstractCodanCMarkerResolution.java?root=Tools_Project&r1=1.3&r2=1.4

[+] CreateLocalVariableQuickFixTest.java  http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CreateLocalVariableQuickFixTest.java?root=Tools_Project&revision=1.1&view=markup

[*] plugin.xml 1.8 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.checkers.ui/plugin.xml?root=Tools_Project&r1=1.7&r2=1.8

[+] messages.properties  http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/messages.properties?root=Tools_Project&revision=1.1&view=markup
[+] QuickFixCreateParameter.java  http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixCreateParameter.java?root=Tools_Project&revision=1.1&view=markup
[+] Messages.java  http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/Messages.java?root=Tools_Project&revision=1.1&view=markup
[+] AbstractAstRewriteQuickFix.java  http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/AbstractAstRewriteQuickFix.java?root=Tools_Project&revision=1.1&view=markup
[+] QuickFixCreateLocalVariable.java  http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixCreateLocalVariable.java?root=Tools_Project&revision=1.1&view=markup
[+] QuickFixCreateField.java  http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixCreateField.java?root=Tools_Project&revision=1.1&view=markup

[*] MANIFEST.MF 1.11 http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.cdt/codan/org.eclipse.cdt.codan.checkers.ui/META-INF/MANIFEST.MF?root=Tools_Project&r1=1.10&r2=1.11
Comment 9 Marc-André Laperle CLA 2010-07-21 12:42:44 EDT
Hi, I tested the quick fix in a simple case:

#include "TestClass.h"

TestClass::TestClass() {
	foo(a, b);
}

void TestClass::foo(int a, int b)
{
}


If I use create field on 'a' and 'b', their type is void instead of int. Should I open a bug for this? Or is this covered by a refactoring bug?
Comment 10 Elena Laskavaia CLA 2010-07-21 14:33:57 EDT
Yes please. I had this problem too. Void as a default does not make any sense.
void a; is semantical nonsense.
Comment 11 Tomasz Wesolowski CLA 2010-07-21 16:04:02 EDT
Void declarations are generated as the fallback when no type can be inferred.

In this case the problem was caused by the fact that tryInferTypeFromFunctionCall failed because of astName.getTranslationUnit().getIndex() returning null. This happened only with "create field" fix, curiously.
I solved the problem by passing the correct project-index to createDeclaration.
Comment 12 Tomasz Wesolowski CLA 2010-07-21 16:05:24 EDT
Created attachment 174907 [details]
Additional fix for type inference
Comment 13 Tomasz Wesolowski CLA 2010-07-21 16:05:28 EDT
Created attachment 174908 [details]
mylyn/context/zip
Comment 14 Tomasz Wesolowski CLA 2010-07-21 16:08:34 EDT
sorry for irrelevant second attachment
Comment 15 Elena Laskavaia CLA 2010-07-21 19:45:05 EDT
this bugs is resolved. please add you new patch to another bug. open one if not already exists. And should should fall back to "int" to "void" in any case.
Comment 16 Elena Laskavaia CLA 2010-07-21 20:14:16 EDT
Here is new bug 320575