1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
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 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
36 #include <QtCore/QList>
37 #include <QtCore/QMap>
38 #include <QtCore/QPair>
39 #include <QtCore/QSharedPointer>
40 #include <QtCore/QString>
42 #include <languageutils/fakemetaobject.h>
44 #include "parser/qmldirparser_p.h"
45 #include "parser/qmljsengine_p.h"
46 #include "qmljs_global.h"
48 QT_QML_BEGIN_NAMESPACE
55 class QMLJS_EXPORT Document
58 typedef QSharedPointer<Document> Ptr;
61 Document(const QString &fileName);
66 static Document::Ptr create(const QString &fileName);
68 bool isQmlDocument() const;
69 bool isJSDocument() const;
71 AST::UiProgram *qmlProgram() const;
72 AST::Program *jsProgram() const;
73 AST::ExpressionNode *expression() const;
74 AST::Node *ast() const;
76 const QmlJS::Engine *engine() const;
78 QList<DiagnosticMessage> diagnosticMessages() const;
80 QString source() const;
81 void setSource(const QString &source);
85 bool parseJavaScript();
86 bool parseExpression();
88 bool isParsedCorrectly() const
89 { return _parsedCorrectly; }
93 int editorRevision() const;
94 void setEditorRevision(int revision);
96 QString fileName() const;
98 QString componentName() const;
101 bool parse_helper(int kind);
102 static void extractPragmas(QString *source);
105 QmlJS::Engine *_engine;
111 bool _parsedCorrectly;
112 QList<QmlJS::DiagnosticMessage> _diagnosticMessages;
115 QString _componentName;
118 // for documentFromSource
119 friend class Snapshot;
122 class QMLJS_EXPORT LibraryInfo
126 DumpNotStartedOrRunning,
133 QList<QmlDirParser::Component> _components;
134 QList<QmlDirParser::Plugin> _plugins;
135 typedef QList<LanguageUtils::FakeMetaObject::ConstPtr> FakeMetaObjectList;
136 FakeMetaObjectList _metaObjects;
138 DumpStatus _dumpStatus;
143 LibraryInfo(const QmlDirParser &parser);
146 QList<QmlDirParser::Component> components() const
147 { return _components; }
149 QList<QmlDirParser::Plugin> plugins() const
152 FakeMetaObjectList metaObjects() const
153 { return _metaObjects; }
155 void setMetaObjects(const FakeMetaObjectList &objects)
156 { _metaObjects = objects; }
161 DumpStatus dumpStatus() const
162 { return _dumpStatus; }
164 QString dumpError() const
165 { return _dumpError; }
167 void setDumpStatus(DumpStatus dumped, const QString &error = QString())
168 { _dumpStatus = dumped; _dumpError = error; }
171 class QMLJS_EXPORT Snapshot
173 typedef QHash<QString, Document::Ptr> _Base;
174 QHash<QString, Document::Ptr> _documents;
175 QHash<QString, QList<Document::Ptr> > _documentsByPath;
176 QHash<QString, LibraryInfo> _libraries;
182 typedef _Base::iterator iterator;
183 typedef _Base::const_iterator const_iterator;
185 const_iterator begin() const { return _documents.begin(); }
186 const_iterator end() const { return _documents.end(); }
188 void insert(const Document::Ptr &document);
189 void insertLibraryInfo(const QString &path, const LibraryInfo &info);
190 void remove(const QString &fileName);
192 Document::Ptr document(const QString &fileName) const;
193 QList<Document::Ptr> documentsInDirectory(const QString &path) const;
194 LibraryInfo libraryInfo(const QString &path) const;
196 Document::Ptr documentFromSource(const QString &code,
197 const QString &fileName) const;
204 #endif // QMLDOCUMENT_H