File indexing completed on 2024-04-21 04:34:33
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 ANALYSISRESULTSPARSER_H 0021 #define ANALYSISRESULTSPARSER_H 0022 0023 #include <QXmlStreamReader> 0024 0025 class AnalysisResults; 0026 class Checker; 0027 0028 /** 0029 * Parser for Krazy2 XML analysis results output. 0030 * It populates an AnalysisResults with the parsed data (issues and checkers). 0031 * The data can be parsed all at once or by calling parse(QString) repeteadly 0032 * with new data chunks each time. 0033 */ 0034 class AnalysisResultsParser { 0035 public: 0036 0037 /** 0038 * Creates a new AnalysisResultsParser. 0039 */ 0040 AnalysisResultsParser(); 0041 0042 /** 0043 * Sets the AnalysisResults to populate when parsing the data. 0044 * 0045 * @param analysisResults The AnalysisResults to populate. 0046 */ 0047 void setAnalysisResults(AnalysisResults* analysisResults); 0048 0049 /** 0050 * Parses the next results data outputted by krazy2 command. 0051 * 0052 * @param data The next results data to parse. 0053 */ 0054 void parse(const QByteArray& data); 0055 0056 private: 0057 0058 /** 0059 * The AnalysisResults to populate when parsing the data. 0060 */ 0061 AnalysisResults* m_analysisResults; 0062 0063 /** 0064 * The QXmlStreamReader to use in the parsing. 0065 */ 0066 QXmlStreamReader m_xmlStreamReader; 0067 0068 /** 0069 * The trimmed text of the current token, if its type is Characters. 0070 */ 0071 QString m_text; 0072 0073 /** 0074 * The checker of which issues are being parsed. 0075 */ 0076 const Checker* m_checker; 0077 0078 /** 0079 * The checker being parsed, if it is the first time it appears and thus is 0080 * being initialized. 0081 */ 0082 Checker* m_checkerBeingInitialized; 0083 0084 /** 0085 * The file type of which checkers are being parsed. 0086 */ 0087 QString m_checkerFileType; 0088 0089 /** 0090 * The name of the file where the issues being parsed occurred. 0091 */ 0092 QString m_issueFileName; 0093 0094 /** 0095 * The message for the issue being parsed. 0096 * The message appears in its own element before the issues. 0097 */ 0098 QString m_issueMessage; 0099 0100 /** 0101 * The details for the issue being parsed. 0102 * The details appear as an attribute in the issue element itself. It 0103 * overrides the issue message for the issue where it appears (although, if 0104 * details are present, there is probably no message). 0105 */ 0106 QString m_issueDetails; 0107 0108 /** 0109 * Checks whether the current token is a start element with the given name 0110 * or not. 0111 * 0112 * @param elementName The name to check. 0113 * @return True if the current token is a start element with the given name, 0114 * false otherwise. 0115 */ 0116 bool isStartElement(const QString& elementName); 0117 0118 /** 0119 * Checks whether the current token is an end element with the given name or 0120 * not. 0121 * 0122 * @param elementName The name to check. 0123 * @return True if the current token is an end element with the given name, 0124 * false otherwise. 0125 */ 0126 bool isEndElement(const QString& elementName); 0127 0128 /** 0129 * Sets the checker file type. 0130 */ 0131 void processFileTypeStart(); 0132 0133 /** 0134 * Sets the current checker, and initializes it (but for the explanation) if 0135 * it is the first time it appears (based on its file type and name). 0136 */ 0137 void processCheckStart(); 0138 0139 /** 0140 * Sets the explanation of the checker (if it is being initialized). 0141 */ 0142 void processExplanationEnd(); 0143 0144 /** 0145 * Sets the absolute file name of the issues. 0146 */ 0147 void processFileStart(); 0148 0149 /** 0150 * Clears the issue message. 0151 */ 0152 void processFileEnd(); 0153 0154 /** 0155 * Sets the issue message. 0156 */ 0157 void processMessageEnd(); 0158 0159 /** 0160 * Sets the issue details. 0161 */ 0162 void processLineStart(); 0163 0164 /** 0165 * Creates and initializes the issue. 0166 * The details message is also cleared (if needed). 0167 */ 0168 void processLineEnd(); 0169 0170 }; 0171 0172 #endif