mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Declare utility methods static.
This commit is contained in:
parent
99fa95b7cd
commit
ecd14f70f8
16 changed files with 61 additions and 79 deletions
|
@ -53,7 +53,7 @@ public class CaseBreakQuickFixBreak extends AbstractAstRewriteQuickFix {
|
||||||
IASTNode containedNode = nodeSelector.findFirstContainedNode(lineInformation.getOffset(), lineInformation.getLength());
|
IASTNode containedNode = nodeSelector.findFirstContainedNode(lineInformation.getOffset(), lineInformation.getLength());
|
||||||
IASTNode beforeBreakNode = null;
|
IASTNode beforeBreakNode = null;
|
||||||
if (containedNode != null)
|
if (containedNode != null)
|
||||||
beforeBreakNode = CxxAstUtils.getInstance().getEnclosingStatement(containedNode);
|
beforeBreakNode = CxxAstUtils.getEnclosingStatement(containedNode);
|
||||||
else
|
else
|
||||||
beforeBreakNode = nodeSelector.findEnclosingNode(lineInformation.getOffset(), lineInformation.getLength());
|
beforeBreakNode = nodeSelector.findEnclosingNode(lineInformation.getOffset(), lineInformation.getLength());
|
||||||
if (beforeBreakNode instanceof IASTCompoundStatement) {
|
if (beforeBreakNode instanceof IASTCompoundStatement) {
|
||||||
|
|
|
@ -1,3 +1,13 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2011 Alena Laskavaia and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Alena Laskavaia - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.codan.internal.checkers.ui.quickfix;
|
package org.eclipse.cdt.codan.internal.checkers.ui.quickfix;
|
||||||
|
|
||||||
import org.eclipse.cdt.codan.core.model.IProblem;
|
import org.eclipse.cdt.codan.core.model.IProblem;
|
||||||
|
|
|
@ -17,7 +17,7 @@ import org.eclipse.core.resources.IMarker;
|
||||||
import org.eclipse.jface.text.IDocument;
|
import org.eclipse.jface.text.IDocument;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* quick fix for catch by value
|
* Quick fix for catch by value
|
||||||
*/
|
*/
|
||||||
public class CatchByConstReferenceQuickFix extends AbstractCodanCMarkerResolution {
|
public class CatchByConstReferenceQuickFix extends AbstractCodanCMarkerResolution {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -18,7 +18,7 @@ import org.eclipse.jface.text.BadLocationException;
|
||||||
import org.eclipse.jface.text.IDocument;
|
import org.eclipse.jface.text.IDocument;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* quick fix for catch by value
|
* Quick fix for catch by value
|
||||||
*/
|
*/
|
||||||
public class CatchByReferenceQuickFix extends AbstractCodanCMarkerResolution {
|
public class CatchByReferenceQuickFix extends AbstractCodanCMarkerResolution {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -40,19 +40,18 @@ public class QuickFixCreateField extends AbstractAstRewriteQuickFix {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void modifyAST(IIndex index, IMarker marker) {
|
public void modifyAST(IIndex index, IMarker marker) {
|
||||||
CxxAstUtils utils = CxxAstUtils.getInstance();
|
|
||||||
try {
|
try {
|
||||||
IASTTranslationUnit ast = getTranslationUnitViaEditor(marker).getAST(index, ITranslationUnit.AST_SKIP_INDEXED_HEADERS);
|
IASTTranslationUnit ast = getTranslationUnitViaEditor(marker).getAST(index, ITranslationUnit.AST_SKIP_INDEXED_HEADERS);
|
||||||
IASTName astName = getASTNameFromMarker(marker, ast);
|
IASTName astName = getASTNameFromMarker(marker, ast);
|
||||||
if (astName == null) {
|
if (astName == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
IASTDeclaration declaration = utils.createDeclaration(astName, ast.getASTNodeFactory(), index);
|
IASTDeclaration declaration = CxxAstUtils.createDeclaration(astName, ast.getASTNodeFactory(), index);
|
||||||
IASTCompositeTypeSpecifier targetCompositeType = utils.getEnclosingCompositeTypeSpecifier(astName);
|
IASTCompositeTypeSpecifier targetCompositeType = CxxAstUtils.getEnclosingCompositeTypeSpecifier(astName);
|
||||||
if (targetCompositeType == null) {
|
if (targetCompositeType == null) {
|
||||||
// We're not in an inline method;
|
// We're not in an inline method;
|
||||||
// check if we're in a method at all
|
// check if we're in a method at all
|
||||||
targetCompositeType = utils.getCompositeTypeFromFunction(utils.getEnclosingFunction(astName), index);
|
targetCompositeType = CxxAstUtils.getCompositeTypeFromFunction(CxxAstUtils.getEnclosingFunction(astName), index);
|
||||||
if (targetCompositeType == null) {
|
if (targetCompositeType == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,15 +33,8 @@ public class QuickFixCreateLocalVariable extends AbstractAstRewriteQuickFix {
|
||||||
return Messages.QuickFixCreateLocalVariable_0;
|
return Messages.QuickFixCreateLocalVariable_0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param ast
|
|
||||||
* @param astName
|
|
||||||
* @param r
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public void modifyAST(IIndex index, IMarker marker) {
|
public void modifyAST(IIndex index, IMarker marker) {
|
||||||
CxxAstUtils utils = CxxAstUtils.getInstance();
|
|
||||||
IASTTranslationUnit ast;
|
IASTTranslationUnit ast;
|
||||||
try {
|
try {
|
||||||
ITranslationUnit tu = getTranslationUnitViaEditor(marker);
|
ITranslationUnit tu = getTranslationUnitViaEditor(marker);
|
||||||
|
@ -61,9 +54,9 @@ public class QuickFixCreateLocalVariable extends AbstractAstRewriteQuickFix {
|
||||||
}
|
}
|
||||||
ASTRewrite r = ASTRewrite.create(ast);
|
ASTRewrite r = ASTRewrite.create(ast);
|
||||||
INodeFactory factory = ast.getASTNodeFactory();
|
INodeFactory factory = ast.getASTNodeFactory();
|
||||||
IASTDeclaration declaration = utils.createDeclaration(astName, factory, index);
|
IASTDeclaration declaration = CxxAstUtils.createDeclaration(astName, factory, index);
|
||||||
IASTDeclarationStatement newStatement = factory.newDeclarationStatement(declaration);
|
IASTDeclarationStatement newStatement = factory.newDeclarationStatement(declaration);
|
||||||
IASTNode targetStatement = utils.getEnclosingStatement(astName);
|
IASTNode targetStatement = CxxAstUtils.getEnclosingStatement(astName);
|
||||||
if (targetStatement == null) {
|
if (targetStatement == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,6 @@ public class QuickFixCreateParameter extends AbstractAstRewriteQuickFix {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void modifyAST(IIndex index, IMarker marker) {
|
public void modifyAST(IIndex index, IMarker marker) {
|
||||||
CxxAstUtils utils = CxxAstUtils.getInstance();
|
|
||||||
CompositeChange c = new CompositeChange(Messages.QuickFixCreateParameter_0);
|
CompositeChange c = new CompositeChange(Messages.QuickFixCreateParameter_0);
|
||||||
try {
|
try {
|
||||||
ITranslationUnit baseTU = getTranslationUnitViaEditor(marker);
|
ITranslationUnit baseTU = getTranslationUnitViaEditor(marker);
|
||||||
|
@ -54,11 +53,11 @@ public class QuickFixCreateParameter extends AbstractAstRewriteQuickFix {
|
||||||
if (astName == null) {
|
if (astName == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
IASTDeclaration declaration = CxxAstUtils.getInstance().createDeclaration(astName, baseAST.getASTNodeFactory(), index);
|
IASTDeclaration declaration = CxxAstUtils.createDeclaration(astName, baseAST.getASTNodeFactory(), index);
|
||||||
// We'll need a FunctionParameterDeclaration later
|
// We'll need a FunctionParameterDeclaration later
|
||||||
final IASTDeclSpecifier finalDeclSpec = (IASTDeclSpecifier) declaration.getChildren()[0];
|
final IASTDeclSpecifier finalDeclSpec = (IASTDeclSpecifier) declaration.getChildren()[0];
|
||||||
final IASTDeclarator finalDeclarator = (IASTDeclarator) declaration.getChildren()[1];
|
final IASTDeclarator finalDeclarator = (IASTDeclarator) declaration.getChildren()[1];
|
||||||
IASTFunctionDefinition function = utils.getEnclosingFunction(astName);
|
IASTFunctionDefinition function = CxxAstUtils.getEnclosingFunction(astName);
|
||||||
if (function == null) {
|
if (function == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -74,7 +73,7 @@ public class QuickFixCreateParameter extends AbstractAstRewriteQuickFix {
|
||||||
HashMap<ITranslationUnit, IASTTranslationUnit> cachedASTs = new HashMap<ITranslationUnit, IASTTranslationUnit>();
|
HashMap<ITranslationUnit, IASTTranslationUnit> cachedASTs = new HashMap<ITranslationUnit, IASTTranslationUnit>();
|
||||||
HashMap<ITranslationUnit, ASTRewrite> cachedRewrites = new HashMap<ITranslationUnit, ASTRewrite>();
|
HashMap<ITranslationUnit, ASTRewrite> cachedRewrites = new HashMap<ITranslationUnit, ASTRewrite>();
|
||||||
for (IIndexName iname : declarations) {
|
for (IIndexName iname : declarations) {
|
||||||
ITranslationUnit declTU = utils.getTranslationUnitFromIndexName(iname);
|
ITranslationUnit declTU = CxxAstUtils.getTranslationUnitFromIndexName(iname);
|
||||||
ASTRewrite rewrite;
|
ASTRewrite rewrite;
|
||||||
IASTTranslationUnit declAST;
|
IASTTranslationUnit declAST;
|
||||||
if (!cachedASTs.containsKey(declTU)) {
|
if (!cachedASTs.containsKey(declTU)) {
|
||||||
|
|
|
@ -51,7 +51,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
|
||||||
*/
|
*/
|
||||||
public class AbstractClassInstantiationChecker extends AbstractIndexAstChecker {
|
public class AbstractClassInstantiationChecker extends AbstractIndexAstChecker {
|
||||||
public static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation"; //$NON-NLS-1$
|
public static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation"; //$NON-NLS-1$
|
||||||
private HashMap<ICPPClassType, ICPPMethod[]> pureVirtualMethodsCache = new HashMap<ICPPClassType, ICPPMethod[]>();
|
private final HashMap<ICPPClassType, ICPPMethod[]> pureVirtualMethodsCache = new HashMap<ICPPClassType, ICPPMethod[]>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initPreferences(IProblemWorkingCopy problem) {
|
public void initPreferences(IProblemWorkingCopy problem) {
|
||||||
|
@ -189,7 +189,7 @@ public class AbstractClassInstantiationChecker extends AbstractIndexAstChecker {
|
||||||
* If it is, reports violations on each pure virtual method
|
* If it is, reports violations on each pure virtual method
|
||||||
*/
|
*/
|
||||||
private void reportProblemsIfAbstract(IType typeToCheck, IASTNode problemNode ) {
|
private void reportProblemsIfAbstract(IType typeToCheck, IASTNode problemNode ) {
|
||||||
IType unwindedType = CxxAstUtils.getInstance().unwindTypedef(typeToCheck);
|
IType unwindedType = CxxAstUtils.unwindTypedef(typeToCheck);
|
||||||
if (!(unwindedType instanceof ICPPClassType) || unwindedType instanceof IProblemBinding) {
|
if (!(unwindedType instanceof ICPPClassType) || unwindedType instanceof IProblemBinding) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,10 +71,9 @@ public class CaseBreakChecker extends AbstractIndexAstChecker implements IChecke
|
||||||
* - "exit"
|
* - "exit"
|
||||||
*/
|
*/
|
||||||
protected boolean isBreakOrExitStatement(IASTStatement statement) {
|
protected boolean isBreakOrExitStatement(IASTStatement statement) {
|
||||||
CxxAstUtils utils = CxxAstUtils.getInstance();
|
|
||||||
return (statement instanceof IASTBreakStatement) || statement instanceof IASTReturnStatement
|
return (statement instanceof IASTBreakStatement) || statement instanceof IASTReturnStatement
|
||||||
|| statement instanceof IASTContinueStatement || statement instanceof IASTGotoStatement
|
|| statement instanceof IASTContinueStatement || statement instanceof IASTGotoStatement
|
||||||
|| utils.isThrowStatement(statement) || utils.isExitStatement(statement);
|
|| CxxAstUtils.isThrowStatement(statement) || CxxAstUtils.isExitStatement(statement);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class CatchByReference extends AbstractIndexAstChecker {
|
||||||
if (spec instanceof IASTNamedTypeSpecifier) {
|
if (spec instanceof IASTNamedTypeSpecifier) {
|
||||||
IASTName tname = ((IASTNamedTypeSpecifier) spec).getName();
|
IASTName tname = ((IASTNamedTypeSpecifier) spec).getName();
|
||||||
IType typeName = (IType) tname.resolveBinding();
|
IType typeName = (IType) tname.resolveBinding();
|
||||||
typeName = CxxAstUtils.getInstance().unwindTypedef(typeName);
|
typeName = CxxAstUtils.unwindTypedef(typeName);
|
||||||
if (typeName instanceof IBasicType || typeName instanceof IPointerType || typeName == null)
|
if (typeName instanceof IBasicType || typeName instanceof IPointerType || typeName == null)
|
||||||
continue;
|
continue;
|
||||||
if (typeName instanceof IProblemBinding && !shouldReportForUnknownType())
|
if (typeName instanceof IProblemBinding && !shouldReportForUnknownType())
|
||||||
|
|
|
@ -179,11 +179,10 @@ public class ProblemBindingChecker extends AbstractIndexAstChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isInClassContext(IASTName name) {
|
private boolean isInClassContext(IASTName name) {
|
||||||
CxxAstUtils utils = CxxAstUtils.getInstance();
|
if (CxxAstUtils.getEnclosingCompositeTypeSpecifier(name) != null) {
|
||||||
if (utils.getEnclosingCompositeTypeSpecifier(name) != null) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
IASTFunctionDefinition function = utils.getEnclosingFunction(name);
|
IASTFunctionDefinition function = CxxAstUtils.getEnclosingFunction(name);
|
||||||
if (function == null) {
|
if (function == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -194,8 +193,7 @@ public class ProblemBindingChecker extends AbstractIndexAstChecker {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isInFunctionContext(IASTName name) {
|
private boolean isInFunctionContext(IASTName name) {
|
||||||
CxxAstUtils utils = CxxAstUtils.getInstance();
|
IASTFunctionDefinition function = CxxAstUtils.getEnclosingFunction(name);
|
||||||
IASTFunctionDefinition function = utils.getEnclosingFunction(name);
|
|
||||||
return (function != null);
|
return (function != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -204,13 +204,14 @@ public class ReturnChecker extends AbstractAstFunctionChecker {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private boolean isCompoundStatement(IASTStatement last) {
|
private boolean isCompoundStatement(IASTStatement last) {
|
||||||
return last instanceof IASTIfStatement || last instanceof IASTWhileStatement || last instanceof IASTDoStatement
|
return last instanceof IASTIfStatement || last instanceof IASTWhileStatement ||
|
||||||
|| last instanceof IASTForStatement || last instanceof IASTSwitchStatement || last instanceof IASTCompoundStatement;
|
last instanceof IASTDoStatement || last instanceof IASTForStatement ||
|
||||||
|
last instanceof IASTSwitchStatement || last instanceof IASTCompoundStatement;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isFuncExitStatement(IASTStatement statement) {
|
protected boolean isFuncExitStatement(IASTStatement statement) {
|
||||||
CxxAstUtils utils = CxxAstUtils.getInstance();
|
return statement instanceof IASTReturnStatement || CxxAstUtils.isThrowStatement(statement) ||
|
||||||
return statement instanceof IASTReturnStatement || utils.isThrowStatement(statement) || utils.isExitStatement(statement);
|
CxxAstUtils.isExitStatement(statement);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -300,7 +301,7 @@ public class ReturnChecker extends AbstractAstFunctionChecker {
|
||||||
type = ((IASTSimpleDeclSpecifier) declSpecifier).getType();
|
type = ((IASTSimpleDeclSpecifier) declSpecifier).getType();
|
||||||
} else if (declSpecifier instanceof IASTNamedTypeSpecifier) {
|
} else if (declSpecifier instanceof IASTNamedTypeSpecifier) {
|
||||||
IBinding binding = ((IASTNamedTypeSpecifier) declSpecifier).getName().resolveBinding();
|
IBinding binding = ((IASTNamedTypeSpecifier) declSpecifier).getName().resolveBinding();
|
||||||
IType utype = CxxAstUtils.getInstance().unwindTypedef((IType) binding);
|
IType utype = CxxAstUtils.unwindTypedef((IType) binding);
|
||||||
if (isVoid(utype))
|
if (isVoid(utype))
|
||||||
return IASTSimpleDeclSpecifier.t_void;
|
return IASTSimpleDeclSpecifier.t_void;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ public final class CxxAstUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class FunctionNameFinderVisitor extends NameFinderVisitor {
|
private static class FunctionNameFinderVisitor extends NameFinderVisitor {
|
||||||
{
|
{
|
||||||
shouldVisitExpressions = true;
|
shouldVisitExpressions = true;
|
||||||
}
|
}
|
||||||
|
@ -90,19 +90,11 @@ public final class CxxAstUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CxxAstUtils instance;
|
// Not instantiatable. All methods are static.
|
||||||
|
|
||||||
private CxxAstUtils() {
|
private CxxAstUtils() {
|
||||||
// private constructor
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized static CxxAstUtils getInstance() {
|
public static IType unwindTypedef(IType type) {
|
||||||
if (instance == null)
|
|
||||||
instance = new CxxAstUtils();
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IType unwindTypedef(IType type) {
|
|
||||||
if (!(type instanceof IBinding))
|
if (!(type instanceof IBinding))
|
||||||
return type;
|
return type;
|
||||||
IBinding typeName = (IBinding) type;
|
IBinding typeName = (IBinding) type;
|
||||||
|
@ -129,21 +121,21 @@ public final class CxxAstUtils {
|
||||||
return macro != null;
|
return macro != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTFunctionDefinition getEnclosingFunction(IASTNode node) {
|
public static IASTFunctionDefinition getEnclosingFunction(IASTNode node) {
|
||||||
while (node != null && !(node instanceof IASTFunctionDefinition)) {
|
while (node != null && !(node instanceof IASTFunctionDefinition)) {
|
||||||
node = node.getParent();
|
node = node.getParent();
|
||||||
}
|
}
|
||||||
return (IASTFunctionDefinition) node;
|
return (IASTFunctionDefinition) node;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTCompositeTypeSpecifier getEnclosingCompositeTypeSpecifier(IASTNode node) {
|
public static IASTCompositeTypeSpecifier getEnclosingCompositeTypeSpecifier(IASTNode node) {
|
||||||
while (node != null && !(node instanceof IASTCompositeTypeSpecifier)) {
|
while (node != null && !(node instanceof IASTCompositeTypeSpecifier)) {
|
||||||
node = node.getParent();
|
node = node.getParent();
|
||||||
}
|
}
|
||||||
return (IASTCompositeTypeSpecifier) node;
|
return (IASTCompositeTypeSpecifier) node;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IASTStatement getEnclosingStatement(IASTNode node) {
|
public static IASTStatement getEnclosingStatement(IASTNode node) {
|
||||||
while (node != null && !(node instanceof IASTStatement)) {
|
while (node != null && !(node instanceof IASTStatement)) {
|
||||||
node = node.getParent();
|
node = node.getParent();
|
||||||
}
|
}
|
||||||
|
@ -158,7 +150,7 @@ public final class CxxAstUtils {
|
||||||
* @param index
|
* @param index
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public IASTDeclaration createDeclaration(IASTName astName, INodeFactory factory, IIndex index) {
|
public static IASTDeclaration createDeclaration(IASTName astName, INodeFactory factory, IIndex index) {
|
||||||
// Depending on context, either a type or a declaration is easier to
|
// Depending on context, either a type or a declaration is easier to
|
||||||
// infer
|
// infer
|
||||||
IType inferredType = null;
|
IType inferredType = null;
|
||||||
|
@ -193,7 +185,7 @@ public final class CxxAstUtils {
|
||||||
*
|
*
|
||||||
* @return inferred type or null if couldn't infer
|
* @return inferred type or null if couldn't infer
|
||||||
*/
|
*/
|
||||||
private IType tryInferTypeFromBinaryExpr(IASTName astName) {
|
private static IType tryInferTypeFromBinaryExpr(IASTName astName) {
|
||||||
if (astName.getParent() instanceof IASTIdExpression && astName.getParent().getParent() instanceof IASTBinaryExpression) {
|
if (astName.getParent() instanceof IASTIdExpression && astName.getParent().getParent() instanceof IASTBinaryExpression) {
|
||||||
IASTNode binaryExpr = astName.getParent().getParent();
|
IASTNode binaryExpr = astName.getParent().getParent();
|
||||||
for (IASTNode node : binaryExpr.getChildren()) {
|
for (IASTNode node : binaryExpr.getChildren()) {
|
||||||
|
@ -214,7 +206,7 @@ public final class CxxAstUtils {
|
||||||
*
|
*
|
||||||
* @return a generated declaration or null if not suitable
|
* @return a generated declaration or null if not suitable
|
||||||
*/
|
*/
|
||||||
private IASTSimpleDeclaration tryInferTypeFromFunctionCall(IASTName astName, INodeFactory factory, IIndex index) {
|
private static IASTSimpleDeclaration tryInferTypeFromFunctionCall(IASTName astName, INodeFactory factory, IIndex index) {
|
||||||
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();
|
||||||
|
@ -304,14 +296,14 @@ public final class CxxAstUtils {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setNameInNestedDeclarator(IASTDeclarator declarator, IASTName astName) {
|
private static void setNameInNestedDeclarator(IASTDeclarator declarator, IASTName astName) {
|
||||||
while (declarator.getNestedDeclarator() != null) {
|
while (declarator.getNestedDeclarator() != null) {
|
||||||
declarator = declarator.getNestedDeclarator();
|
declarator = declarator.getNestedDeclarator();
|
||||||
}
|
}
|
||||||
declarator.setName(astName);
|
declarator.setName(astName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ITranslationUnit getTranslationUnitFromIndexName(IIndexName decl) throws CoreException {
|
public static ITranslationUnit getTranslationUnitFromIndexName(IIndexName decl) throws CoreException {
|
||||||
Path path = new Path(decl.getFile().getLocation().getFullPath());
|
Path path = new Path(decl.getFile().getLocation().getFullPath());
|
||||||
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
|
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
|
||||||
ITranslationUnit tu = (ITranslationUnit) CoreModel.getDefault().create(file);
|
ITranslationUnit tu = (ITranslationUnit) CoreModel.getDefault().create(file);
|
||||||
|
@ -328,7 +320,7 @@ public final class CxxAstUtils {
|
||||||
* the index to use for name lookup
|
* the index to use for name lookup
|
||||||
* @return Either a type specifier or null
|
* @return Either a type specifier or null
|
||||||
*/
|
*/
|
||||||
public IASTCompositeTypeSpecifier getCompositeTypeFromFunction(final IASTFunctionDefinition function, final IIndex index) {
|
public static IASTCompositeTypeSpecifier getCompositeTypeFromFunction(final IASTFunctionDefinition function, final IIndex index) {
|
||||||
// return value to be set via visitor
|
// return value to be set via visitor
|
||||||
final IASTCompositeTypeSpecifier returnSpecifier[] = { null };
|
final IASTCompositeTypeSpecifier returnSpecifier[] = { null };
|
||||||
final HashMap<ITranslationUnit, IASTTranslationUnit> astCache = new HashMap<ITranslationUnit, IASTTranslationUnit>();
|
final HashMap<ITranslationUnit, IASTTranslationUnit> astCache = new HashMap<ITranslationUnit, IASTTranslationUnit>();
|
||||||
|
@ -389,7 +381,7 @@ public final class CxxAstUtils {
|
||||||
* @param body
|
* @param body
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public boolean isThrowStatement(IASTNode body) {
|
public static boolean isThrowStatement(IASTNode body) {
|
||||||
if (!(body instanceof IASTExpressionStatement))
|
if (!(body instanceof IASTExpressionStatement))
|
||||||
return false;
|
return false;
|
||||||
IASTExpression expression = ((IASTExpressionStatement) body).getExpression();
|
IASTExpression expression = ((IASTExpressionStatement) body).getExpression();
|
||||||
|
@ -398,7 +390,7 @@ public final class CxxAstUtils {
|
||||||
return ((IASTUnaryExpression) expression).getOperator() == IASTUnaryExpression.op_throw;
|
return ((IASTUnaryExpression) expression).getOperator() == IASTUnaryExpression.op_throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isExitStatement(IASTNode body) {
|
public static boolean isExitStatement(IASTNode body) {
|
||||||
if (!(body instanceof IASTExpressionStatement))
|
if (!(body instanceof IASTExpressionStatement))
|
||||||
return false;
|
return false;
|
||||||
IASTExpression expression = ((IASTExpressionStatement) body).getExpression();
|
IASTExpression expression = ((IASTExpressionStatement) body).getExpression();
|
||||||
|
@ -407,6 +399,4 @@ public final class CxxAstUtils {
|
||||||
IASTExpression functionNameExpression = ((IASTFunctionCallExpression) expression).getFunctionNameExpression();
|
IASTExpression functionNameExpression = ((IASTFunctionCallExpression) expression).getFunctionNameExpression();
|
||||||
return functionNameExpression.getRawSignature().equals("exit"); //$NON-NLS-1$
|
return functionNameExpression.getRawSignature().equals("exit"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,13 +31,6 @@ import org.eclipse.cdt.core.dom.ast.c.ICBasicType;
|
||||||
* Test CxxAstUtils
|
* Test CxxAstUtils
|
||||||
*/
|
*/
|
||||||
public class CxxAstUtilsTest extends CodanFastCxxAstTestCase {
|
public class CxxAstUtilsTest extends CodanFastCxxAstTestCase {
|
||||||
private CxxAstUtils instance;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
instance = CxxAstUtils.getInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IChecker getChecker() {
|
public IChecker getChecker() {
|
||||||
return null; // not testing checker
|
return null; // not testing checker
|
||||||
|
@ -65,7 +58,7 @@ public class CxxAstUtilsTest extends CodanFastCxxAstTestCase {
|
||||||
if (spec instanceof IASTNamedTypeSpecifier) {
|
if (spec instanceof IASTNamedTypeSpecifier) {
|
||||||
IASTName tname = ((IASTNamedTypeSpecifier) spec).getName();
|
IASTName tname = ((IASTNamedTypeSpecifier) spec).getName();
|
||||||
IType typeName = (IType) tname.resolveBinding();
|
IType typeName = (IType) tname.resolveBinding();
|
||||||
result[0] = instance.unwindTypedef(typeName);
|
result[0] = CxxAstUtils.unwindTypedef(typeName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
|
@ -95,7 +88,7 @@ public class CxxAstUtilsTest extends CodanFastCxxAstTestCase {
|
||||||
@Override
|
@Override
|
||||||
public int visit(IASTStatement stmt) {
|
public int visit(IASTStatement stmt) {
|
||||||
if (stmt instanceof IASTExpressionStatement) {
|
if (stmt instanceof IASTExpressionStatement) {
|
||||||
boolean check = instance.isInMacro(((IASTExpressionStatement) stmt).getExpression());
|
boolean check = CxxAstUtils.isInMacro(((IASTExpressionStatement) stmt).getExpression());
|
||||||
result[i] = check;
|
result[i] = check;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue