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/QPair>
37 #include <QtCore/QSharedPointer>
38 #include <QtCore/QString>
40 #include <languageutils/fakemetaobject.h>
42 #include "parser/qmldirparser_p.h"
43 #include "parser/qmljsengine_p.h"
44 #include "qmljs_global.h"
46 QT_QML_BEGIN_NAMESPACE
53 class QMLJS_EXPORT Document
56 typedef QSharedPointer<Document> Ptr;
58 // used in a 3-bit bitfield
62 JavaScriptLanguage = 1,
68 Document(const QString &fileName, Language language);
73 static Document::Ptr create(const QString &fileName, Language language);
75 Document::Ptr ptr() const;
77 bool isQmlDocument() const;
78 Language language() const;
80 AST::UiProgram *qmlProgram() const;
81 AST::Program *jsProgram() const;
82 AST::ExpressionNode *expression() const;
83 AST::Node *ast() const;
85 const QmlJS::Engine *engine() const;
87 QList<DiagnosticMessage> diagnosticMessages() const;
89 QString source() const;
90 void setSource(const QString &source);
94 bool parseJavaScript();
95 bool parseExpression();
97 bool isParsedCorrectly() const
98 { return _parsedCorrectly; }
102 int editorRevision() const;
103 void setEditorRevision(int revision);
105 QString fileName() const;
106 QString path() const;
107 QString componentName() const;
110 bool parse_helper(int kind);
113 QmlJS::Engine *_engine;
116 QList<QmlJS::DiagnosticMessage> _diagnosticMessages;
119 QString _componentName;
121 QWeakPointer<Document> _ptr;
123 Language _language : 3;
124 bool _parsedCorrectly : 1;
126 // for documentFromSource
127 friend class Snapshot;
130 class QMLJS_EXPORT LibraryInfo
133 enum PluginTypeInfoStatus {
149 QList<QmlDirParser::Component> _components;
150 QList<QmlDirParser::Plugin> _plugins;
151 QList<QmlDirParser::TypeInfo> _typeinfos;
152 typedef QList<LanguageUtils::FakeMetaObject::ConstPtr> FakeMetaObjectList;
153 FakeMetaObjectList _metaObjects;
155 PluginTypeInfoStatus _dumpStatus;
159 explicit LibraryInfo(Status status = NotScanned);
160 explicit LibraryInfo(const QmlDirParser &parser);
163 QList<QmlDirParser::Component> components() const
164 { return _components; }
166 QList<QmlDirParser::Plugin> plugins() const
169 QList<QmlDirParser::TypeInfo> typeInfos() const
170 { return _typeinfos; }
172 FakeMetaObjectList metaObjects() const
173 { return _metaObjects; }
175 void setMetaObjects(const FakeMetaObjectList &objects)
176 { _metaObjects = objects; }
179 { return _status == Found; }
181 bool wasScanned() const
182 { return _status != NotScanned; }
184 PluginTypeInfoStatus pluginTypeInfoStatus() const
185 { return _dumpStatus; }
187 QString pluginTypeInfoError() const
188 { return _dumpError; }
190 void setPluginTypeInfoStatus(PluginTypeInfoStatus dumped, const QString &error = QString())
191 { _dumpStatus = dumped; _dumpError = error; }
194 class QMLJS_EXPORT Snapshot
196 typedef QHash<QString, Document::Ptr> _Base;
197 QHash<QString, Document::Ptr> _documents;
198 QHash<QString, QList<Document::Ptr> > _documentsByPath;
199 QHash<QString, LibraryInfo> _libraries;
205 typedef _Base::iterator iterator;
206 typedef _Base::const_iterator const_iterator;
208 const_iterator begin() const { return _documents.begin(); }
209 const_iterator end() const { return _documents.end(); }
211 void insert(const Document::Ptr &document, bool allowInvalid = false);
212 void insertLibraryInfo(const QString &path, const LibraryInfo &info);
213 void remove(const QString &fileName);
215 Document::Ptr document(const QString &fileName) const;
216 QList<Document::Ptr> documentsInDirectory(const QString &path) const;
217 LibraryInfo libraryInfo(const QString &path) const;
219 Document::Ptr documentFromSource(const QString &code,
220 const QString &fileName,
221 Document::Language language) const;
228 #endif // QMLDOCUMENT_H