forked from qt-creator/qt-creator
QmlDesigner: Add exportedTypeNames(TypeId) to project storage
Task-number: QDS-10265 Change-Id: If440f87b6719b865216e3890c8492c3682cf42dd Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io> Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io>
This commit is contained in:
@@ -153,6 +153,12 @@ public:
|
|||||||
return Sqlite::withDeferredTransaction(database, [&] { return fetchTypeId(typeNameId); });
|
return Sqlite::withDeferredTransaction(database, [&] { return fetchTypeId(typeNameId); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Storage::Info::ExportedTypeNames exportedTypeNames(TypeId typeId) const override
|
||||||
|
{
|
||||||
|
return selectExportedTypesByTypeIdStatement
|
||||||
|
.template valuesWithTransaction<Storage::Info::ExportedTypeName>(4, typeId);
|
||||||
|
}
|
||||||
|
|
||||||
ImportId importId(const Storage::Import &import) const override
|
ImportId importId(const Storage::Import &import) const override
|
||||||
{
|
{
|
||||||
return Sqlite::withDeferredTransaction(database, [&] {
|
return Sqlite::withDeferredTransaction(database, [&] {
|
||||||
@@ -2748,7 +2754,7 @@ public:
|
|||||||
" ON defaultPropertyId=propertyDeclarationId WHERE t.typeId=?",
|
" ON defaultPropertyId=propertyDeclarationId WHERE t.typeId=?",
|
||||||
database};
|
database};
|
||||||
mutable ReadStatement<4, 1> selectExportedTypesByTypeIdStatement{
|
mutable ReadStatement<4, 1> selectExportedTypesByTypeIdStatement{
|
||||||
"SELECT moduleId, name, majorVersion, minorVersion FROM "
|
"SELECT moduleId, name, ifnull(majorVersion, -1), ifnull(minorVersion, -1) FROM "
|
||||||
"exportedTypeNames WHERE typeId=?",
|
"exportedTypeNames WHERE typeId=?",
|
||||||
database};
|
database};
|
||||||
mutable ReadStatement<7> selectTypesStatement{
|
mutable ReadStatement<7> selectTypesStatement{
|
||||||
|
@@ -63,10 +63,115 @@ constexpr TypeTraits operator&(TypeTraits first, TypeTraits second)
|
|||||||
|
|
||||||
using TypeNameString = ::Utils::BasicSmallString<63>;
|
using TypeNameString = ::Utils::BasicSmallString<63>;
|
||||||
|
|
||||||
|
class VersionNumber
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit VersionNumber() = default;
|
||||||
|
explicit VersionNumber(int value)
|
||||||
|
: value{value}
|
||||||
|
{}
|
||||||
|
|
||||||
|
explicit operator bool() const { return value >= 0; }
|
||||||
|
|
||||||
|
friend bool operator==(VersionNumber first, VersionNumber second) noexcept
|
||||||
|
{
|
||||||
|
return first.value == second.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend bool operator!=(VersionNumber first, VersionNumber second) noexcept
|
||||||
|
{
|
||||||
|
return !(first == second);
|
||||||
|
}
|
||||||
|
|
||||||
|
friend bool operator<(VersionNumber first, VersionNumber second) noexcept
|
||||||
|
{
|
||||||
|
return first.value < second.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
int value = -1;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Version
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit Version() = default;
|
||||||
|
explicit Version(VersionNumber major, VersionNumber minor = VersionNumber{})
|
||||||
|
: major{major}
|
||||||
|
, minor{minor}
|
||||||
|
{}
|
||||||
|
|
||||||
|
explicit Version(int major, int minor)
|
||||||
|
: major{major}
|
||||||
|
, minor{minor}
|
||||||
|
{}
|
||||||
|
|
||||||
|
explicit Version(int major)
|
||||||
|
: major{major}
|
||||||
|
{}
|
||||||
|
|
||||||
|
friend bool operator==(Version first, Version second) noexcept
|
||||||
|
{
|
||||||
|
return first.major == second.major && first.minor == second.minor;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend bool operator<(Version first, Version second) noexcept
|
||||||
|
{
|
||||||
|
return std::tie(first.major, first.minor) < std::tie(second.major, second.minor);
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit operator bool() const { return major && minor; }
|
||||||
|
|
||||||
|
public:
|
||||||
|
VersionNumber major;
|
||||||
|
VersionNumber minor;
|
||||||
|
};
|
||||||
} // namespace QmlDesigner::Storage
|
} // namespace QmlDesigner::Storage
|
||||||
|
|
||||||
namespace QmlDesigner::Storage::Info {
|
namespace QmlDesigner::Storage::Info {
|
||||||
|
|
||||||
|
class ExportedTypeName
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit ExportedTypeName() = default;
|
||||||
|
|
||||||
|
explicit ExportedTypeName(ModuleId moduleId,
|
||||||
|
::Utils::SmallStringView name,
|
||||||
|
Storage::Version version = Storage::Version{})
|
||||||
|
: name{name}
|
||||||
|
, version{version}
|
||||||
|
, moduleId{moduleId}
|
||||||
|
{}
|
||||||
|
|
||||||
|
explicit ExportedTypeName(ModuleId moduleId,
|
||||||
|
::Utils::SmallStringView name,
|
||||||
|
int majorVersion,
|
||||||
|
int minorVersion)
|
||||||
|
: name{name}
|
||||||
|
, version{majorVersion, minorVersion}
|
||||||
|
, moduleId{moduleId}
|
||||||
|
{}
|
||||||
|
|
||||||
|
friend bool operator==(const ExportedTypeName &first, const ExportedTypeName &second)
|
||||||
|
{
|
||||||
|
return first.moduleId == second.moduleId && first.version == second.version
|
||||||
|
&& first.name == second.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend bool operator<(const ExportedTypeName &first, const ExportedTypeName &second)
|
||||||
|
{
|
||||||
|
return std::tie(first.moduleId, first.name, first.version)
|
||||||
|
< std::tie(second.moduleId, second.name, second.version);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
::Utils::SmallString name;
|
||||||
|
Storage::Version version;
|
||||||
|
ModuleId moduleId;
|
||||||
|
};
|
||||||
|
|
||||||
|
using ExportedTypeNames = std::vector<ExportedTypeName>;
|
||||||
|
|
||||||
class PropertyDeclaration
|
class PropertyDeclaration
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@@ -26,6 +26,7 @@ public:
|
|||||||
Storage::Version version) const
|
Storage::Version version) const
|
||||||
= 0;
|
= 0;
|
||||||
virtual TypeId typeId(ImportedTypeNameId typeNameId) const = 0;
|
virtual TypeId typeId(ImportedTypeNameId typeNameId) const = 0;
|
||||||
|
virtual Storage::Info::ExportedTypeNames exportedTypeNames(TypeId typeId) const = 0;
|
||||||
virtual ImportId importId(const Storage::Import &import) const = 0;
|
virtual ImportId importId(const Storage::Import &import) const = 0;
|
||||||
virtual ImportedTypeNameId importedTypeNameId(ImportId sourceId, Utils::SmallStringView typeName)
|
virtual ImportedTypeNameId importedTypeNameId(ImportId sourceId, Utils::SmallStringView typeName)
|
||||||
= 0;
|
= 0;
|
||||||
|
@@ -15,70 +15,6 @@
|
|||||||
|
|
||||||
namespace QmlDesigner::Storage {
|
namespace QmlDesigner::Storage {
|
||||||
|
|
||||||
class VersionNumber
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit VersionNumber() = default;
|
|
||||||
explicit VersionNumber(int value)
|
|
||||||
: value{value}
|
|
||||||
{}
|
|
||||||
|
|
||||||
explicit operator bool() const { return value >= 0; }
|
|
||||||
|
|
||||||
friend bool operator==(VersionNumber first, VersionNumber second) noexcept
|
|
||||||
{
|
|
||||||
return first.value == second.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend bool operator!=(VersionNumber first, VersionNumber second) noexcept
|
|
||||||
{
|
|
||||||
return !(first == second);
|
|
||||||
}
|
|
||||||
|
|
||||||
friend bool operator<(VersionNumber first, VersionNumber second) noexcept
|
|
||||||
{
|
|
||||||
return first.value < second.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
int value = -1;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Version
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit Version() = default;
|
|
||||||
explicit Version(VersionNumber major, VersionNumber minor = VersionNumber{})
|
|
||||||
: major{major}
|
|
||||||
, minor{minor}
|
|
||||||
{}
|
|
||||||
|
|
||||||
explicit Version(int major, int minor)
|
|
||||||
: major{major}
|
|
||||||
, minor{minor}
|
|
||||||
{}
|
|
||||||
|
|
||||||
explicit Version(int major)
|
|
||||||
: major{major}
|
|
||||||
{}
|
|
||||||
|
|
||||||
friend bool operator==(Version first, Version second) noexcept
|
|
||||||
{
|
|
||||||
return first.major == second.major && first.minor == second.minor;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend bool operator<(Version first, Version second) noexcept
|
|
||||||
{
|
|
||||||
return std::tie(first.major, first.minor) < std::tie(second.major, second.minor);
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit operator bool() const { return major && minor; }
|
|
||||||
|
|
||||||
public:
|
|
||||||
VersionNumber major;
|
|
||||||
VersionNumber minor;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Import
|
class Import
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@@ -5,6 +5,8 @@ add_qtc_library(TestMatchers OBJECT
|
|||||||
DEPENDS
|
DEPENDS
|
||||||
Googletest Utils QmlDesigner
|
Googletest Utils QmlDesigner
|
||||||
SOURCES
|
SOURCES
|
||||||
|
info_exportedtypenames-matcher.h
|
||||||
import-matcher.h
|
import-matcher.h
|
||||||
unittest-matchers.h
|
unittest-matchers.h
|
||||||
|
version-matcher.h
|
||||||
)
|
)
|
||||||
|
@@ -3,36 +3,10 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "version-matcher.h"
|
||||||
|
|
||||||
#include <projectstorage/projectstoragetypes.h>
|
#include <projectstorage/projectstoragetypes.h>
|
||||||
|
|
||||||
#include <gmock/gmock-matchers.h>
|
|
||||||
#include <gmock/gmock-more-matchers.h>
|
|
||||||
|
|
||||||
template<typename Matcher>
|
|
||||||
auto IsVersionNumber(const Matcher &matcher)
|
|
||||||
{
|
|
||||||
return Field(&QmlDesigner::Storage::VersionNumber::value, matcher);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Matcher>
|
|
||||||
auto IsMinorVersion(const Matcher &matcher)
|
|
||||||
{
|
|
||||||
return Field(&QmlDesigner::Storage::Version::minor, matcher);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Matcher>
|
|
||||||
auto IsMajorVersion(const Matcher &matcher)
|
|
||||||
{
|
|
||||||
return Field(&QmlDesigner::Storage::Version::major, matcher);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename MajorMatcher, typename MinorMatcher>
|
|
||||||
auto IsVersion(const MajorMatcher &majorMatcher, const MinorMatcher &minorMatcher)
|
|
||||||
{
|
|
||||||
return AllOf(IsMajorVersion(IsVersionNumber(majorMatcher)),
|
|
||||||
IsMinorVersion(IsVersionNumber(minorMatcher)));
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename ModuleIdMatcher,
|
template<typename ModuleIdMatcher,
|
||||||
typename SourceIdMatcher,
|
typename SourceIdMatcher,
|
||||||
typename MajorVersionMatcher,
|
typename MajorVersionMatcher,
|
||||||
|
33
tests/unit/tests/matchers/info_exportedtypenames-matcher.h
Normal file
33
tests/unit/tests/matchers/info_exportedtypenames-matcher.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
// Copyright (C) 2023 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "version-matcher.h"
|
||||||
|
|
||||||
|
#include <projectstorage/projectstorageinfotypes.h>
|
||||||
|
|
||||||
|
template<typename ModuleIdMatcher,
|
||||||
|
typename NameMatcher,
|
||||||
|
typename MajorVersionMatcher,
|
||||||
|
typename MinorVersionMatcher>
|
||||||
|
auto IsInfoExportTypeNames(const ModuleIdMatcher &moduleIdMatcher,
|
||||||
|
const NameMatcher &nameMatcher,
|
||||||
|
const MajorVersionMatcher &majorVersionMatcher,
|
||||||
|
const MinorVersionMatcher &minorVersionMatcher)
|
||||||
|
{
|
||||||
|
return AllOf(Field(&QmlDesigner::Storage::Info::ExportedTypeName::moduleId, moduleIdMatcher),
|
||||||
|
Field(&QmlDesigner::Storage::Info::ExportedTypeName::name, nameMatcher),
|
||||||
|
Field(&QmlDesigner::Storage::Info::ExportedTypeName::version,
|
||||||
|
IsVersion(majorVersionMatcher, minorVersionMatcher)));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename ModuleIdMatcher, typename NameMatcher, typename VersionMatcher>
|
||||||
|
auto IsInfoExportTypeNames(const ModuleIdMatcher &moduleIdMatcher,
|
||||||
|
const NameMatcher &nameMatcher,
|
||||||
|
const VersionMatcher &versionMatcher)
|
||||||
|
{
|
||||||
|
return AllOf(Field(&QmlDesigner::Storage::Info::ExportedTypeName::moduleId, moduleIdMatcher),
|
||||||
|
Field(&QmlDesigner::Storage::Info::ExportedTypeName::name, nameMatcher),
|
||||||
|
Field(&QmlDesigner::Storage::Info::ExportedTypeName::version, versionMatcher));
|
||||||
|
}
|
34
tests/unit/tests/matchers/version-matcher.h
Normal file
34
tests/unit/tests/matchers/version-matcher.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
// Copyright (C) 2023 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <projectstorage/projectstorageinfotypes.h>
|
||||||
|
|
||||||
|
#include <gmock/gmock-matchers.h>
|
||||||
|
#include <gmock/gmock-more-matchers.h>
|
||||||
|
|
||||||
|
template<typename Matcher>
|
||||||
|
auto IsVersionNumber(const Matcher &matcher)
|
||||||
|
{
|
||||||
|
return Field(&QmlDesigner::Storage::VersionNumber::value, matcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Matcher>
|
||||||
|
auto IsMinorVersion(const Matcher &matcher)
|
||||||
|
{
|
||||||
|
return Field(&QmlDesigner::Storage::Version::minor, matcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Matcher>
|
||||||
|
auto IsMajorVersion(const Matcher &matcher)
|
||||||
|
{
|
||||||
|
return Field(&QmlDesigner::Storage::Version::major, matcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename MajorMatcher, typename MinorMatcher>
|
||||||
|
auto IsVersion(const MajorMatcher &majorMatcher, const MinorMatcher &minorMatcher)
|
||||||
|
{
|
||||||
|
return AllOf(IsMajorVersion(IsVersionNumber(majorMatcher)),
|
||||||
|
IsMinorVersion(IsVersionNumber(minorMatcher)));
|
||||||
|
}
|
@@ -114,6 +114,11 @@ public:
|
|||||||
QmlDesigner::Storage::Version version),
|
QmlDesigner::Storage::Version version),
|
||||||
(const, override));
|
(const, override));
|
||||||
|
|
||||||
|
MOCK_METHOD(QmlDesigner::Storage::Info::ExportedTypeNames,
|
||||||
|
exportedTypeNames,
|
||||||
|
(QmlDesigner::TypeId),
|
||||||
|
(const, override));
|
||||||
|
|
||||||
MOCK_METHOD(QmlDesigner::ImportId,
|
MOCK_METHOD(QmlDesigner::ImportId,
|
||||||
importId,
|
importId,
|
||||||
(const QmlDesigner::Storage::Import &import),
|
(const QmlDesigner::Storage::Import &import),
|
||||||
|
@@ -600,6 +600,11 @@ std::ostream &operator<<(std::ostream &out, const Type &type)
|
|||||||
{
|
{
|
||||||
return out << "(" << type.defaultPropertyId << ")";
|
return out << "(" << type.defaultPropertyId << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ostream &operator<<(std::ostream &out, const ExportedTypeName &name)
|
||||||
|
{
|
||||||
|
return out << "(\"" << name.name << "\"," << name.moduleId << ", " << name.version << ")";
|
||||||
|
}
|
||||||
} // namespace Storage::Info
|
} // namespace Storage::Info
|
||||||
|
|
||||||
namespace Storage::Synchronization {
|
namespace Storage::Synchronization {
|
||||||
|
@@ -170,9 +170,11 @@ std::ostream &operator<<(std::ostream &out, Version version);
|
|||||||
namespace Storage::Info {
|
namespace Storage::Info {
|
||||||
class ProjectDeclaration;
|
class ProjectDeclaration;
|
||||||
class Type;
|
class Type;
|
||||||
|
class ExportedTypeName;
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &out, const ProjectDeclaration &declaration);
|
std::ostream &operator<<(std::ostream &out, const ProjectDeclaration &declaration);
|
||||||
std::ostream &operator<<(std::ostream &out, const Type &type);
|
std::ostream &operator<<(std::ostream &out, const Type &type);
|
||||||
|
std::ostream &operator<<(std::ostream &out, const ExportedTypeName &name);
|
||||||
|
|
||||||
} // namespace Storage::Info
|
} // namespace Storage::Info
|
||||||
|
|
||||||
|
@@ -25,27 +25,6 @@ add_qtc_test(unittest GTEST
|
|||||||
unittests-main.cpp
|
unittests-main.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
function(extend_qtc_test_with_target_sources target)
|
|
||||||
cmake_parse_arguments(_arg "" "" "DEFINES;INCLUDES" ${ARGN})
|
|
||||||
|
|
||||||
get_target_property(${target}Sources ${target} SOURCES)
|
|
||||||
# work around issue with CMake < 3.14 where target sources can contain
|
|
||||||
# $<TARGET_OBJECTS:...>
|
|
||||||
list(FILTER ${target}Sources EXCLUDE REGEX "^\\$<TARGET_OBJECTS:.*")
|
|
||||||
|
|
||||||
get_target_property(${target}SourcesDir ${target} SOURCES_DIR)
|
|
||||||
extend_qtc_test(unittest
|
|
||||||
SOURCES_PREFIX "${${target}SourcesDir}"
|
|
||||||
SOURCES ${${target}Sources}
|
|
||||||
DEFINES
|
|
||||||
$<TARGET_PROPERTY:${target},INTERFACE_COMPILE_DEFINITIONS>
|
|
||||||
${_arg_DEFINES}
|
|
||||||
INCLUDES
|
|
||||||
$<TARGET_PROPERTY:${target},INTERFACE_INCLUDE_DIRECTORIES>
|
|
||||||
${_arg_INCLUDES}
|
|
||||||
)
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
finalize_qtc_gtest(unittest
|
finalize_qtc_gtest(unittest
|
||||||
EXCLUDE_SOURCES_REGEX ".c$"
|
EXCLUDE_SOURCES_REGEX ".c$"
|
||||||
EXCLUDE_ALL_FROM_PRECHECK
|
EXCLUDE_ALL_FROM_PRECHECK
|
||||||
|
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include "../utils/googletest.h"
|
#include "../utils/googletest.h"
|
||||||
|
|
||||||
|
#include <matchers/info_exportedtypenames-matcher.h>
|
||||||
|
|
||||||
#include <modelnode.h>
|
#include <modelnode.h>
|
||||||
#include <projectstorage/projectstorage.h>
|
#include <projectstorage/projectstorage.h>
|
||||||
#include <projectstorage/sourcepathcache.h>
|
#include <projectstorage/sourcepathcache.h>
|
||||||
@@ -6943,4 +6945,29 @@ TEST_F(ProjectStorage, synchronize_document_imports_adds_import)
|
|||||||
ASSERT_TRUE(storage.importId(imports.back()));
|
ASSERT_TRUE(storage.importId(imports.back()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ProjectStorage, get_exported_type_names)
|
||||||
|
{
|
||||||
|
auto package{createSimpleSynchronizationPackage()};
|
||||||
|
storage.synchronize(package);
|
||||||
|
auto typeId = fetchTypeId(sourceId2, "QObject");
|
||||||
|
|
||||||
|
auto exportedTypeNames = storage.exportedTypeNames(typeId);
|
||||||
|
|
||||||
|
ASSERT_THAT(exportedTypeNames,
|
||||||
|
UnorderedElementsAre(IsInfoExportTypeNames(qmlModuleId, "Object", 2, -1),
|
||||||
|
IsInfoExportTypeNames(qmlModuleId, "Obj", 2, -1),
|
||||||
|
IsInfoExportTypeNames(qmlNativeModuleId, "QObject", -1, -1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(ProjectStorage, get_no_exported_type_names_if_type_id_is_invalid)
|
||||||
|
{
|
||||||
|
auto package{createSimpleSynchronizationPackage()};
|
||||||
|
storage.synchronize(package);
|
||||||
|
TypeId typeId;
|
||||||
|
|
||||||
|
auto exportedTypeNames = storage.exportedTypeNames(typeId);
|
||||||
|
|
||||||
|
ASSERT_THAT(exportedTypeNames, IsEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
Reference in New Issue
Block a user