Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc-Andre Laperle2011-03-22 00:29:50 -0400
committerMarc-Andre Laperle2011-03-22 00:29:50 -0400
commitba7cd25db13a8445fc032dc35c998e7970a83eac (patch)
treebae6c5f94d0ee5bbce8823e366324ca384412475
parent2981fa7e31cb5176500c936bc6f15933138d36b1 (diff)
downloadorg.eclipse.cdt-ba7cd25db13a8445fc032dc35c998e7970a83eac.tar.gz
org.eclipse.cdt-ba7cd25db13a8445fc032dc35c998e7970a83eac.tar.xz
org.eclipse.cdt-ba7cd25db13a8445fc032dc35c998e7970a83eac.zip
Bug 339463 - Quick fix create local variable and others do not infer parameter types in method calls
-rw-r--r--codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java19
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CreateLocalVariableQuickFixTest.java14
2 files changed, 32 insertions, 1 deletions
diff --git a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java
index 4fa38cc85e..b297756c36 100644
--- a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java
+++ b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtils.java
@@ -24,6 +24,7 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
+import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
@@ -73,6 +74,22 @@ public final class CxxAstUtils {
return PROCESS_ABORT;
}
}
+
+ private class FunctionNameFinderVisitor extends NameFinderVisitor {
+ {
+ shouldVisitExpressions = true;
+ }
+
+ @Override
+ public int visit(IASTExpression expression) {
+ if(expression instanceof IASTFieldReference) {
+ this.name = ((IASTFieldReference) expression).getFieldName();
+ return PROCESS_ABORT;
+ }
+ return super.visit(expression);
+ }
+ }
+
private static CxxAstUtils instance;
private CxxAstUtils() {
@@ -201,7 +218,7 @@ public final class CxxAstUtils {
if (astName.getParent() instanceof IASTIdExpression && astName.getParent().getParent() instanceof IASTFunctionCallExpression
&& astName.getParent().getPropertyInParent() == IASTFunctionCallExpression.ARGUMENT) {
IASTFunctionCallExpression call = (IASTFunctionCallExpression) astName.getParent().getParent();
- NameFinderVisitor visitor = new NameFinderVisitor();
+ FunctionNameFinderVisitor visitor = new FunctionNameFinderVisitor();
call.getFunctionNameExpression().accept(visitor);
IASTName funcname = visitor.name;
int expectedParametersNum = 0;
diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CreateLocalVariableQuickFixTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CreateLocalVariableQuickFixTest.java
index d1eb6a0b7d..fe530b17e5 100644
--- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CreateLocalVariableQuickFixTest.java
+++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CreateLocalVariableQuickFixTest.java
@@ -84,4 +84,18 @@ public class CreateLocalVariableQuickFixTest extends QuickFixTestCase {
String result = runQuickFixOneFile();
assertContainedIn("void (*aFuncPtr)();", result); //$NON-NLS-1$
}
+
+ //class Foo {
+ // void bar(char);
+ //};
+ //void func() {
+ //Foo foo;
+ //foo.bar(aChar);
+ //}
+ public void testInMethodCall() throws Exception {
+ loadcode(getAboveComment());
+ indexFiles();
+ String result = runQuickFixOneFile();
+ assertContainedIn("char aChar", result); //$NON-NLS-1$
+ }
}

Back to the top