1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 14:12:10 +02:00

Bug 339463 - Quick fix create local variable and others do not infer parameter types in method calls

This commit is contained in:
Marc-Andre Laperle 2011-03-22 04:29:50 +00:00
parent 2981fa7e31
commit ba7cd25db1
2 changed files with 32 additions and 1 deletions

View file

@ -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.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTExpression; import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement; 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.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression; import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator; import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
@ -73,6 +74,22 @@ public final class CxxAstUtils {
return PROCESS_ABORT; 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 static CxxAstUtils instance;
private CxxAstUtils() { private CxxAstUtils() {
@ -201,7 +218,7 @@ public final class CxxAstUtils {
if (astName.getParent() instanceof IASTIdExpression && astName.getParent().getParent() instanceof IASTFunctionCallExpression if (astName.getParent() instanceof IASTIdExpression && astName.getParent().getParent() instanceof IASTFunctionCallExpression
&& astName.getParent().getPropertyInParent() == IASTFunctionCallExpression.ARGUMENT) { && astName.getParent().getPropertyInParent() == IASTFunctionCallExpression.ARGUMENT) {
IASTFunctionCallExpression call = (IASTFunctionCallExpression) astName.getParent().getParent(); IASTFunctionCallExpression call = (IASTFunctionCallExpression) astName.getParent().getParent();
NameFinderVisitor visitor = new NameFinderVisitor(); FunctionNameFinderVisitor visitor = new FunctionNameFinderVisitor();
call.getFunctionNameExpression().accept(visitor); call.getFunctionNameExpression().accept(visitor);
IASTName funcname = visitor.name; IASTName funcname = visitor.name;
int expectedParametersNum = 0; int expectedParametersNum = 0;

View file

@ -84,4 +84,18 @@ public class CreateLocalVariableQuickFixTest extends QuickFixTestCase {
String result = runQuickFixOneFile(); String result = runQuickFixOneFile();
assertContainedIn("void (*aFuncPtr)();", result); //$NON-NLS-1$ 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$
}
} }