diff options
author | Christian Kamm <christian.d.kamm@nokia.com> | 2011-09-13 08:42:52 +0200 |
---|---|---|
committer | Christian Kamm <christian.d.kamm@nokia.com> | 2011-09-14 11:48:11 +0200 |
commit | b5312090028a338ac3f945f8692cadde7eb2172b (patch) | |
tree | d5bc33e28336f9d3f340a49d7536ba7baee0cb20 /src/libs/qmljs/parser/qmldirparser.cpp | |
parent | c0c9312495cab51c753298c02d1f6d57d1daed9e (diff) | |
download | qt-creator-b5312090028a338ac3f945f8692cadde7eb2172b.tar.gz |
QmlJS: Merge parser updates from Qt5.
Change-Id: Ibed38abca8f7e7bae7d424751a18c83f4c9e9bc5
Reviewed-on: http://codereview.qt-project.org/4732
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
Diffstat (limited to 'src/libs/qmljs/parser/qmldirparser.cpp')
-rw-r--r-- | src/libs/qmljs/parser/qmldirparser.cpp | 53 |
1 files changed, 45 insertions, 8 deletions
diff --git a/src/libs/qmljs/parser/qmldirparser.cpp b/src/libs/qmljs/parser/qmldirparser.cpp index 5bb1061739..3914ebc1b3 100644 --- a/src/libs/qmljs/parser/qmldirparser.cpp +++ b/src/libs/qmljs/parser/qmldirparser.cpp @@ -32,8 +32,11 @@ #include "qmldirparser_p.h" #include "qmlerror.h" +bool Qml_isFileCaseCorrect(const QString &) { return true; } +#include <qmlutils_p.h> #include <QtCore/QTextStream> +#include <QtCore/QFile> #include <QtCore/QtDebug> QT_BEGIN_NAMESPACE @@ -57,6 +60,16 @@ void QmlDirParser::setUrl(const QUrl &url) _url = url; } +QString QmlDirParser::fileSource() const +{ + return _filePathSouce; +} + +void QmlDirParser::setFileSource(const QString &filePath) +{ + _filePathSouce = filePath; +} + QString QmlDirParser::source() const { return _source; @@ -83,6 +96,23 @@ bool QmlDirParser::parse() _plugins.clear(); _components.clear(); + if (_source.isEmpty() && !_filePathSouce.isEmpty()) { + QFile file(_filePathSouce); + if (!Qml_isFileCaseCorrect(_filePathSouce)) { + QmlError error; + error.setDescription(QString::fromUtf8("cannot load module \"$$URI$$\": File name case mismatch for \"%1\"").arg(_filePathSouce)); + _errors.prepend(error); + return false; + } else if (file.open(QFile::ReadOnly)) { + _source = QString::fromUtf8(file.readAll()); + } else { + QmlError error; + error.setDescription(QString::fromUtf8("module \"$$URI$$\" definition \"%1\" not readable").arg(_filePathSouce)); + _errors.prepend(error); + return false; + } + } + QTextStream stream(&_source); int lineNumber = 0; @@ -102,9 +132,9 @@ bool QmlDirParser::parse() while (index != length) { const QChar ch = line.at(index); - if (ch.isSpace()) { + if (QmlUtils::isSpace(ch)) { do { ++index; } - while (index != length && line.at(index).isSpace()); + while (index != length && QmlUtils::isSpace(line.at(index))); } else if (ch == QLatin1Char('#')) { // recognized a comment @@ -114,7 +144,7 @@ bool QmlDirParser::parse() const int start = index; do { ++index; } - while (index != length && !line.at(index).isSpace()); + while (index != length && !QmlUtils::isSpace(line.at(index))); const QString lexeme = line.mid(start, index - start); @@ -148,7 +178,7 @@ bool QmlDirParser::parse() QString::fromUtf8("internal types require 2 arguments, but %1 were provided").arg(sectionCount - 1)); continue; } - Component entry(sections[1], sections[2], -1, -1); + Component entry(sections[1].toUtf8(), sections[2], -1, -1); entry.internal = true; _components.append(entry); } else if (sections[0] == QLatin1String("typeinfo")) { @@ -164,7 +194,7 @@ bool QmlDirParser::parse() } else if (sectionCount == 2) { // No version specified (should only be used for relative qmldir files) - const Component entry(sections[0], sections[1], -1, -1); + const Component entry(sections[0].toUtf8(), sections[1], -1, -1); _components.append(entry); } else if (sectionCount == 3) { const QString &version = sections[1]; @@ -182,7 +212,7 @@ bool QmlDirParser::parse() const int minorVersion = version.mid(dotIndex + 1).toInt(&validVersionNumber); if (validVersionNumber) { - const Component entry(sections[0], sections[2], majorVersion, minorVersion); + const Component entry(sections[0].toUtf8(), sections[2], majorVersion, minorVersion); _components.append(entry); } @@ -215,9 +245,16 @@ bool QmlDirParser::hasError() const return false; } -QList<QmlError> QmlDirParser::errors() const +QList<QmlError> QmlDirParser::errors(const QString &uri) const { - return _errors; + QList<QmlError> errors = _errors; + for (int i = 0; i < errors.size(); ++i) { + QmlError &e = errors[i]; + QString description = e.description(); + description.replace(QLatin1String("$$URI$$"), uri); + e.setDescription(description); + } + return errors; } QList<QmlDirParser::Plugin> QmlDirParser::plugins() const |