forked from qt-creator/qt-creator
QmlDesigner: Improve alias property name support
Use aliasPropertyNameTail member in updater. Task-number: QDS-7117 Change-Id: Ic77f220de3d144af4dc870979d3287b66a32949f Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
@@ -161,6 +161,17 @@ Storage::ImportedTypeName createImportedTypeName(const QStringView rawtypeName,
|
||||
foundImport->second};
|
||||
}
|
||||
|
||||
std::pair<Utils::SmallString, Utils::SmallString> createAccessPaths(const QStringList &accessPath)
|
||||
{
|
||||
if (accessPath.size() == 1)
|
||||
return {accessPath[0], {}};
|
||||
|
||||
if (accessPath.size() == 2)
|
||||
return {accessPath[0], accessPath[1]};
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void addPropertyDeclarations(Storage::Type &type,
|
||||
QmlDom::QmlObject &rootObject,
|
||||
const QualifiedImports &qualifiedImports,
|
||||
@@ -176,12 +187,15 @@ void addPropertyDeclarations(Storage::Type &type,
|
||||
auto resolvedAlias = rootObject.resolveAlias(rootObjectItem,
|
||||
property.ownerAs<QmlDom::ScriptExpression>());
|
||||
if (resolvedAlias.valid()) {
|
||||
auto [aliasPropertyName, aliasPropertyNameTail] = createAccessPaths(
|
||||
resolvedAlias.accessedPath);
|
||||
|
||||
type.propertyDeclarations.emplace_back(Utils::SmallString{propertyDeclaration.name},
|
||||
createImportedTypeName(resolvedAlias.typeName,
|
||||
qualifiedImports),
|
||||
Storage::PropertyDeclarationTraits::None,
|
||||
Utils::SmallString{
|
||||
resolvedAlias.accessedPath.join('.')});
|
||||
aliasPropertyName,
|
||||
aliasPropertyNameTail);
|
||||
}
|
||||
} else {
|
||||
type.propertyDeclarations.emplace_back(Utils::SmallString{propertyDeclaration.name},
|
||||
|
@@ -72,7 +72,26 @@ MATCHER_P4(IsAliasPropertyDeclaration,
|
||||
return propertyDeclaration.name == name
|
||||
&& Storage::ImportedTypeName{typeName} == propertyDeclaration.typeName
|
||||
&& propertyDeclaration.traits == traits
|
||||
&& propertyDeclaration.aliasPropertyName == aliasPropertyName;
|
||||
&& propertyDeclaration.aliasPropertyName == aliasPropertyName
|
||||
&& propertyDeclaration.aliasPropertyNameTail.empty();
|
||||
}
|
||||
|
||||
MATCHER_P5(IsAliasPropertyDeclaration,
|
||||
name,
|
||||
typeName,
|
||||
traits,
|
||||
aliasPropertyName,
|
||||
aliasPropertyNameTail,
|
||||
std::string(negation ? "isn't " : "is ")
|
||||
+ PrintToString(Storage::PropertyDeclaration{name, typeName, traits, aliasPropertyName}))
|
||||
{
|
||||
const Storage::PropertyDeclaration &propertyDeclaration = arg;
|
||||
|
||||
return propertyDeclaration.name == name
|
||||
&& Storage::ImportedTypeName{typeName} == propertyDeclaration.typeName
|
||||
&& propertyDeclaration.traits == traits
|
||||
&& propertyDeclaration.aliasPropertyName == aliasPropertyName
|
||||
&& propertyDeclaration.aliasPropertyNameTail == aliasPropertyNameTail;
|
||||
}
|
||||
|
||||
MATCHER_P2(IsFunctionDeclaration,
|
||||
@@ -436,7 +455,8 @@ TEST_F(QmlDocumentParser, IndirectAliasProperties)
|
||||
UnorderedElementsAre(IsAliasPropertyDeclaration("textSize",
|
||||
Storage::ImportedType{"Item"},
|
||||
Storage::PropertyDeclarationTraits::None,
|
||||
"text.size")));
|
||||
"text",
|
||||
"size")));
|
||||
}
|
||||
|
||||
TEST_F(QmlDocumentParser, InvalidAliasPropertiesAreSkipped)
|
||||
|
Reference in New Issue
Block a user