File indexing completed on 2024-04-28 05:49:07
0001 /* This file is part of the Kate project. 0002 * 0003 * SPDX-FileCopyrightText: 2017 Héctor Mesa Jiménez <hector@lcc.uma.es> 0004 * 0005 * SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include <QObject> 0011 #include <QString> 0012 #include <QStringList> 0013 0014 #include "diagnostics/diagnostic_types.h" 0015 0016 class KateProject; 0017 namespace KTextEditor 0018 { 0019 class MainWindow; 0020 } 0021 0022 /** 0023 * Information provider for a code analysis tool 0024 */ 0025 class KateProjectCodeAnalysisTool : public QObject 0026 { 0027 Q_OBJECT 0028 protected: 0029 explicit KateProjectCodeAnalysisTool(QObject *parent = nullptr); 0030 0031 /** 0032 * Current project 0033 */ 0034 KateProject *m_project = nullptr; 0035 0036 KTextEditor::MainWindow *m_mainWindow; 0037 0038 public: 0039 ~KateProjectCodeAnalysisTool() override; 0040 0041 /** 0042 * bind to this project 0043 * @param project project this tool will analyze 0044 */ 0045 virtual void setProject(KateProject *project); 0046 0047 /** 0048 * @return tool descriptive name 0049 */ 0050 virtual QString name() const = 0; 0051 0052 /** 0053 * @return tool short description 0054 */ 0055 virtual QString description() const = 0; 0056 0057 /** 0058 * @returns a string containing the file extensions this 0059 * tool should be run, separated by '|', 0060 * e.g. "cpp|cxx" 0061 * NOTE that this is used directly as part of a regular expression. 0062 * If more flexibility is required this method probably will change 0063 */ 0064 virtual QString fileExtensions() const = 0; 0065 0066 /** 0067 * filter relevant files 0068 * @param files set of files in project 0069 * @return relevant files that can be analyzed 0070 */ 0071 virtual QStringList filter(const QStringList &files) const = 0; 0072 0073 /** 0074 * @return tool path 0075 */ 0076 virtual QString path() const = 0; 0077 0078 /** 0079 * @return arguments required for the tool 0080 * NOTE that this method is not const because here setActualFilesCount might be called 0081 */ 0082 virtual QStringList arguments() = 0; 0083 0084 /** 0085 * @return warning message when the tool is not installed 0086 */ 0087 virtual QString notInstalledMessage() const = 0; 0088 0089 /** 0090 * parse output line 0091 * @param line 0092 * @return file, line, severity, message 0093 */ 0094 virtual FileDiagnostics parseLine(const QString &line) const = 0; 0095 0096 /** 0097 * Tells the tool runner if the returned process exit code 0098 * was a successful one. 0099 * 0100 * The default implementation returns true on exitCode 0. 0101 * 0102 * Override this method for a tool that use a non-zero exit code 0103 * e.g. if the processing itself was successful but not all files 0104 * had no linter errors. 0105 */ 0106 virtual bool isSuccessfulExitCode(int exitCode) const; 0107 0108 /** 0109 * @return messages passed to the tool through stdin 0110 * This is used when the files are not passed as arguments to the tool. 0111 * 0112 * NOTE that this method is not const because here setActualFilesCount might be called 0113 */ 0114 virtual QString stdinMessages() = 0; 0115 0116 /** 0117 * @returns the number of files to be processed after the filter 0118 * has been applied 0119 */ 0120 int getActualFilesCount() const; 0121 0122 /** 0123 * To be called by derived classes 0124 */ 0125 void setActualFilesCount(int count); 0126 0127 void setMainWindow(KTextEditor::MainWindow *mainWin); 0128 0129 private: 0130 int m_filesCount = 0; 0131 }; 0132 0133 Q_DECLARE_METATYPE(KateProjectCodeAnalysisTool *)