aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorOlivier De Cannière <olivier.decanniere@qt.io>2023-05-05 09:30:27 +0200
committerOlivier De Cannière <olivier.decanniere@qt.io>2023-05-30 13:42:35 +0200
commitcdd7fe05f676ed1664a156beaf63093237a3beac (patch)
tree8f7adccde1adc0e8404a96a895c5170b84f3f0cc /tests/auto
parent65cb77165ba18442a524faf44f712ae26661965c (diff)
QQmlSA: Create an abstraction layer for static analysis
This patch adds abstractions for QML Elements, Bindings, Methods and Properties. This abstraction layer avoids exposing internal details and should be more suited for static analysis tasks. It is now possible to write qmllint plugins without including private headers. As a drive-by, change tst_qmllint:verifyJsRoot to open files in text mode instead of binary. This fixes an issue where line endings cause issues on Windows. Fixes: QTBUG-102276 Change-Id: I6b6e53f1e0078734a18f3aa51807fbe875b375f0 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qml/qmllint/lintplugin.cpp44
-rw-r--r--tests/auto/qml/qmllint/lintplugin.h2
-rw-r--r--tests/auto/qml/qmllint/tst_qmllint.cpp31
-rw-r--r--tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp70
-rw-r--r--tests/auto/quickcontrols/sanity/quickcontrolssanity.cpp34
-rw-r--r--tests/auto/quickcontrols/sanity/tst_sanity.cpp8
6 files changed, 96 insertions, 93 deletions
diff --git a/tests/auto/qml/qmllint/lintplugin.cpp b/tests/auto/qml/qmllint/lintplugin.cpp
index 47279adcaa..86c0d450f0 100644
--- a/tests/auto/qml/qmllint/lintplugin.cpp
+++ b/tests/auto/qml/qmllint/lintplugin.cpp
@@ -5,7 +5,7 @@
using namespace Qt::StringLiterals;
-static constexpr LoggerWarningId plugin { "testPlugin.test" };
+static constexpr QQmlJS::LoggerWarningId plugin{ "testPlugin.test" };
class ElementTest : public QQmlSA::ElementPass
{
@@ -17,25 +17,25 @@ public:
bool shouldRun(const QQmlSA::Element &element) override
{
- return element->baseType() == m_rectangle;
+ return element.baseType() == m_rectangle;
}
void run(const QQmlSA::Element &element) override
{
- auto property = element->property(u"radius"_s);
- if (!property.isValid() || element->property(u"radius"_s).typeName() != u"double") {
- emitWarning(u"Failed to verify radius property", plugin, element->sourceLocation());
+ auto property = element.property(u"radius"_s);
+ if (!property.isValid() || element.property(u"radius"_s).typeName() != u"double") {
+ emitWarning(u"Failed to verify radius property", plugin, element.sourceLocation());
return;
}
- auto bindings = element->propertyBindings(u"radius"_s);
+ auto bindings = element.propertyBindings(u"radius"_s);
if (bindings.isEmpty() || bindings.constFirst().numberValue() != 5) {
emitWarning(u"Failed to verify radius property binding", plugin,
- element->sourceLocation());
+ element.sourceLocation());
return;
}
- emitWarning(u"ElementTest OK", plugin, element->sourceLocation());
+ emitWarning(u"ElementTest OK", plugin, element.sourceLocation());
}
private:
@@ -48,37 +48,37 @@ public:
PropertyTest(QQmlSA::PassManager *manager) : QQmlSA::PropertyPass(manager) { }
void onBinding(const QQmlSA::Element &element, const QString &propertyName,
- const QQmlJSMetaPropertyBinding &binding, const QQmlSA::Element &bindingScope,
+ const QQmlSA::Binding &binding, const QQmlSA::Element &bindingScope,
const QQmlSA::Element &value) override
{
emitWarning(u"Saw binding on %1 property %2 with value %3 (and type %4) in scope %5"_s
- .arg(element->baseTypeName(), propertyName,
+ .arg(element.baseTypeName(), propertyName,
value.isNull()
? u"NULL"_s
- : (value->internalName().isNull() ? value->baseTypeName()
- : value->baseTypeName()))
+ : (value.internalName().isNull() ? value.baseTypeName()
+ : value.baseTypeName()))
.arg(binding.bindingType())
- .arg(bindingScope->baseTypeName()),
- plugin, bindingScope->sourceLocation());
+ .arg(bindingScope.baseTypeName()),
+ plugin, bindingScope.sourceLocation());
}
void onRead(const QQmlSA::Element &element, const QString &propertyName,
- const QQmlSA::Element &readScope, QQmlJS::SourceLocation location) override
+ const QQmlSA::Element &readScope, QQmlSA::SourceLocation location) override
{
emitWarning(u"Saw read on %1 property %2 in scope %3"_s.arg(
- element->baseTypeName(), propertyName, readScope->baseTypeName()),
+ element.baseTypeName(), propertyName, readScope.baseTypeName()),
plugin, location);
}
void onWrite(const QQmlSA::Element &element, const QString &propertyName,
const QQmlSA::Element &value, const QQmlSA::Element &writeScope,
- QQmlJS::SourceLocation location) override
+ QQmlSA::SourceLocation location) override
{
emitWarning(u"Saw write on %1 property %2 with value %3 in scope %4"_s.arg(
- element->baseTypeName(), propertyName,
- (value->internalName().isNull() ? value->baseTypeName()
- : value->internalName()),
- writeScope->baseTypeName()),
+ element.baseTypeName(), propertyName,
+ (value.internalName().isNull() ? value.baseTypeName()
+ : value.internalName()),
+ writeScope.baseTypeName()),
plugin, location);
}
};
@@ -109,7 +109,7 @@ private:
void LintPlugin::registerPasses(QQmlSA::PassManager *manager, const QQmlSA::Element &rootElement)
{
- if (!rootElement->filePath().endsWith(u"_pluginTest.qml"))
+ if (!rootElement.filePath().endsWith(u"_pluginTest.qml"))
return;
manager->registerElementPass(std::make_unique<ElementTest>(manager));
diff --git a/tests/auto/qml/qmllint/lintplugin.h b/tests/auto/qml/qmllint/lintplugin.h
index 76733ca7a7..28d30b225d 100644
--- a/tests/auto/qml/qmllint/lintplugin.h
+++ b/tests/auto/qml/qmllint/lintplugin.h
@@ -6,7 +6,7 @@
#include <QtPlugin>
#include <QtCore/qobject.h>
-#include <QtQmlCompiler/private/qqmlsa_p.h>
+#include <QtQmlCompiler/qqmlsa.h>
class LintPlugin : public QObject, public QQmlSA::LintPlugin
{
diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp
index 8c35553745..cfd93eaf39 100644
--- a/tests/auto/qml/qmllint/tst_qmllint.cpp
+++ b/tests/auto/qml/qmllint/tst_qmllint.cpp
@@ -117,7 +117,7 @@ private:
QStringList importDirs = {}, QStringList qmltypesFiles = {},
QStringList resources = {},
DefaultImportOption defaultImports = UseDefaultImports,
- QList<QQmlJSLogger::Category> *categories = nullptr, bool autoFixable = false,
+ QList<QQmlJS::LoggerCategory> *categories = nullptr, bool autoFixable = false,
LintType type = LintFile);
void searchWarnings(const QJsonArray &warnings, const QString &string,
@@ -139,7 +139,7 @@ private:
void runTest(const QString &testFile, const Result &result, QStringList importDirs = {},
QStringList qmltypesFiles = {}, QStringList resources = {},
DefaultImportOption defaultImports = UseDefaultImports,
- QList<QQmlJSLogger::Category> *categories = nullptr);
+ QList<QQmlJS::LoggerCategory> *categories = nullptr);
QString m_qmllintPath;
QString m_qmljsrootgenPath;
@@ -357,12 +357,12 @@ void TestQmllint::verifyJsRoot()
QString currentJsRootContent, generatedJsRootContent;
QFile currentJsRoot(currentJsRootPath);
- QVERIFY(currentJsRoot.open(QFile::ReadOnly));
+ QVERIFY(currentJsRoot.open(QFile::ReadOnly | QIODevice::Text));
currentJsRootContent = QString::fromUtf8(currentJsRoot.readAll());
currentJsRoot.close();
QFile generatedJsRoot(dir.path() + QDir::separator() + "jsroot.qmltypes");
- QVERIFY(generatedJsRoot.open(QFile::ReadOnly));
+ QVERIFY(generatedJsRoot.open(QFile::ReadOnly | QIODevice::Text));
generatedJsRootContent = QString::fromUtf8(generatedJsRoot.readAll());
generatedJsRoot.close();
@@ -1305,8 +1305,10 @@ void TestQmllint::compilerWarnings()
auto category = std::find(categories.begin(), categories.end(), qmlCompiler);
Q_ASSERT(category != categories.end());
- if (enableCompilerWarnings)
- category->setLevel(u"warning"_s);
+ if (enableCompilerWarnings) {
+ category->setLevel(QtWarningMsg);
+ category->setIgnored(false);
+ }
runTest(filename, result, {}, {}, {}, UseDefaultImports, &categories);
}
@@ -1401,7 +1403,7 @@ QString TestQmllint::runQmllint(const QString &fileToLint, bool shouldSucceed,
void TestQmllint::callQmllint(const QString &fileToLint, bool shouldSucceed, QJsonArray *warnings,
QStringList importPaths, QStringList qmldirFiles,
QStringList resources, DefaultImportOption defaultImports,
- QList<QQmlJSLogger::Category> *categories, bool autoFixable,
+ QList<QQmlJS::LoggerCategory> *categories, bool autoFixable,
LintType type)
{
QJsonArray jsonOutput;
@@ -1415,15 +1417,14 @@ void TestQmllint::callQmllint(const QString &fileToLint, bool shouldSucceed, QJs
? m_defaultImportPaths + importPaths
: importPaths;
if (type == LintFile) {
- const QList<QQmlJSLogger::Category> resolvedCategories = categories != nullptr
- ? *categories
- : QQmlJSLogger::defaultCategories();
+ const QList<QQmlJS::LoggerCategory> resolvedCategories =
+ categories != nullptr ? *categories : QQmlJSLogger::defaultCategories();
lintResult = m_linter.lintFile(
lintedFile, nullptr, true, &jsonOutput, resolvedImportPaths, qmldirFiles,
resources, resolvedCategories);
} else {
- lintResult = m_linter.lintModule(
- fileToLint, true, &jsonOutput, resolvedImportPaths, resources);
+ lintResult =
+ m_linter.lintModule(fileToLint, true, &jsonOutput, resolvedImportPaths, resources);
}
bool success = lintResult == QQmlJSLinter::LintSuccess;
@@ -1480,7 +1481,7 @@ void TestQmllint::callQmllint(const QString &fileToLint, bool shouldSucceed, QJs
void TestQmllint::runTest(const QString &testFile, const Result &result, QStringList importDirs,
QStringList qmltypesFiles, QStringList resources,
DefaultImportOption defaultImports,
- QList<QQmlJSLogger::Category> *categories)
+ QList<QQmlJS::LoggerCategory> *categories)
{
QJsonArray warnings;
callQmllint(testFile, result.flags.testFlag(Result::Flag::ExitsNormally), &warnings, importDirs,
@@ -1670,12 +1671,12 @@ void TestQmllint::qrcUrlImport()
void TestQmllint::attachedPropertyReuse()
{
-
auto categories = QQmlJSLogger::defaultCategories();
auto category = std::find(categories.begin(), categories.end(), qmlAttachedPropertyReuse);
Q_ASSERT(category != categories.end());
- category->setLevel(u"warning"_s);
+ category->setLevel(QtWarningMsg);
+ category->setIgnored(false);
runTest("attachedPropNotReused.qml",
Result { { Message { QStringLiteral("Using attached type QQuickKeyNavigationAttached "
"already initialized in a parent "
diff --git a/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp b/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp
index 09c6601858..aeda087dfc 100644
--- a/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp
+++ b/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp
@@ -160,14 +160,14 @@ void tst_qqmljsscope::orderedBindings()
QCOMPARE(std::distance(pBindingsBegin, pBindingsEnd), 2);
// check that the bindings are properly ordered
- QCOMPARE(pBindingsBegin->bindingType(), QQmlJSMetaPropertyBinding::Object);
- QCOMPARE(std::next(pBindingsBegin)->bindingType(), QQmlJSMetaPropertyBinding::Interceptor);
+ QCOMPARE(pBindingsBegin->bindingType(), QQmlSA::BindingType::Object);
+ QCOMPARE(std::next(pBindingsBegin)->bindingType(), QQmlSA::BindingType::Interceptor);
auto [itemsBindingsBegin, itemsBindingsEnd] = root->ownPropertyBindings(u"items"_s);
QCOMPARE(std::distance(itemsBindingsBegin, itemsBindingsEnd), 2);
- QCOMPARE(itemsBindingsBegin->bindingType(), QQmlJSMetaPropertyBinding::Object);
- QCOMPARE(std::next(itemsBindingsBegin)->bindingType(), QQmlJSMetaPropertyBinding::Object);
+ QCOMPARE(itemsBindingsBegin->bindingType(), QQmlSA::BindingType::Object);
+ QCOMPARE(std::next(itemsBindingsBegin)->bindingType(), QQmlSA::BindingType::Object);
QCOMPARE(itemsBindingsBegin->objectType()->baseTypeName(), u"Item"_s);
QCOMPARE(std::next(itemsBindingsBegin)->objectType()->baseTypeName(), u"Text"_s);
@@ -184,8 +184,8 @@ void tst_qqmljsscope::signalCreationDifferences()
const auto conflicting = root->ownMethods(u"conflictingPropertyChanged"_s);
QCOMPARE(conflicting.size(), 2);
- QCOMPARE(conflicting[0].methodType(), QQmlJSMetaMethod::Signal);
- QCOMPARE(conflicting[1].methodType(), QQmlJSMetaMethod::Signal);
+ QCOMPARE(conflicting[0].methodType(), QQmlJSMetaMethodType::Signal);
+ QCOMPARE(conflicting[1].methodType(), QQmlJSMetaMethodType::Signal);
const QQmlJSMetaMethod *explicitMethod = nullptr;
if (conflicting[0].isImplicitQmlPropertyChangeSignal())
@@ -302,7 +302,7 @@ void tst_qqmljsscope::groupedProperties()
const auto getBindingsWithinGroup =
[&](QMultiHash<QString, QQmlJSMetaPropertyBinding> *bindings, qsizetype index) -> void {
const auto &binding = anchorBindings[index];
- QCOMPARE(binding.bindingType(), QQmlJSMetaPropertyBinding::GroupProperty);
+ QCOMPARE(binding.bindingType(), QQmlSA::BindingType::GroupProperty);
auto anchorScope = binding.groupType();
QVERIFY(anchorScope);
*bindings = anchorScope->ownPropertyBindings();
@@ -316,14 +316,14 @@ void tst_qqmljsscope::groupedProperties()
QMultiHash<QString, QQmlJSMetaPropertyBinding> bindingsOfType;
getBindingsWithinGroup(&bindingsOfType, 0);
QCOMPARE(bindingsOfType.size(), 2);
- QCOMPARE(value(bindingsOfType, u"left"_s).bindingType(), QQmlJSMetaPropertyBinding::Script);
+ QCOMPARE(value(bindingsOfType, u"left"_s).bindingType(), QQmlSA::BindingType::Script);
QCOMPARE(value(bindingsOfType, u"leftMargin"_s).bindingType(),
- QQmlJSMetaPropertyBinding::NumberLiteral);
+ QQmlSA::BindingType::NumberLiteral);
QMultiHash<QString, QQmlJSMetaPropertyBinding> bindingsOfBaseType;
getBindingsWithinGroup(&bindingsOfBaseType, 1);
QCOMPARE(bindingsOfBaseType.size(), 1);
- QCOMPARE(value(bindingsOfBaseType, u"top"_s).bindingType(), QQmlJSMetaPropertyBinding::Script);
+ QCOMPARE(value(bindingsOfBaseType, u"top"_s).bindingType(), QQmlSA::BindingType::Script);
}
void tst_qqmljsscope::descriptiveNameOfNull()
@@ -363,8 +363,8 @@ void tst_qqmljsscope::groupedPropertiesConsistency()
// The binding order in QQmlJSScope case is "reversed": first come
// bindings on the leaf type, followed by the bindings on the base type
- QCOMPARE(fontBindings[0].bindingType(), QQmlJSMetaPropertyBinding::GroupProperty);
- QCOMPARE(fontBindings[1].bindingType(), QQmlJSMetaPropertyBinding::Script);
+ QCOMPARE(fontBindings[0].bindingType(), QQmlSA::BindingType::GroupProperty);
+ QCOMPARE(fontBindings[1].bindingType(), QQmlSA::BindingType::Script);
}
}
@@ -378,7 +378,7 @@ void tst_qqmljsscope::groupedPropertySyntax()
// The binding order in QQmlJSScope case is "reversed": first come
// bindings on the leaf type, followed by the bindings on the base type
- QCOMPARE(fontBindings[0].bindingType(), QQmlJSMetaPropertyBinding::GroupProperty);
+ QCOMPARE(fontBindings[0].bindingType(), QQmlSA::BindingType::GroupProperty);
auto fontScope = fontBindings[0].groupType();
QVERIFY(fontScope);
QCOMPARE(fontScope->accessSemantics(), QQmlJSScope::AccessSemantics::Value);
@@ -390,9 +390,8 @@ void tst_qqmljsscope::groupedPropertySyntax()
return bindings.value(key, QQmlJSMetaPropertyBinding(QQmlJS::SourceLocation {}));
};
- QCOMPARE(value(subbindings, u"pixelSize"_s).bindingType(),
- QQmlJSMetaPropertyBinding::NumberLiteral);
- QCOMPARE(value(subbindings, u"bold"_s).bindingType(), QQmlJSMetaPropertyBinding::BoolLiteral);
+ QCOMPARE(value(subbindings, u"pixelSize"_s).bindingType(), QQmlSA::BindingType::NumberLiteral);
+ QCOMPARE(value(subbindings, u"bold"_s).bindingType(), QQmlSA::BindingType::BoolLiteral);
}
void tst_qqmljsscope::attachedProperties()
@@ -407,7 +406,7 @@ void tst_qqmljsscope::attachedProperties()
const auto getBindingsWithinAttached =
[&](QMultiHash<QString, QQmlJSMetaPropertyBinding> *bindings, qsizetype index) -> void {
const auto &binding = keysBindings[index];
- QCOMPARE(binding.bindingType(), QQmlJSMetaPropertyBinding::AttachedProperty);
+ QCOMPARE(binding.bindingType(), QQmlSA::BindingType::AttachedProperty);
auto keysScope = binding.attachingType();
QVERIFY(keysScope);
QCOMPARE(keysScope->accessSemantics(), QQmlJSScope::AccessSemantics::Reference);
@@ -422,23 +421,21 @@ void tst_qqmljsscope::attachedProperties()
QMultiHash<QString, QQmlJSMetaPropertyBinding> bindingsOfType;
getBindingsWithinAttached(&bindingsOfType, 0);
QCOMPARE(bindingsOfType.size(), 2);
- QCOMPARE(value(bindingsOfType, u"enabled"_s).bindingType(),
- QQmlJSMetaPropertyBinding::BoolLiteral);
- QCOMPARE(value(bindingsOfType, u"forwardTo"_s).bindingType(),
- QQmlJSMetaPropertyBinding::Script);
+ QCOMPARE(value(bindingsOfType, u"enabled"_s).bindingType(), QQmlSA::BindingType::BoolLiteral);
+ QCOMPARE(value(bindingsOfType, u"forwardTo"_s).bindingType(), QQmlSA::BindingType::Script);
QMultiHash<QString, QQmlJSMetaPropertyBinding> bindingsOfBaseType;
getBindingsWithinAttached(&bindingsOfBaseType, 1);
QCOMPARE(bindingsOfBaseType.size(), 1);
- QCOMPARE(value(bindingsOfBaseType, u"priority"_s).bindingType(),
- QQmlJSMetaPropertyBinding::Script);
+ QCOMPARE(value(bindingsOfBaseType, u"priority"_s).bindingType(), QQmlSA::BindingType::Script);
}
inline QString getScopeName(const QQmlJSScope::ConstPtr &scope)
{
Q_ASSERT(scope);
QQmlJSScope::ScopeType type = scope->scopeType();
- if (type == QQmlJSScope::GroupedPropertyScope || type == QQmlJSScope::AttachedPropertyScope)
+ if (type == QQmlSA::ScopeType::GroupedPropertyScope
+ || type == QQmlSA::ScopeType::AttachedPropertyScope)
return scope->internalName();
return scope->baseTypeName();
}
@@ -537,8 +534,9 @@ void tst_qqmljsscope::scriptIndices()
const auto suitableScope = [](const QQmlJSScope::ConstPtr &scope) {
const auto type = scope->scopeType();
- return type == QQmlJSScope::QMLScope || type == QQmlJSScope::GroupedPropertyScope
- || type == QQmlJSScope::AttachedPropertyScope;
+ return type == QQmlSA::ScopeType::QMLScope
+ || type == QQmlSA::ScopeType::GroupedPropertyScope
+ || type == QQmlSA::ScopeType::AttachedPropertyScope;
};
QList<QQmlJSScope::ConstPtr> queue;
@@ -550,7 +548,7 @@ void tst_qqmljsscope::scriptIndices()
if (suitableScope(current)) {
const auto methods = current->ownMethods();
for (const auto &method : methods) {
- if (method.methodType() == QQmlJSMetaMethod::Signal)
+ if (method.methodType() == QQmlJSMetaMethodType::Signal)
continue;
QString name = method.methodName();
auto relativeIndex = method.jsFunctionIndex();
@@ -563,7 +561,7 @@ void tst_qqmljsscope::scriptIndices()
const auto bindings = current->ownPropertyBindings();
for (const auto &binding : bindings) {
- if (binding.bindingType() != QQmlJSMetaPropertyBinding::Script)
+ if (binding.bindingType() != QQmlSA::BindingType::Script)
continue;
QString name = binding.propertyName();
auto relativeIndex = binding.scriptIndex();
@@ -711,32 +709,32 @@ void tst_qqmljsscope::resolvedNonUniqueScopes()
{
auto topLevelBindings = root->propertyBindings(u"Component"_s);
QCOMPARE(topLevelBindings.size(), 1);
- QCOMPARE(topLevelBindings[0].bindingType(), QQmlJSMetaPropertyBinding::AttachedProperty);
+ QCOMPARE(topLevelBindings[0].bindingType(), QQmlSA::BindingType::AttachedProperty);
auto componentScope = topLevelBindings[0].attachingType();
auto componentBindings = componentScope->ownPropertyBindings();
QCOMPARE(componentBindings.size(), 2);
auto onCompletedBinding = value(componentBindings, u"onCompleted"_s);
QVERIFY(onCompletedBinding.isValid());
- QCOMPARE(onCompletedBinding.bindingType(), QQmlJSMetaPropertyBinding::Script);
- QCOMPARE(onCompletedBinding.scriptKind(), QQmlJSMetaPropertyBinding::Script_SignalHandler);
+ QCOMPARE(onCompletedBinding.bindingType(), QQmlSA::BindingType::Script);
+ QCOMPARE(onCompletedBinding.scriptKind(), QQmlSA::ScriptBindingKind::Script_SignalHandler);
auto onDestructionBinding = value(componentBindings, u"onDestruction"_s);
QVERIFY(onDestructionBinding.isValid());
- QCOMPARE(onDestructionBinding.bindingType(), QQmlJSMetaPropertyBinding::Script);
+ QCOMPARE(onDestructionBinding.bindingType(), QQmlSA::BindingType::Script);
QCOMPARE(onDestructionBinding.scriptKind(),
- QQmlJSMetaPropertyBinding::Script_SignalHandler);
+ QQmlSA::ScriptBindingKind::Script_SignalHandler);
}
{
auto topLevelBindings = root->propertyBindings(u"p"_s);
QCOMPARE(topLevelBindings.size(), 1);
- QCOMPARE(topLevelBindings[0].bindingType(), QQmlJSMetaPropertyBinding::GroupProperty);
+ QCOMPARE(topLevelBindings[0].bindingType(), QQmlSA::BindingType::GroupProperty);
auto pScope = topLevelBindings[0].groupType();
auto pBindings = pScope->ownPropertyBindings();
QCOMPARE(pBindings.size(), 1);
auto onXChangedBinding = value(pBindings, u"onXChanged"_s);
QVERIFY(onXChangedBinding.isValid());
- QCOMPARE(onXChangedBinding.bindingType(), QQmlJSMetaPropertyBinding::Script);
- QCOMPARE(onXChangedBinding.scriptKind(), QQmlJSMetaPropertyBinding::Script_SignalHandler);
+ QCOMPARE(onXChangedBinding.bindingType(), QQmlSA::BindingType::Script);
+ QCOMPARE(onXChangedBinding.scriptKind(), QQmlSA::ScriptBindingKind::Script_SignalHandler);
}
}
diff --git a/tests/auto/quickcontrols/sanity/quickcontrolssanity.cpp b/tests/auto/quickcontrols/sanity/quickcontrolssanity.cpp
index 7d8a216c78..801fc3ca2a 100644
--- a/tests/auto/quickcontrols/sanity/quickcontrolssanity.cpp
+++ b/tests/auto/quickcontrols/sanity/quickcontrolssanity.cpp
@@ -10,7 +10,7 @@ QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
-static constexpr LoggerWarningId qmlControlsSanity{ "QuickControlsSanity.controls-sanity" };
+static constexpr QQmlJS::LoggerWarningId qmlControlsSanity{ "QuickControlsSanity.controls-sanity" };
AnchorsElementPass::AnchorsElementPass(QQmlSA::PassManager *manager)
: QQmlSA::ElementPass(manager), m_item(resolveType("QtQuick"_L1, "Item"_L1))
@@ -19,14 +19,14 @@ AnchorsElementPass::AnchorsElementPass(QQmlSA::PassManager *manager)
bool AnchorsElementPass::shouldRun(const QQmlSA::Element &element)
{
- return !m_item.isNull() && element->inherits(m_item)
- && element->hasOwnPropertyBindings("anchors"_L1);
+ return !m_item.isNull() && element.inherits(m_item)
+ && element.hasOwnPropertyBindings("anchors"_L1);
}
void AnchorsElementPass::run(const QQmlSA::Element &element)
{
- const auto anchorBindings = element->propertyBindings("anchors"_L1);
- for (auto &&anchors : anchorBindings) {
+ const auto anchorBindings = element.propertyBindings("anchors"_L1);
+ for (const auto &anchors : anchorBindings) {
emitWarning(u"Using anchors here"_s, qmlControlsSanity, anchors.sourceLocation());
}
}
@@ -38,17 +38,19 @@ SignalHandlerPass::SignalHandlerPass(QQmlSA::PassManager *manager)
bool SignalHandlerPass::shouldRun(const QQmlSA::Element &element)
{
- return !m_qtobject.isNull() && element->inherits(m_qtobject);
+ return !m_qtobject.isNull() && element.inherits(m_qtobject);
}
void SignalHandlerPass::run(const QQmlSA::Element &element)
{
- for (auto &&[propertyName, propertyBinding] :
- element->ownPropertyBindings().asKeyValueRange()) {
+ const auto &ownBindings = element.ownPropertyBindings();
+ for (auto it = ownBindings.constBegin(); it != ownBindings.constEnd(); ++it) {
+ const auto &propertyName = it.key();
+ const auto &propertyBinding = it.value();
// Already script binding, check if the script kind is signal handler
- if (propertyBinding.bindingType() == QQmlJSMetaPropertyBinding::Script) {
- if (propertyBinding.scriptKind() == QQmlJSMetaPropertyBinding::Script_SignalHandler) {
+ if (propertyBinding.bindingType() == QQmlSA::BindingType::Script) {
+ if (propertyBinding.scriptKind() == QQmlSA::ScriptBindingKind::Script_SignalHandler) {
emitWarning(u"Declared signal handler \"%1\""_s.arg(propertyName),
qmlControlsSanity, propertyBinding.sourceLocation());
}
@@ -56,11 +58,11 @@ void SignalHandlerPass::run(const QQmlSA::Element &element)
}
// Current property is attached property, recursively go through attaching type
- if (propertyBinding.bindingType() == QQmlJSMetaPropertyBinding::AttachedProperty) {
- const auto scope = propertyBinding.attachingType();
+ if (propertyBinding.bindingType() == QQmlSA::BindingType::AttachedProperty) {
+ const auto scope = QQmlSA::Element{ propertyBinding.attachingType() };
run(scope);
}
- };
+ }
}
FunctionDeclarationPass::FunctionDeclarationPass(QQmlSA::PassManager *manager)
@@ -76,12 +78,12 @@ bool FunctionDeclarationPass::shouldRun(const QQmlSA::Element &element)
void FunctionDeclarationPass::run(const QQmlSA::Element &element)
{
- for (auto &&method : element->ownMethods()) {
- if (method.methodType() != QQmlJSMetaMethod::Method)
+ for (const auto &method : element.ownMethods()) {
+ if (method.methodType() != QQmlSA::MethodType::Method)
continue;
emitWarning(u"Declared function \"%1\""_s.arg(method.methodName()), qmlControlsSanity,
- element->sourceLocation());
+ element.sourceLocation());
}
}
diff --git a/tests/auto/quickcontrols/sanity/tst_sanity.cpp b/tests/auto/quickcontrols/sanity/tst_sanity.cpp
index af3f119745..cde062d49e 100644
--- a/tests/auto/quickcontrols/sanity/tst_sanity.cpp
+++ b/tests/auto/quickcontrols/sanity/tst_sanity.cpp
@@ -48,7 +48,7 @@ private:
QStringList m_importPaths;
QQmlJSLinter m_linter;
- QList<QQmlJSLogger::Category> m_categories;
+ QList<QQmlJS::LoggerCategory> m_categories;
};
tst_Sanity::tst_Sanity()
@@ -65,9 +65,11 @@ tst_Sanity::tst_Sanity()
for (auto &category : m_categories) {
if (category == qmlDeferredPropertyId || category == qmlAttachedPropertyReuse) {
- category.setLevel(u"warning"_s);
+ category.setLevel(QtWarningMsg);
+ category.setIgnored(false);
} else {
- category.setLevel(u"disable"_s);
+ category.setLevel(QtCriticalMsg);
+ category.setIgnored(true);
}
}
}