| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  | /**************************************************************************
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** This file is part of Qt Creator | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2010-03-05 11:25:49 +01:00
										 |  |  | ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  | ** | 
					
						
							|  |  |  | ** Contact: Nokia Corporation (qt-info@nokia.com) | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Commercial Usage | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Licensees holding valid Qt Commercial licenses may use this file in | 
					
						
							|  |  |  | ** accordance with the Qt Commercial License Agreement provided with the | 
					
						
							|  |  |  | ** Software or, alternatively, in accordance with the terms contained in | 
					
						
							|  |  |  | ** a written agreement between you and Nokia. | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** GNU Lesser General Public License Usage | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
					
						
							|  |  |  | ** General Public License version 2.1 as published by the Free Software | 
					
						
							|  |  |  | ** Foundation and appearing in the file LICENSE.LGPL included in the | 
					
						
							|  |  |  | ** packaging of this file.  Please review the following information to | 
					
						
							|  |  |  | ** ensure the GNU Lesser General Public License version 2.1 requirements | 
					
						
							|  |  |  | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | ** If you are unsure which license is appropriate for your use, please | 
					
						
							|  |  |  | ** contact the sales department at http://qt.nokia.com/contact.
 | 
					
						
							|  |  |  | ** | 
					
						
							|  |  |  | **************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-18 16:15:23 +01:00
										 |  |  | #include "qmljsdocument.h"
 | 
					
						
							| 
									
										
										
										
											2010-02-02 15:55:17 +01:00
										 |  |  | #include "qmljsbind.h"
 | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  | #include <qmljs/parser/qmljsast_p.h>
 | 
					
						
							|  |  |  | #include <qmljs/parser/qmljslexer_p.h>
 | 
					
						
							|  |  |  | #include <qmljs/parser/qmljsparser_p.h>
 | 
					
						
							|  |  |  | #include <qmljs/parser/qmljsnodepool_p.h>
 | 
					
						
							|  |  |  | #include <qmljs/parser/qmljsastfwd_p.h>
 | 
					
						
							| 
									
										
										
										
											2010-01-26 17:23:18 +01:00
										 |  |  | #include <QtCore/QDir>
 | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | using namespace QmlJS; | 
					
						
							|  |  |  | using namespace QmlJS::AST; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-18 16:15:23 +01:00
										 |  |  | Document::Document(const QString &fileName) | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  |     : _engine(0) | 
					
						
							|  |  |  |     , _pool(0) | 
					
						
							| 
									
										
										
										
											2010-01-22 10:26:25 +01:00
										 |  |  |     , _ast(0) | 
					
						
							| 
									
										
										
										
											2010-02-03 15:59:15 +01:00
										 |  |  |     , _bind(0) | 
					
						
							| 
									
										
										
										
											2010-03-29 12:56:25 +02:00
										 |  |  |     , _isQmlDocument(false) | 
					
						
							| 
									
										
										
										
											2010-07-07 17:52:02 +02:00
										 |  |  |     , _editorRevision(0) | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  |     , _parsedCorrectly(false) | 
					
						
							| 
									
										
										
										
											2010-04-01 14:42:39 +02:00
										 |  |  |     , _fileName(QDir::cleanPath(fileName)) | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-01-26 17:23:18 +01:00
										 |  |  |     QFileInfo fileInfo(fileName); | 
					
						
							| 
									
										
										
										
											2010-04-01 14:42:39 +02:00
										 |  |  |     _path = QDir::cleanPath(fileInfo.absolutePath()); | 
					
						
							| 
									
										
										
										
											2010-01-27 09:24:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-31 13:42:42 +02:00
										 |  |  |     // ### Should use mime type
 | 
					
						
							|  |  |  |     if (fileInfo.suffix() == QLatin1String("qml") | 
					
						
							|  |  |  |             || fileInfo.suffix() == QLatin1String("qmlproject")) { | 
					
						
							| 
									
										
										
										
											2010-03-29 12:56:25 +02:00
										 |  |  |         _isQmlDocument = true; | 
					
						
							| 
									
										
										
										
											2010-01-27 09:24:49 +01:00
										 |  |  |         _componentName = fileInfo.baseName(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (! _componentName.isEmpty()) { | 
					
						
							|  |  |  |             // ### TODO: check the component name.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (! _componentName.at(0).isUpper()) | 
					
						
							|  |  |  |                 _componentName.clear(); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-01-26 17:23:18 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-18 16:15:23 +01:00
										 |  |  | Document::~Document() | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-02-03 15:59:15 +01:00
										 |  |  |     if (_bind) | 
					
						
							|  |  |  |         delete _bind; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  |     if (_engine) | 
					
						
							|  |  |  |         delete _engine; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (_pool) | 
					
						
							|  |  |  |         delete _pool; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-18 16:15:23 +01:00
										 |  |  | Document::Ptr Document::create(const QString &fileName) | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-01-18 16:15:23 +01:00
										 |  |  |     Document::Ptr doc(new Document(fileName)); | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  |     return doc; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-29 12:56:25 +02:00
										 |  |  | bool Document::isQmlDocument() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return _isQmlDocument; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool Document::isJSDocument() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return ! _isQmlDocument; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-18 16:15:23 +01:00
										 |  |  | AST::UiProgram *Document::qmlProgram() const | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-01-22 10:26:25 +01:00
										 |  |  |     return cast<UiProgram *>(_ast); | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-18 16:15:23 +01:00
										 |  |  | AST::Program *Document::jsProgram() const | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-01-22 10:26:25 +01:00
										 |  |  |     return cast<Program *>(_ast); | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-26 14:53:11 +01:00
										 |  |  | AST::ExpressionNode *Document::expression() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (_ast) | 
					
						
							|  |  |  |         return _ast->expressionCast(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-19 10:16:57 +01:00
										 |  |  | AST::Node *Document::ast() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-01-22 10:26:25 +01:00
										 |  |  |     return _ast; | 
					
						
							| 
									
										
										
										
											2010-01-19 10:16:57 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-18 16:15:23 +01:00
										 |  |  | QList<DiagnosticMessage> Document::diagnosticMessages() const | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     return _diagnosticMessages; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-18 16:15:23 +01:00
										 |  |  | QString Document::source() const | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     return _source; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-18 16:15:23 +01:00
										 |  |  | void Document::setSource(const QString &source) | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     _source = source; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-07 17:52:02 +02:00
										 |  |  | int Document::editorRevision() const | 
					
						
							| 
									
										
										
										
											2010-01-25 14:18:53 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-07-07 17:52:02 +02:00
										 |  |  |     return _editorRevision; | 
					
						
							| 
									
										
										
										
											2010-01-25 14:18:53 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-07 17:52:02 +02:00
										 |  |  | void Document::setEditorRevision(int revision) | 
					
						
							| 
									
										
										
										
											2010-01-25 14:18:53 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-07-07 17:52:02 +02:00
										 |  |  |     _editorRevision = revision; | 
					
						
							| 
									
										
										
										
											2010-01-25 14:18:53 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-11 10:19:41 +01:00
										 |  |  | QString Document::fileName() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return _fileName; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString Document::path() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return _path; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString Document::componentName() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return _componentName; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-08 21:37:59 +01:00
										 |  |  | bool Document::parse_helper(int startToken) | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     Q_ASSERT(! _engine); | 
					
						
							|  |  |  |     Q_ASSERT(! _pool); | 
					
						
							| 
									
										
										
										
											2010-01-22 10:26:25 +01:00
										 |  |  |     Q_ASSERT(! _ast); | 
					
						
							| 
									
										
										
										
											2010-02-03 15:59:15 +01:00
										 |  |  |     Q_ASSERT(! _bind); | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     _engine = new Engine(); | 
					
						
							|  |  |  |     _pool = new NodePool(_fileName, _engine); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Lexer lexer(_engine); | 
					
						
							|  |  |  |     Parser parser(_engine); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-15 14:50:16 +02:00
										 |  |  |     QString source = _source; | 
					
						
							|  |  |  |     if (startToken == QmlJSGrammar::T_FEED_JS_PROGRAM) | 
					
						
							|  |  |  |         extractPragmas(&source); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     lexer.setCode(source, /*line = */ 1); | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-08 21:37:59 +01:00
										 |  |  |     switch (startToken) { | 
					
						
							|  |  |  |     case QmlJSGrammar::T_FEED_UI_PROGRAM: | 
					
						
							|  |  |  |         _parsedCorrectly = parser.parse(); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case QmlJSGrammar::T_FEED_JS_PROGRAM: | 
					
						
							|  |  |  |         _parsedCorrectly = parser.parseProgram(); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     case QmlJSGrammar::T_FEED_JS_EXPRESSION: | 
					
						
							|  |  |  |         _parsedCorrectly = parser.parseExpression(); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |         Q_ASSERT(0); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     _ast = parser.rootNode(); | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  |     _diagnosticMessages = parser.diagnosticMessages(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-03 15:59:15 +01:00
										 |  |  |     _bind = new Bind(this); | 
					
						
							| 
									
										
										
										
											2010-02-02 15:55:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  |     return _parsedCorrectly; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-29 12:56:25 +02:00
										 |  |  | bool Document::parse() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (isQmlDocument()) | 
					
						
							|  |  |  |         return parseQml(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return parseJavaScript(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-08 21:37:59 +01:00
										 |  |  | bool Document::parseQml() | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-02-08 21:37:59 +01:00
										 |  |  |     return parse_helper(QmlJSGrammar::T_FEED_UI_PROGRAM); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-02-02 15:55:17 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-08 21:37:59 +01:00
										 |  |  | bool Document::parseJavaScript() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return parse_helper(QmlJSGrammar::T_FEED_JS_PROGRAM); | 
					
						
							| 
									
										
										
										
											2010-01-22 10:26:25 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool Document::parseExpression() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-02-08 21:37:59 +01:00
										 |  |  |     return parse_helper(QmlJSGrammar::T_FEED_JS_EXPRESSION); | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-03 15:59:15 +01:00
										 |  |  | Bind *Document::bind() const | 
					
						
							| 
									
										
										
										
											2010-02-02 15:55:17 +01:00
										 |  |  | { | 
					
						
							|  |  |  |     return _bind; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-06-15 14:50:16 +02:00
										 |  |  | // this is essentially a copy of QDeclarativeScriptParser::extractPragmas
 | 
					
						
							|  |  |  | void Document::extractPragmas(QString *source) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const QChar forwardSlash(QLatin1Char('/')); | 
					
						
							|  |  |  |     const QChar star(QLatin1Char('*')); | 
					
						
							|  |  |  |     const QChar newline(QLatin1Char('\n')); | 
					
						
							|  |  |  |     const QChar dot(QLatin1Char('.')); | 
					
						
							|  |  |  |     const QChar semicolon(QLatin1Char(';')); | 
					
						
							|  |  |  |     const QChar space(QLatin1Char(' ')); | 
					
						
							|  |  |  |     const QString pragma(QLatin1String(".pragma ")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const QChar *pragmaData = pragma.constData(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QString &script = *source; | 
					
						
							|  |  |  |     const QChar *data = script.constData(); | 
					
						
							|  |  |  |     const int length = script.count(); | 
					
						
							|  |  |  |     for (int ii = 0; ii < length; ++ii) { | 
					
						
							|  |  |  |         const QChar &c = data[ii]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (c.isSpace()) | 
					
						
							|  |  |  |             continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (c == forwardSlash) { | 
					
						
							|  |  |  |             ++ii; | 
					
						
							|  |  |  |             if (ii >= length) | 
					
						
							|  |  |  |                 return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             const QChar &c = data[ii]; | 
					
						
							|  |  |  |             if (c == forwardSlash) { | 
					
						
							|  |  |  |                 // Find next newline
 | 
					
						
							|  |  |  |                 while (ii < length && data[++ii] != newline) {}; | 
					
						
							|  |  |  |             } else if (c == star) { | 
					
						
							|  |  |  |                 // Find next star
 | 
					
						
							|  |  |  |                 while (true) { | 
					
						
							|  |  |  |                     while (ii < length && data[++ii] != star) {}; | 
					
						
							|  |  |  |                     if (ii + 1 >= length) | 
					
						
							|  |  |  |                         return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     if (data[ii + 1] == forwardSlash) { | 
					
						
							|  |  |  |                         ++ii; | 
					
						
							|  |  |  |                         break; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 return; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } else if (c == dot) { | 
					
						
							|  |  |  |             // Could be a pragma!
 | 
					
						
							|  |  |  |             if (ii + pragma.length() >= length || | 
					
						
							|  |  |  |                 0 != ::memcmp(data + ii, pragmaData, sizeof(QChar) * pragma.length())) | 
					
						
							|  |  |  |                 return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             int pragmaStatementIdx = ii; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             ii += pragma.length(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             while (ii < length && data[ii].isSpace()) { ++ii; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             int startIdx = ii; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             while (ii < length && data[ii].isLetter()) { ++ii; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             int endIdx = ii; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (ii != length && data[ii] != forwardSlash && !data[ii].isSpace() && data[ii] != semicolon) | 
					
						
							|  |  |  |                 return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             QString p(data + startIdx, endIdx - startIdx); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (p != QLatin1String("library")) | 
					
						
							|  |  |  |                 return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             for (int jj = pragmaStatementIdx; jj < endIdx; ++jj) script[jj] = space; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-18 15:43:33 +01:00
										 |  |  | LibraryInfo::LibraryInfo() | 
					
						
							|  |  |  |     : _valid(false) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | LibraryInfo::LibraryInfo(const QmlDirParser &parser) | 
					
						
							|  |  |  |     : _valid(true) | 
					
						
							|  |  |  |     , _components(parser.components()) | 
					
						
							|  |  |  |     , _plugins(parser.plugins()) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | LibraryInfo::~LibraryInfo() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  | Snapshot::Snapshot() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Snapshot::~Snapshot() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-18 16:15:23 +01:00
										 |  |  | void Snapshot::insert(const Document::Ptr &document) | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-04-01 11:27:49 +02:00
										 |  |  |     if (document && (document->qmlProgram() || document->jsProgram())) { | 
					
						
							| 
									
										
										
										
											2010-05-17 12:01:54 +02:00
										 |  |  |         const QString fileName = document->fileName(); | 
					
						
							|  |  |  |         const QString path = document->path(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-18 13:40:35 +02:00
										 |  |  |         remove(fileName); | 
					
						
							| 
									
										
										
										
											2010-05-17 12:01:54 +02:00
										 |  |  |         _documentsByPath.insert(path, document); | 
					
						
							|  |  |  |         _documents.insert(fileName, document); | 
					
						
							| 
									
										
										
										
											2010-04-01 11:27:49 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-01-18 13:13:34 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-03-18 15:43:33 +01:00
										 |  |  | void Snapshot::insertLibraryInfo(const QString &path, const LibraryInfo &info) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-04-01 14:42:39 +02:00
										 |  |  |     _libraries.insert(QDir::cleanPath(path), info); | 
					
						
							| 
									
										
										
										
											2010-03-18 15:43:33 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-18 13:40:35 +02:00
										 |  |  | void Snapshot::remove(const QString &fileName) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Document::Ptr doc = _documents.value(fileName); | 
					
						
							|  |  |  |     if (!doc.isNull()) { | 
					
						
							|  |  |  |         _documentsByPath.remove(doc->path(), doc); | 
					
						
							|  |  |  |         _documents.remove(fileName); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-16 10:36:09 +01:00
										 |  |  | Document::Ptr Snapshot::documentFromSource(const QString &code, | 
					
						
							|  |  |  |                                            const QString &fileName) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Document::Ptr newDoc = Document::create(fileName); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (Document::Ptr thisDocument = document(fileName)) { | 
					
						
							| 
									
										
										
										
											2010-07-07 17:52:02 +02:00
										 |  |  |         newDoc->_editorRevision = thisDocument->_editorRevision; | 
					
						
							| 
									
										
										
										
											2010-02-16 10:36:09 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     newDoc->setSource(code); | 
					
						
							|  |  |  |     return newDoc; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-01 14:42:39 +02:00
										 |  |  | Document::Ptr Snapshot::document(const QString &fileName) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return _documents.value(QDir::cleanPath(fileName)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QList<Document::Ptr> Snapshot::documentsInDirectory(const QString &path) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return _documentsByPath.values(QDir::cleanPath(path)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | LibraryInfo Snapshot::libraryInfo(const QString &path) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return _libraries.value(QDir::cleanPath(path)); | 
					
						
							|  |  |  | } |