aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-10-12 11:38:08 +0200
committerUlf Hermann <ulf.hermann@qt.io>2020-10-15 09:37:06 +0200
commited9ffa109eb2f242b59443ad430204a90c8028c4 (patch)
tree6bc947fc1b2083bda907be03fac18d97b32a670a /src/qmlcompiler
parent9344fcf1a6f4dc6c8176912ac7f2c37e05bf873f (diff)
qmllint: Unify the printing of diagnostics
We can use QQmlJS::DiagnosticMessage to carry message, type, and location. Change-Id: I3868bc8035b4da13efad0d1b7d2f8dfeff1ef234 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmlcompiler')
-rw-r--r--src/qmlcompiler/qqmljsimporter.cpp48
-rw-r--r--src/qmlcompiler/qqmljsimporter_p.h6
-rw-r--r--src/qmlcompiler/qqmljsimportvisitor.cpp16
-rw-r--r--src/qmlcompiler/qqmljsimportvisitor_p.h5
-rw-r--r--src/qmlcompiler/qqmljstypereader_p.h5
5 files changed, 53 insertions, 27 deletions
diff --git a/src/qmlcompiler/qqmljsimporter.cpp b/src/qmlcompiler/qqmljsimporter.cpp
index e33538b653..717b559c44 100644
--- a/src/qmlcompiler/qqmljsimporter.cpp
+++ b/src/qmlcompiler/qqmljsimporter.cpp
@@ -61,12 +61,20 @@ void QQmlJSImporter::readQmltypes(
{
const QFileInfo fileInfo(filename);
if (!fileInfo.exists()) {
- m_warnings.append(QLatin1String("QML types file does not exist: ") + filename);
+ m_warnings.append({
+ QStringLiteral("QML types file does not exist: ") + filename,
+ QtWarningMsg,
+ QQmlJS::SourceLocation()
+ });
return;
}
if (fileInfo.isDir()) {
- m_warnings.append(QLatin1String("QML types file cannot be a directory: ") + filename);
+ m_warnings.append({
+ QStringLiteral("QML types file cannot be a directory: ") + filename,
+ QtWarningMsg,
+ QQmlJS::SourceLocation()
+ });
return;
}
@@ -76,15 +84,19 @@ void QQmlJSImporter::readQmltypes(
QStringList dependencyStrings;
auto succ = reader(objects, &dependencyStrings);
if (!succ)
- m_warnings.append(reader.errorMessage());
+ m_warnings.append({ reader.errorMessage(), QtCriticalMsg, QQmlJS::SourceLocation() });
if (dependencyStrings.isEmpty())
return;
- m_warnings.append(QStringLiteral("Found deprecated dependency specifications in %1."
- "Specify dependencies in qmldir and use qmltyperegistrar to "
- "generate qmltypes files without dependencies.")
- .arg(filename));
+ m_warnings.append({
+ QStringLiteral("Found deprecated dependency specifications in %1."
+ "Specify dependencies in qmldir and use qmltyperegistrar "
+ "to generate qmltypes files without dependencies.")
+ .arg(filename),
+ QtWarningMsg,
+ QQmlJS::SourceLocation()
+ });
for (const QString &dependency : qAsConst(dependencyStrings)) {
const auto blank = dependency.indexOf(u' ');
@@ -125,9 +137,13 @@ QQmlJSImporter::Import QQmlJSImporter::readQmldir(const QString &path)
for (auto it = components.begin(), end = components.end(); it != end; ++it) {
const QString filePath = path + QLatin1Char('/') + it->fileName;
if (!QFile::exists(filePath)) {
- m_warnings.append(it->fileName + QLatin1String(" is listed as component in ")
- + path + SlashQmldir
- + QLatin1String(" but does not exist.\n"));
+ m_warnings.append({
+ it->fileName + QStringLiteral(" is listed as component in ")
+ + path + SlashQmldir
+ + QStringLiteral(" but does not exist.\n"),
+ QtWarningMsg,
+ QQmlJS::SourceLocation()
+ });
continue;
}
@@ -150,8 +166,12 @@ QQmlJSImporter::Import QQmlJSImporter::readQmldir(const QString &path)
if (typeInfos.isEmpty() && !reader.plugins().isEmpty()) {
const QString defaultTypeInfoPath = path + SlashPluginsDotQmltypes;
if (QFile::exists(defaultTypeInfoPath)) {
- m_warnings.append(QStringLiteral("typeinfo not declared in qmldir file: ")
- + defaultTypeInfoPath);
+ m_warnings.append({
+ QStringLiteral("typeinfo not declared in qmldir file: ")
+ + defaultTypeInfoPath,
+ QtWarningMsg,
+ QQmlJS::SourceLocation()
+ });
readQmltypes(defaultTypeInfoPath, &result.objects, &result.dependencies);
}
}
@@ -287,9 +307,7 @@ QQmlJSScope::Ptr QQmlJSImporter::localFile2ScopeTree(const QString &filePath)
QQmlJSScope::Ptr result = typeReader();
m_importedFiles.insert(filePath, result);
- const QStringList errors = typeReader.errors();
- for (const QString &error : errors)
- m_warnings.append(error);
+ m_warnings.append(typeReader.errors());
AvailableTypes types;
types.qmlNames.insert(importDirectory(QFileInfo(filePath).canonicalPath()));
diff --git a/src/qmlcompiler/qqmljsimporter_p.h b/src/qmlcompiler/qqmljsimporter_p.h
index 2f4d51a33c..1acd2a5ed1 100644
--- a/src/qmlcompiler/qqmljsimporter_p.h
+++ b/src/qmlcompiler/qqmljsimporter_p.h
@@ -61,9 +61,9 @@ public:
const QString &module, const QString &prefix = QString(),
QTypeRevision version = QTypeRevision());
- QStringList takeWarnings()
+ QList<QQmlJS::DiagnosticMessage> takeWarnings()
{
- QStringList result = std::move(m_warnings);
+ const auto result = std::move(m_warnings);
m_warnings.clear();
return result;
}
@@ -102,7 +102,7 @@ private:
QStringList m_importPaths;
QHash<QPair<QString, QTypeRevision>, Import> m_seenImports;
QHash<QString, QQmlJSScope::Ptr> m_importedFiles;
- QStringList m_warnings;
+ QList<QQmlJS::DiagnosticMessage> m_warnings;
};
QT_END_NAMESPACE
diff --git a/src/qmlcompiler/qqmljsimportvisitor.cpp b/src/qmlcompiler/qqmljsimportvisitor.cpp
index 87f9bc086e..0b79339b62 100644
--- a/src/qmlcompiler/qqmljsimportvisitor.cpp
+++ b/src/qmlcompiler/qqmljsimportvisitor.cpp
@@ -138,10 +138,12 @@ bool QQmlJSImportVisitor::visit(UiSourceElement *sourceElement)
// nothing to do
} else {
const auto loc = sourceElement->firstSourceLocation();
- m_errors.append(
- QStringLiteral("unsupportedd sourceElement at ")
- + QString::fromLatin1("%1:%2: ").arg(loc.startLine).arg(loc.startColumn)
- + QString::number(sourceElement->sourceElement->kind));
+ m_errors.append({
+ QStringLiteral("unsupportedd sourceElement %1")
+ .arg(sourceElement->sourceElement->kind),
+ QtWarningMsg,
+ loc
+ });
}
return true;
}
@@ -167,7 +169,11 @@ bool QQmlJSImportVisitor::visit(QQmlJS::AST::UiEnumDeclaration *uied)
void QQmlJSImportVisitor::throwRecursionDepthError()
{
- m_errors.append(QStringLiteral("Maximum statement or expression depth exceeded"));
+ m_errors.append({
+ QStringLiteral("Maximum statement or expression depth exceeded"),
+ QtCriticalMsg,
+ QQmlJS::SourceLocation()
+ });
}
QT_END_NAMESPACE
diff --git a/src/qmlcompiler/qqmljsimportvisitor_p.h b/src/qmlcompiler/qqmljsimportvisitor_p.h
index c8cbd66f14..8f0d937968 100644
--- a/src/qmlcompiler/qqmljsimportvisitor_p.h
+++ b/src/qmlcompiler/qqmljsimportvisitor_p.h
@@ -42,6 +42,7 @@
#include "qqmljsscope_p.h"
#include <private/qqmljsast_p.h>
+#include <private/qqmljsdiagnosticmessage_p.h>
QT_BEGIN_NAMESPACE
@@ -49,7 +50,7 @@ class QQmlJSImportVisitor : public QQmlJS::AST::Visitor
{
public:
QQmlJSScope::Ptr result(const QString &scopeName) const;
- QStringList errors() const { return m_errors; }
+ QList<QQmlJS::DiagnosticMessage> errors() const { return m_errors; }
private:
bool visit(QQmlJS::AST::UiObjectDefinition *) override;
@@ -66,7 +67,7 @@ private:
QQmlJSScope::ConstPtr m_rootObject;
QHash<QString, QQmlJSScope::Ptr> m_objects;
- QStringList m_errors;
+ QList<QQmlJS::DiagnosticMessage> m_errors;
};
QT_END_NAMESPACE
diff --git a/src/qmlcompiler/qqmljstypereader_p.h b/src/qmlcompiler/qqmljstypereader_p.h
index 0ac4571c95..4a6c2c2cd0 100644
--- a/src/qmlcompiler/qqmljstypereader_p.h
+++ b/src/qmlcompiler/qqmljstypereader_p.h
@@ -42,6 +42,7 @@
#include "qqmljsscope_p.h"
#include <QtQml/private/qqmljsastfwd_p.h>
+#include <QtQml/private/qqmljsdiagnosticmessage_p.h>
#include <QtCore/qpair.h>
#include <QtCore/qset.h>
@@ -61,12 +62,12 @@ public:
QQmlJSScope::Ptr operator()();
QList<Import> imports() const { return m_imports; }
- QStringList errors() const { return m_errors; }
+ QList<QQmlJS::DiagnosticMessage> errors() const { return m_errors; }
private:
QString m_file;
QList<Import> m_imports;
- QStringList m_errors;
+ QList<QQmlJS::DiagnosticMessage> m_errors;
};
QT_END_NAMESPACE