OSDN Git Service

Merge remote-tracking branch 'origin/2.2'
[qt-creator-jp/qt-creator-jp.git] / src / libs / qmljs / qmljsdocument.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
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.
18 **
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.
22 **
23 ** Other Usage
24 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at info@qt.nokia.com.
30 **
31 **************************************************************************/
32 #ifndef QMLDOCUMENT_H
33 #define QMLDOCUMENT_H
34
35 #include <QtCore/QList>
36 #include <QtCore/QMap>
37 #include <QtCore/QPair>
38 #include <QtCore/QSharedPointer>
39 #include <QtCore/QString>
40
41 #include <languageutils/fakemetaobject.h>
42
43 #include "parser/qmldirparser_p.h"
44 #include "parser/qmljsengine_p.h"
45 #include "qmljs_global.h"
46
47 QT_QML_BEGIN_NAMESPACE
48
49 namespace QmlJS {
50
51 class Bind;
52 class Snapshot;
53
54 class QMLJS_EXPORT Document
55 {
56 public:
57     typedef QSharedPointer<Document> Ptr;
58
59 protected:
60     Document(const QString &fileName);
61
62 public:
63     ~Document();
64
65     static Document::Ptr create(const QString &fileName);
66
67     Document::Ptr ptr() const;
68
69     bool isQmlDocument() const;
70     bool isJSDocument() const;
71
72     AST::UiProgram *qmlProgram() const;
73     AST::Program *jsProgram() const;
74     AST::ExpressionNode *expression() const;
75     AST::Node *ast() const;
76
77     const QmlJS::Engine *engine() const;
78
79     QList<DiagnosticMessage> diagnosticMessages() const;
80
81     QString source() const;
82     void setSource(const QString &source);
83
84     bool parse();
85     bool parseQml();
86     bool parseJavaScript();
87     bool parseExpression();
88
89     bool isParsedCorrectly() const
90     { return _parsedCorrectly; }
91
92     Bind *bind() const;
93
94     int editorRevision() const;
95     void setEditorRevision(int revision);
96
97     QString fileName() const;
98     QString path() const;
99     QString componentName() const;
100
101 private:
102     bool parse_helper(int kind);
103     static void extractPragmas(QString *source);
104
105 private:
106     QmlJS::Engine *_engine;
107     NodePool *_pool;
108     AST::Node *_ast;
109     Bind *_bind;
110     bool _isQmlDocument;
111     int _editorRevision;
112     bool _parsedCorrectly;
113     QList<QmlJS::DiagnosticMessage> _diagnosticMessages;
114     QString _fileName;
115     QString _path;
116     QString _componentName;
117     QString _source;
118     QWeakPointer<Document> _ptr;
119
120     // for documentFromSource
121     friend class Snapshot;
122 };
123
124 class QMLJS_EXPORT LibraryInfo
125 {
126 public:
127     enum PluginTypeInfoStatus {
128         NoTypeInfo,
129         DumpDone,
130         DumpError,
131         TypeInfoFileDone,
132         TypeInfoFileError
133     };
134
135 private:
136     bool _valid;
137     QList<QmlDirParser::Component> _components;
138     QList<QmlDirParser::Plugin> _plugins;
139     typedef QList<LanguageUtils::FakeMetaObject::ConstPtr> FakeMetaObjectList;
140     FakeMetaObjectList _metaObjects;
141
142     PluginTypeInfoStatus _dumpStatus;
143     QString _dumpError;
144
145 public:
146     LibraryInfo();
147     LibraryInfo(const QmlDirParser &parser);
148     ~LibraryInfo();
149
150     QList<QmlDirParser::Component> components() const
151     { return _components; }
152
153     QList<QmlDirParser::Plugin> plugins() const
154     { return _plugins; }
155
156     FakeMetaObjectList metaObjects() const
157     { return _metaObjects; }
158
159     void setMetaObjects(const FakeMetaObjectList &objects)
160     { _metaObjects = objects; }
161
162     bool isValid() const
163     { return _valid; }
164
165     PluginTypeInfoStatus pluginTypeInfoStatus() const
166     { return _dumpStatus; }
167
168     QString pluginTypeInfoError() const
169     { return _dumpError; }
170
171     void setPluginTypeInfoStatus(PluginTypeInfoStatus dumped, const QString &error = QString())
172     { _dumpStatus = dumped; _dumpError = error; }
173 };
174
175 class QMLJS_EXPORT Snapshot
176 {
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;
181
182 public:
183     Snapshot();
184     ~Snapshot();
185
186     typedef _Base::iterator iterator;
187     typedef _Base::const_iterator const_iterator;
188
189     const_iterator begin() const { return _documents.begin(); }
190     const_iterator end() const { return _documents.end(); }
191
192     void insert(const Document::Ptr &document);
193     void insertLibraryInfo(const QString &path, const LibraryInfo &info);
194     void remove(const QString &fileName);
195
196     Document::Ptr document(const QString &fileName) const;
197     QList<Document::Ptr> documentsInDirectory(const QString &path) const;
198     LibraryInfo libraryInfo(const QString &path) const;
199
200     Document::Ptr documentFromSource(const QString &code,
201                                      const QString &fileName) const;
202 };
203
204 } // namespace QmlJS
205
206 QT_QML_END_NAMESPACE
207
208 #endif // QMLDOCUMENT_H