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:
parent
2981fa7e31
commit
ba7cd25db1
2 changed files with 32 additions and 1 deletions
|
@ -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;
|
||||
|
|
|
@ -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$
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue