QmlDesigner: qml document parser traits

A file component is always of the reference kind. Sets the file
component trait too.

Task-number: QDS-12665
Change-Id: I800b32a4d204fb016c1274d05c08695b01581ae4
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2024-07-30 17:20:52 +02:00
parent 7ead23ae0e
commit e3a062837d
7 changed files with 66 additions and 26 deletions

View File

@@ -2624,6 +2624,9 @@ void ProjectStorage::synchronizeTypeAnnotations(Storage::Synchronization::TypeAn
void ProjectStorage::synchronizeTypeTrait(const Storage::Synchronization::Type &type)
{
if (type.changeLevel == Storage::Synchronization::ChangeLevel::Minimal)
return;
s->updateTypeTraitStatement.write(type.typeId, type.traits.type);
}

View File

@@ -1113,7 +1113,6 @@ void ProjectStorageUpdater::parseQmlComponent(Utils::SmallStringView relativeFil
package.updatedSourceIds.push_back(sourceId);
type.typeName = SourcePath{qmlFilePath}.name();
type.traits = Storage::TypeTraitsKind::Reference;
type.sourceId = sourceId;
type.exportedTypes = std::move(exportedTypes);

View File

@@ -297,6 +297,15 @@ void addEnumeraton(Storage::Synchronization::Type &type, const QmlDom::Component
}
}
Storage::TypeTraits createTypeTraits()
{
Storage::TypeTraits traits = Storage::TypeTraitsKind::Reference;
traits.isFileComponent = true;
return traits;
}
} // namespace
Storage::Synchronization::Type QmlDocumentParser::parse(const QString &sourceContent,
@@ -363,6 +372,7 @@ Storage::Synchronization::Type QmlDocumentParser::parse(const QString &sourceCon
directoryPath,
m_storage);
type.traits = createTypeTraits();
type.prototype = createImportedTypeName(qmlObject.name(), qualifiedImports);
type.defaultPropertyName = qmlObject.localDefaultPropertyName();
addImports(imports, qmlFile->imports(), sourceId, directoryPath, m_storage);

View File

@@ -872,8 +872,9 @@ std::ostream &operator<<(std::ostream &out, const Type &type)
using Utils::operator<<;
return out << "( typename: \"" << type.typeName << "\", prototype: {\"" << type.prototype
<< "\", " << type.prototypeId << "}, " << "\", extension: {\"" << type.extension
<< "\", " << type.extensionId << "}, " << type.traits << ", source: " << type.sourceId
<< ", exports: " << type.exportedTypes << ", properties: " << type.propertyDeclarations
<< "\", " << type.extensionId << "}, traits" << type.traits
<< ", source: " << type.sourceId << ", exports: " << type.exportedTypes
<< ", properties: " << type.propertyDeclarations
<< ", functions: " << type.functionDeclarations
<< ", signals: " << type.signalDeclarations << ", changeLevel: " << type.changeLevel
<< ", default: " << type.defaultPropertyName << ")";

View File

@@ -5829,7 +5829,7 @@ TEST_F(ProjectStorage, minimal_updates)
"QQuickItem",
{},
Storage::Synchronization::ImportedType{},
TypeTraitsKind::Reference,
TypeTraitsKind::None,
sourceId1,
{Storage::Synchronization::ExportedType{qtQuickModuleId, "Item", Storage::Version{2, 0}},
Storage::Synchronization::ExportedType{qtQuickNativeModuleId, "QQuickItem"}},

View File

@@ -185,8 +185,11 @@ public:
});
firstType.prototype = Storage::Synchronization::ImportedType{"Object"};
firstType.traits = TypeTraitsKind::Reference;
secondType.prototype = Storage::Synchronization::ImportedType{"Object2"};
secondType.traits = TypeTraitsKind::Reference;
thirdType.prototype = Storage::Synchronization::ImportedType{"Object3"};
thirdType.traits = TypeTraitsKind::Reference;
setContent(u"/path/First.qml", qmlDocument1);
setContent(u"/path/First2.qml", qmlDocument2);
@@ -842,7 +845,7 @@ TEST_F(ProjectStorageUpdater, synchronize_add_only_qml_document_in_directory)
UnorderedElementsAre(
AllOf(IsStorageType("First.qml",
Storage::Synchronization::ImportedType{},
TypeTraitsKind::Reference,
TypeTraitsKind::None,
qmlDocumentSourceId1,
Storage::Synchronization::ChangeLevel::Minimal),
Field(&Storage::Synchronization::Type::exportedTypes,
@@ -903,7 +906,7 @@ TEST_F(ProjectStorageUpdater, synchronize_removes_qml_document)
UnorderedElementsAre(
AllOf(IsStorageType("First.qml",
Storage::Synchronization::ImportedType{},
TypeTraitsKind::Reference,
TypeTraitsKind::None,
qmlDocumentSourceId1,
Storage::Synchronization::ChangeLevel::Minimal),
Field(&Storage::Synchronization::Type::exportedTypes,
@@ -912,7 +915,7 @@ TEST_F(ProjectStorageUpdater, synchronize_removes_qml_document)
IsExportedType(pathModuleId, "First", -1, -1)))),
AllOf(IsStorageType("First2.qml",
Storage::Synchronization::ImportedType{},
TypeTraitsKind::Reference,
TypeTraitsKind::None,
qmlDocumentSourceId2,
Storage::Synchronization::ChangeLevel::Minimal),
Field(&Storage::Synchronization::Type::exportedTypes,
@@ -964,7 +967,7 @@ TEST_F(ProjectStorageUpdater, synchronize_removes_qml_document_in_qmldir_only)
UnorderedElementsAre(
AllOf(IsStorageType("First.qml",
Storage::Synchronization::ImportedType{},
TypeTraitsKind::Reference,
TypeTraitsKind::None,
qmlDocumentSourceId1,
Storage::Synchronization::ChangeLevel::Minimal),
Field(&Storage::Synchronization::Type::exportedTypes,
@@ -972,7 +975,7 @@ TEST_F(ProjectStorageUpdater, synchronize_removes_qml_document_in_qmldir_only)
IsExportedType(pathModuleId, "First", -1, -1)))),
AllOf(IsStorageType("First2.qml",
Storage::Synchronization::ImportedType{},
TypeTraitsKind::Reference,
TypeTraitsKind::None,
qmlDocumentSourceId2,
Storage::Synchronization::ChangeLevel::Minimal),
Field(&Storage::Synchronization::Type::exportedTypes,
@@ -1021,7 +1024,7 @@ TEST_F(ProjectStorageUpdater, synchronize_add_qml_document_to_qmldir)
UnorderedElementsAre(
AllOf(IsStorageType("First.qml",
Storage::Synchronization::ImportedType{},
TypeTraitsKind::Reference,
TypeTraitsKind::None,
qmlDocumentSourceId1,
Storage::Synchronization::ChangeLevel::Minimal),
Field(&Storage::Synchronization::Type::exportedTypes,
@@ -1029,7 +1032,7 @@ TEST_F(ProjectStorageUpdater, synchronize_add_qml_document_to_qmldir)
IsExportedType(pathModuleId, "First", -1, -1)))),
AllOf(IsStorageType("First2.qml",
Storage::Synchronization::ImportedType{},
TypeTraitsKind::Reference,
TypeTraitsKind::None,
qmlDocumentSourceId2,
Storage::Synchronization::ChangeLevel::Minimal),
Field(&Storage::Synchronization::Type::exportedTypes,
@@ -1077,7 +1080,7 @@ TEST_F(ProjectStorageUpdater, synchronize_remove_qml_document_from_qmldir)
UnorderedElementsAre(
AllOf(IsStorageType("First.qml",
Storage::Synchronization::ImportedType{},
TypeTraitsKind::Reference,
TypeTraitsKind::None,
qmlDocumentSourceId1,
Storage::Synchronization::ChangeLevel::Minimal),
Field(&Storage::Synchronization::Type::exportedTypes,
@@ -1085,7 +1088,7 @@ TEST_F(ProjectStorageUpdater, synchronize_remove_qml_document_from_qmldir)
IsExportedType(pathModuleId, "First", -1, -1)))),
AllOf(IsStorageType("First2.qml",
Storage::Synchronization::ImportedType{},
TypeTraitsKind::Reference,
TypeTraitsKind::None,
qmlDocumentSourceId2,
Storage::Synchronization::ChangeLevel::Minimal),
Field(&Storage::Synchronization::Type::exportedTypes,
@@ -1145,7 +1148,7 @@ TEST_F(ProjectStorageUpdater, synchronize_qml_documents_dont_update_if_up_to_dat
IsExportedType(pathModuleId, "First2", -1, -1)))),
AllOf(IsStorageType("Second.qml",
Storage::Synchronization::ImportedType{},
TypeTraitsKind::Reference,
TypeTraitsKind::None,
qmlDocumentSourceId3,
Storage::Synchronization::ChangeLevel::Minimal),
Field(&Storage::Synchronization::Type::exportedTypes,
@@ -1306,7 +1309,7 @@ TEST_F(ProjectStorageUpdater, synchroniz_if_qmldir_file_has_changed_and_some_rem
UnorderedElementsAre(AllOf(
IsStorageType("First2.qml",
Storage::Synchronization::ImportedType{},
TypeTraitsKind::Reference,
TypeTraitsKind::None,
qmlDocumentSourceId2,
Storage::Synchronization::ChangeLevel::Minimal),
Field(&Storage::Synchronization::Type::exportedTypes,
@@ -2569,7 +2572,7 @@ TEST_F(ProjectStorageUpdater, watcher_updates_add_only_qml_document_in_directory
UnorderedElementsAre(
AllOf(IsStorageType("First.qml",
Storage::Synchronization::ImportedType{},
TypeTraitsKind::Reference,
TypeTraitsKind::None,
qmlDocumentSourceId1,
Storage::Synchronization::ChangeLevel::Minimal),
Field(&Storage::Synchronization::Type::exportedTypes,
@@ -2630,7 +2633,7 @@ TEST_F(ProjectStorageUpdater, watcher_updates_removes_qml_document)
UnorderedElementsAre(
AllOf(IsStorageType("First.qml",
Storage::Synchronization::ImportedType{},
TypeTraitsKind::Reference,
TypeTraitsKind::None,
qmlDocumentSourceId1,
Storage::Synchronization::ChangeLevel::Minimal),
Field(&Storage::Synchronization::Type::exportedTypes,
@@ -2639,7 +2642,7 @@ TEST_F(ProjectStorageUpdater, watcher_updates_removes_qml_document)
IsExportedType(pathModuleId, "First", -1, -1)))),
AllOf(IsStorageType("First2.qml",
Storage::Synchronization::ImportedType{},
TypeTraitsKind::Reference,
TypeTraitsKind::None,
qmlDocumentSourceId2,
Storage::Synchronization::ChangeLevel::Minimal),
Field(&Storage::Synchronization::Type::exportedTypes,
@@ -2691,7 +2694,7 @@ TEST_F(ProjectStorageUpdater, watcher_updates_removes_qml_document_in_qmldir_onl
UnorderedElementsAre(
AllOf(IsStorageType("First.qml",
Storage::Synchronization::ImportedType{},
TypeTraitsKind::Reference,
TypeTraitsKind::None,
qmlDocumentSourceId1,
Storage::Synchronization::ChangeLevel::Minimal),
Field(&Storage::Synchronization::Type::exportedTypes,
@@ -2699,7 +2702,7 @@ TEST_F(ProjectStorageUpdater, watcher_updates_removes_qml_document_in_qmldir_onl
IsExportedType(pathModuleId, "First", -1, -1)))),
AllOf(IsStorageType("First2.qml",
Storage::Synchronization::ImportedType{},
TypeTraitsKind::Reference,
TypeTraitsKind::None,
qmlDocumentSourceId2,
Storage::Synchronization::ChangeLevel::Minimal),
Field(&Storage::Synchronization::Type::exportedTypes,
@@ -2748,7 +2751,7 @@ TEST_F(ProjectStorageUpdater, watcher_updates_directories_add_qml_document_to_qm
UnorderedElementsAre(
AllOf(IsStorageType("First.qml",
Storage::Synchronization::ImportedType{},
TypeTraitsKind::Reference,
TypeTraitsKind::None,
qmlDocumentSourceId1,
Storage::Synchronization::ChangeLevel::Minimal),
Field(&Storage::Synchronization::Type::exportedTypes,
@@ -2756,7 +2759,7 @@ TEST_F(ProjectStorageUpdater, watcher_updates_directories_add_qml_document_to_qm
IsExportedType(pathModuleId, "First", -1, -1)))),
AllOf(IsStorageType("First2.qml",
Storage::Synchronization::ImportedType{},
TypeTraitsKind::Reference,
TypeTraitsKind::None,
qmlDocumentSourceId2,
Storage::Synchronization::ChangeLevel::Minimal),
Field(&Storage::Synchronization::Type::exportedTypes,
@@ -2804,7 +2807,7 @@ TEST_F(ProjectStorageUpdater, watcher_updates_directories_remove_qml_document_fr
UnorderedElementsAre(
AllOf(IsStorageType("First.qml",
Storage::Synchronization::ImportedType{},
TypeTraitsKind::Reference,
TypeTraitsKind::None,
qmlDocumentSourceId1,
Storage::Synchronization::ChangeLevel::Minimal),
Field(&Storage::Synchronization::Type::exportedTypes,
@@ -2812,7 +2815,7 @@ TEST_F(ProjectStorageUpdater, watcher_updates_directories_remove_qml_document_fr
IsExportedType(pathModuleId, "First", -1, -1)))),
AllOf(IsStorageType("First2.qml",
Storage::Synchronization::ImportedType{},
TypeTraitsKind::Reference,
TypeTraitsKind::None,
qmlDocumentSourceId2,
Storage::Synchronization::ChangeLevel::Minimal),
Field(&Storage::Synchronization::Type::exportedTypes,
@@ -2872,7 +2875,7 @@ TEST_F(ProjectStorageUpdater, watcher_updates_directories_dont_update_qml_docume
IsExportedType(pathModuleId, "First2", -1, -1)))),
AllOf(IsStorageType("Second.qml",
Storage::Synchronization::ImportedType{},
TypeTraitsKind::Reference,
TypeTraitsKind::None,
qmlDocumentSourceId3,
Storage::Synchronization::ChangeLevel::Minimal),
Field(&Storage::Synchronization::Type::exportedTypes,
@@ -2942,7 +2945,7 @@ TEST_F(ProjectStorageUpdater, watcher_updates_qmldirs_dont_update_qml_documents_
IsExportedType(pathModuleId, "First2", -1, -1)))),
AllOf(IsStorageType("Second.qml",
Storage::Synchronization::ImportedType{},
TypeTraitsKind::Reference,
TypeTraitsKind::None,
qmlDocumentSourceId3,
Storage::Synchronization::ChangeLevel::Minimal),
Field(&Storage::Synchronization::Type::exportedTypes,

View File

@@ -21,6 +21,7 @@ using QmlDesigner::ModuleId;
using QmlDesigner::SourceContextId;
using QmlDesigner::SourceId;
using QmlDesigner::Storage::ModuleKind;
using Storage::TypeTraits;
MATCHER_P(HasPrototype, prototype, std::string(negation ? "isn't " : "is ") + PrintToString(prototype))
{
@@ -517,4 +518,27 @@ TEST_F(QmlDocumentParser, default_property)
ASSERT_THAT(type.defaultPropertyName, Eq("foos"));
}
TEST_F(QmlDocumentParser, has_file_component_trait)
{
QString component = R"(import Example
Item{
})";
auto type = parser.parse(component, imports, qmlFileSourceId, directoryPath);
ASSERT_TRUE(type.traits.isFileComponent);
}
TEST_F(QmlDocumentParser, has_is_reference_trait)
{
QString component = R"(import Example
Item{
})";
auto type = parser.parse(component, imports, qmlFileSourceId, directoryPath);
ASSERT_THAT(type.traits.kind, QmlDesigner::Storage::TypeTraitsKind::Reference);
}
} // namespace