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"
47 namespace Interpreter {
51 class QMLJS_EXPORT Document
54 typedef QSharedPointer<Document> Ptr;
57 Document(const QString &fileName);
62 static Document::Ptr create(const QString &fileName);
64 bool isQmlDocument() const;
65 bool isJSDocument() const;
67 AST::UiProgram *qmlProgram() const;
68 AST::Program *jsProgram() const;
69 AST::ExpressionNode *expression() const;
70 AST::Node *ast() const;
72 QList<DiagnosticMessage> diagnosticMessages() const;
74 QString source() const;
75 void setSource(const QString &source);
79 bool parseJavaScript();
80 bool parseExpression();
82 bool isParsedCorrectly() const
83 { return _parsedCorrectly; }
87 int documentRevision() const;
88 void setDocumentRevision(int documentRevision);
90 QString fileName() const;
92 QString componentName() const;
95 bool parse_helper(int kind);
98 QmlJS::Engine *_engine;
103 int _documentRevision;
104 bool _parsedCorrectly;
105 QList<QmlJS::DiagnosticMessage> _diagnosticMessages;
108 QString _componentName;
111 // for documentFromSource
112 friend class Snapshot;
115 class QMLJS_EXPORT LibraryInfo
118 QList<QmlDirParser::Component> _components;
119 QList<QmlDirParser::Plugin> _plugins;
120 typedef QList<const Interpreter::FakeMetaObject *> FakeMetaObjectList;
121 FakeMetaObjectList _metaObjects;
125 LibraryInfo(const QmlDirParser &parser);
128 QList<QmlDirParser::Component> components() const
129 { return _components; }
131 QList<QmlDirParser::Plugin> plugins() const
134 FakeMetaObjectList metaObjects() const
135 { return _metaObjects; }
137 void setMetaObjects(const FakeMetaObjectList &objects)
138 { _metaObjects = objects; }
144 class QMLJS_EXPORT Snapshot
146 typedef QHash<QString, Document::Ptr> _Base;
147 QHash<QString, Document::Ptr> _documents;
148 QMultiHash<QString, Document::Ptr> _documentsByPath;
149 QHash<QString, LibraryInfo> _libraries;
155 typedef _Base::iterator iterator;
156 typedef _Base::const_iterator const_iterator;
158 const_iterator begin() const { return _documents.begin(); }
159 const_iterator end() const { return _documents.end(); }
161 void insert(const Document::Ptr &document);
162 void insertLibraryInfo(const QString &path, const LibraryInfo &info);
163 void remove(const QString &fileName);
165 Document::Ptr document(const QString &fileName) const;
166 QList<Document::Ptr> documentsInDirectory(const QString &path) const;
167 LibraryInfo libraryInfo(const QString &path) const;
169 Document::Ptr documentFromSource(const QString &code,
170 const QString &fileName) const;
172 QList<Document::Ptr> importedDocuments(const Document::Ptr &doc, const QString &importPath) const;
173 QMap<QString, Document::Ptr> componentsDefinedByImportedDocuments(const Document::Ptr &doc, const QString &importPath) const;
176 } // end of namespace Qml
178 #endif // QMLDOCUMENT_H