forked from qt-creator/qt-creator
QmlDesigner: Improve enumeration support in the qml document parser
An enumeration like a qualified type contains a '.' too. So this has to be differentiated. Task-number: QDS-6191 Change-Id: If094abaaa29c5a0079a3c3855534d9b53b2bc94d Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -120,15 +120,16 @@ void addImports(Storage::Imports &imports,
|
|||||||
Storage::ImportedTypeName createImportedTypeName(const QStringView rawtypeName,
|
Storage::ImportedTypeName createImportedTypeName(const QStringView rawtypeName,
|
||||||
const QualifiedImports &qualifiedImports)
|
const QualifiedImports &qualifiedImports)
|
||||||
{
|
{
|
||||||
if (!rawtypeName.contains('.')) {
|
if (!rawtypeName.contains('.'))
|
||||||
return Storage::ImportedType{Utils::SmallString{rawtypeName}};
|
return Storage::ImportedType{Utils::SmallString{rawtypeName}};
|
||||||
}
|
|
||||||
|
|
||||||
auto foundDot = std::find(rawtypeName.begin(), rawtypeName.end(), '.');
|
auto foundDot = std::find(rawtypeName.begin(), rawtypeName.end(), '.');
|
||||||
|
|
||||||
QStringView alias(rawtypeName.begin(), foundDot);
|
QStringView alias(rawtypeName.begin(), foundDot);
|
||||||
|
|
||||||
auto foundImport = qualifiedImports.find(alias.toString());
|
auto foundImport = qualifiedImports.find(alias.toString());
|
||||||
|
if (foundImport == qualifiedImports.end())
|
||||||
|
return Storage::ImportedType{Utils::SmallString{rawtypeName}};
|
||||||
|
|
||||||
QStringView typeName(std::next(foundDot), rawtypeName.end());
|
QStringView typeName(std::next(foundDot), rawtypeName.end());
|
||||||
|
|
||||||
|
@@ -187,6 +187,38 @@ TEST_F(QmlDocumentParser, QualifiedProperties)
|
|||||||
Storage::PropertyDeclarationTraits::None)));
|
Storage::PropertyDeclarationTraits::None)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(QmlDocumentParser, EnumerationInProperties)
|
||||||
|
{
|
||||||
|
auto type = parser.parse(R"(import Example 2.1 as Example
|
||||||
|
Item{ property Enumeration.Foo foo})",
|
||||||
|
imports,
|
||||||
|
qmlFileSourceId);
|
||||||
|
|
||||||
|
ASSERT_THAT(type.propertyDeclarations,
|
||||||
|
UnorderedElementsAre(IsPropertyDeclaration("foo",
|
||||||
|
Storage::ImportedType("Enumeration.Foo"),
|
||||||
|
Storage::PropertyDeclarationTraits::None)));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(QmlDocumentParser, QualifiedEnumerationInProperties)
|
||||||
|
{
|
||||||
|
auto exampleModuleId = storage.moduleId("Example");
|
||||||
|
|
||||||
|
auto type = parser.parse(R"(import Example 2.1 as Example
|
||||||
|
Item{ property Example.Enumeration.Foo foo})",
|
||||||
|
imports,
|
||||||
|
qmlFileSourceId);
|
||||||
|
|
||||||
|
ASSERT_THAT(type.propertyDeclarations,
|
||||||
|
UnorderedElementsAre(IsPropertyDeclaration(
|
||||||
|
"foo",
|
||||||
|
Storage::QualifiedImportedType("Enumeration.Foo",
|
||||||
|
Storage::Import{exampleModuleId,
|
||||||
|
Storage::Version{2, 1},
|
||||||
|
qmlFileSourceId}),
|
||||||
|
Storage::PropertyDeclarationTraits::None)));
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(QmlDocumentParser, Imports)
|
TEST_F(QmlDocumentParser, Imports)
|
||||||
{
|
{
|
||||||
ModuleId fooDirectoryModuleId = storage.moduleId("/path/foo");
|
ModuleId fooDirectoryModuleId = storage.moduleId("/path/foo");
|
||||||
|
Reference in New Issue
Block a user