forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user