From ecd14f70f8ffe70114d2bbb0129ab703d96d1813 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Mon, 9 Jan 2012 10:52:51 -0800 Subject: [PATCH] Declare utility methods static. --- .../ui/quickfix/CaseBreakQuickFixBreak.java | 2 +- .../ui/quickfix/CaseBreakQuickFixComment.java | 10 +++++ .../CatchByConstReferenceQuickFix.java | 2 +- .../ui/quickfix/CatchByReferenceQuickFix.java | 4 +- .../QuickFixAssignmentInCondition.java | 2 +- .../ui/quickfix/QuickFixCreateField.java | 9 ++--- .../quickfix/QuickFixCreateLocalVariable.java | 13 ++----- .../ui/quickfix/QuickFixCreateParameter.java | 9 ++--- .../AbstractClassInstantiationChecker.java | 4 +- .../internal/checkers/CaseBreakChecker.java | 3 +- .../internal/checkers/CatchByReference.java | 4 +- .../ClassMembersInitializationChecker.java | 2 +- .../checkers/ProblemBindingChecker.java | 12 +++--- .../internal/checkers/ReturnChecker.java | 11 +++--- .../cdt/codan/core/cxx/CxxAstUtils.java | 38 +++++++------------ .../cdt/codan/core/cxx/CxxAstUtilsTest.java | 15 ++------ 16 files changed, 61 insertions(+), 79 deletions(-) diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixBreak.java b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixBreak.java index 97878a20028..7de791f5e8c 100644 --- a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixBreak.java +++ b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixBreak.java @@ -53,7 +53,7 @@ public class CaseBreakQuickFixBreak extends AbstractAstRewriteQuickFix { IASTNode containedNode = nodeSelector.findFirstContainedNode(lineInformation.getOffset(), lineInformation.getLength()); IASTNode beforeBreakNode = null; if (containedNode != null) - beforeBreakNode = CxxAstUtils.getInstance().getEnclosingStatement(containedNode); + beforeBreakNode = CxxAstUtils.getEnclosingStatement(containedNode); else beforeBreakNode = nodeSelector.findEnclosingNode(lineInformation.getOffset(), lineInformation.getLength()); if (beforeBreakNode instanceof IASTCompoundStatement) { diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixComment.java b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixComment.java index 7a15d6430d9..2ed2893fabc 100644 --- a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixComment.java +++ b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CaseBreakQuickFixComment.java @@ -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; import org.eclipse.cdt.codan.core.model.IProblem; diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CatchByConstReferenceQuickFix.java b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CatchByConstReferenceQuickFix.java index f8337c4b683..4a469d0923e 100644 --- a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CatchByConstReferenceQuickFix.java +++ b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CatchByConstReferenceQuickFix.java @@ -17,7 +17,7 @@ import org.eclipse.core.resources.IMarker; import org.eclipse.jface.text.IDocument; /** - * quick fix for catch by value + * Quick fix for catch by value */ public class CatchByConstReferenceQuickFix extends AbstractCodanCMarkerResolution { @Override diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CatchByReferenceQuickFix.java b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CatchByReferenceQuickFix.java index 9136c2ff6ce..3218e48e567 100644 --- a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CatchByReferenceQuickFix.java +++ b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/CatchByReferenceQuickFix.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Alena Laskavaia - initial API and implementation + * Alena Laskavaia - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.codan.internal.checkers.ui.quickfix; @@ -18,7 +18,7 @@ import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; /** - * quick fix for catch by value + * Quick fix for catch by value */ public class CatchByReferenceQuickFix extends AbstractCodanCMarkerResolution { @Override diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixAssignmentInCondition.java b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixAssignmentInCondition.java index c4d0f14efc0..422713fc7e5 100644 --- a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixAssignmentInCondition.java +++ b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixAssignmentInCondition.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Andrew Gvozdev - initial API and implementation + * Andrew Gvozdev - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.codan.internal.checkers.ui.quickfix; diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixCreateField.java b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixCreateField.java index b460058bb37..a499c3e0b1c 100644 --- a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixCreateField.java +++ b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixCreateField.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Tomasz Wesolowski - initial API and implementation + * Tomasz Wesolowski - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.codan.internal.checkers.ui.quickfix; @@ -40,19 +40,18 @@ public class QuickFixCreateField extends AbstractAstRewriteQuickFix { @Override public void modifyAST(IIndex index, IMarker marker) { - CxxAstUtils utils = CxxAstUtils.getInstance(); try { IASTTranslationUnit ast = getTranslationUnitViaEditor(marker).getAST(index, ITranslationUnit.AST_SKIP_INDEXED_HEADERS); IASTName astName = getASTNameFromMarker(marker, ast); if (astName == null) { return; } - IASTDeclaration declaration = utils.createDeclaration(astName, ast.getASTNodeFactory(), index); - IASTCompositeTypeSpecifier targetCompositeType = utils.getEnclosingCompositeTypeSpecifier(astName); + IASTDeclaration declaration = CxxAstUtils.createDeclaration(astName, ast.getASTNodeFactory(), index); + IASTCompositeTypeSpecifier targetCompositeType = CxxAstUtils.getEnclosingCompositeTypeSpecifier(astName); if (targetCompositeType == null) { // We're not in an inline method; // 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) { return; } diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixCreateLocalVariable.java b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixCreateLocalVariable.java index ff330b1c7bb..cf9eecc07bc 100644 --- a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixCreateLocalVariable.java +++ b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixCreateLocalVariable.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Tomasz Wesolowski - initial API and implementation + * Tomasz Wesolowski - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.codan.internal.checkers.ui.quickfix; @@ -33,15 +33,8 @@ public class QuickFixCreateLocalVariable extends AbstractAstRewriteQuickFix { return Messages.QuickFixCreateLocalVariable_0; } - /** - * - * @param ast - * @param astName - * @param r - */ @Override public void modifyAST(IIndex index, IMarker marker) { - CxxAstUtils utils = CxxAstUtils.getInstance(); IASTTranslationUnit ast; try { ITranslationUnit tu = getTranslationUnitViaEditor(marker); @@ -61,9 +54,9 @@ public class QuickFixCreateLocalVariable extends AbstractAstRewriteQuickFix { } ASTRewrite r = ASTRewrite.create(ast); INodeFactory factory = ast.getASTNodeFactory(); - IASTDeclaration declaration = utils.createDeclaration(astName, factory, index); + IASTDeclaration declaration = CxxAstUtils.createDeclaration(astName, factory, index); IASTDeclarationStatement newStatement = factory.newDeclarationStatement(declaration); - IASTNode targetStatement = utils.getEnclosingStatement(astName); + IASTNode targetStatement = CxxAstUtils.getEnclosingStatement(astName); if (targetStatement == null) { return; } diff --git a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixCreateParameter.java b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixCreateParameter.java index afc17a25008..0ffefec2e0d 100644 --- a/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixCreateParameter.java +++ b/codan/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/internal/checkers/ui/quickfix/QuickFixCreateParameter.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Tomasz Wesolowski - initial API and implementation + * Tomasz Wesolowski - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.codan.internal.checkers.ui.quickfix; @@ -45,7 +45,6 @@ public class QuickFixCreateParameter extends AbstractAstRewriteQuickFix { @Override public void modifyAST(IIndex index, IMarker marker) { - CxxAstUtils utils = CxxAstUtils.getInstance(); CompositeChange c = new CompositeChange(Messages.QuickFixCreateParameter_0); try { ITranslationUnit baseTU = getTranslationUnitViaEditor(marker); @@ -54,11 +53,11 @@ public class QuickFixCreateParameter extends AbstractAstRewriteQuickFix { if (astName == null) { return; } - IASTDeclaration declaration = CxxAstUtils.getInstance().createDeclaration(astName, baseAST.getASTNodeFactory(), index); + IASTDeclaration declaration = CxxAstUtils.createDeclaration(astName, baseAST.getASTNodeFactory(), index); // We'll need a FunctionParameterDeclaration later final IASTDeclSpecifier finalDeclSpec = (IASTDeclSpecifier) declaration.getChildren()[0]; final IASTDeclarator finalDeclarator = (IASTDeclarator) declaration.getChildren()[1]; - IASTFunctionDefinition function = utils.getEnclosingFunction(astName); + IASTFunctionDefinition function = CxxAstUtils.getEnclosingFunction(astName); if (function == null) { return; } @@ -74,7 +73,7 @@ public class QuickFixCreateParameter extends AbstractAstRewriteQuickFix { HashMap cachedASTs = new HashMap(); HashMap cachedRewrites = new HashMap(); for (IIndexName iname : declarations) { - ITranslationUnit declTU = utils.getTranslationUnitFromIndexName(iname); + ITranslationUnit declTU = CxxAstUtils.getTranslationUnitFromIndexName(iname); ASTRewrite rewrite; IASTTranslationUnit declAST; if (!cachedASTs.containsKey(declTU)) { diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AbstractClassInstantiationChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AbstractClassInstantiationChecker.java index 927f37209a9..0461da5b940 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AbstractClassInstantiationChecker.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/AbstractClassInstantiationChecker.java @@ -51,7 +51,7 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; */ public class AbstractClassInstantiationChecker extends AbstractIndexAstChecker { public static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.AbstractClassCreation"; //$NON-NLS-1$ - private HashMap pureVirtualMethodsCache = new HashMap(); + private final HashMap pureVirtualMethodsCache = new HashMap(); @Override public void initPreferences(IProblemWorkingCopy problem) { @@ -189,7 +189,7 @@ public class AbstractClassInstantiationChecker extends AbstractIndexAstChecker { * If it is, reports violations on each pure virtual method */ 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) { return; } diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CaseBreakChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CaseBreakChecker.java index 13f4f3c21ef..dc39e19c277 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CaseBreakChecker.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CaseBreakChecker.java @@ -71,10 +71,9 @@ public class CaseBreakChecker extends AbstractIndexAstChecker implements IChecke * - "exit" */ protected boolean isBreakOrExitStatement(IASTStatement statement) { - CxxAstUtils utils = CxxAstUtils.getInstance(); return (statement instanceof IASTBreakStatement) || statement instanceof IASTReturnStatement || statement instanceof IASTContinueStatement || statement instanceof IASTGotoStatement - || utils.isThrowStatement(statement) || utils.isExitStatement(statement); + || CxxAstUtils.isThrowStatement(statement) || CxxAstUtils.isExitStatement(statement); } @Override diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CatchByReference.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CatchByReference.java index 6d493a11e80..ee4de9bbcd9 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CatchByReference.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/CatchByReference.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Alena Laskavaia - initial API and implementation + * Alena Laskavaia - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.codan.internal.checkers; @@ -72,7 +72,7 @@ public class CatchByReference extends AbstractIndexAstChecker { if (spec instanceof IASTNamedTypeSpecifier) { IASTName tname = ((IASTNamedTypeSpecifier) spec).getName(); IType typeName = (IType) tname.resolveBinding(); - typeName = CxxAstUtils.getInstance().unwindTypedef(typeName); + typeName = CxxAstUtils.unwindTypedef(typeName); if (typeName instanceof IBasicType || typeName instanceof IPointerType || typeName == null) continue; if (typeName instanceof IProblemBinding && !shouldReportForUnknownType()) diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ClassMembersInitializationChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ClassMembersInitializationChecker.java index ccd265c378e..ca27fa12035 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ClassMembersInitializationChecker.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ClassMembersInitializationChecker.java @@ -6,7 +6,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Anton Gorenkov - initial implementation + * Anton Gorenkov - initial implementation *******************************************************************************/ package org.eclipse.cdt.codan.internal.checkers; diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ProblemBindingChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ProblemBindingChecker.java index a5eba7e178c..e6efcdea7d4 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ProblemBindingChecker.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ProblemBindingChecker.java @@ -6,8 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Marc-Andre Laperle - Initial API and implementation - * Tomasz Wesolowski - Extension for fixes + * Marc-Andre Laperle - Initial API and implementation + * Tomasz Wesolowski - Extension for fixes *******************************************************************************/ package org.eclipse.cdt.codan.internal.checkers; @@ -179,11 +179,10 @@ public class ProblemBindingChecker extends AbstractIndexAstChecker { } private boolean isInClassContext(IASTName name) { - CxxAstUtils utils = CxxAstUtils.getInstance(); - if (utils.getEnclosingCompositeTypeSpecifier(name) != null) { + if (CxxAstUtils.getEnclosingCompositeTypeSpecifier(name) != null) { return true; } - IASTFunctionDefinition function = utils.getEnclosingFunction(name); + IASTFunctionDefinition function = CxxAstUtils.getEnclosingFunction(name); if (function == null) { return false; } @@ -194,8 +193,7 @@ public class ProblemBindingChecker extends AbstractIndexAstChecker { } private boolean isInFunctionContext(IASTName name) { - CxxAstUtils utils = CxxAstUtils.getInstance(); - IASTFunctionDefinition function = utils.getEnclosingFunction(name); + IASTFunctionDefinition function = CxxAstUtils.getEnclosingFunction(name); return (function != null); } diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java index 8747dfacb2b..07825aa1ab4 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/ReturnChecker.java @@ -204,13 +204,14 @@ public class ReturnChecker extends AbstractAstFunctionChecker { * @return */ private boolean isCompoundStatement(IASTStatement last) { - return last instanceof IASTIfStatement || last instanceof IASTWhileStatement || last instanceof IASTDoStatement - || last instanceof IASTForStatement || last instanceof IASTSwitchStatement || last instanceof IASTCompoundStatement; + return last instanceof IASTIfStatement || last instanceof IASTWhileStatement || + last instanceof IASTDoStatement || last instanceof IASTForStatement || + last instanceof IASTSwitchStatement || last instanceof IASTCompoundStatement; } protected boolean isFuncExitStatement(IASTStatement statement) { - CxxAstUtils utils = CxxAstUtils.getInstance(); - return statement instanceof IASTReturnStatement || utils.isThrowStatement(statement) || utils.isExitStatement(statement); + return statement instanceof IASTReturnStatement || CxxAstUtils.isThrowStatement(statement) || + CxxAstUtils.isExitStatement(statement); } /** @@ -300,7 +301,7 @@ public class ReturnChecker extends AbstractAstFunctionChecker { type = ((IASTSimpleDeclSpecifier) declSpecifier).getType(); } else if (declSpecifier instanceof IASTNamedTypeSpecifier) { IBinding binding = ((IASTNamedTypeSpecifier) declSpecifier).getName().resolveBinding(); - IType utype = CxxAstUtils.getInstance().unwindTypedef((IType) binding); + IType utype = CxxAstUtils.unwindTypedef((IType) binding); if (isVoid(utype)) return IASTSimpleDeclSpecifier.t_void; } 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 e7214b3016d..afe58718799 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 @@ -75,7 +75,7 @@ public final class CxxAstUtils { } } - private class FunctionNameFinderVisitor extends NameFinderVisitor { + private static class FunctionNameFinderVisitor extends NameFinderVisitor { { shouldVisitExpressions = true; } @@ -90,19 +90,11 @@ public final class CxxAstUtils { } } - private static CxxAstUtils instance; - + // Not instantiatable. All methods are static. private CxxAstUtils() { - // private constructor } - public synchronized static CxxAstUtils getInstance() { - if (instance == null) - instance = new CxxAstUtils(); - return instance; - } - - public IType unwindTypedef(IType type) { + public static IType unwindTypedef(IType type) { if (!(type instanceof IBinding)) return type; IBinding typeName = (IBinding) type; @@ -129,21 +121,21 @@ public final class CxxAstUtils { return macro != null; } - public IASTFunctionDefinition getEnclosingFunction(IASTNode node) { + public static IASTFunctionDefinition getEnclosingFunction(IASTNode node) { while (node != null && !(node instanceof IASTFunctionDefinition)) { node = node.getParent(); } return (IASTFunctionDefinition) node; } - public IASTCompositeTypeSpecifier getEnclosingCompositeTypeSpecifier(IASTNode node) { + public static IASTCompositeTypeSpecifier getEnclosingCompositeTypeSpecifier(IASTNode node) { while (node != null && !(node instanceof IASTCompositeTypeSpecifier)) { node = node.getParent(); } return (IASTCompositeTypeSpecifier) node; } - public IASTStatement getEnclosingStatement(IASTNode node) { + public static IASTStatement getEnclosingStatement(IASTNode node) { while (node != null && !(node instanceof IASTStatement)) { node = node.getParent(); } @@ -158,7 +150,7 @@ public final class CxxAstUtils { * @param index * @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 // infer IType inferredType = null; @@ -193,7 +185,7 @@ public final class CxxAstUtils { * * @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) { IASTNode binaryExpr = astName.getParent().getParent(); for (IASTNode node : binaryExpr.getChildren()) { @@ -214,7 +206,7 @@ public final class CxxAstUtils { * * @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 && astName.getParent().getPropertyInParent() == IASTFunctionCallExpression.ARGUMENT) { IASTFunctionCallExpression call = (IASTFunctionCallExpression) astName.getParent().getParent(); @@ -304,14 +296,14 @@ public final class CxxAstUtils { return null; } - private void setNameInNestedDeclarator(IASTDeclarator declarator, IASTName astName) { + private static void setNameInNestedDeclarator(IASTDeclarator declarator, IASTName astName) { while (declarator.getNestedDeclarator() != null) { declarator = declarator.getNestedDeclarator(); } 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()); IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path); ITranslationUnit tu = (ITranslationUnit) CoreModel.getDefault().create(file); @@ -328,7 +320,7 @@ public final class CxxAstUtils { * the index to use for name lookup * @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 final IASTCompositeTypeSpecifier returnSpecifier[] = { null }; final HashMap astCache = new HashMap(); @@ -389,7 +381,7 @@ public final class CxxAstUtils { * @param body * @return */ - public boolean isThrowStatement(IASTNode body) { + public static boolean isThrowStatement(IASTNode body) { if (!(body instanceof IASTExpressionStatement)) return false; IASTExpression expression = ((IASTExpressionStatement) body).getExpression(); @@ -398,7 +390,7 @@ public final class CxxAstUtils { return ((IASTUnaryExpression) expression).getOperator() == IASTUnaryExpression.op_throw; } - public boolean isExitStatement(IASTNode body) { + public static boolean isExitStatement(IASTNode body) { if (!(body instanceof IASTExpressionStatement)) return false; IASTExpression expression = ((IASTExpressionStatement) body).getExpression(); @@ -407,6 +399,4 @@ public final class CxxAstUtils { IASTExpression functionNameExpression = ((IASTFunctionCallExpression) expression).getFunctionNameExpression(); return functionNameExpression.getRawSignature().equals("exit"); //$NON-NLS-1$ } - - } diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtilsTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtilsTest.java index 4d8a8d4ab14..7e4c036ca05 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtilsTest.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/cxx/CxxAstUtilsTest.java @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2009,2010 QNX Software Systems + * Copyright (c) 2009, 2010 QNX Software Systems * 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: - * QNX Software Systems (Alena Laskavaia) - initial API and implementation + * QNX Software Systems (Alena Laskavaia) - initial API and implementation *******************************************************************************/ package org.eclipse.cdt.codan.core.cxx; @@ -31,13 +31,6 @@ import org.eclipse.cdt.core.dom.ast.c.ICBasicType; * Test CxxAstUtils */ public class CxxAstUtilsTest extends CodanFastCxxAstTestCase { - private CxxAstUtils instance; - - @Override - protected void setUp() throws Exception { - instance = CxxAstUtils.getInstance(); - } - @Override public IChecker getChecker() { return null; // not testing checker @@ -65,7 +58,7 @@ public class CxxAstUtilsTest extends CodanFastCxxAstTestCase { if (spec instanceof IASTNamedTypeSpecifier) { IASTName tname = ((IASTNamedTypeSpecifier) spec).getName(); IType typeName = (IType) tname.resolveBinding(); - result[0] = instance.unwindTypedef(typeName); + result[0] = CxxAstUtils.unwindTypedef(typeName); } } return PROCESS_CONTINUE; @@ -95,7 +88,7 @@ public class CxxAstUtilsTest extends CodanFastCxxAstTestCase { @Override public int visit(IASTStatement stmt) { if (stmt instanceof IASTExpressionStatement) { - boolean check = instance.isInMacro(((IASTExpressionStatement) stmt).getExpression()); + boolean check = CxxAstUtils.isInMacro(((IASTExpressionStatement) stmt).getExpression()); result[i] = check; i++; }