mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-25 09:55:29 +02:00
Bug 320575 incorrect type inference for add field, patch from Tomasz Wesolowski
This commit is contained in:
parent
8ce10b8b62
commit
fd46566d60
4 changed files with 11 additions and 13 deletions
|
@ -46,7 +46,7 @@ public class QuickFixCreateField extends AbstractAstRewriteQuickFix {
|
|||
return;
|
||||
}
|
||||
IASTDeclaration declaration = utils
|
||||
.createDeclaration(astName, ast.getASTNodeFactory());
|
||||
.createDeclaration(astName, ast.getASTNodeFactory(), index);
|
||||
IASTCompositeTypeSpecifier targetCompositeType = utils
|
||||
.getEnclosingCompositeTypeSpecifier(astName);
|
||||
if (targetCompositeType == null) {
|
||||
|
|
|
@ -55,7 +55,7 @@ public class QuickFixCreateLocalVariable extends AbstractAstRewriteQuickFix {
|
|||
}
|
||||
ASTRewrite r = ASTRewrite.create(ast);
|
||||
INodeFactory factory = ast.getASTNodeFactory();
|
||||
IASTDeclaration declaration = utils.createDeclaration(astName, factory);
|
||||
IASTDeclaration declaration = utils.createDeclaration(astName, factory, index);
|
||||
IASTDeclarationStatement newStatement = factory
|
||||
.newDeclarationStatement(declaration);
|
||||
IASTNode targetStatement = utils.getEnclosingStatement(astName);
|
||||
|
|
|
@ -55,7 +55,7 @@ public class QuickFixCreateParameter extends AbstractAstRewriteQuickFix {
|
|||
return;
|
||||
}
|
||||
IASTDeclaration declaration = CxxAstUtils.getInstance()
|
||||
.createDeclaration(astName, baseAST.getASTNodeFactory());
|
||||
.createDeclaration(astName, baseAST.getASTNodeFactory(), index);
|
||||
// We'll need a FunctionParameterDeclaration later
|
||||
final IASTDeclSpecifier finalDeclSpec = (IASTDeclSpecifier) declaration
|
||||
.getChildren()[0];
|
||||
|
|
|
@ -143,10 +143,11 @@ public final class CxxAstUtils {
|
|||
* a name for the declaration
|
||||
* @param factory
|
||||
* the factory
|
||||
* @param index
|
||||
* @return
|
||||
*/
|
||||
public IASTDeclaration createDeclaration(IASTName astName,
|
||||
INodeFactory factory) {
|
||||
INodeFactory factory, IIndex index) {
|
||||
|
||||
// Depending on context, either a type or a declaration is easier to
|
||||
// infer
|
||||
|
@ -156,7 +157,7 @@ public final class CxxAstUtils {
|
|||
|
||||
inferredType = tryInferTypeFromBinaryExpr(astName);
|
||||
if (inferredType == null)
|
||||
declaration = tryInferTypeFromFunctionCall(astName, factory);
|
||||
declaration = tryInferTypeFromFunctionCall(astName, factory, index);
|
||||
|
||||
// After the inference, create the statement is needed
|
||||
|
||||
|
@ -208,11 +209,12 @@ public final class CxxAstUtils {
|
|||
/**
|
||||
* For a function call, tries to find a matching function declaration.
|
||||
* Checks the argument count.
|
||||
* @param index
|
||||
*
|
||||
* @return a generated declaration or null if not suitable
|
||||
*/
|
||||
private IASTSimpleDeclaration tryInferTypeFromFunctionCall(
|
||||
IASTName astName, INodeFactory factory) {
|
||||
IASTName astName, INodeFactory factory, IIndex index) {
|
||||
if (astName.getParent() instanceof IASTIdExpression
|
||||
&& astName.getParent().getParent() instanceof IASTFunctionCallExpression
|
||||
&& astName.getParent().getPropertyInParent() == IASTFunctionCallExpression.ARGUMENT) {
|
||||
|
@ -238,10 +240,6 @@ public final class CxxAstUtils {
|
|||
return null;
|
||||
}
|
||||
|
||||
IIndex index = astName.getTranslationUnit().getIndex();
|
||||
if (index == null) {
|
||||
return null;
|
||||
}
|
||||
IBinding[] bindings;
|
||||
{
|
||||
IBinding binding = funcname.resolveBinding();
|
||||
|
@ -311,9 +309,9 @@ public final class CxxAstUtils {
|
|||
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
// skip
|
||||
} catch (CoreException e) {
|
||||
e.printStackTrace();
|
||||
Activator.log(e);
|
||||
} finally {
|
||||
index.releaseReadLock();
|
||||
}
|
||||
|
@ -403,7 +401,7 @@ public final class CxxAstUtils {
|
|||
} catch (InterruptedException e) {
|
||||
return PROCESS_ABORT;
|
||||
} catch (CoreException e) {
|
||||
e.printStackTrace();
|
||||
Activator.log(e);
|
||||
return PROCESS_ABORT;
|
||||
} finally {
|
||||
index.releaseReadLock();
|
||||
|
|
Loading…
Add table
Reference in a new issue