diff options
author | Olivier De Cannière <[email protected]> | 2023-05-05 09:30:27 +0200 |
---|---|---|
committer | Olivier De Cannière <[email protected]> | 2023-05-30 13:42:35 +0200 |
commit | cdd7fe05f676ed1664a156beaf63093237a3beac (patch) | |
tree | 8f7adccde1adc0e8404a96a895c5170b84f3f0cc /src/qmlcompiler/qqmljsloggingutils.cpp | |
parent | 65cb77165ba18442a524faf44f712ae26661965c (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 <[email protected]>
Diffstat (limited to 'src/qmlcompiler/qqmljsloggingutils.cpp')
-rw-r--r-- | src/qmlcompiler/qqmljsloggingutils.cpp | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/src/qmlcompiler/qqmljsloggingutils.cpp b/src/qmlcompiler/qqmljsloggingutils.cpp new file mode 100644 index 0000000000..2ce5eeb439 --- /dev/null +++ b/src/qmlcompiler/qqmljsloggingutils.cpp @@ -0,0 +1,128 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include "qqmljsloggingutils.h" +#include "qqmljsloggingutils_p.h" + +QT_BEGIN_NAMESPACE + +namespace QQmlJS { + +LoggerCategory::LoggerCategory() : d_ptr{ new LoggerCategoryPrivate } { } + +LoggerCategory::LoggerCategory(QString name, QString settingsName, QString description, + QtMsgType level, bool ignored, bool isDefault) + : d_ptr{ new LoggerCategoryPrivate } +{ + Q_D(LoggerCategory); + d->m_name = name; + d->m_settingsName = settingsName; + d->m_description = description; + d->m_level = level; + d->m_ignored = ignored; + d->m_isDefault = isDefault; +} + +LoggerCategory::LoggerCategory(const LoggerCategory &other) + : d_ptr{ new LoggerCategoryPrivate{ *other.d_func() } } +{ +} + +LoggerCategory::LoggerCategory(LoggerCategory &&) = default; + +LoggerCategory &LoggerCategory::operator=(const LoggerCategory &other) +{ + *d_func() = *other.d_func(); + return *this; +} + +LoggerCategory &LoggerCategory::operator=(LoggerCategory &&) = default; + +LoggerCategory::~LoggerCategory() = default; + +QString LoggerCategory::name() const +{ + Q_D(const LoggerCategory); + return d->m_name; +} + +QString LoggerCategory::settingsName() const +{ + Q_D(const LoggerCategory); + return d->m_settingsName; +} + +QString LoggerCategory::description() const +{ + Q_D(const LoggerCategory); + return d->m_description; +} + +QtMsgType LoggerCategory::level() const +{ + Q_D(const LoggerCategory); + return d->m_level; +} + +bool LoggerCategory::isIgnored() const +{ + Q_D(const LoggerCategory); + return d->m_ignored; +} + +bool LoggerCategory::isDefault() const +{ + Q_D(const LoggerCategory); + return d->m_isDefault; +} + +LoggerWarningId LoggerCategory::id() const +{ + Q_D(const LoggerCategory); + return d->id(); +} + +void LoggerCategory::setLevel(QtMsgType type) +{ + Q_D(LoggerCategory); + d->setLevel(type); +} + +void LoggerCategoryPrivate::setLevel(QtMsgType type) +{ + if (m_level == type) + return; + + m_level = type; + m_changed = true; +} + +void LoggerCategory::setIgnored(bool isIgnored) +{ + Q_D(LoggerCategory); + d->setIgnored(isIgnored); +} + +void LoggerCategoryPrivate::setIgnored(bool isIgnored) +{ + if (m_ignored == isIgnored) + return; + + m_ignored = isIgnored; + m_changed = true; +} + +bool LoggerCategoryPrivate::hasChanged() const +{ + return m_changed; +} + +LoggerCategoryPrivate *LoggerCategoryPrivate::get(LoggerCategory *loggerCategory) +{ + Q_ASSERT(loggerCategory); + return loggerCategory->d_func(); +} + +} // namespace QQmlJS + +QT_END_NAMESPACE |