1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** Licensees holding valid Qt Commercial licenses may use this file in
12 ** accordance with the Qt Commercial License Agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Nokia.
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** If you are unsure which license is appropriate for your use, please
26 ** contact the sales department at http://qt.nokia.com/contact.
28 **************************************************************************/
32 #include <QtCore/QList>
33 #include <QtCore/QMap>
34 #include <QtCore/QPair>
35 #include <QtCore/QSharedPointer>
36 #include <QtCore/QString>
38 #include "parser/qmldirparser_p.h"
39 #include "parser/qmljsengine_p.h"
40 #include "qmljs_global.h"
42 QT_QML_BEGIN_NAMESPACE
49 namespace Interpreter {
53 class QMLJS_EXPORT Document
56 typedef QSharedPointer<Document> Ptr;
59 Document(const QString &fileName);
64 static Document::Ptr create(const QString &fileName);
66 bool isQmlDocument() const;
67 bool isJSDocument() const;
69 AST::UiProgram *qmlProgram() const;
70 AST::Program *jsProgram() const;
71 AST::ExpressionNode *expression() const;
72 AST::Node *ast() const;
74 QList<DiagnosticMessage> diagnosticMessages() const;
76 QString source() const;
77 void setSource(const QString &source);
81 bool parseJavaScript();
82 bool parseExpression();
84 bool isParsedCorrectly() const
85 { return _parsedCorrectly; }
89 int editorRevision() const;
90 void setEditorRevision(int revision);
92 QString fileName() const;
94 QString componentName() const;
97 bool parse_helper(int kind);
98 static void extractPragmas(QString *source);
101 QmlJS::Engine *_engine;
107 bool _parsedCorrectly;
108 QList<QmlJS::DiagnosticMessage> _diagnosticMessages;
111 QString _componentName;
114 // for documentFromSource
115 friend class Snapshot;
118 class QMLJS_EXPORT LibraryInfo
121 QList<QmlDirParser::Component> _components;
122 QList<QmlDirParser::Plugin> _plugins;
123 typedef QList<const Interpreter::FakeMetaObject *> FakeMetaObjectList;
124 FakeMetaObjectList _metaObjects;
128 LibraryInfo(const QmlDirParser &parser);
131 QList<QmlDirParser::Component> components() const
132 { return _components; }
134 QList<QmlDirParser::Plugin> plugins() const
137 FakeMetaObjectList metaObjects() const
138 { return _metaObjects; }
140 void setMetaObjects(const FakeMetaObjectList &objects)
141 { _metaObjects = objects; }
147 class QMLJS_EXPORT Snapshot
149 typedef QHash<QString, Document::Ptr> _Base;
150 QHash<QString, Document::Ptr> _documents;
151 QHash<QString, QList<Document::Ptr> > _documentsByPath;
152 QHash<QString, LibraryInfo> _libraries;
158 typedef _Base::iterator iterator;
159 typedef _Base::const_iterator const_iterator;
161 const_iterator begin() const { return _documents.begin(); }
162 const_iterator end() const { return _documents.end(); }
164 void insert(const Document::Ptr &document);
165 void insertLibraryInfo(const QString &path, const LibraryInfo &info);
166 void remove(const QString &fileName);
168 Document::Ptr document(const QString &fileName) const;
169 QList<Document::Ptr> documentsInDirectory(const QString &path) const;
170 LibraryInfo libraryInfo(const QString &path) const;
172 Document::Ptr documentFromSource(const QString &code,
173 const QString &fileName) const;
180 #endif // QMLDOCUMENT_H