From af92b8417ae76946c7d10772d8848abbe1126209 Mon Sep 17 00:00:00 2001 From: Elliott Baron Date: Wed, 16 Dec 2009 16:51:53 -0500 Subject: Update codan plugins to HEAD. * org.eclipse.cdt.codan.checkers.ui: Updated. * org.eclipse.cdt.codan.checkers: Updated. * org.eclipse.cdt.codan.core: Updated. * org.eclipse.cdt.codan.ui: Updated. --- org.eclipse.cdt.codan.checkers.ui/.classpath | 2 +- .../.settings/CVS/Template | 0 org.eclipse.cdt.codan.checkers.ui/CVS/Entries | 2 +- .../META-INF/CVS/Template | 0 org.eclipse.cdt.codan.checkers.ui/src/CVS/Template | 0 .../src/org/CVS/Template | 0 .../src/org/eclipse/CVS/Template | 0 .../src/org/eclipse/cdt/CVS/Template | 0 .../src/org/eclipse/cdt/codan/CVS/Template | 0 .../org/eclipse/cdt/codan/checkers/CVS/Template | 0 .../org/eclipse/cdt/codan/checkers/ui/CVS/Template | 0 .../cdt/codan/checkers/ui/quickfix/CVS/Template | 0 org.eclipse.cdt.codan.checkers/.classpath | 2 +- .../.settings/CVS/Template | 0 org.eclipse.cdt.codan.checkers/CVS/Entries | 4 +- .../META-INF/CVS/Template | 0 org.eclipse.cdt.codan.checkers/plugin.xml | 23 ++++ org.eclipse.cdt.codan.checkers/src/CVS/Template | 0 .../src/org/CVS/Template | 0 .../src/org/eclipse/CVS/Template | 0 .../src/org/eclipse/cdt/CVS/Template | 0 .../src/org/eclipse/cdt/codan/CVS/Template | 0 .../org/eclipse/cdt/codan/checkers/CVS/Template | 0 .../eclipse/cdt/codan/checkers/sample/CVS/Entries | 2 + .../eclipse/cdt/codan/checkers/sample/CVS/Template | 0 .../codan/checkers/sample/CatchUsesReference.java | 82 ++++++++++++ .../sample/SuggestedParenthesisChecker.java | 143 +++++++++++++++++++++ org.eclipse.cdt.codan.core/.classpath | 2 +- org.eclipse.cdt.codan.core/.settings/CVS/Entries | 1 + org.eclipse.cdt.codan.core/.settings/CVS/Template | 0 .../.settings/org.eclipse.jdt.ui.prefs | 54 ++++++++ org.eclipse.cdt.codan.core/CVS/Entries | 2 +- org.eclipse.cdt.codan.core/META-INF/CVS/Entries | 2 +- org.eclipse.cdt.codan.core/META-INF/CVS/Template | 0 org.eclipse.cdt.codan.core/META-INF/MANIFEST.MF | 3 +- org.eclipse.cdt.codan.core/schema/CVS/Template | 0 org.eclipse.cdt.codan.core/src/CVS/Template | 0 org.eclipse.cdt.codan.core/src/org/CVS/Template | 0 .../src/org/eclipse/CVS/Template | 0 .../src/org/eclipse/cdt/CVS/Template | 0 .../src/org/eclipse/cdt/codan/CVS/Template | 0 .../src/org/eclipse/cdt/codan/core/CVS/Entries | 1 - .../src/org/eclipse/cdt/codan/core/CVS/Template | 0 .../cdt/codan/core/CodanPreferencesLoader.java | 119 ----------------- .../codan/core/model/AbstractIndexAstChecker.java | 14 +- .../org/eclipse/cdt/codan/core/model/CVS/Entries | 15 +-- .../org/eclipse/cdt/codan/core/model/CVS/Template | 0 .../org/eclipse/cdt/codan/core/model/IChecker.java | 16 ++- .../org/eclipse/cdt/codan/core/model/IProblem.java | 28 ++++ .../cdt/codan/core/model/IProblemCategory.java | 19 ++- .../cdt/codan/core/model/IProblemElement.java | 2 +- .../cdt/codan/core/model/IProblemProfile.java | 6 +- .../cdt/codan/core/model/IProblemReporter.java | 1 + .../cdt/codan/core/model/ProblemProfile.java | 103 --------------- .../org/eclipse/cdt/codan/internal/CVS/Template | 0 .../eclipse/cdt/codan/internal/core/CVS/Entries | 5 +- .../eclipse/cdt/codan/internal/core/CVS/Template | 0 .../cdt/codan/internal/core/CheckersRegisry.java | 88 ++++++++++--- .../cdt/codan/internal/core/CodanBuilder.java | 33 +++++ .../internal/core/CodanPreferencesLoader.java | 119 +++++++++++++++++ .../cdt/codan/internal/core/model/CVS/Entries | 5 +- .../cdt/codan/internal/core/model/CVS/Template | 0 .../core/model/CodanMarkerProblemReporter.java | 2 +- .../internal/core/model/CodanProblemCategory.java | 4 +- .../codan/internal/core/model/ProblemProfile.java | 105 +++++++++++++++ org.eclipse.cdt.codan.ui/.settings/CVS/Template | 0 org.eclipse.cdt.codan.ui/META-INF/CVS/Template | 0 org.eclipse.cdt.codan.ui/src/CVS/Template | 0 org.eclipse.cdt.codan.ui/src/org/CVS/Template | 0 .../src/org/eclipse/CVS/Template | 0 .../src/org/eclipse/cdt/CVS/Template | 0 .../src/org/eclipse/cdt/codan/CVS/Template | 0 .../org/eclipse/cdt/codan/internal/CVS/Template | 0 .../org/eclipse/cdt/codan/internal/ui/CVS/Template | 0 .../cdt/codan/internal/ui/preferences/CVS/Entries | 2 +- .../cdt/codan/internal/ui/preferences/CVS/Template | 0 .../ui/preferences/ProblemsTreeEditor.java | 2 +- .../src/org/eclipse/cdt/codan/ui/CVS/Template | 0 .../org/eclipse/cdt/codan/ui/actions/CVS/Template | 0 79 files changed, 735 insertions(+), 278 deletions(-) create mode 100644 org.eclipse.cdt.codan.checkers.ui/.settings/CVS/Template create mode 100644 org.eclipse.cdt.codan.checkers.ui/META-INF/CVS/Template create mode 100644 org.eclipse.cdt.codan.checkers.ui/src/CVS/Template create mode 100644 org.eclipse.cdt.codan.checkers.ui/src/org/CVS/Template create mode 100644 org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/CVS/Template create mode 100644 org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/CVS/Template create mode 100644 org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/CVS/Template create mode 100644 org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/checkers/CVS/Template create mode 100644 org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/checkers/ui/CVS/Template create mode 100644 org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/checkers/ui/quickfix/CVS/Template create mode 100644 org.eclipse.cdt.codan.checkers/.settings/CVS/Template create mode 100644 org.eclipse.cdt.codan.checkers/META-INF/CVS/Template create mode 100644 org.eclipse.cdt.codan.checkers/src/CVS/Template create mode 100644 org.eclipse.cdt.codan.checkers/src/org/CVS/Template create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/CVS/Template create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/CVS/Template create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/CVS/Template create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/CVS/Template create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CVS/Template create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CatchUsesReference.java create mode 100644 org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/SuggestedParenthesisChecker.java create mode 100644 org.eclipse.cdt.codan.core/.settings/CVS/Template create mode 100644 org.eclipse.cdt.codan.core/.settings/org.eclipse.jdt.ui.prefs create mode 100644 org.eclipse.cdt.codan.core/META-INF/CVS/Template create mode 100644 org.eclipse.cdt.codan.core/schema/CVS/Template create mode 100644 org.eclipse.cdt.codan.core/src/CVS/Template create mode 100644 org.eclipse.cdt.codan.core/src/org/CVS/Template create mode 100644 org.eclipse.cdt.codan.core/src/org/eclipse/CVS/Template create mode 100644 org.eclipse.cdt.codan.core/src/org/eclipse/cdt/CVS/Template create mode 100644 org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/CVS/Template create mode 100644 org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CVS/Template delete mode 100644 org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanPreferencesLoader.java create mode 100644 org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CVS/Template delete mode 100644 org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ProblemProfile.java create mode 100644 org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/CVS/Template create mode 100644 org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CVS/Template create mode 100644 org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanPreferencesLoader.java create mode 100644 org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CVS/Template create mode 100644 org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/ProblemProfile.java create mode 100644 org.eclipse.cdt.codan.ui/.settings/CVS/Template create mode 100644 org.eclipse.cdt.codan.ui/META-INF/CVS/Template create mode 100644 org.eclipse.cdt.codan.ui/src/CVS/Template create mode 100644 org.eclipse.cdt.codan.ui/src/org/CVS/Template create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/CVS/Template create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/CVS/Template create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/CVS/Template create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/CVS/Template create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CVS/Template create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CVS/Template create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Template create mode 100644 org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Template diff --git a/org.eclipse.cdt.codan.checkers.ui/.classpath b/org.eclipse.cdt.codan.checkers.ui/.classpath index 1fa3e68..64c5e31 100644 --- a/org.eclipse.cdt.codan.checkers.ui/.classpath +++ b/org.eclipse.cdt.codan.checkers.ui/.classpath @@ -1,6 +1,6 @@ - + diff --git a/org.eclipse.cdt.codan.checkers.ui/.settings/CVS/Template b/org.eclipse.cdt.codan.checkers.ui/.settings/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.checkers.ui/CVS/Entries b/org.eclipse.cdt.codan.checkers.ui/CVS/Entries index 47e41bc..1583ce7 100644 --- a/org.eclipse.cdt.codan.checkers.ui/CVS/Entries +++ b/org.eclipse.cdt.codan.checkers.ui/CVS/Entries @@ -1,4 +1,4 @@ -/.classpath/1.1/Sat Apr 18 02:11:07 2009// +/.classpath/1.2/Wed Dec 16 21:48:51 2009// /.project/1.1/Sat Apr 18 02:11:07 2009// D/.settings//// D/META-INF//// diff --git a/org.eclipse.cdt.codan.checkers.ui/META-INF/CVS/Template b/org.eclipse.cdt.codan.checkers.ui/META-INF/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.checkers.ui/src/CVS/Template b/org.eclipse.cdt.codan.checkers.ui/src/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.checkers.ui/src/org/CVS/Template b/org.eclipse.cdt.codan.checkers.ui/src/org/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/CVS/Template b/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/CVS/Template b/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/CVS/Template b/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/checkers/CVS/Template b/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/checkers/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/checkers/ui/CVS/Template b/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/checkers/ui/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/checkers/ui/quickfix/CVS/Template b/org.eclipse.cdt.codan.checkers.ui/src/org/eclipse/cdt/codan/checkers/ui/quickfix/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.checkers/.classpath b/org.eclipse.cdt.codan.checkers/.classpath index 1fa3e68..64c5e31 100644 --- a/org.eclipse.cdt.codan.checkers/.classpath +++ b/org.eclipse.cdt.codan.checkers/.classpath @@ -1,6 +1,6 @@ - + diff --git a/org.eclipse.cdt.codan.checkers/.settings/CVS/Template b/org.eclipse.cdt.codan.checkers/.settings/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.checkers/CVS/Entries b/org.eclipse.cdt.codan.checkers/CVS/Entries index 79d42fe..f0bd9f5 100644 --- a/org.eclipse.cdt.codan.checkers/CVS/Entries +++ b/org.eclipse.cdt.codan.checkers/CVS/Entries @@ -1,7 +1,7 @@ -/.classpath/1.2/Fri Apr 17 20:50:15 2009// +/.classpath/1.3/Wed Dec 16 21:48:51 2009// /.project/1.1/Thu Apr 9 12:48:43 2009// D/.settings//// D/META-INF//// /build.properties/1.1/Thu Apr 9 12:48:44 2009// -/plugin.xml/1.5/Sat May 9 01:16:26 2009// +/plugin.xml/1.7/Wed Dec 16 21:48:51 2009// D/src//// diff --git a/org.eclipse.cdt.codan.checkers/META-INF/CVS/Template b/org.eclipse.cdt.codan.checkers/META-INF/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.checkers/plugin.xml b/org.eclipse.cdt.codan.checkers/plugin.xml index e2dac3e..63b999e 100644 --- a/org.eclipse.cdt.codan.checkers/plugin.xml +++ b/org.eclipse.cdt.codan.checkers/plugin.xml @@ -40,5 +40,28 @@ name="Class has a virtual method and non-virtual destructor"> + + + + + + + + + diff --git a/org.eclipse.cdt.codan.checkers/src/CVS/Template b/org.eclipse.cdt.codan.checkers/src/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.checkers/src/org/CVS/Template b/org.eclipse.cdt.codan.checkers/src/org/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/CVS/Template b/org.eclipse.cdt.codan.checkers/src/org/eclipse/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/CVS/Template b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/CVS/Template b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/CVS/Template b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CVS/Entries b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CVS/Entries index 7071b8d..705d9ab 100644 --- a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CVS/Entries +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CVS/Entries @@ -1,3 +1,5 @@ /AssignmentInConditionChecker.java/1.4/Fri Jul 31 20:39:13 2009// +/CatchUsesReference.java/1.2/Sat Nov 21 02:25:12 2009// /NonVirtualDestructor.java/1.4/Fri Jul 31 20:39:13 2009// /StatementHasNoEffectChecker.java/1.5/Fri Jul 31 20:39:13 2009// +/SuggestedParenthesisChecker.java/1.2/Sat Nov 21 03:03:08 2009// diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CVS/Template b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CatchUsesReference.java b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CatchUsesReference.java new file mode 100644 index 0000000..b3556cc --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/CatchUsesReference.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2009 Alena Laskavaia + * 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.checkers.sample; + +import org.eclipse.cdt.codan.core.model.AbstractIndexAstChecker; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; +import org.eclipse.cdt.core.dom.ast.IASTDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTDeclarator; +import org.eclipse.cdt.core.dom.ast.IASTPointerOperator; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; +import org.eclipse.cdt.core.dom.ast.IASTStatement; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTCatchHandler; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTReferenceOperator; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTTryBlockStatement; + +/** + * @author Alena + * + */ +public class CatchUsesReference extends AbstractIndexAstChecker { + private static final String ER_ID = "org.eclipse.cdt.codan.checkers.sample.CatchUsesReference"; + + public void processAst(IASTTranslationUnit ast) { + // traverse the ast using the visitor pattern. + ast.accept(new OnCatch()); + } + + class OnCatch extends ASTVisitor { + OnCatch() { + shouldVisitStatements = true; + } + public int visit(IASTStatement stmt) { + if (stmt instanceof ICPPASTTryBlockStatement) { + ICPPASTTryBlockStatement tblock = (ICPPASTTryBlockStatement) stmt; + ICPPASTCatchHandler[] catchHandlers = tblock.getCatchHandlers(); + for (int i = 0; i < catchHandlers.length; i++) { + ICPPASTCatchHandler catchHandler = catchHandlers[i]; + if (usesReference(catchHandler)) { + reportProblem(ER_ID, catchHandler.getDeclaration(), "Catch clause uses reference in declaration of exception"); + } + } + + return PROCESS_SKIP; + } + return PROCESS_CONTINUE; + } + /** + * @param catchHandler + * @return + */ + private boolean usesReference(ICPPASTCatchHandler catchHandler) { + IASTDeclaration declaration = catchHandler.getDeclaration(); + if (declaration instanceof IASTSimpleDeclaration) { + IASTDeclarator[] declarators = ((IASTSimpleDeclaration) declaration).getDeclarators(); + for (int i = 0; i < declarators.length; i++) { + IASTDeclarator d = declarators[i]; + IASTPointerOperator[] pointerOperators = d.getPointerOperators(); + for (int j = 0; j < pointerOperators.length; j++) { + IASTPointerOperator po = pointerOperators[j]; + if (po instanceof ICPPASTReferenceOperator) { + return true; + } + + } + } + } + return false; + } + } + + +} diff --git a/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/SuggestedParenthesisChecker.java b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/SuggestedParenthesisChecker.java new file mode 100644 index 0000000..27712b4 --- /dev/null +++ b/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/checkers/sample/SuggestedParenthesisChecker.java @@ -0,0 +1,143 @@ +/******************************************************************************* + * Copyright (c) 2009 Alena Laskavaia + * 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.checkers.sample; + +import org.eclipse.cdt.codan.core.model.AbstractIndexAstChecker; +import org.eclipse.cdt.core.dom.ast.ASTNodeProperty; +import org.eclipse.cdt.core.dom.ast.ASTVisitor; +import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression; +import org.eclipse.cdt.core.dom.ast.IASTExpression; +import org.eclipse.cdt.core.dom.ast.IASTForStatement; +import org.eclipse.cdt.core.dom.ast.IASTIfStatement; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression; + +/** + * This checker finds a problems that cause by lack of understanding operator + * precedence in C. In any case it is better to surround expressions in + * parenthesis to improve readability. Example: ! x>0 && x<10 (this would be + * (!x)>0 && x<10 in C) We only look for &&, || and ! operators (and binary | & + * ^ ~) + * + * @author Alena + * + */ +public class SuggestedParenthesisChecker extends AbstractIndexAstChecker { + private static final String ER_ID = "org.eclipse.cdt.codan.checkers.sample.SuggestedParenthesisProblem"; + + public void processAst(IASTTranslationUnit ast) { + // traverse the ast using the visitor pattern. + ast.accept(new ExpressionVisitor()); + } + + class ExpressionVisitor extends ASTVisitor { + private SuspiciousExpressionVisitor svis; + + ExpressionVisitor() { + shouldVisitExpressions = true; + svis = new SuspiciousExpressionVisitor(); + } + + public int visit(IASTExpression expression) { + int precedence = getPrecedence(expression); + if (precedence == 2) { // unary not + if (isUsedAsOperand(expression)) { + reportProblem(ER_ID, expression, + "Suggested parenthesis around expression"); + return PROCESS_SKIP; + } + } + if (precedence >= 0) { + synchronized (svis) { // since we use only one instance of this + // visitor sync just in case + svis.init(expression); + expression.accept(svis); + if (svis.suspicious == true) { + reportProblem(ER_ID, svis.other, + "Suggested parenthesis around expression"); + return PROCESS_SKIP; + } + } + } + return PROCESS_CONTINUE; + } + + private boolean isUsedAsOperand(IASTExpression expression) { + ASTNodeProperty prop = expression.getPropertyInParent(); + if (prop == IASTBinaryExpression.OPERAND_ONE + || prop == IASTBinaryExpression.OPERAND_TWO + || prop == IASTUnaryExpression.OPERAND) + return true; + return false; + } + } + + private int getPrecedence(IASTExpression e) { + if (e instanceof IASTBinaryExpression) { + IASTBinaryExpression binExpr = (IASTBinaryExpression) e; + int operator = binExpr.getOperator(); + if (operator == IASTBinaryExpression.op_binaryAnd) + return 8; + if (operator == IASTBinaryExpression.op_binaryXor) + return 9; + if (operator == IASTBinaryExpression.op_binaryOr) + return 10; + if (operator == IASTBinaryExpression.op_logicalAnd) + return 11; + if (operator == IASTBinaryExpression.op_logicalOr) + return 12; + } + if (e instanceof IASTUnaryExpression) { + IASTUnaryExpression binExpr = (IASTUnaryExpression) e; + int operator = binExpr.getOperator(); + if (operator == IASTUnaryExpression.op_not) + return 2; + if (operator == IASTUnaryExpression.op_tilde) + return 2; + } + return -1; + } + + class SuspiciousExpressionVisitor extends ASTVisitor { + IASTExpression parent; + IASTExpression other; + boolean suspicious = false; + + void init(IASTExpression e) { + parent = e; + suspicious = false; + } + + SuspiciousExpressionVisitor() { + shouldVisitExpressions = true; + } + + public int visit(IASTExpression expression) { + if (expression == parent) + return PROCESS_CONTINUE; + if (expression instanceof IASTUnaryExpression) { + IASTUnaryExpression uExpr = (IASTUnaryExpression) expression; + int operator = uExpr.getOperator(); + if (operator == IASTUnaryExpression.op_bracketedPrimary) { + return PROCESS_SKIP; + } + } + if (getPrecedence(expression) < 0) // not considered operator + return PROCESS_CONTINUE; + if (getPrecedence(expression) == getPrecedence(parent)) { + return PROCESS_SKIP; + } + suspicious = true; + other = expression; + return PROCESS_ABORT; + } + } +} diff --git a/org.eclipse.cdt.codan.core/.classpath b/org.eclipse.cdt.codan.core/.classpath index 16d067f..5e4c1fe 100644 --- a/org.eclipse.cdt.codan.core/.classpath +++ b/org.eclipse.cdt.codan.core/.classpath @@ -2,6 +2,6 @@ - + diff --git a/org.eclipse.cdt.codan.core/.settings/CVS/Entries b/org.eclipse.cdt.codan.core/.settings/CVS/Entries index b6cae13..eb6c3d6 100644 --- a/org.eclipse.cdt.codan.core/.settings/CVS/Entries +++ b/org.eclipse.cdt.codan.core/.settings/CVS/Entries @@ -1,2 +1,3 @@ /org.eclipse.jdt.core.prefs/1.3/Mon Aug 10 18:31:46 2009// +/org.eclipse.jdt.ui.prefs/1.1/Fri Nov 20 19:03:54 2009// D diff --git a/org.eclipse.cdt.codan.core/.settings/CVS/Template b/org.eclipse.cdt.codan.core/.settings/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.core/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.cdt.codan.core/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 0000000..2117213 --- /dev/null +++ b/org.eclipse.cdt.codan.core/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,54 @@ +#Fri Nov 20 13:57:56 EST 2009 +eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=true +sp_cleanup.add_missing_deprecated_annotations=true +sp_cleanup.add_missing_methods=false +sp_cleanup.add_missing_nls_tags=false +sp_cleanup.add_missing_override_annotations=true +sp_cleanup.add_serial_version_id=false +sp_cleanup.always_use_blocks=true +sp_cleanup.always_use_parentheses_in_expressions=false +sp_cleanup.always_use_this_for_non_static_field_access=false +sp_cleanup.always_use_this_for_non_static_method_access=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=true +sp_cleanup.format_source_code_changes_only=false +sp_cleanup.make_local_variable_final=false +sp_cleanup.make_parameters_final=false +sp_cleanup.make_private_fields_final=true +sp_cleanup.make_type_abstract_if_missing_method=false +sp_cleanup.make_variable_declarations_final=false +sp_cleanup.never_use_blocks=false +sp_cleanup.never_use_parentheses_in_expressions=true +sp_cleanup.on_save_use_additional_actions=true +sp_cleanup.organize_imports=true +sp_cleanup.qualify_static_field_accesses_with_declaring_class=false +sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_with_declaring_class=false +sp_cleanup.qualify_static_method_accesses_with_declaring_class=false +sp_cleanup.remove_private_constructors=true +sp_cleanup.remove_trailing_whitespaces=true +sp_cleanup.remove_trailing_whitespaces_all=true +sp_cleanup.remove_trailing_whitespaces_ignore_empty=false +sp_cleanup.remove_unnecessary_casts=true +sp_cleanup.remove_unnecessary_nls_tags=true +sp_cleanup.remove_unused_imports=true +sp_cleanup.remove_unused_local_variables=false +sp_cleanup.remove_unused_private_fields=true +sp_cleanup.remove_unused_private_members=false +sp_cleanup.remove_unused_private_methods=true +sp_cleanup.remove_unused_private_types=true +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_parentheses_in_expressions=false +sp_cleanup.use_this_for_non_static_field_access=false +sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true +sp_cleanup.use_this_for_non_static_method_access=false +sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true diff --git a/org.eclipse.cdt.codan.core/CVS/Entries b/org.eclipse.cdt.codan.core/CVS/Entries index 2fa8e25..cb575f0 100644 --- a/org.eclipse.cdt.codan.core/CVS/Entries +++ b/org.eclipse.cdt.codan.core/CVS/Entries @@ -1,4 +1,4 @@ -/.classpath/1.2/Fri Apr 17 20:50:15 2009// +/.classpath/1.3/Wed Dec 16 21:48:48 2009// /.project/1.1/Thu Apr 9 12:46:50 2009// D/.settings//// D/META-INF//// diff --git a/org.eclipse.cdt.codan.core/META-INF/CVS/Entries b/org.eclipse.cdt.codan.core/META-INF/CVS/Entries index 86baf3a..222d593 100644 --- a/org.eclipse.cdt.codan.core/META-INF/CVS/Entries +++ b/org.eclipse.cdt.codan.core/META-INF/CVS/Entries @@ -1,2 +1,2 @@ -/MANIFEST.MF/1.4/Sat Aug 22 21:16:49 2009// +/MANIFEST.MF/1.5/Wed Dec 16 21:48:48 2009// D diff --git a/org.eclipse.cdt.codan.core/META-INF/CVS/Template b/org.eclipse.cdt.codan.core/META-INF/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.core/META-INF/MANIFEST.MF b/org.eclipse.cdt.codan.core/META-INF/MANIFEST.MF index b77eb2c..b6eba46 100644 --- a/org.eclipse.cdt.codan.core/META-INF/MANIFEST.MF +++ b/org.eclipse.cdt.codan.core/META-INF/MANIFEST.MF @@ -11,4 +11,5 @@ Require-Bundle: org.eclipse.core.runtime, Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: J2SE-1.5 Export-Package: org.eclipse.cdt.codan.core, - org.eclipse.cdt.codan.core.model + org.eclipse.cdt.codan.core.model, + org.eclipse.cdt.codan.internal.core;x-friends:="org.eclipse.cdt.codan.core,org.eclipse.cdt.codan.core.test,org.eclipse.cdt.codan.ui" diff --git a/org.eclipse.cdt.codan.core/schema/CVS/Template b/org.eclipse.cdt.codan.core/schema/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.core/src/CVS/Template b/org.eclipse.cdt.codan.core/src/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.core/src/org/CVS/Template b/org.eclipse.cdt.codan.core/src/org/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/CVS/Template b/org.eclipse.cdt.codan.core/src/org/eclipse/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/CVS/Template b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/CVS/Template b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CVS/Entries b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CVS/Entries index fec4197..d3c5192 100644 --- a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CVS/Entries +++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CVS/Entries @@ -1,6 +1,5 @@ /CodanApplication.java/1.2/Sat Aug 22 21:16:48 2009// /CodanCorePlugin.java/1.3/Sat Aug 22 21:16:48 2009// -/CodanPreferencesLoader.java/1.1/Sat Aug 22 21:16:49 2009// /CodanRuntime.java/1.1/Sat Aug 22 21:16:48 2009// /PreferenceConstants.java/1.2/Sat Apr 18 04:01:43 2009// D/builder//// diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CVS/Template b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanPreferencesLoader.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanPreferencesLoader.java deleted file mode 100644 index 6fd6318..0000000 --- a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/CodanPreferencesLoader.java +++ /dev/null @@ -1,119 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Alena Laskavaia - * 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.core; - -import org.eclipse.cdt.codan.core.model.CodanSeverity; -import org.eclipse.cdt.codan.core.model.IProblem; -import org.eclipse.cdt.codan.core.model.IProblemProfile; -import org.eclipse.cdt.codan.internal.core.model.CodanProblem; -import org.eclipse.core.runtime.preferences.IEclipsePreferences; - -/** - * @author Alena - * - */ -public class CodanPreferencesLoader { - private IProblemProfile baseModel; - - /** - * @param workspaceProfile - */ - public CodanPreferencesLoader(IProblemProfile profile) { - setInput(profile); - } - - /** - * - */ - public CodanPreferencesLoader() { - } - - public void setInput(Object model) { - baseModel = (IProblemProfile) model; - } - - /** - * @return - */ - public IProblem[] getProblems() { - IProblem[] problems = baseModel.getProblems(); - return problems; - } - - /** - * @param id - * @param s - */ - public void setProperty(String id, String s) { - IProblem prob = baseModel.findProblem(id); - if (!(prob instanceof CodanProblem)) - return; - String sevs = s; - boolean enabled = true; - if (sevs.startsWith("-")) { - sevs = sevs.substring(1); - enabled = false; - } - ((CodanProblem) prob).setEnabled(enabled); - CodanSeverity sev; - try { - sev = CodanSeverity.valueOf(sevs); - } catch (RuntimeException e) { - sev = CodanSeverity.Warning; - } - ((CodanProblem) prob).setSeverity(sev); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return getInput().toString(); - } - - /** - * @return - */ - public IProblemProfile getInput() { - return baseModel; - } - - /** - * @param id - * @return - */ - public String getProperty(String id) { - IProblem prob = baseModel.findProblem(id); - if (!(prob instanceof CodanProblem)) - return null; - String enabled = prob.isEnabled() ? "" : "-"; - String severity = prob.getSeverity().toString(); - String res = enabled + severity; - return res; - } - - /** - * @param storePreferences - */ - public void load(IEclipsePreferences storePreferences) { - IProblem[] probs = getProblems(); - for (int i = 0; i < probs.length; i++) { - String id = probs[i].getId(); - String s = storePreferences.get(id, null); - if (s != null) { - setProperty(id, s); - } - } - } -} diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractIndexAstChecker.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractIndexAstChecker.java index 2c87b07..d805f2f 100644 --- a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractIndexAstChecker.java +++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractIndexAstChecker.java @@ -85,12 +85,18 @@ public abstract class AbstractIndexAstChecker extends AbstractChecker implements if (astFile == null) { astFile = file; } - getProblemReporter().reportProblem( - id, - new ProblemLocation(astFile, astLocation - .getStartingLineNumber()), message); + ProblemLocation loc; + if (astLocation.getStartingLineNumber() == astLocation + .getEndingLineNumber()) + loc = new ProblemLocation(astFile, astLocation.getNodeOffset(), + astLocation.getNodeOffset() + astLocation.getNodeLength()); + else + loc = new ProblemLocation(astFile, astLocation + .getStartingLineNumber()); + getProblemReporter().reportProblem(id, loc, message); } + @Override public boolean runInEditor() { return true; } diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CVS/Entries b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CVS/Entries index 736d312..8635b9d 100644 --- a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CVS/Entries +++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CVS/Entries @@ -1,17 +1,16 @@ /AbstractChecker.java/1.4/Sat Aug 22 21:31:29 2009// -/AbstractIndexAstChecker.java/1.5/Sat Aug 22 21:31:29 2009// +/AbstractIndexAstChecker.java/1.6/Wed Dec 16 21:48:48 2009// /CodanSeverity.java/1.2/Wed Apr 22 01:26:56 2009// /ICAstChecker.java/1.1/Thu Apr 9 12:46:50 2009// -/IChecker.java/1.2/Sat Aug 22 21:31:29 2009// +/IChecker.java/1.3/Wed Dec 16 21:48:48 2009// /ICheckersRegistry.java/1.1/Sat Aug 22 21:16:48 2009// /ICodanAstReconciler.java/1.1/Sat Aug 22 21:16:48 2009// /ICodanBuilder.java/1.1/Sat Aug 22 21:16:48 2009// -/IProblem.java/1.3/Sat Aug 22 21:16:48 2009// -/IProblemCategory.java/1.2/Thu Apr 16 01:46:57 2009// -/IProblemElement.java/1.1/Thu Apr 16 01:46:57 2009// +/IProblem.java/1.4/Wed Dec 16 21:48:48 2009// +/IProblemCategory.java/1.3/Wed Dec 16 21:48:48 2009// +/IProblemElement.java/1.2/Wed Dec 16 21:48:48 2009// /IProblemLocation.java/1.1/Sat Aug 22 21:16:48 2009// -/IProblemProfile.java/1.3/Sat May 9 01:54:38 2009// -/IProblemReporter.java/1.1/Sat Aug 22 21:16:48 2009// +/IProblemProfile.java/1.4/Wed Dec 16 21:48:48 2009// +/IProblemReporter.java/1.2/Wed Dec 16 21:48:48 2009// /ProblemLocation.java/1.1/Sat Aug 22 21:16:48 2009// -/ProblemProfile.java/1.4/Sat Aug 22 21:16:48 2009// D diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CVS/Template b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IChecker.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IChecker.java index 4f995db..60f7cb2 100644 --- a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IChecker.java +++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IChecker.java @@ -12,9 +12,23 @@ package org.eclipse.cdt.codan.core.model; import org.eclipse.core.resources.IResource; +/** + * Interface that checker must implement. CDT Checker must be able to process a resource. + */ public interface IChecker { - public boolean processResource(IResource resource); + /** + * Main method that checker should implement that actually detects errors + * @param resource - resource to run on + * @return true if need to traverse children + */ + boolean processResource(IResource resource); + /** + * Implement this method to trim down type of resource you are interested in, + * usually it will be c/c++ files only + * @param resource + * @return + */ boolean enabledInContext(IResource resource); /** diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblem.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblem.java index 52cfff2..bbab313 100644 --- a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblem.java +++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblem.java @@ -12,15 +12,38 @@ package org.eclipse.cdt.codan.core.model; import java.util.Collection; +/** + * Interface representing code analysis problem + * + */ public interface IProblem extends IProblemElement { + /** + * Name of the problem - user visible "title", not the message + */ String getName(); + /** + * Unique problem id. Should be qualified by plugin name to maintain uniqueness. + * @return + */ String getId(); + /** + * Is enabled in current context (usually within profile) + * @return true if enabled + */ boolean isEnabled(); + /** + * Get current severity + * @return severity + */ CodanSeverity getSeverity(); + /** + * Message pattern, java patter like 'Variable {0} is never used here' + * @return pattern + */ String getMessagePattern(); void setSeverity(CodanSeverity sev); @@ -31,6 +54,11 @@ public interface IProblem extends IProblemElement { public void setProperty(Object key, Object value); + /** + * Get custom property + * @param property name + * @return property object + */ public Object getProperty(Object key); public Collection getPropertyKeys(); diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemCategory.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemCategory.java index 45a62a0..cd3de3a 100644 --- a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemCategory.java +++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemCategory.java @@ -10,20 +10,37 @@ *******************************************************************************/ package org.eclipse.cdt.codan.core.model; +/** + * Problem category + * + */ public interface IProblemCategory extends IProblemElement { + /** + * Category name + */ String getName(); + /** + * Unique category id + * @return id + */ String getId(); - Object[] getChildren(); + /** + * Category children (other categories or problems) + * @return + */ + IProblemElement[] getChildren(); /** + * Find problem by id within children recursively * @param id * @return */ IProblem findProblem(String id); /** + * Find category by id within children recursively * @param id * @return */ diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemElement.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemElement.java index b9f7fb8..318f304 100644 --- a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemElement.java +++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemElement.java @@ -11,7 +11,7 @@ package org.eclipse.cdt.codan.core.model; /** - * @author Alena + * Problem category or problem * */ public interface IProblemElement extends Cloneable { diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemProfile.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemProfile.java index 9dc465e..896eb10 100644 --- a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemProfile.java +++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemProfile.java @@ -11,8 +11,10 @@ package org.eclipse.cdt.codan.core.model; /** - * Problem Profile contains tree of categories and problems. Profiles can have - * different categories and different problems set, problems with the same id + * Problem Profile contains tree of categories and problems. For user profile is quick way + * to switch between problems sets depends on task he is doing (i.e. find real bugs, vs doing code style report) + * User can set different profiles in different projects. + * Profiles can have different categories and different problems set, problems with the same id * can have different severities/enablement in different profiles. To obtain * profile use class {@link CheckersRegisry#getResourceProfile, * CheckersRegisry#getDefaultProfile() or CheckersRegisry#getWorkspaceProfile()} diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemReporter.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemReporter.java index 814cc40..059f155 100644 --- a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemReporter.java +++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemReporter.java @@ -16,6 +16,7 @@ package org.eclipse.cdt.codan.core.model; * */ public interface IProblemReporter { + public static final String GENERIC_CODE_ANALYSIS_MARKER_TYPE = "org.eclipse.cdt.codan.core.codanProblem"; /** * Report a problem with "problemId" id on location determined by "loc", * using problem specific error message customised by args. diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ProblemProfile.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ProblemProfile.java deleted file mode 100644 index ae90e76..0000000 --- a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/ProblemProfile.java +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 Alena Laskavaia - * 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.core.model; - -import java.util.ArrayList; -import java.util.Collection; - -import org.eclipse.cdt.codan.internal.core.model.CodanProblemCategory; - -/** - * @author Alena - * - */ -public class ProblemProfile implements IProblemProfile, Cloneable { - private IProblemCategory rootCategory = new CodanProblemCategory("root", - "root"); - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.cdt.codan.core.model.IProblemProfile#getProblem(java.lang - * .String) - */ - public IProblem findProblem(String id) { - return getRoot().findProblem(id); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.cdt.codan.core.model.IProblemProfile#getProblems() - */ - public IProblem[] getProblems() { - Collection problems = new ArrayList(); - collectProblems(getRoot(), problems); - return problems.toArray(new IProblem[problems.size()]); - } - - /** - * @param root - * @param problems - */ - protected void collectProblems(IProblemCategory parent, - Collection problems) { - Object[] children = parent.getChildren(); - for (Object object : children) { - if (object instanceof IProblemCategory) { - IProblemCategory cat = (IProblemCategory) object; - collectProblems(cat, problems); - } else if (object instanceof IProblem) { - problems.add((IProblem) object); - } - } - } - - public IProblemCategory getRoot() { - return rootCategory; - } - - public void addProblem(IProblem p, IProblemCategory cat) { - if (cat == null) - cat = getRoot(); - ((CodanProblemCategory) cat).addChild(p); - } - - public IProblemCategory findCategory(String id) { - return getRoot().findCategory(id); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#clone() - */ - @Override - public Object clone() { - try { - ProblemProfile clone = (ProblemProfile) super.clone(); - clone.rootCategory = (IProblemCategory) ((CodanProblemCategory) this.rootCategory) - .clone(); - return clone; - } catch (CloneNotSupportedException e) { - return this; - } - } - - /** - * @param p - * @param cat - */ - public void addCategory(IProblemCategory category, IProblemCategory parent) { - ((CodanProblemCategory) parent).addChild(category); - } -} diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/CVS/Template b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CVS/Entries b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CVS/Entries index 74cd7a6..49bf43c 100644 --- a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CVS/Entries +++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CVS/Entries @@ -1,4 +1,5 @@ -/CheckersRegisry.java/1.1/Sat Aug 22 21:16:49 2009// -/CodanBuilder.java/1.2/Sat Aug 22 21:31:29 2009// +/CheckersRegisry.java/1.3/Wed Dec 16 21:48:48 2009// +/CodanBuilder.java/1.3/Wed Dec 16 21:48:48 2009// +/CodanPreferencesLoader.java/1.1/Wed Sep 23 23:29:36 2009// /CodeAnlysisNature.java/1.1/Sat Aug 22 21:16:49 2009// D/model//// diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CVS/Template b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CheckersRegisry.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CheckersRegisry.java index 82ace80..5661622 100644 --- a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CheckersRegisry.java +++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CheckersRegisry.java @@ -16,16 +16,15 @@ import java.util.HashMap; import java.util.Iterator; import org.eclipse.cdt.codan.core.CodanCorePlugin; -import org.eclipse.cdt.codan.core.CodanPreferencesLoader; import org.eclipse.cdt.codan.core.PreferenceConstants; import org.eclipse.cdt.codan.core.model.IChecker; import org.eclipse.cdt.codan.core.model.ICheckersRegistry; import org.eclipse.cdt.codan.core.model.IProblem; import org.eclipse.cdt.codan.core.model.IProblemCategory; import org.eclipse.cdt.codan.core.model.IProblemProfile; -import org.eclipse.cdt.codan.core.model.ProblemProfile; import org.eclipse.cdt.codan.internal.core.model.CodanProblem; import org.eclipse.cdt.codan.internal.core.model.CodanProblemCategory; +import org.eclipse.cdt.codan.internal.core.model.ProblemProfile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ProjectScope; @@ -45,6 +44,7 @@ public class CheckersRegisry implements Iterable, ICheckersRegistry { private Collection checkers = new ArrayList(); private static CheckersRegisry instance; private HashMap profiles = new HashMap(); + private HashMap> problemList = new HashMap>(); private CheckersRegisry() { instance = this; @@ -136,7 +136,9 @@ public class CheckersRegisry implements Iterable, ICheckersRegistry { } } if (!hasRef) { - addProblem(new CodanProblem(id, name), null); + CodanProblem p = new CodanProblem(id, name); + addProblem(p, null); + addRefProblem(checkerObj, p); } } } catch (Exception e) { @@ -184,7 +186,9 @@ public class CheckersRegisry implements Iterable, ICheckersRegistry { return elementValue; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see org.eclipse.cdt.codan.core.model.ICheckersRegistry#iterator() */ public Iterator iterator() { @@ -197,15 +201,23 @@ public class CheckersRegisry implements Iterable, ICheckersRegistry { return instance; } - /* (non-Javadoc) - * @see org.eclipse.cdt.codan.core.model.ICheckersRegistry#addChecker(org.eclipse.cdt.codan.core.model.IChecker) + /* + * (non-Javadoc) + * + * @see + * org.eclipse.cdt.codan.core.model.ICheckersRegistry#addChecker(org.eclipse + * .cdt.codan.core.model.IChecker) */ public void addChecker(IChecker checker) { checkers.add(checker); } - /* (non-Javadoc) - * @see org.eclipse.cdt.codan.core.model.ICheckersRegistry#addProblem(org.eclipse.cdt.codan.core.model.IProblem, java.lang.String) + /* + * (non-Javadoc) + * + * @see + * org.eclipse.cdt.codan.core.model.ICheckersRegistry#addProblem(org.eclipse + * .cdt.codan.core.model.IProblem, java.lang.String) */ public void addProblem(IProblem p, String category) { IProblemCategory cat = getDefaultProfile().findCategory(category); @@ -214,8 +226,12 @@ public class CheckersRegisry implements Iterable, ICheckersRegistry { ((ProblemProfile) getDefaultProfile()).addProblem(p, cat); } - /* (non-Javadoc) - * @see org.eclipse.cdt.codan.core.model.ICheckersRegistry#addCategory(org.eclipse.cdt.codan.core.model.IProblemCategory, java.lang.String) + /* + * (non-Javadoc) + * + * @see + * org.eclipse.cdt.codan.core.model.ICheckersRegistry#addCategory(org.eclipse + * .cdt.codan.core.model.IProblemCategory, java.lang.String) */ public void addCategory(IProblemCategory p, String category) { IProblemCategory cat = getDefaultProfile().findCategory(category); @@ -224,21 +240,46 @@ public class CheckersRegisry implements Iterable, ICheckersRegistry { ((ProblemProfile) getDefaultProfile()).addCategory(p, cat); } - /* (non-Javadoc) - * @see org.eclipse.cdt.codan.core.model.ICheckersRegistry#addRefProblem(org.eclipse.cdt.codan.core.model.IChecker, org.eclipse.cdt.codan.core.model.IProblem) + /* + * (non-Javadoc) + * + * @see + * org.eclipse.cdt.codan.core.model.ICheckersRegistry#addRefProblem(org. + * eclipse.cdt.codan.core.model.IChecker, + * org.eclipse.cdt.codan.core.model.IProblem) */ public void addRefProblem(IChecker c, IProblem p) { + Collection plist = problemList.get(c); + if (plist == null) { + plist = new ArrayList(); + problemList.put(c, plist); + } + plist.add(p); + } + + /** + * Returns list of problems registered for given checker + * @return collection of problems or null + */ + public Collection getRefProblems(IChecker checker) { + return problemList.get(checker); } - /* (non-Javadoc) - * @see org.eclipse.cdt.codan.core.model.ICheckersRegistry#getDefaultProfile() + /* + * (non-Javadoc) + * + * @see + * org.eclipse.cdt.codan.core.model.ICheckersRegistry#getDefaultProfile() */ public IProblemProfile getDefaultProfile() { return profiles.get(DEFAULT); } - /* (non-Javadoc) - * @see org.eclipse.cdt.codan.core.model.ICheckersRegistry#getWorkspaceProfile() + /* + * (non-Javadoc) + * + * @see + * org.eclipse.cdt.codan.core.model.ICheckersRegistry#getWorkspaceProfile() */ public IProblemProfile getWorkspaceProfile() { IProblemProfile wp = profiles.get(ResourcesPlugin.getWorkspace()); @@ -262,8 +303,12 @@ public class CheckersRegisry implements Iterable, ICheckersRegistry { profiles.put(element, profile); } - /* (non-Javadoc) - * @see org.eclipse.cdt.codan.core.model.ICheckersRegistry#getResourceProfile(org.eclipse.core.resources.IResource) + /* + * (non-Javadoc) + * + * @see + * org.eclipse.cdt.codan.core.model.ICheckersRegistry#getResourceProfile + * (org.eclipse.core.resources.IResource) */ public IProblemProfile getResourceProfile(IResource element) { IProblemProfile prof = profiles.get(element); @@ -296,8 +341,11 @@ public class CheckersRegisry implements Iterable, ICheckersRegistry { return prof; } - /* (non-Javadoc) - * @see org.eclipse.cdt.codan.core.model.ICheckersRegistry#getResourceProfileWorkingCopy(org.eclipse.core.resources.IResource) + /* + * (non-Javadoc) + * + * @seeorg.eclipse.cdt.codan.core.model.ICheckersRegistry# + * getResourceProfileWorkingCopy(org.eclipse.core.resources.IResource) */ public IProblemProfile getResourceProfileWorkingCopy(IResource element) { if (element instanceof IProject) { diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanBuilder.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanBuilder.java index 7d58351..56916b8 100644 --- a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanBuilder.java +++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanBuilder.java @@ -12,6 +12,8 @@ package org.eclipse.cdt.codan.internal.core; import java.io.File; import java.net.URI; +import java.util.Collection; +import java.util.Iterator; import java.util.Map; import org.eclipse.cdt.codan.core.CodanCorePlugin; @@ -20,6 +22,8 @@ import org.eclipse.cdt.codan.core.model.ICAstChecker; import org.eclipse.cdt.codan.core.model.IChecker; import org.eclipse.cdt.codan.core.model.ICodanAstReconciler; import org.eclipse.cdt.codan.core.model.ICodanBuilder; +import org.eclipse.cdt.codan.core.model.IProblem; +import org.eclipse.cdt.codan.core.model.IProblemProfile; import org.eclipse.cdt.codan.core.model.IProblemReporter; import org.eclipse.cdt.codan.internal.core.model.CodanMarkerProblemReporter; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; @@ -122,6 +126,8 @@ public class CodanBuilder extends IncrementalProjectBuilder implements boolean run = false; if (checker.enabledInContext(resource)) run = true; + if (areProblemsForCheckerEnabled(checker, resource)) + run = true; if (run) checker.processResource(resource); } catch (Throwable e) { @@ -161,6 +167,9 @@ public class CodanBuilder extends IncrementalProjectBuilder implements boolean run = false; if (checker.enabledInContext(resource)) run = true; + if (areProblemsForCheckerEnabled(checker, resource)) { + run = true; + } if (run && checker instanceof ICAstChecker && checker.runInEditor()) ((ICAstChecker) checker).processAst(ast); @@ -171,6 +180,30 @@ public class CodanBuilder extends IncrementalProjectBuilder implements } } + /** + * @param checker + * @param resource + * @return + */ + private boolean areProblemsForCheckerEnabled(IChecker checker, + IResource resource) { + IProblemProfile resourceProfile = CheckersRegisry.getInstance() + .getResourceProfile(resource); + Collection refProblems = CheckersRegisry.getInstance() + .getRefProblems(checker); + for (Iterator iterator = refProblems.iterator(); iterator.hasNext();) { + IProblem p = (IProblem) iterator.next(); + // we need to check problem enablement in particular profile + IProblem problem = resourceProfile.findProblem(p.getId()); + if (problem == null) + throw new IllegalArgumentException("Id is not registered"); + if (problem.isEnabled()) + return true; + } + // no problem is enabled for this checker, skip the checker + return false; + } + protected void fullBuild(final IProgressMonitor monitor) throws CoreException { try { diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanPreferencesLoader.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanPreferencesLoader.java new file mode 100644 index 0000000..bafff9a --- /dev/null +++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanPreferencesLoader.java @@ -0,0 +1,119 @@ +/******************************************************************************* + * Copyright (c) 2009 Alena Laskavaia + * 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.core; + +import org.eclipse.cdt.codan.core.model.CodanSeverity; +import org.eclipse.cdt.codan.core.model.IProblem; +import org.eclipse.cdt.codan.core.model.IProblemProfile; +import org.eclipse.cdt.codan.internal.core.model.CodanProblem; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; + +/** + * @author Alena + * + */ +public class CodanPreferencesLoader { + private IProblemProfile baseModel; + + /** + * @param workspaceProfile + */ + public CodanPreferencesLoader(IProblemProfile profile) { + setInput(profile); + } + + /** + * + */ + public CodanPreferencesLoader() { + } + + public void setInput(Object model) { + baseModel = (IProblemProfile) model; + } + + /** + * @return + */ + public IProblem[] getProblems() { + IProblem[] problems = baseModel.getProblems(); + return problems; + } + + /** + * @param id + * @param s + */ + public void setProperty(String id, String s) { + IProblem prob = baseModel.findProblem(id); + if (!(prob instanceof CodanProblem)) + return; + String sevs = s; + boolean enabled = true; + if (sevs.startsWith("-")) { + sevs = sevs.substring(1); + enabled = false; + } + ((CodanProblem) prob).setEnabled(enabled); + CodanSeverity sev; + try { + sev = CodanSeverity.valueOf(sevs); + } catch (RuntimeException e) { + sev = CodanSeverity.Warning; + } + ((CodanProblem) prob).setSeverity(sev); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return getInput().toString(); + } + + /** + * @return + */ + public IProblemProfile getInput() { + return baseModel; + } + + /** + * @param id + * @return + */ + public String getProperty(String id) { + IProblem prob = baseModel.findProblem(id); + if (!(prob instanceof CodanProblem)) + return null; + String enabled = prob.isEnabled() ? "" : "-"; + String severity = prob.getSeverity().toString(); + String res = enabled + severity; + return res; + } + + /** + * @param storePreferences + */ + public void load(IEclipsePreferences storePreferences) { + IProblem[] probs = getProblems(); + for (int i = 0; i < probs.length; i++) { + String id = probs[i].getId(); + String s = storePreferences.get(id, null); + if (s != null) { + setProperty(id, s); + } + } + } +} diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CVS/Entries b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CVS/Entries index cf1f6cc..5f7a029 100644 --- a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CVS/Entries +++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CVS/Entries @@ -1,4 +1,5 @@ -/CodanMarkerProblemReporter.java/1.1/Sat Aug 22 21:16:48 2009// +/CodanMarkerProblemReporter.java/1.2/Wed Dec 16 21:48:48 2009// /CodanProblem.java/1.1/Sat Aug 22 21:16:48 2009// -/CodanProblemCategory.java/1.1/Sat Aug 22 21:16:48 2009// +/CodanProblemCategory.java/1.2/Wed Dec 16 21:48:48 2009// +/ProblemProfile.java/1.1/Wed Sep 23 23:29:36 2009// D diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CVS/Template b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CodanMarkerProblemReporter.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CodanMarkerProblemReporter.java index ebf00c9..a4599c5 100644 --- a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CodanMarkerProblemReporter.java +++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CodanMarkerProblemReporter.java @@ -23,7 +23,7 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; public class CodanMarkerProblemReporter implements IProblemReporter { - public static final String GENERIC_CODE_ANALYSIS_MARKER_TYPE = "org.eclipse.cdt.codan.core.codanProblem"; + /* * (non-Javadoc) diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CodanProblemCategory.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CodanProblemCategory.java index 289e0fd..fc63480 100644 --- a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CodanProblemCategory.java +++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CodanProblemCategory.java @@ -40,8 +40,8 @@ public class CodanProblemCategory implements IProblemCategory, Cloneable { return name; } - public Object[] getChildren() { - return list.toArray(); + public IProblemElement[] getChildren() { + return (IProblemElement[]) list.toArray(new IProblemElement[list.size()]); } public void addChild(IProblemElement p) { diff --git a/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/ProblemProfile.java b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/ProblemProfile.java new file mode 100644 index 0000000..d2330f1 --- /dev/null +++ b/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/ProblemProfile.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2009 Alena Laskavaia + * 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.core.model; + +import java.util.ArrayList; +import java.util.Collection; + +import org.eclipse.cdt.codan.core.model.IProblem; +import org.eclipse.cdt.codan.core.model.IProblemCategory; +import org.eclipse.cdt.codan.core.model.IProblemProfile; + +/** + * @author Alena + * + */ +public class ProblemProfile implements IProblemProfile, Cloneable { + private IProblemCategory rootCategory = new CodanProblemCategory("root", + "root"); + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.cdt.codan.core.model.IProblemProfile#getProblem(java.lang + * .String) + */ + public IProblem findProblem(String id) { + return getRoot().findProblem(id); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.codan.core.model.IProblemProfile#getProblems() + */ + public IProblem[] getProblems() { + Collection problems = new ArrayList(); + collectProblems(getRoot(), problems); + return problems.toArray(new IProblem[problems.size()]); + } + + /** + * @param root + * @param problems + */ + protected void collectProblems(IProblemCategory parent, + Collection problems) { + Object[] children = parent.getChildren(); + for (Object object : children) { + if (object instanceof IProblemCategory) { + IProblemCategory cat = (IProblemCategory) object; + collectProblems(cat, problems); + } else if (object instanceof IProblem) { + problems.add((IProblem) object); + } + } + } + + public IProblemCategory getRoot() { + return rootCategory; + } + + public void addProblem(IProblem p, IProblemCategory cat) { + if (cat == null) + cat = getRoot(); + ((CodanProblemCategory) cat).addChild(p); + } + + public IProblemCategory findCategory(String id) { + return getRoot().findCategory(id); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#clone() + */ + @Override + public Object clone() { + try { + ProblemProfile clone = (ProblemProfile) super.clone(); + clone.rootCategory = (IProblemCategory) ((CodanProblemCategory) this.rootCategory) + .clone(); + return clone; + } catch (CloneNotSupportedException e) { + return this; + } + } + + /** + * @param p + * @param cat + */ + public void addCategory(IProblemCategory category, IProblemCategory parent) { + ((CodanProblemCategory) parent).addChild(category); + } +} diff --git a/org.eclipse.cdt.codan.ui/.settings/CVS/Template b/org.eclipse.cdt.codan.ui/.settings/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.ui/META-INF/CVS/Template b/org.eclipse.cdt.codan.ui/META-INF/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.ui/src/CVS/Template b/org.eclipse.cdt.codan.ui/src/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.ui/src/org/CVS/Template b/org.eclipse.cdt.codan.ui/src/org/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/CVS/Template b/org.eclipse.cdt.codan.ui/src/org/eclipse/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/CVS/Template b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/CVS/Template b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/CVS/Template b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CVS/Template b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CVS/Entries b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CVS/Entries index fb8ead1..980f899 100644 --- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CVS/Entries +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CVS/Entries @@ -5,4 +5,4 @@ /Messages.java/1.1/Thu Apr 9 12:47:54 2009// /Messages.properties/1.1/Thu Apr 9 12:47:54 2009// /PreferenceInitializer.java/1.2/Thu Apr 16 01:46:56 2009// -/ProblemsTreeEditor.java/1.7/Sat Aug 22 21:16:50 2009// +/ProblemsTreeEditor.java/1.8/Wed Dec 16 21:48:50 2009// diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CVS/Template b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/ProblemsTreeEditor.java b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/ProblemsTreeEditor.java index 6ba82c6..26e433e 100644 --- a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/ProblemsTreeEditor.java +++ b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/ProblemsTreeEditor.java @@ -10,12 +10,12 @@ *******************************************************************************/ package org.eclipse.cdt.codan.internal.ui.preferences; -import org.eclipse.cdt.codan.core.CodanPreferencesLoader; import org.eclipse.cdt.codan.core.PreferenceConstants; import org.eclipse.cdt.codan.core.model.CodanSeverity; import org.eclipse.cdt.codan.core.model.IProblem; import org.eclipse.cdt.codan.core.model.IProblemCategory; import org.eclipse.cdt.codan.core.model.IProblemProfile; +import org.eclipse.cdt.codan.internal.core.CodanPreferencesLoader; import org.eclipse.jface.viewers.BaseLabelProvider; import org.eclipse.jface.viewers.CellEditor; import org.eclipse.jface.viewers.CheckStateChangedEvent; diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Template b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/CVS/Template new file mode 100644 index 0000000..e69de29 diff --git a/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Template b/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/ui/actions/CVS/Template new file mode 100644 index 0000000..e69de29 -- cgit