forked from qt-creator/qt-creator
QmlDesigner: Use ModuleId for Type instead of Module
We already know the module id because it's the source id of the module. Change-Id: Ice241d38c12c7ca79a525464c53b7d552095a0fc Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -1274,7 +1274,7 @@ private:
|
||||
|
||||
TypeId declareType(Storage::Type &type)
|
||||
{
|
||||
if (type.module.name.isEmpty() && type.typeName.isEmpty()) {
|
||||
if (!type.moduleId && type.typeName.isEmpty()) {
|
||||
auto [moduleId, typeId] = selectModuleAndTypeIdBySourceIdStatement
|
||||
.template value<ModuleAndTypeId>(&type.sourceId);
|
||||
type.typeId = typeId;
|
||||
@@ -1282,8 +1282,6 @@ private:
|
||||
return type.typeId;
|
||||
}
|
||||
|
||||
type.moduleId = fetchModuleIdUnguarded(type.module);
|
||||
|
||||
if (!type.moduleId)
|
||||
throw ModuleDoesNotExists{};
|
||||
|
||||
@@ -1935,10 +1933,10 @@ public:
|
||||
"SELECT name, ifnull(majorVersion, -1), ifnull(minorVersion, -1) FROM exportedTypeNames "
|
||||
"WHERE typeId=? AND kind=1",
|
||||
database};
|
||||
mutable ReadStatement<7> selectTypesStatement{
|
||||
"SELECT m.name, m.moduleId, t.name, typeId, (SELECT name FROM types WHERE "
|
||||
mutable ReadStatement<6> selectTypesStatement{
|
||||
"SELECT moduleId, name, typeId, (SELECT name FROM types WHERE "
|
||||
"typeId=t.prototypeId), accessSemantics, ifnull(sourceId, -1) FROM types AS "
|
||||
"t JOIN modules AS m USING (moduleId)",
|
||||
"t",
|
||||
database};
|
||||
ReadStatement<1> selectNotUpdatedTypesInSourcesStatement{
|
||||
"SELECT typeId FROM types WHERE (sourceId IN carray(?1) AND typeId NOT IN carray(?2))",
|
||||
|
@@ -632,7 +632,7 @@ class Type
|
||||
{
|
||||
public:
|
||||
explicit Type() = default;
|
||||
explicit Type(Module module,
|
||||
explicit Type(ModuleId moduleId,
|
||||
Utils::SmallStringView typeName,
|
||||
ImportedTypeName prototype,
|
||||
TypeAccessSemantics accessSemantics,
|
||||
@@ -650,26 +650,26 @@ public:
|
||||
, functionDeclarations{std::move(functionDeclarations)}
|
||||
, signalDeclarations{std::move(signalDeclarations)}
|
||||
, enumerationDeclarations{std::move(enumerationDeclarations)}
|
||||
, module{std::move(module)}
|
||||
, moduleId{moduleId}
|
||||
, accessSemantics{accessSemantics}
|
||||
, sourceId{sourceId}
|
||||
, changeLevel{changeLevel}
|
||||
{}
|
||||
|
||||
explicit Type(Utils::SmallStringView moduleName,
|
||||
explicit Type(ModuleId moduleId,
|
||||
Utils::SmallStringView typeName,
|
||||
Utils::SmallStringView prototype,
|
||||
int accessSemantics,
|
||||
int sourceId)
|
||||
: typeName{typeName}
|
||||
, prototype{NativeType{prototype}}
|
||||
, module{moduleName}
|
||||
, moduleId{moduleId}
|
||||
, accessSemantics{static_cast<TypeAccessSemantics>(accessSemantics)}
|
||||
, sourceId{sourceId}
|
||||
|
||||
{}
|
||||
|
||||
explicit Type(Utils::SmallStringView moduleName,
|
||||
explicit Type(int moduleId,
|
||||
Utils::SmallStringView typeName,
|
||||
long long typeId,
|
||||
Utils::SmallStringView prototype,
|
||||
@@ -677,22 +677,7 @@ public:
|
||||
int sourceId)
|
||||
: typeName{typeName}
|
||||
, prototype{NativeType{prototype}}
|
||||
, module{moduleName}
|
||||
, accessSemantics{static_cast<TypeAccessSemantics>(accessSemantics)}
|
||||
, sourceId{sourceId}
|
||||
, typeId{typeId}
|
||||
{}
|
||||
|
||||
explicit Type(Utils::SmallStringView moduleName,
|
||||
int moduleId,
|
||||
Utils::SmallStringView typeName,
|
||||
long long typeId,
|
||||
Utils::SmallStringView prototype,
|
||||
int accessSemantics,
|
||||
int sourceId)
|
||||
: typeName{typeName}
|
||||
, prototype{NativeType{prototype}}
|
||||
, module{moduleName, moduleId}
|
||||
, moduleId{moduleId}
|
||||
, accessSemantics{static_cast<TypeAccessSemantics>(accessSemantics)}
|
||||
, sourceId{sourceId}
|
||||
, typeId{typeId}
|
||||
@@ -705,7 +690,7 @@ public:
|
||||
&& first.propertyDeclarations == second.propertyDeclarations
|
||||
&& first.functionDeclarations == second.functionDeclarations
|
||||
&& first.signalDeclarations == second.signalDeclarations
|
||||
&& first.module == second.module && first.sourceId == second.sourceId
|
||||
&& first.moduleId == second.moduleId && first.sourceId == second.sourceId
|
||||
&& first.sourceId == second.sourceId;
|
||||
}
|
||||
|
||||
@@ -717,7 +702,6 @@ public:
|
||||
FunctionDeclarations functionDeclarations;
|
||||
SignalDeclarations signalDeclarations;
|
||||
EnumerationDeclarations enumerationDeclarations;
|
||||
Module module;
|
||||
TypeAccessSemantics accessSemantics = TypeAccessSemantics::Invalid;
|
||||
SourceId sourceId;
|
||||
TypeId typeId;
|
||||
|
@@ -71,13 +71,12 @@ void ProjectUpdater::update()
|
||||
|
||||
sourceIds.push_back(qmlDirSourceId);
|
||||
|
||||
Utils::SmallString moduleName{parser.typeNamespace()};
|
||||
SourceContextId directoryId = m_pathCache.sourceContextId(qmlDirSourceId);
|
||||
|
||||
parseTypeInfos(parser.typeInfos(), directoryId, imports, types, sourceIds, fileStatuses);
|
||||
parseQmlComponents(createComponentReferences(parser.components()),
|
||||
directoryId,
|
||||
moduleName,
|
||||
ModuleId{&qmlDirSourceId},
|
||||
imports,
|
||||
types,
|
||||
sourceIds,
|
||||
@@ -151,7 +150,7 @@ void ProjectUpdater::parseTypeInfo(SourceId sourceId,
|
||||
|
||||
void ProjectUpdater::parseQmlComponents(ComponentReferences components,
|
||||
SourceContextId directoryId,
|
||||
Utils::SmallStringView moduleName,
|
||||
ModuleId moduleId,
|
||||
Storage::Imports &imports,
|
||||
Storage::Types &types,
|
||||
SourceIds &sourceIds,
|
||||
@@ -184,7 +183,7 @@ void ProjectUpdater::parseQmlComponents(ComponentReferences components,
|
||||
auto type = m_qmlDocumentParser.parse(content, imports);
|
||||
|
||||
type.typeName = fileName;
|
||||
type.module.name = moduleName;
|
||||
type.moduleId = moduleId;
|
||||
type.accessSemantics = Storage::TypeAccessSemantics::Reference;
|
||||
type.sourceId = sourceId;
|
||||
type.exportedTypes.push_back(
|
||||
|
@@ -105,7 +105,7 @@ private:
|
||||
FileStatuses &fileStatuses);
|
||||
void parseQmlComponents(ComponentReferences components,
|
||||
SourceContextId directoryId,
|
||||
Utils::SmallStringView moduleName,
|
||||
ModuleId moduleId,
|
||||
Storage::Imports &imports,
|
||||
Storage::Types &types,
|
||||
SourceIds &sourceIds,
|
||||
|
@@ -1101,7 +1101,7 @@ std::ostream &operator<<(std::ostream &out, const QualifiedImportedType &importe
|
||||
std::ostream &operator<<(std::ostream &out, const Type &type)
|
||||
{
|
||||
using Utils::operator<<;
|
||||
return out << "(module: " << type.module << ", typename: \"" << type.typeName
|
||||
return out << "(moduleId: " << type.moduleId << ", typename: \"" << type.typeName
|
||||
<< "\", prototype: " << type.prototype << ", " << type.accessSemantics
|
||||
<< ", source: " << type.sourceId << ", exports: " << type.exportedTypes
|
||||
<< ", properties: " << type.propertyDeclarations
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -49,17 +49,17 @@ using QmlDesigner::IdPaths;
|
||||
using QmlDesigner::Storage::Version;
|
||||
|
||||
MATCHER_P5(IsStorageType,
|
||||
module,
|
||||
moduleId,
|
||||
typeName,
|
||||
prototype,
|
||||
accessSemantics,
|
||||
sourceId,
|
||||
std::string(negation ? "isn't " : "is ")
|
||||
+ PrintToString(Storage::Type{module, typeName, prototype, accessSemantics, sourceId}))
|
||||
+ PrintToString(Storage::Type{moduleId, typeName, prototype, accessSemantics, sourceId}))
|
||||
{
|
||||
const Storage::Type &type = arg;
|
||||
|
||||
return type.module == module && type.typeName == typeName
|
||||
return type.moduleId == moduleId && type.typeName == typeName
|
||||
&& type.accessSemantics == accessSemantics && type.sourceId == sourceId
|
||||
&& Storage::ImportedTypeName{prototype} == type.prototype;
|
||||
}
|
||||
@@ -199,18 +199,20 @@ protected:
|
||||
qmlDocumentParserMock,
|
||||
qmlTypesParserMock};
|
||||
SourceId objectTypeSourceId{sourcePathCache.sourceId("/path/Object")};
|
||||
Storage::Type objectType{Storage::Module{"Qml"},
|
||||
|
||||
SourceId qmltypesPathSourceId = sourcePathCache.sourceId("/path/example.qmltypes");
|
||||
SourceId qmltypes2PathSourceId = sourcePathCache.sourceId("/path/example2.qmltypes");
|
||||
SourceId qmlDirPathSourceId = sourcePathCache.sourceId("/path/qmldir");
|
||||
QmlDesigner::ModuleId exampleModuleId{&qmlDirPathSourceId};
|
||||
SourceId qmlDocumentSourceId1 = sourcePathCache.sourceId("/path/First.qml");
|
||||
SourceId qmlDocumentSourceId2 = sourcePathCache.sourceId("/path/First.2.qml");
|
||||
SourceId qmlDocumentSourceId3 = sourcePathCache.sourceId("/path/Second.qml");
|
||||
Storage::Type objectType{exampleModuleId,
|
||||
"QObject",
|
||||
Storage::NativeType{},
|
||||
Storage::TypeAccessSemantics::Reference,
|
||||
objectTypeSourceId,
|
||||
{Storage::ExportedType{"Object"}, Storage::ExportedType{"Obj"}}};
|
||||
SourceId qmltypesPathSourceId = sourcePathCache.sourceId("/path/example.qmltypes");
|
||||
SourceId qmltypes2PathSourceId = sourcePathCache.sourceId("/path/example2.qmltypes");
|
||||
SourceId qmlDirPathSourceId = sourcePathCache.sourceId("/path/qmldir");
|
||||
SourceId qmlDocumentSourceId1 = sourcePathCache.sourceId("/path/First.qml");
|
||||
SourceId qmlDocumentSourceId2 = sourcePathCache.sourceId("/path/First.2.qml");
|
||||
SourceId qmlDocumentSourceId3 = sourcePathCache.sourceId("/path/Second.qml");
|
||||
QString qmlDocument1{"First{}"};
|
||||
QString qmlDocument2{"Second{}"};
|
||||
QString qmlDocument3{"Third{}"};
|
||||
@@ -417,21 +419,21 @@ TEST_F(ProjectStorageUpdater, SynchronizeQmlDocuments)
|
||||
synchronize(ElementsAre(IsModule("Example", qmlDirPathSourceId)),
|
||||
UnorderedElementsAre(import1, import2, import3),
|
||||
UnorderedElementsAre(
|
||||
AllOf(IsStorageType(Storage::Module{"Example"},
|
||||
AllOf(IsStorageType(exampleModuleId,
|
||||
"First.qml",
|
||||
Storage::ImportedType{"Object"},
|
||||
TypeAccessSemantics::Reference,
|
||||
qmlDocumentSourceId1),
|
||||
Field(&Storage::Type::exportedTypes,
|
||||
ElementsAre(IsExportedType("FirstType", 1, 0)))),
|
||||
AllOf(IsStorageType(Storage::Module{"Example"},
|
||||
AllOf(IsStorageType(exampleModuleId,
|
||||
"First.2.qml",
|
||||
Storage::ImportedType{"Object2"},
|
||||
TypeAccessSemantics::Reference,
|
||||
qmlDocumentSourceId2),
|
||||
Field(&Storage::Type::exportedTypes,
|
||||
ElementsAre(IsExportedType("FirstType", 2, 2)))),
|
||||
AllOf(IsStorageType(Storage::Module{"Example"},
|
||||
AllOf(IsStorageType(exampleModuleId,
|
||||
"Second.qml",
|
||||
Storage::ImportedType{"Object3"},
|
||||
TypeAccessSemantics::Reference,
|
||||
@@ -462,14 +464,14 @@ TEST_F(ProjectStorageUpdater, SynchronizeQmlDocumentsDontUpdateIfUpToDate)
|
||||
projectStorageMock,
|
||||
synchronize(ElementsAre(IsModule("Example", qmlDirPathSourceId)),
|
||||
UnorderedElementsAre(import1, import2),
|
||||
UnorderedElementsAre(AllOf(IsStorageType(Storage::Module{"Example"},
|
||||
UnorderedElementsAre(AllOf(IsStorageType(exampleModuleId,
|
||||
"First.qml",
|
||||
Storage::ImportedType{"Object"},
|
||||
TypeAccessSemantics::Reference,
|
||||
qmlDocumentSourceId1),
|
||||
Field(&Storage::Type::exportedTypes,
|
||||
ElementsAre(IsExportedType("FirstType", 1, 0)))),
|
||||
AllOf(IsStorageType(Storage::Module{"Example"},
|
||||
AllOf(IsStorageType(exampleModuleId,
|
||||
"First.2.qml",
|
||||
Storage::ImportedType{"Object2"},
|
||||
TypeAccessSemantics::Reference,
|
||||
@@ -509,4 +511,15 @@ TEST_F(ProjectStorageUpdater, SynchronizeModules)
|
||||
updater.update();
|
||||
}
|
||||
|
||||
TEST_F(ProjectStorageUpdater, UpdateQmldirDocuments)
|
||||
{
|
||||
QString qmldir{"module Example\nFirstType 1.1 First.qml\nFirstType 2.2 "
|
||||
"First.2.qml\nSecondType 2.1 OldSecond.qml\nSecondType 2.2 Second.qml\n"};
|
||||
ON_CALL(fileSystemMock, contentAsQString(Eq(QString("/path/qmldir")))).WillByDefault(Return(qmldir));
|
||||
ON_CALL(projectStorageMock, fetchFileStatus(Eq(qmlDocumentSourceId3)))
|
||||
.WillByDefault(Return(FileStatus{qmlDocumentSourceId3, 22, 14}));
|
||||
|
||||
updater.pathsWithIdsChanged({});
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
Reference in New Issue
Block a user