File indexing completed on 2024-04-14 04:29:51

0001 /*
0002  * This file is part of KDevelop Krazy2 Plugin.
0003  *
0004  * Copyright 2012 Daniel Calviño Sánchez <danxuliu@gmail.com>
0005  *
0006  * This program is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU General Public License
0008  * as published by the Free Software Foundation; either version 2
0009  * of the License, or (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU General Public License
0017  * along with this program. If not, see <http://www.gnu.org/licenses/>.
0018  */
0019 
0020 #ifndef ANALYSISRESULTS_H
0021 #define ANALYSISRESULTS_H
0022 
0023 #include <QHash>
0024 #include <QList>
0025 
0026 class Checker;
0027 class Issue;
0028 
0029 /**
0030  * Analysis results for issues found by Krazy2.
0031  * The results store the issues found by Krazy2. Once added to the results, an
0032  * issue can't be modified.
0033  *
0034  * Each issue is associated with a checker, and several issues can be associated
0035  * with the same checker. A checker is identified by its file type and name.
0036  *
0037  * The results take ownership of the added issues and its checkers, so they are
0038  * deleted when the results are deleted.
0039  */
0040 class AnalysisResults {
0041 public:
0042 
0043     /**
0044      * Creates a new empty AnalysisResults.
0045      */
0046     AnalysisResults();
0047 
0048     /**
0049      * Deletes the issues and their associated checkers.
0050      */
0051     virtual ~AnalysisResults();
0052 
0053     /**
0054      * Adds a new checker to this AnalysisResults.
0055      * The checker must have a file type and name.
0056      * If there is a previous checker with the same file type and name, the new
0057      * checker will be ignored.
0058      *
0059      * @param checker The checker to add.
0060      */
0061     void addChecker(const Checker* checker);
0062 
0063     /**
0064      * Returns the checker with the given file type and name.
0065      *
0066      * @return The checker, or a null pointer if there is no checker for the
0067      *         file type and the name.
0068      */
0069     const Checker* findChecker(const QString& fileType, const QString& name) const;
0070 
0071     /**
0072      * Adds a new issue to this AnalysisResults.
0073      * The issue must have a file name and a checker.
0074      * The checker of the issue must have been added previously to this
0075      * AnalysisResults.
0076      *
0077      * @param issue The issue to add.
0078      */
0079     void addIssue(const Issue* issue);
0080 
0081     /**
0082      * Returns a list with all the issues added to this AnalysisResults.
0083      *
0084      * @return All the issues added to this AnalysisResults.
0085      */
0086     const QList<const Issue*>& issues() const;
0087 
0088     /**
0089      * Adds a copy of all the issues from the given AnalysisResults.
0090      * If an issue references a checker with the same file type and name as one
0091      * already added to this AnalysisResults, the already added Checker is used.
0092      * Else, a copy of the referenced checker is added to this AnalysisResults.
0093      *
0094      * If an issue to be added has the same checker (based on the file type and
0095      * name), file name and line as one already added to this AnalysisResults,
0096      * the issue to be added is ignored (that is, a duplicated issue is not
0097      * added).
0098      *
0099      * @param analysisResults The AnalysisResults to add its issues.
0100      */
0101     void addAnalysisResults(const AnalysisResults* analysisResults);
0102 
0103 private:
0104 
0105     /**
0106      * The issues stored.
0107      */
0108     QList<const Issue*> m_issues;
0109 
0110     /**
0111      * All the checkers associated to the issues.
0112      */
0113     QHash<QString, const Checker*> m_checkers;
0114 
0115 };
0116 
0117 #endif