Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qqmljslinterrenamedcomponents.cpp
Go to the documentation of this file.
1
// Copyright (C) 2026 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
// Qt-Security score:significant
4
5
#
include
"qqmljslinterrenamedcomponents_p.h"
6
7
QT_BEGIN_NAMESPACE
8
9
namespace
QQmlJS
{
10
11
using
namespace
Qt
::
StringLiterals
;
12
13
static
QString
qmlNameFromFilePath
(QStringView path)
14
{
15
if
(!path.endsWith(
".qml"_L1
))
16
return
{};
17
18
QStringView result(path);
19
result.chop(
".qml"_L1
.size());
20
if
(result.endsWith(
".ui"_L1
))
21
result.chop(
".ui"_L1
.size());
22
const
qsizetype start = path.lastIndexOf(
"/"_L1
);
23
result.slice(start == -1 ? 0 : start + 1);
24
return
result.toString();
25
}
26
27
static
void
removeModuleImportQualifiers
(QStringList *names)
28
{
29
for
(QString &name : *names) {
30
if
(qsizetype idx = name.lastIndexOf(u'.'); idx != -1)
31
name.slice(idx + 1);
32
}
33
}
34
35
void
LinterRenamedComponents
::
handleRenamedType
(
const
QQmlJSScope::ConstPtr &scope,
36
const
QStringView name,
37
const
QQmlJS::SourceLocation &location,
38
QQmlJSLogger *logger)
const
39
{
40
if
(scope.isNull())
41
return
;
42
43
const
auto
factory = scope.factory();
44
const
QString oldName = qmlNameFromFilePath(factory ? factory->filePath() : scope->filePath());
45
if
(oldName != name)
46
return
;
47
48
QStringList names = m_scopeToName->values(scope);
49
removeModuleImportQualifiers(&names);
50
auto
begin = names.begin();
51
auto
end = std::remove(begin, names.end(), oldName);
52
std::sort(begin, end);
53
names.erase(std::unique(begin, end), names.end());
54
55
if
(names.size() == 0)
56
return
;
57
58
logger->log(
59
"\"%2\" is explicitly renamed to \"%1\" via a qmldir entry or QT_QML_SOURCE_TYPENAME CMake property, use \"%1\" instead."_L1
60
.arg(qJoin(names.begin(), names.end(), QString(),
"\", \""_L1
), name),
61
qmlRenamedType, location);
62
}
63
}
// namespace QQmlJS
64
65
QT_END_NAMESPACE
QQmlJS::LinterRenamedComponents
Definition
qqmljslinterrenamedcomponents_p.h:31
QQmlJS::LinterRenamedComponents::handleRenamedType
void handleRenamedType(const QQmlJSScope::ConstPtr &scope, const QStringView name, const QQmlJS::SourceLocation &location, QQmlJSLogger *logger) const
Definition
qqmljslinterrenamedcomponents.cpp:35
QQmlJS
Definition
qv4bytecodegenerator_p.h:27
QQmlJS::removeModuleImportQualifiers
static void removeModuleImportQualifiers(QStringList *names)
Definition
qqmljslinterrenamedcomponents.cpp:27
QQmlJS::qmlNameFromFilePath
static QString qmlNameFromFilePath(QStringView path)
Definition
qqmljslinterrenamedcomponents.cpp:13
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
qtdeclarative
src
qmllint
qqmljslinterrenamedcomponents.cpp
Generated on
for Qt by
1.18.0