1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at info@qt.nokia.com.
31 **************************************************************************/
35 #include <QtCore/QList>
36 #include <QtCore/QMap>
37 #include <QtCore/QPair>
38 #include <QtCore/QSharedPointer>
39 #include <QtCore/QString>
41 #include <languageutils/fakemetaobject.h>
43 #include "parser/qmldirparser_p.h"
44 #include "parser/qmljsengine_p.h"
45 #include "qmljs_global.h"
47 QT_QML_BEGIN_NAMESPACE
54 class QMLJS_EXPORT Document
57 typedef QSharedPointer<Document> Ptr;
60 Document(const QString &fileName);
65 static Document::Ptr create(const QString &fileName);
67 Document::Ptr ptr() const;
69 bool isQmlDocument() const;
70 bool isJSDocument() const;
72 AST::UiProgram *qmlProgram() const;
73 AST::Program *jsProgram() const;
74 AST::ExpressionNode *expression() const;
75 AST::Node *ast() const;
77 const QmlJS::Engine *engine() const;
79 QList<DiagnosticMessage> diagnosticMessages() const;
81 QString source() const;
82 void setSource(const QString &source);
86 bool parseJavaScript();
87 bool parseExpression();
89 bool isParsedCorrectly() const
90 { return _parsedCorrectly; }
94 int editorRevision() const;
95 void setEditorRevision(int revision);
97 QString fileName() const;
99 QString componentName() const;
102 bool parse_helper(int kind);
103 static void extractPragmas(QString *source);
106 QmlJS::Engine *_engine;
112 bool _parsedCorrectly;
113 QList<QmlJS::DiagnosticMessage> _diagnosticMessages;
116 QString _componentName;
118 QWeakPointer<Document> _ptr;
120 // for documentFromSource
121 friend class Snapshot;
124 class QMLJS_EXPORT LibraryInfo
127 enum PluginTypeInfoStatus {
137 QList<QmlDirParser::Component> _components;
138 QList<QmlDirParser::Plugin> _plugins;
139 typedef QList<LanguageUtils::FakeMetaObject::ConstPtr> FakeMetaObjectList;
140 FakeMetaObjectList _metaObjects;
142 PluginTypeInfoStatus _dumpStatus;
147 LibraryInfo(const QmlDirParser &parser);
150 QList<QmlDirParser::Component> components() const
151 { return _components; }
153 QList<QmlDirParser::Plugin> plugins() const
156 FakeMetaObjectList metaObjects() const
157 { return _metaObjects; }
159 void setMetaObjects(const FakeMetaObjectList &objects)
160 { _metaObjects = objects; }
165 PluginTypeInfoStatus pluginTypeInfoStatus() const
166 { return _dumpStatus; }
168 QString pluginTypeInfoError() const
169 { return _dumpError; }
171 void setPluginTypeInfoStatus(PluginTypeInfoStatus dumped, const QString &error = QString())
172 { _dumpStatus = dumped; _dumpError = error; }
175 class QMLJS_EXPORT Snapshot
177 typedef QHash<QString, Document::Ptr> _Base;
178 QHash<QString, Document::Ptr> _documents;
179 QHash<QString, QList<Document::Ptr> > _documentsByPath;
180 QHash<QString, LibraryInfo> _libraries;
186 typedef _Base::iterator iterator;
187 typedef _Base::const_iterator const_iterator;
189 const_iterator begin() const { return _documents.begin(); }
190 const_iterator end() const { return _documents.end(); }
192 void insert(const Document::Ptr &document);
193 void insertLibraryInfo(const QString &path, const LibraryInfo &info);
194 void remove(const QString &fileName);
196 Document::Ptr document(const QString &fileName) const;
197 QList<Document::Ptr> documentsInDirectory(const QString &path) const;
198 LibraryInfo libraryInfo(const QString &path) const;
200 Document::Ptr documentFromSource(const QString &code,
201 const QString &fileName) const;
208 #endif // QMLDOCUMENT_H