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 CHECKERLISTPARSER_H 0021 #define CHECKERLISTPARSER_H 0022 0023 #include <QXmlStreamReader> 0024 0025 class Checker; 0026 0027 /** 0028 * Parser for Krazy2 XML checker list output. 0029 * It populates a list with the parsed checkers. The parser does not take 0030 * ownership of the checkers, so they must be deleted when no longer needed. The 0031 * data can be parsed all at once or by calling parse(QString) repeteadly with 0032 * new data chunks each time. 0033 */ 0034 class CheckerListParser { 0035 public: 0036 0037 /** 0038 * Creates a new CheckerListParser. 0039 */ 0040 CheckerListParser(); 0041 0042 /** 0043 * Sets the checker list to populate when parsing the data. 0044 * The given list must be empty. The checkers added to the given list must 0045 * be deleted when no longer needed. 0046 * 0047 * @param checkerList The checker list to populate. 0048 */ 0049 void setCheckerList(QList<const Checker*>* checkerList); 0050 0051 /** 0052 * Parses the next checker list data outputted by krazy2 command. 0053 * 0054 * @param data The next checker list data to parse. 0055 */ 0056 void parse(const QString& data); 0057 0058 private: 0059 0060 /** 0061 * The checker list to populate when parsing the data. 0062 */ 0063 QList<const Checker*>* m_checkerList; 0064 0065 /** 0066 * The QXmlStreamReader to use in the parsing. 0067 */ 0068 QXmlStreamReader m_xmlStreamReader; 0069 0070 /** 0071 * The checker being parsed. 0072 */ 0073 Checker* m_checkerBeingInitialized; 0074 0075 /** 0076 * The trimmed text of the current token, if its type is Characters. 0077 */ 0078 QString m_text; 0079 0080 /** 0081 * The file type of which checkers are being parsed. 0082 */ 0083 QString m_fileType; 0084 0085 /** 0086 * Whether the checkers being parsed are extra or no. 0087 */ 0088 bool m_extra; 0089 0090 /** 0091 * Checks whether the current token is a start element with the given name 0092 * or not. 0093 * 0094 * @param elementName The name to check. 0095 * @return True if the current token is a start element with the given name, 0096 * false otherwise. 0097 */ 0098 bool isStartElement(const QString& elementName); 0099 0100 /** 0101 * Checks whether the current token is an end element with the given name or 0102 * not. 0103 * 0104 * @param elementName The name to check. 0105 * @return True if the current token is an end element with the given name, 0106 * false otherwise. 0107 */ 0108 bool isEndElement(const QString& elementName); 0109 0110 /** 0111 * Sets the checker file type. 0112 */ 0113 void processFileTypeStart(); 0114 0115 /** 0116 * Creates and initializes the checker (but for the explanation). 0117 */ 0118 void processPluginStart(); 0119 0120 /** 0121 * Sets the explanation of the checker. 0122 */ 0123 void processExplanationEnd(); 0124 0125 /** 0126 * Enables the extra flag. 0127 */ 0128 void processExtraStart(); 0129 0130 /** 0131 * Disables the extra flag. 0132 */ 0133 void processExtraEnd(); 0134 0135 }; 0136 0137 #endif