File indexing completed on 2024-05-19 04:41:58

0001 /*
0002     SPDX-FileCopyrightText: 2013 Sven Brauch <svenbrauch@googlemail.com>
0003     SPDX-FileCopyrightText: 2014 Denis Steckelmacher <steckdenis@yahoo.fr>
0004 
0005     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006 */
0007 
0008 #ifndef __CACHE_H__
0009 #define __CACHE_H__
0010 
0011 #include "duchainexport.h"
0012 #include <serialization/indexedstring.h>
0013 #include <util/path.h>
0014 
0015 #include <QHash>
0016 #include <QString>
0017 #include <QFileInfoList>
0018 #include <QList>
0019 #include <QSet>
0020 #include <QMutex>
0021 
0022 class QStringList;
0023 
0024 namespace QmlJS
0025 {
0026 
0027 /**
0028  * Cache for values that may be slow to compute (search paths, things
0029  * involving QStandardPaths, etc)
0030  */
0031 class KDEVQMLJSDUCHAIN_EXPORT Cache
0032 {
0033 private:
0034     Cache();
0035 
0036 public:
0037     static Cache& instance();
0038 
0039     /**
0040      * List of the paths in which the modules will be looked for
0041      */
0042     KDevelop::Path::List libraryPaths(const KDevelop::IndexedString& baseFile) const;
0043 
0044     /**
0045      * Path corresponding to a module name
0046      *
0047      * The path returned can either be the one of a module file shipped with
0048      * kdev-qmljs, or the path of a directory containing the module components
0049      * (one .qml file per component, and possibly .so files if the module has
0050      * native components)
0051      *
0052      * @param version If not null, the file being looked for is "uri_version.qml".
0053      *                If null, then the untouched uri is used for searching.
0054      */
0055     QString modulePath(const KDevelop::IndexedString& baseFile, const QString& uri,
0056                        const QString& version = QStringLiteral("2.0"));
0057 
0058     /**
0059      * Return the list of the paths of the given files.
0060      *
0061      * Files having a name ending in ".so" are replaced with the path of their
0062      * qmlplugindump dump.
0063      */
0064     QStringList getFileNames(const QFileInfoList& fileInfos);
0065 
0066     /**
0067      * Set the custom include directories list of a file
0068      */
0069     void setFileCustomIncludes(const KDevelop::IndexedString& file,
0070                                const KDevelop::Path::List& dirs);
0071 
0072     /**
0073      * Add a dependency between two URLs
0074      */
0075     void addDependency(const KDevelop::IndexedString& file, const KDevelop::IndexedString& dependency);
0076 
0077     /**
0078      * List of the files that depend on a given URL
0079      */
0080     QList<KDevelop::IndexedString> filesThatDependOn(const KDevelop::IndexedString& file);
0081 
0082     /**
0083      * List of the dependencies of a file
0084      */
0085     QList<KDevelop::IndexedString> dependencies(const KDevelop::IndexedString& file);
0086 
0087     /**
0088      * Return whether a file is up to date (all its dependencies are up to date
0089      * and the file has been freshly parsed)
0090      */
0091     bool isUpToDate(const KDevelop::IndexedString& file);
0092     void setUpToDate(const KDevelop::IndexedString& file, bool upToDate);
0093 
0094 private:
0095     KDevelop::Path::List libraryPaths_internal(const KDevelop::IndexedString& baseFile) const;
0096 
0097     struct PluginDumpExecutable {
0098         QString executable;
0099         QString quickVersion;       // Version of QtQuick that should be imported when this qmlplugindump is used
0100 
0101         PluginDumpExecutable(const QString& e, const QString &v)
0102         : executable(e), quickVersion(v)
0103         {}
0104     };
0105 
0106     mutable QMutex m_mutex;
0107     QHash<QString, QString> m_modulePaths;
0108     QList<PluginDumpExecutable> m_pluginDumpExecutables;
0109     QHash<KDevelop::IndexedString, QSet<KDevelop::IndexedString>> m_dependees;
0110     QHash<KDevelop::IndexedString, QSet<KDevelop::IndexedString>> m_dependencies;
0111     QHash<KDevelop::IndexedString, bool> m_isUpToDate;
0112     QHash<KDevelop::IndexedString, KDevelop::Path::List> m_includeDirs;
0113 };
0114 
0115 }
0116 
0117 #endif