aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qmldirparser
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/qmldirparser')
-rw-r--r--src/qml/qmldirparser/qmldirparser.pri7
-rw-r--r--src/qml/qmldirparser/qqmldirparser.cpp24
-rw-r--r--src/qml/qmldirparser/qqmldirparser_p.h30
-rw-r--r--src/qml/qmldirparser/qqmlerror.cpp365
-rw-r--r--src/qml/qmldirparser/qqmlerror.h91
-rw-r--r--src/qml/qmldirparser/qqmlsourcecoordinate_p.h72
6 files changed, 34 insertions, 555 deletions
diff --git a/src/qml/qmldirparser/qmldirparser.pri b/src/qml/qmldirparser/qmldirparser.pri
index 660e7b395a..fefe2e75be 100644
--- a/src/qml/qmldirparser/qmldirparser.pri
+++ b/src/qml/qmldirparser/qmldirparser.pri
@@ -2,10 +2,7 @@ INCLUDEPATH += $$PWD
INCLUDEPATH += $$OUT_PWD
HEADERS += \
- $$PWD/qqmldirparser_p.h \
- $$PWD/qqmlerror.h \
- $$PWD/qqmlsourcecoordinate_p.h
+ $$PWD/qqmldirparser_p.h
SOURCES += \
- $$PWD/qqmldirparser.cpp \
- $$PWD/qqmlerror.cpp
+ $$PWD/qqmldirparser.cpp
diff --git a/src/qml/qmldirparser/qqmldirparser.cpp b/src/qml/qmldirparser/qqmldirparser.cpp
index e944b52e47..d7662b11f5 100644
--- a/src/qml/qmldirparser/qqmldirparser.cpp
+++ b/src/qml/qmldirparser/qqmldirparser.cpp
@@ -38,7 +38,6 @@
****************************************************************************/
#include "qqmldirparser_p.h"
-#include "qqmlerror.h"
#include <QtCore/QtDebug>
@@ -297,8 +296,8 @@ bool QQmlDirParser::parse(const QString &source)
void QQmlDirParser::reportError(quint16 line, quint16 column, const QString &description)
{
QQmlJS::DiagnosticMessage error;
- error.loc.startLine = line;
- error.loc.startColumn = column;
+ error.line = line;
+ error.column = column;
error.message = description;
_errors.append(error);
}
@@ -311,27 +310,20 @@ bool QQmlDirParser::hasError() const
return false;
}
-void QQmlDirParser::setError(const QQmlError &e)
+void QQmlDirParser::setError(const QQmlJS::DiagnosticMessage &e)
{
_errors.clear();
- reportError(e.line(), e.column(), e.description());
+ reportError(e.line, e.column, e.message);
}
-QList<QQmlError> QQmlDirParser::errors(const QString &uri) const
+QList<QQmlJS::DiagnosticMessage> QQmlDirParser::errors(const QString &uri) const
{
- QUrl url(uri);
- QList<QQmlError> errors;
+ QList<QQmlJS::DiagnosticMessage> errors;
const int numErrors = _errors.size();
errors.reserve(numErrors);
for (int i = 0; i < numErrors; ++i) {
- const QQmlJS::DiagnosticMessage &msg = _errors.at(i);
- QQmlError e;
- QString description = msg.message;
- description.replace(QLatin1String("$$URI$$"), uri);
- e.setDescription(description);
- e.setUrl(url);
- e.setLine(msg.loc.startLine);
- e.setColumn(msg.loc.startColumn);
+ QQmlJS::DiagnosticMessage e = _errors.at(i);
+ e.message.replace(QLatin1String("$$URI$$"), uri);
errors << e;
}
return errors;
diff --git a/src/qml/qmldirparser/qqmldirparser_p.h b/src/qml/qmldirparser/qqmldirparser_p.h
index cff9cb11a4..0957c8373a 100644
--- a/src/qml/qmldirparser/qqmldirparser_p.h
+++ b/src/qml/qmldirparser/qqmldirparser_p.h
@@ -56,10 +56,10 @@
#include <QtCore/QDebug>
#include <private/qqmljsengine_p.h>
#include <private/qv4global_p.h>
+#include <private/qqmljsdiagnosticmessage_p.h>
QT_BEGIN_NAMESPACE
-class QQmlError;
class QQmlEngine;
class Q_QML_PRIVATE_EXPORT QQmlDirParser
{
@@ -70,18 +70,30 @@ public:
bool parse(const QString &source);
bool hasError() const;
- void setError(const QQmlError &);
- QList<QQmlError> errors(const QString &uri) const;
+ void setError(const QQmlJS::DiagnosticMessage &);
+ QList<QQmlJS::DiagnosticMessage> errors(const QString &uri) const;
QString typeNamespace() const;
void setTypeNamespace(const QString &s);
+ static void checkNonRelative(const char *item, const QString &typeName, const QString &fileName)
+ {
+ if (fileName.startsWith(QLatin1Char('/')) || fileName.contains(QLatin1Char(':'))) {
+ qWarning() << item << typeName
+ << "is specified with non-relative URL" << fileName << "in a qmldir file."
+ << "URLs in qmldir files should be relative to the qmldir file's directory.";
+ }
+ }
+
struct Plugin
{
Plugin() {}
Plugin(const QString &name, const QString &path)
- : name(name), path(path) {}
+ : name(name), path(path)
+ {
+ checkNonRelative("Plugin", name, path);
+ }
QString name;
QString path;
@@ -93,7 +105,10 @@ public:
Component(const QString &typeName, const QString &fileName, int majorVersion, int minorVersion)
: typeName(typeName), fileName(fileName), majorVersion(majorVersion), minorVersion(minorVersion),
- internal(false), singleton(false) {}
+ internal(false), singleton(false)
+ {
+ checkNonRelative("Component", typeName, fileName);
+ }
QString typeName;
QString fileName;
@@ -108,7 +123,10 @@ public:
Script() {}
Script(const QString &nameSpace, const QString &fileName, int majorVersion, int minorVersion)
- : nameSpace(nameSpace), fileName(fileName), majorVersion(majorVersion), minorVersion(minorVersion) {}
+ : nameSpace(nameSpace), fileName(fileName), majorVersion(majorVersion), minorVersion(minorVersion)
+ {
+ checkNonRelative("Script", nameSpace, fileName);
+ }
QString nameSpace;
QString fileName;
diff --git a/src/qml/qmldirparser/qqmlerror.cpp b/src/qml/qmldirparser/qqmlerror.cpp
deleted file mode 100644
index 5e181f7e27..0000000000
--- a/src/qml/qmldirparser/qqmlerror.cpp
+++ /dev/null
@@ -1,365 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtQml module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qqmlerror.h"
-#include "qqmlsourcecoordinate_p.h"
-
-#include <QtCore/qdebug.h>
-#include <QtCore/qfile.h>
-#include <QtCore/qstringlist.h>
-#include <QtCore/qvector.h>
-
-#ifndef QT_NO_QOBJECT
-#include <QtCore/qobject.h>
-#include <QtCore/qpointer.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QQmlError
- \since 5.0
- \inmodule QtQml
- \brief The QQmlError class encapsulates a QML error.
-
- QQmlError includes a textual description of the error, as well
- as location information (the file, line, and column). The toString()
- method creates a single-line, human-readable string containing all of
- this information, for example:
- \code
- file:///home/user/test.qml:7:8: Invalid property assignment: double expected
- \endcode
-
- You can use qDebug(), qInfo(), or qWarning() to output errors to the console.
- This method will attempt to open the file indicated by the error
- and include additional contextual information.
- \code
- file:///home/user/test.qml:7:8: Invalid property assignment: double expected
- y: "hello"
- ^
- \endcode
-
- \sa QQuickView::errors(), QQmlComponent::errors()
-*/
-class QQmlErrorPrivate
-{
-public:
- QQmlErrorPrivate();
-
- QUrl url;
- QString description;
- quint16 line;
- quint16 column;
- QtMsgType messageType;
-#ifndef QT_NO_QOBJECT
- QPointer<QObject> object;
-#endif
-};
-
-QQmlErrorPrivate::QQmlErrorPrivate()
-: line(0), column(0), messageType(QtMsgType::QtWarningMsg)
-{
-}
-
-/*!
- Creates an empty error object.
-*/
-QQmlError::QQmlError()
-: d(nullptr)
-{
-}
-
-/*!
- Creates a copy of \a other.
-*/
-QQmlError::QQmlError(const QQmlError &other)
-: d(nullptr)
-{
- *this = other;
-}
-
-/*!
- Assigns \a other to this error object.
-*/
-QQmlError &QQmlError::operator=(const QQmlError &other)
-{
- if (!other.d) {
- delete d;
- d = nullptr;
- } else {
- if (!d)
- d = new QQmlErrorPrivate;
- d->url = other.d->url;
- d->description = other.d->description;
- d->line = other.d->line;
- d->column = other.d->column;
-#ifndef QT_NO_QOBJECT
- d->object = other.d->object;
-#endif
- d->messageType = other.d->messageType;
- }
- return *this;
-}
-
-/*!
- \internal
-*/
-QQmlError::~QQmlError()
-{
- delete d; d = nullptr;
-}
-
-/*!
- Returns true if this error is valid, otherwise false.
-*/
-bool QQmlError::isValid() const
-{
- return d != nullptr;
-}
-
-/*!
- Returns the url for the file that caused this error.
-*/
-QUrl QQmlError::url() const
-{
- if (d)
- return d->url;
- return QUrl();
-}
-
-/*!
- Sets the \a url for the file that caused this error.
-*/
-void QQmlError::setUrl(const QUrl &url)
-{
- if (!d)
- d = new QQmlErrorPrivate;
- d->url = url;
-}
-
-/*!
- Returns the error description.
-*/
-QString QQmlError::description() const
-{
- if (d)
- return d->description;
- return QString();
-}
-
-/*!
- Sets the error \a description.
-*/
-void QQmlError::setDescription(const QString &description)
-{
- if (!d)
- d = new QQmlErrorPrivate;
- d->description = description;
-}
-
-/*!
- Returns the error line number.
-*/
-int QQmlError::line() const
-{
- if (d)
- return qmlSourceCoordinate(d->line);
- return -1;
-}
-
-/*!
- Sets the error \a line number.
-*/
-void QQmlError::setLine(int line)
-{
- if (!d)
- d = new QQmlErrorPrivate;
- d->line = qmlSourceCoordinate(line);
-}
-
-/*!
- Returns the error column number.
-*/
-int QQmlError::column() const
-{
- if (d)
- return qmlSourceCoordinate(d->column);
- return -1;
-}
-
-/*!
- Sets the error \a column number.
-*/
-void QQmlError::setColumn(int column)
-{
- if (!d)
- d = new QQmlErrorPrivate;
- d->column = qmlSourceCoordinate(column);
-}
-
-#ifndef QT_NO_QOBJECT
-/*!
- Returns the nearest object where this error occurred.
- Exceptions in bound property expressions set this to the object
- to which the property belongs. It will be 0 for all
- other exceptions.
- */
-QObject *QQmlError::object() const
-{
- if (d)
- return d->object;
- return nullptr;
-}
-
-/*!
- Sets the nearest \a object where this error occurred.
- */
-void QQmlError::setObject(QObject *object)
-{
- if (!d)
- d = new QQmlErrorPrivate;
- d->object = object;
-}
-#endif // QT_NO_QOBJECT
-
-/*!
- \since 5.9
-
- Returns the message type.
- */
-QtMsgType QQmlError::messageType() const
-{
- if (d)
- return d->messageType;
- return QtMsgType::QtWarningMsg;
-}
-
-/*!
- \since 5.9
-
- Sets the \a messageType for this message. The message type determines which
- QDebug handlers are responsible for receiving the message.
- */
-void QQmlError::setMessageType(QtMsgType messageType)
-{
- if (!d)
- d = new QQmlErrorPrivate;
- d->messageType = messageType;
-}
-
-/*!
- Returns the error as a human readable string.
-*/
-QString QQmlError::toString() const
-{
- QString rv;
-
- QUrl u(url());
- int l(line());
-
- if (u.isEmpty() || (u.isLocalFile() && u.path().isEmpty()))
- rv += QLatin1String("<Unknown File>");
- else
- rv += u.toString();
-
- if (l != -1) {
- rv += QLatin1Char(':') + QString::number(l);
-
- int c(column());
- if (c != -1)
- rv += QLatin1Char(':') + QString::number(c);
- }
-
- rv += QLatin1String(": ") + description();
-
- return rv;
-}
-
-/*!
- \relates QQmlError
- \fn QDebug operator<<(QDebug debug, const QQmlError &error)
-
- Outputs a human readable version of \a error to \a debug.
-*/
-
-QDebug operator<<(QDebug debug, const QQmlError &error)
-{
- debug << qPrintable(error.toString());
-
- QUrl url = error.url();
-
- if (error.line() > 0 && url.scheme() == QLatin1String("file")) {
- QString file = url.toLocalFile();
- QFile f(file);
- if (f.open(QIODevice::ReadOnly)) {
- QByteArray data = f.readAll();
- QTextStream stream(data, QIODevice::ReadOnly);
-#if QT_CONFIG(textcodec)
- stream.setCodec("UTF-8");
-#endif
- const QString code = stream.readAll();
- const auto lines = code.splitRef(QLatin1Char('\n'));
-
- if (lines.count() >= error.line()) {
- const QStringRef &line = lines.at(error.line() - 1);
- debug << "\n " << line.toLocal8Bit().constData();
-
- if(error.column() > 0) {
- int column = qMax(0, error.column() - 1);
- column = qMin(column, line.length());
-
- QByteArray ind;
- ind.reserve(column);
- for (int i = 0; i < column; ++i) {
- const QChar ch = line.at(i);
- if (ch.isSpace())
- ind.append(ch.unicode());
- else
- ind.append(' ');
- }
- ind.append('^');
- debug << "\n " << ind.constData();
- }
- }
- }
- }
- return debug;
-}
-
-QT_END_NAMESPACE
diff --git a/src/qml/qmldirparser/qqmlerror.h b/src/qml/qmldirparser/qqmlerror.h
deleted file mode 100644
index f4221358e9..0000000000
--- a/src/qml/qmldirparser/qqmlerror.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtQml module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QQMLERROR_H
-#define QQMLERROR_H
-
-#include <QtQml/qtqmlglobal.h>
-
-#include <QtCore/qurl.h>
-#include <QtCore/qstring.h>
-
-QT_BEGIN_NAMESPACE
-
-// ### Qt 6: should this be called QQmlMessage, since it can have a message type?
-class QDebug;
-class QQmlErrorPrivate;
-class Q_QML_EXPORT QQmlError
-{
-public:
- QQmlError();
- QQmlError(const QQmlError &);
- QQmlError &operator=(const QQmlError &);
- ~QQmlError();
-
- bool isValid() const;
-
- QUrl url() const;
- void setUrl(const QUrl &);
- QString description() const;
- void setDescription(const QString &);
- int line() const;
- void setLine(int);
- int column() const;
- void setColumn(int);
-
-#ifndef QT_NO_QOBJECT
- QObject *object() const;
- void setObject(QObject *);
-#endif
-
- QtMsgType messageType() const;
- void setMessageType(QtMsgType messageType);
-
- QString toString() const;
-private:
- QQmlErrorPrivate *d;
-};
-
-QDebug Q_QML_EXPORT operator<<(QDebug debug, const QQmlError &error);
-
-Q_DECLARE_TYPEINFO(QQmlError, Q_MOVABLE_TYPE);
-
-QT_END_NAMESPACE
-
-#endif // QQMLERROR_H
diff --git a/src/qml/qmldirparser/qqmlsourcecoordinate_p.h b/src/qml/qmldirparser/qqmlsourcecoordinate_p.h
deleted file mode 100644
index 76ac741ae8..0000000000
--- a/src/qml/qmldirparser/qqmlsourcecoordinate_p.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtQml module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QQMLSOURCECOORDINATE_P_H
-#define QQMLSOURCECOORDINATE_P_H
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists purely as an
-// implementation detail. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <QtCore/qglobal.h>
-
-#include <climits>
-
-QT_BEGIN_NAMESPACE
-
-inline quint16 qmlSourceCoordinate(int n)
-{
- return (n > 0 && n <= static_cast<int>(USHRT_MAX)) ? static_cast<quint16>(n) : 0;
-}
-
-inline int qmlSourceCoordinate(quint16 n)
-{
- return (n == 0) ? -1 : static_cast<int>(n);
-}
-
-QT_END_NAMESPACE
-
-#endif // QQMLSOURCECOORDINATE_P_H