diff options
| author | Andrei Golubev <andrei.golubev@qt.io> | 2022-06-07 12:38:21 +0200 |
|---|---|---|
| committer | Andrei Golubev <andrei.golubev@qt.io> | 2022-06-09 09:12:59 +0200 |
| commit | 206d2f95c82e215fad7458cc97460472e10900a9 (patch) | |
| tree | 47d1038b264d5f1615c1cd6ce2266e7b71b68191 /src/qmlcompiler/qqmljsutils.cpp | |
| parent | aa312a6d0e47bdf86d9ecff623aa15374b699fc4 (diff) | |
qmltc: Set alias property methods in QmltcVisitor
We can now sensibly do alias setup in the visitor so no need to keep
a special prototype pass around for it
Pick-to: 6.4
Change-Id: I29d2d395cfa6d66eabb36d7fdbd9bfa3bc3df988
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljsutils.cpp')
| -rw-r--r-- | src/qmlcompiler/qqmljsutils.cpp | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/src/qmlcompiler/qqmljsutils.cpp b/src/qmlcompiler/qqmljsutils.cpp index 9e506ca6bb..430d864933 100644 --- a/src/qmlcompiler/qqmljsutils.cpp +++ b/src/qmlcompiler/qqmljsutils.cpp @@ -28,6 +28,7 @@ #include "qqmljsutils_p.h" #include "qqmljstyperesolver_p.h" +#include "qqmljsscopesbyid_p.h" #include <algorithm> @@ -38,16 +39,15 @@ using namespace Qt::StringLiterals; Fully resolves alias \a property and returns the information about the origin, which is not an alias. */ -QQmlJSUtils::ResolvedAlias -QQmlJSUtils::resolveAlias(const QQmlJSTypeResolver *typeResolver, - const QQmlJSMetaProperty &property, - const QQmlJSScope::ConstPtr &owner, - const QQmlJSUtils::AliasResolutionVisitor &visitor) +template<typename ScopeForId> +static QQmlJSUtils::ResolvedAlias +resolveAlias(ScopeForId scopeForId, const QQmlJSMetaProperty &property, + const QQmlJSScope::ConstPtr &owner, const QQmlJSUtils::AliasResolutionVisitor &visitor) { Q_ASSERT(property.isAlias()); Q_ASSERT(owner); - ResolvedAlias result {}; + QQmlJSUtils::ResolvedAlias result {}; result.owner = owner; for (QQmlJSMetaProperty nextProperty = property; nextProperty.isAlias();) { @@ -56,13 +56,13 @@ QQmlJSUtils::resolveAlias(const QQmlJSTypeResolver *typeResolver, // we have an alias pointing to an alias. this way we avoid a check // whether a property is an alias at the very end of the loop body QQmlJSScope::ConstPtr resultOwner = result.owner; - result = ResolvedAlias {}; + result = QQmlJSUtils::ResolvedAlias {}; visitor.reset(); auto aliasExprBits = nextProperty.aliasExpression().split(u'.'); // resolve id first: - resultOwner = typeResolver->scopeForId(aliasExprBits[0], resultOwner); + resultOwner = scopeForId(aliasExprBits[0], resultOwner); if (!resultOwner) return {}; @@ -92,6 +92,30 @@ QQmlJSUtils::resolveAlias(const QQmlJSTypeResolver *typeResolver, return result; } +QQmlJSUtils::ResolvedAlias QQmlJSUtils::resolveAlias(const QQmlJSTypeResolver *typeResolver, + const QQmlJSMetaProperty &property, + const QQmlJSScope::ConstPtr &owner, + const AliasResolutionVisitor &visitor) +{ + return ::resolveAlias( + [&](const QString &id, const QQmlJSScope::ConstPtr &referrer) { + return typeResolver->scopeForId(id, referrer); + }, + property, owner, visitor); +} + +QQmlJSUtils::ResolvedAlias QQmlJSUtils::resolveAlias(const QQmlJSScopesById &idScopes, + const QQmlJSMetaProperty &property, + const QQmlJSScope::ConstPtr &owner, + const AliasResolutionVisitor &visitor) +{ + return ::resolveAlias( + [&](const QString &id, const QQmlJSScope::ConstPtr &referrer) { + return idScopes.scope(id, referrer); + }, + property, owner, visitor); +} + std::optional<FixSuggestion> QQmlJSUtils::didYouMean(const QString &userInput, QStringList candidates, QQmlJS::SourceLocation location) |
