2010-01-18 13:13:34 +01:00
|
|
|
/**************************************************************************
|
|
|
|
**
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2010-01-18 13:13:34 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Contact: Nokia Corporation (info@qt.nokia.com)
|
2010-01-18 13:13:34 +01:00
|
|
|
**
|
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2010-01-18 13:13:34 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
**
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
|
|
|
** Nokia at qt-info@nokia.com.
|
2010-01-18 13:13:34 +01:00
|
|
|
**
|
|
|
|
**************************************************************************/
|
|
|
|
#ifndef QMLDOCUMENT_H
|
|
|
|
#define QMLDOCUMENT_H
|
|
|
|
|
|
|
|
#include <QtCore/QList>
|
|
|
|
#include <QtCore/QMap>
|
|
|
|
#include <QtCore/QPair>
|
|
|
|
#include <QtCore/QSharedPointer>
|
|
|
|
#include <QtCore/QString>
|
|
|
|
|
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"
|
2010-01-18 13:13:34 +01:00
|
|
|
|
2010-09-23 15:09:06 +02:00
|
|
|
QT_QML_BEGIN_NAMESPACE
|
|
|
|
|
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;
|
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:
|
2010-01-18 16:15:23 +01:00
|
|
|
typedef QSharedPointer<Document> Ptr;
|
2010-01-18 13:13:34 +01:00
|
|
|
|
|
|
|
protected:
|
2010-01-18 16:15:23 +01:00
|
|
|
Document(const QString &fileName);
|
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
|
|
|
|
2010-01-18 16:15:23 +01:00
|
|
|
static Document::Ptr create(const QString &fileName);
|
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;
|
|
|
|
bool isJSDocument() 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-06-15 14:50:16 +02:00
|
|
|
static void extractPragmas(QString *source);
|
2010-02-08 21:37:59 +01:00
|
|
|
|
2010-01-18 13:13:34 +01:00
|
|
|
private:
|
|
|
|
QmlJS::Engine *_engine;
|
2010-02-03 15:59:15 +01:00
|
|
|
NodePool *_pool;
|
|
|
|
AST::Node *_ast;
|
|
|
|
Bind *_bind;
|
2010-03-29 12:56:25 +02:00
|
|
|
bool _isQmlDocument;
|
2010-07-07 17:52:02 +02:00
|
|
|
int _editorRevision;
|
2010-01-25 14:18:53 +01:00
|
|
|
bool _parsedCorrectly;
|
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;
|
2010-02-16 10:36:09 +01:00
|
|
|
|
|
|
|
// for documentFromSource
|
|
|
|
friend class Snapshot;
|
2010-01-18 13:13:34 +01:00
|
|
|
};
|
|
|
|
|
2010-03-18 15:43:33 +01:00
|
|
|
class QMLJS_EXPORT LibraryInfo
|
|
|
|
{
|
2010-11-24 09:30:46 +01:00
|
|
|
public:
|
|
|
|
enum DumpStatus {
|
|
|
|
DumpNotStartedOrRunning,
|
|
|
|
DumpDone,
|
|
|
|
DumpError
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2010-03-18 15:43:33 +01:00
|
|
|
bool _valid;
|
|
|
|
QList<QmlDirParser::Component> _components;
|
|
|
|
QList<QmlDirParser::Plugin> _plugins;
|
2011-01-04 17:04:44 +01:00
|
|
|
typedef QList<LanguageUtils::FakeMetaObject::ConstPtr> FakeMetaObjectList;
|
2010-06-09 14:27:30 +02:00
|
|
|
FakeMetaObjectList _metaObjects;
|
2010-11-24 09:30:46 +01:00
|
|
|
|
|
|
|
DumpStatus _dumpStatus;
|
|
|
|
QString _dumpError;
|
2010-03-18 15:43:33 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
LibraryInfo();
|
|
|
|
LibraryInfo(const QmlDirParser &parser);
|
|
|
|
~LibraryInfo();
|
|
|
|
|
|
|
|
QList<QmlDirParser::Component> components() const
|
|
|
|
{ return _components; }
|
|
|
|
|
|
|
|
QList<QmlDirParser::Plugin> plugins() const
|
|
|
|
{ return _plugins; }
|
|
|
|
|
2010-06-09 14:27:30 +02:00
|
|
|
FakeMetaObjectList metaObjects() const
|
|
|
|
{ return _metaObjects; }
|
|
|
|
|
|
|
|
void setMetaObjects(const FakeMetaObjectList &objects)
|
|
|
|
{ _metaObjects = objects; }
|
|
|
|
|
2010-03-18 15:43:33 +01:00
|
|
|
bool isValid() const
|
|
|
|
{ return _valid; }
|
2010-10-14 14:44:50 +02:00
|
|
|
|
2010-11-24 09:30:46 +01:00
|
|
|
DumpStatus dumpStatus() const
|
|
|
|
{ return _dumpStatus; }
|
|
|
|
|
|
|
|
QString dumpError() const
|
|
|
|
{ return _dumpError; }
|
2010-10-14 14:44:50 +02:00
|
|
|
|
2010-11-24 09:30:46 +01:00
|
|
|
void setDumpStatus(DumpStatus dumped, const QString &error = QString())
|
|
|
|
{ _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;
|
2010-01-26 17:23:18 +01:00
|
|
|
|
2010-01-18 13:13:34 +01:00
|
|
|
public:
|
|
|
|
Snapshot();
|
|
|
|
~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(); }
|
|
|
|
|
2010-01-18 16:15:23 +01:00
|
|
|
void insert(const Document::Ptr &document);
|
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
|
|
|
|
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
|
|
|
|
2010-02-16 10:36:09 +01:00
|
|
|
Document::Ptr documentFromSource(const QString &code,
|
|
|
|
const QString &fileName) const;
|
2010-01-18 13:13:34 +01:00
|
|
|
};
|
|
|
|
|
2010-09-23 15:09:06 +02:00
|
|
|
} // namespace QmlJS
|
|
|
|
|
|
|
|
QT_QML_END_NAMESPACE
|
2010-01-18 13:13:34 +01:00
|
|
|
|
|
|
|
#endif // QMLDOCUMENT_H
|