1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of Qt Creator. 7 ** 8 ** Commercial License Usage 9 ** Licensees holding valid commercial Qt licenses may use this file in 10 ** accordance with the commercial license agreement provided with the 11 ** Software or, alternatively, in accordance with the terms contained in 12 ** a written agreement between you and The Qt Company. For licensing terms 13 ** and conditions see https://www.qt.io/terms-conditions. For further 14 ** information use the contact form at https://www.qt.io/contact-us. 15 ** 16 ** GNU General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU 18 ** General Public License version 3 as published by the Free Software 19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 ** included in the packaging of this file. Please review the following 21 ** information to ensure the GNU General Public License requirements will 22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 ** 24 ****************************************************************************/ 25 26 #pragma once 27 28 #include "itestparser.h" 29 30 #include <qmljs/qmljsdocument.h> 31 #include <utils/id.h> 32 33 #include <QFutureWatcher> 34 #include <QMap> 35 #include <QObject> 36 #include <QTimer> 37 38 QT_BEGIN_NAMESPACE 39 class QThreadPool; 40 QT_END_NAMESPACE 41 42 namespace ProjectExplorer { class Project; } 43 44 namespace Autotest { 45 46 namespace Internal { 47 48 class TestCodeParser : public QObject 49 { 50 Q_OBJECT 51 public: 52 enum State { 53 Idle, 54 PartialParse, 55 FullParse, 56 Shutdown 57 }; 58 59 TestCodeParser(); 60 61 void setState(State state); state()62 State state() const { return m_parserState; } isParsing()63 bool isParsing() const { return m_parserState == PartialParse || m_parserState == FullParse; } setDirty()64 void setDirty() { m_dirty = true; } 65 void syncTestFrameworks(const QList<ITestParser *> &parsers); 66 #ifdef WITH_TESTS furtherParsingExpected()67 bool furtherParsingExpected() const 68 { return m_singleShotScheduled || m_postponedUpdateType != UpdateType::NoUpdate; } 69 #endif 70 71 signals: 72 void aboutToPerformFullParse(); 73 void testParseResultReady(const TestParseResultPtr result); 74 void parsingStarted(); 75 void parsingFinished(); 76 void parsingFailed(); 77 void requestRemoval(const Utils::FilePath &filePath); 78 void requestRemoveAllFrameworkItems(); 79 80 public: 81 void emitUpdateTestTree(ITestParser *parser = nullptr); 82 void updateTestTree(const QSet<ITestParser *> &parsers = {}); 83 void onCppDocumentUpdated(const CPlusPlus::Document::Ptr &document); 84 void onQmlDocumentUpdated(const QmlJS::Document::Ptr &document); 85 void onStartupProjectChanged(ProjectExplorer::Project *project); 86 void onProjectPartsUpdated(ProjectExplorer::Project *project); 87 void aboutToShutdown(); 88 89 private: 90 bool postponed(const Utils::FilePaths &fileList); 91 void scanForTests(const Utils::FilePaths &fileList = Utils::FilePaths(), 92 const QList<ITestParser *> &parsers = {}); 93 94 // qml files must be handled slightly different 95 void onDocumentUpdated(const Utils::FilePath &fileName, bool isQmlFile = false); 96 void onTaskStarted(Utils::Id type); 97 void onAllTasksFinished(Utils::Id type); 98 void onFinished(); 99 void onPartialParsingFinished(); 100 void parsePostponedFiles(); 101 void releaseParserInternals(); 102 103 // used internally to indicate a parse that failed due to having triggered a parse for a file that 104 // is not (yet) part of the CppModelManager's snapshot 105 bool m_parsingHasFailed = false; 106 107 bool m_codeModelParsing = false; 108 enum class UpdateType { 109 NoUpdate, 110 PartialUpdate, 111 FullUpdate 112 } m_postponedUpdateType = UpdateType::NoUpdate; 113 bool m_dirty = false; 114 bool m_singleShotScheduled = false; 115 bool m_reparseTimerTimedOut = false; 116 QSet<Utils::FilePath> m_postponedFiles; 117 State m_parserState = Idle; 118 QFutureWatcher<TestParseResultPtr> m_futureWatcher; 119 QList<ITestParser *> m_testCodeParsers; // ptrs are still owned by TestFrameworkManager 120 QTimer m_reparseTimer; 121 QSet<ITestParser *> m_updateParsers; 122 QThreadPool *m_threadPool = nullptr; 123 }; 124 125 } // namespace Internal 126 } // namespace Autotest 127