2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-01-18 13:13:34 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2010-01-18 13:13:34 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-01-18 13:13:34 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2010-01-18 13:13:34 +01:00
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
**
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2013-03-12 12:09:22 +01:00
|
|
|
#ifndef QMLJSDOCUMENT_H
|
|
|
|
#define QMLJSDOCUMENT_H
|
2010-01-18 13:13:34 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QList>
|
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <QString>
|
2010-01-18 13:13:34 +01:00
|
|
|
|
2011-01-04 17:04:44 +01:00
|
|
|
#include <languageutils/fakemetaobject.h>
|
|
|
|
|
2010-03-18 15:43:33 +01:00
|
|
|
#include "parser/qmldirparser_p.h"
|
2010-01-18 13:13:34 +01:00
|
|
|
#include "parser/qmljsengine_p.h"
|
2010-01-18 16:15:23 +01:00
|
|
|
#include "qmljs_global.h"
|
2013-11-06 14:17:23 +01:00
|
|
|
#include "qmljsconstants.h"
|
2013-10-16 15:08:27 +02:00
|
|
|
#include "qmljsimportdependencies.h"
|
2010-01-18 13:13:34 +01:00
|
|
|
|
2010-01-18 16:15:23 +01:00
|
|
|
namespace QmlJS {
|
2010-01-18 13:13:34 +01:00
|
|
|
|
2010-02-02 15:55:17 +01:00
|
|
|
class Bind;
|
2010-02-16 10:36:09 +01:00
|
|
|
class Snapshot;
|
2013-10-16 15:08:27 +02:00
|
|
|
class ImportDependencies;
|
2010-02-02 15:55:17 +01:00
|
|
|
|
2010-01-18 16:15:23 +01:00
|
|
|
class QMLJS_EXPORT Document
|
2010-01-18 13:13:34 +01:00
|
|
|
{
|
|
|
|
public:
|
2011-11-03 13:47:03 +01:00
|
|
|
typedef QSharedPointer<const Document> Ptr;
|
|
|
|
typedef QSharedPointer<Document> MutablePtr;
|
2010-01-18 13:13:34 +01:00
|
|
|
|
2013-10-16 14:59:28 +02:00
|
|
|
static bool isQmlLikeLanguage(Language::Enum languge);
|
|
|
|
static bool isFullySupportedLanguage(Language::Enum language);
|
|
|
|
static bool isQmlLikeOrJsLanguage(Language::Enum language);
|
2014-01-22 18:38:45 +01:00
|
|
|
static QList<Language::Enum> companionLanguages(Language::Enum language);
|
2010-01-18 13:13:34 +01:00
|
|
|
protected:
|
2013-10-16 14:59:28 +02:00
|
|
|
Document(const QString &fileName, Language::Enum language);
|
2010-01-18 13:13:34 +01:00
|
|
|
|
|
|
|
public:
|
2010-01-18 16:15:23 +01:00
|
|
|
~Document();
|
2010-01-18 13:13:34 +01:00
|
|
|
|
2013-10-16 14:59:28 +02:00
|
|
|
static MutablePtr create(const QString &fileName, Language::Enum language);
|
2010-01-18 13:13:34 +01:00
|
|
|
|
2011-05-04 11:12:45 +02:00
|
|
|
Document::Ptr ptr() const;
|
|
|
|
|
2010-03-29 12:56:25 +02:00
|
|
|
bool isQmlDocument() const;
|
2013-10-16 14:59:28 +02:00
|
|
|
Language::Enum language() const;
|
|
|
|
void setLanguage(Language::Enum l);
|
2010-03-29 12:56:25 +02:00
|
|
|
|
2013-11-13 16:31:04 +01:00
|
|
|
QString importId() const;
|
|
|
|
QByteArray fingerprint() const;
|
2010-02-03 15:59:15 +01:00
|
|
|
AST::UiProgram *qmlProgram() const;
|
|
|
|
AST::Program *jsProgram() const;
|
|
|
|
AST::ExpressionNode *expression() const;
|
|
|
|
AST::Node *ast() const;
|
2010-01-19 10:16:57 +01:00
|
|
|
|
2010-11-23 12:57:48 +01:00
|
|
|
const QmlJS::Engine *engine() const;
|
|
|
|
|
2010-02-03 15:59:15 +01:00
|
|
|
QList<DiagnosticMessage> diagnosticMessages() const;
|
2010-01-18 13:13:34 +01:00
|
|
|
|
|
|
|
QString source() const;
|
|
|
|
void setSource(const QString &source);
|
|
|
|
|
2010-03-29 12:56:25 +02:00
|
|
|
bool parse();
|
2010-01-18 13:13:34 +01:00
|
|
|
bool parseQml();
|
|
|
|
bool parseJavaScript();
|
2010-01-22 10:26:25 +01:00
|
|
|
bool parseExpression();
|
2010-01-18 13:13:34 +01:00
|
|
|
|
|
|
|
bool isParsedCorrectly() const
|
|
|
|
{ return _parsedCorrectly; }
|
|
|
|
|
2010-02-03 15:59:15 +01:00
|
|
|
Bind *bind() const;
|
2010-02-02 15:55:17 +01:00
|
|
|
|
2010-07-07 17:52:02 +02:00
|
|
|
int editorRevision() const;
|
|
|
|
void setEditorRevision(int revision);
|
2010-01-25 14:18:53 +01:00
|
|
|
|
2010-02-11 10:19:41 +01:00
|
|
|
QString fileName() const;
|
|
|
|
QString path() const;
|
|
|
|
QString componentName() const;
|
2010-01-18 13:13:34 +01:00
|
|
|
|
2010-02-08 21:37:59 +01:00
|
|
|
private:
|
|
|
|
bool parse_helper(int kind);
|
|
|
|
|
2010-01-18 13:13:34 +01:00
|
|
|
private:
|
|
|
|
QmlJS::Engine *_engine;
|
2010-02-03 15:59:15 +01:00
|
|
|
AST::Node *_ast;
|
|
|
|
Bind *_bind;
|
2010-01-18 13:13:34 +01:00
|
|
|
QList<QmlJS::DiagnosticMessage> _diagnosticMessages;
|
|
|
|
QString _fileName;
|
|
|
|
QString _path;
|
|
|
|
QString _componentName;
|
|
|
|
QString _source;
|
2011-05-04 11:12:45 +02:00
|
|
|
QWeakPointer<Document> _ptr;
|
2013-11-13 16:31:04 +01:00
|
|
|
QByteArray _fingerprint;
|
2011-09-09 10:55:11 +02:00
|
|
|
int _editorRevision;
|
2013-10-16 14:59:28 +02:00
|
|
|
Language::Enum _language;
|
2012-12-06 12:11:12 +01:00
|
|
|
bool _parsedCorrectly;
|
2010-02-16 10:36:09 +01:00
|
|
|
|
|
|
|
// for documentFromSource
|
|
|
|
friend class Snapshot;
|
2010-01-18 13:13:34 +01:00
|
|
|
};
|
|
|
|
|
2011-10-12 08:36:02 +02:00
|
|
|
class QMLJS_EXPORT ModuleApiInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QString uri;
|
|
|
|
LanguageUtils::ComponentVersion version;
|
|
|
|
QString cppName;
|
2013-11-13 16:31:04 +01:00
|
|
|
|
|
|
|
void addToHash(QCryptographicHash &hash) const;
|
2011-10-12 08:36:02 +02:00
|
|
|
};
|
|
|
|
|
2010-03-18 15:43:33 +01:00
|
|
|
class QMLJS_EXPORT LibraryInfo
|
|
|
|
{
|
2010-11-24 09:30:46 +01:00
|
|
|
public:
|
2011-05-12 15:29:00 +02:00
|
|
|
enum PluginTypeInfoStatus {
|
|
|
|
NoTypeInfo,
|
2010-11-24 09:30:46 +01:00
|
|
|
DumpDone,
|
2011-05-12 15:29:00 +02:00
|
|
|
DumpError,
|
|
|
|
TypeInfoFileDone,
|
|
|
|
TypeInfoFileError
|
2010-11-24 09:30:46 +01:00
|
|
|
};
|
|
|
|
|
2011-05-27 14:51:30 +02:00
|
|
|
enum Status {
|
|
|
|
NotScanned,
|
|
|
|
NotFound,
|
|
|
|
Found
|
|
|
|
};
|
|
|
|
|
2010-11-24 09:30:46 +01:00
|
|
|
private:
|
2011-05-27 14:51:30 +02:00
|
|
|
Status _status;
|
2010-03-18 15:43:33 +01:00
|
|
|
QList<QmlDirParser::Component> _components;
|
|
|
|
QList<QmlDirParser::Plugin> _plugins;
|
2011-09-02 13:25:08 +02:00
|
|
|
QList<QmlDirParser::TypeInfo> _typeinfos;
|
2011-01-04 17:04:44 +01:00
|
|
|
typedef QList<LanguageUtils::FakeMetaObject::ConstPtr> FakeMetaObjectList;
|
2010-06-09 14:27:30 +02:00
|
|
|
FakeMetaObjectList _metaObjects;
|
2011-10-12 08:36:02 +02:00
|
|
|
QList<ModuleApiInfo> _moduleApis;
|
2013-11-13 16:31:04 +01:00
|
|
|
QByteArray _fingerprint;
|
2010-11-24 09:30:46 +01:00
|
|
|
|
2011-05-12 15:29:00 +02:00
|
|
|
PluginTypeInfoStatus _dumpStatus;
|
2010-11-24 09:30:46 +01:00
|
|
|
QString _dumpError;
|
2010-03-18 15:43:33 +01:00
|
|
|
|
|
|
|
public:
|
2011-05-27 14:51:30 +02:00
|
|
|
explicit LibraryInfo(Status status = NotScanned);
|
2013-11-13 16:31:04 +01:00
|
|
|
explicit LibraryInfo(const QmlDirParser &parser, const QByteArray &fingerprint = QByteArray());
|
2010-03-18 15:43:33 +01:00
|
|
|
~LibraryInfo();
|
|
|
|
|
2013-11-13 16:31:04 +01:00
|
|
|
QByteArray calculateFingerprint() const;
|
|
|
|
void updateFingerprint();
|
|
|
|
QByteArray fingerprint() const
|
|
|
|
{ return _fingerprint; }
|
|
|
|
|
2010-03-18 15:43:33 +01:00
|
|
|
QList<QmlDirParser::Component> components() const
|
|
|
|
{ return _components; }
|
|
|
|
|
|
|
|
QList<QmlDirParser::Plugin> plugins() const
|
|
|
|
{ return _plugins; }
|
|
|
|
|
2011-09-02 13:25:08 +02:00
|
|
|
QList<QmlDirParser::TypeInfo> typeInfos() const
|
|
|
|
{ return _typeinfos; }
|
|
|
|
|
2010-06-09 14:27:30 +02:00
|
|
|
FakeMetaObjectList metaObjects() const
|
|
|
|
{ return _metaObjects; }
|
|
|
|
|
|
|
|
void setMetaObjects(const FakeMetaObjectList &objects)
|
|
|
|
{ _metaObjects = objects; }
|
|
|
|
|
2011-10-12 08:36:02 +02:00
|
|
|
QList<ModuleApiInfo> moduleApis() const
|
|
|
|
{ return _moduleApis; }
|
|
|
|
|
|
|
|
void setModuleApis(const QList<ModuleApiInfo> &apis)
|
|
|
|
{ _moduleApis = apis; }
|
|
|
|
|
2010-03-18 15:43:33 +01:00
|
|
|
bool isValid() const
|
2011-05-27 14:51:30 +02:00
|
|
|
{ return _status == Found; }
|
|
|
|
|
|
|
|
bool wasScanned() const
|
|
|
|
{ return _status != NotScanned; }
|
2010-10-14 14:44:50 +02:00
|
|
|
|
2013-11-19 10:42:57 +01:00
|
|
|
bool wasFound() const
|
|
|
|
{ return _status != NotFound; }
|
|
|
|
|
2011-05-12 15:29:00 +02:00
|
|
|
PluginTypeInfoStatus pluginTypeInfoStatus() const
|
2010-11-24 09:30:46 +01:00
|
|
|
{ return _dumpStatus; }
|
|
|
|
|
2011-05-12 15:29:00 +02:00
|
|
|
QString pluginTypeInfoError() const
|
2010-11-24 09:30:46 +01:00
|
|
|
{ return _dumpError; }
|
2010-10-14 14:44:50 +02:00
|
|
|
|
2011-05-12 15:29:00 +02:00
|
|
|
void setPluginTypeInfoStatus(PluginTypeInfoStatus dumped, const QString &error = QString())
|
2010-11-24 09:30:46 +01:00
|
|
|
{ _dumpStatus = dumped; _dumpError = error; }
|
2010-03-18 15:43:33 +01:00
|
|
|
};
|
|
|
|
|
2010-01-26 17:23:18 +01:00
|
|
|
class QMLJS_EXPORT Snapshot
|
2010-01-18 13:13:34 +01:00
|
|
|
{
|
2010-04-01 11:27:49 +02:00
|
|
|
typedef QHash<QString, Document::Ptr> _Base;
|
|
|
|
QHash<QString, Document::Ptr> _documents;
|
2010-08-31 10:23:48 +02:00
|
|
|
QHash<QString, QList<Document::Ptr> > _documentsByPath;
|
2010-04-01 11:27:49 +02:00
|
|
|
QHash<QString, LibraryInfo> _libraries;
|
2013-10-16 15:08:27 +02:00
|
|
|
ImportDependencies _dependencies;
|
2010-01-26 17:23:18 +01:00
|
|
|
|
2010-01-18 13:13:34 +01:00
|
|
|
public:
|
|
|
|
Snapshot();
|
2013-10-16 15:08:27 +02:00
|
|
|
Snapshot(const Snapshot &o);
|
2010-01-18 13:13:34 +01:00
|
|
|
~Snapshot();
|
|
|
|
|
2010-01-26 17:23:18 +01:00
|
|
|
typedef _Base::iterator iterator;
|
|
|
|
typedef _Base::const_iterator const_iterator;
|
|
|
|
|
|
|
|
const_iterator begin() const { return _documents.begin(); }
|
|
|
|
const_iterator end() const { return _documents.end(); }
|
|
|
|
|
2011-08-16 14:11:30 +02:00
|
|
|
void insert(const Document::Ptr &document, bool allowInvalid = false);
|
2010-03-18 15:43:33 +01:00
|
|
|
void insertLibraryInfo(const QString &path, const LibraryInfo &info);
|
2010-05-18 13:40:35 +02:00
|
|
|
void remove(const QString &fileName);
|
2010-01-18 13:13:34 +01:00
|
|
|
|
2013-10-16 15:08:27 +02:00
|
|
|
const ImportDependencies *importDependencies() const;
|
|
|
|
ImportDependencies *importDependencies();
|
|
|
|
|
2010-04-01 14:42:39 +02:00
|
|
|
Document::Ptr document(const QString &fileName) const;
|
|
|
|
QList<Document::Ptr> documentsInDirectory(const QString &path) const;
|
|
|
|
LibraryInfo libraryInfo(const QString &path) const;
|
2010-03-18 15:43:33 +01:00
|
|
|
|
2011-11-03 13:47:03 +01:00
|
|
|
Document::MutablePtr documentFromSource(const QString &code,
|
2011-09-09 10:55:11 +02:00
|
|
|
const QString &fileName,
|
2013-10-16 14:59:28 +02:00
|
|
|
Language::Enum language) const;
|
2010-01-18 13:13:34 +01:00
|
|
|
};
|
|
|
|
|
2010-09-23 15:09:06 +02:00
|
|
|
} // namespace QmlJS
|
|
|
|
|
2013-03-12 12:09:22 +01:00
|
|
|
#endif // QMLJSDOCUMENT_H
|