forked from qt-creator/qt-creator
QmlDesigner: Add singleton support to the QmlTypesParser
Task-number: QDS-13602 Change-Id: Ie3506ffe36ba232dcd3fa888cc29064bdb44f872 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -132,6 +132,7 @@ struct TypeTraits
|
|||||||
, isEnum{false}
|
, isEnum{false}
|
||||||
, isFileComponent{false}
|
, isFileComponent{false}
|
||||||
, usesCustomParser{false}
|
, usesCustomParser{false}
|
||||||
|
, isSingleton{false}
|
||||||
, dummy{0U}
|
, dummy{0U}
|
||||||
, canBeContainer{FlagIs::False}
|
, canBeContainer{FlagIs::False}
|
||||||
, forceClip{FlagIs::False}
|
, forceClip{FlagIs::False}
|
||||||
@@ -204,7 +205,8 @@ struct TypeTraits
|
|||||||
unsigned int isEnum : 1;
|
unsigned int isEnum : 1;
|
||||||
unsigned int isFileComponent : 1;
|
unsigned int isFileComponent : 1;
|
||||||
unsigned int usesCustomParser : 1;
|
unsigned int usesCustomParser : 1;
|
||||||
unsigned int dummy : 25;
|
unsigned int isSingleton : 1;
|
||||||
|
unsigned int dummy : 24;
|
||||||
};
|
};
|
||||||
|
|
||||||
unsigned int type;
|
unsigned int type;
|
||||||
|
@@ -118,13 +118,18 @@ Storage::TypeTraits createAccessTypeTraits(QQmlJSScope::AccessSemantics accessSe
|
|||||||
return Storage::TypeTraitsKind::None;
|
return Storage::TypeTraitsKind::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
Storage::TypeTraits createTypeTraits(QQmlJSScope::AccessSemantics accessSematics, bool hasCustomParser)
|
Storage::TypeTraits createTypeTraits(QQmlJSScope::AccessSemantics accessSematics,
|
||||||
|
bool hasCustomParser,
|
||||||
|
bool isSingleton)
|
||||||
{
|
{
|
||||||
auto typeTrait = createAccessTypeTraits(accessSematics);
|
auto typeTrait = createAccessTypeTraits(accessSematics);
|
||||||
|
|
||||||
if (hasCustomParser)
|
if (hasCustomParser)
|
||||||
typeTrait.usesCustomParser = true;
|
typeTrait.usesCustomParser = true;
|
||||||
|
|
||||||
|
if (isSingleton)
|
||||||
|
typeTrait.isSingleton = true;
|
||||||
|
|
||||||
return typeTrait;
|
return typeTrait;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -451,7 +456,9 @@ void addType(Storage::Synchronization::Types &types,
|
|||||||
Utils::SmallStringView{typeName},
|
Utils::SmallStringView{typeName},
|
||||||
Storage::Synchronization::ImportedType{TypeNameString{component.baseTypeName()}},
|
Storage::Synchronization::ImportedType{TypeNameString{component.baseTypeName()}},
|
||||||
Storage::Synchronization::ImportedType{TypeNameString{component.extensionTypeName()}},
|
Storage::Synchronization::ImportedType{TypeNameString{component.extensionTypeName()}},
|
||||||
createTypeTraits(component.accessSemantics(), component.hasCustomParser()),
|
createTypeTraits(component.accessSemantics(),
|
||||||
|
component.hasCustomParser(),
|
||||||
|
component.isSingleton()),
|
||||||
sourceId,
|
sourceId,
|
||||||
createExports(exports, typeName, storage, cppModuleId),
|
createExports(exports, typeName, storage, cppModuleId),
|
||||||
createProperties(component.ownProperties(), enumerationTypes, componentNameWithoutNamespace),
|
createProperties(component.ownProperties(), enumerationTypes, componentNameWithoutNamespace),
|
||||||
|
@@ -63,13 +63,20 @@ MATCHER_P(HasFlag, flag, std::string(negation ? "hasn't " : "has ") + PrintToStr
|
|||||||
|
|
||||||
MATCHER_P(UsesCustomParser,
|
MATCHER_P(UsesCustomParser,
|
||||||
value,
|
value,
|
||||||
std::string(negation ? "don't used custom parser " : "uses custom parser"))
|
std::string(negation ? "don't used custom parser " : "uses custom parser "))
|
||||||
{
|
{
|
||||||
const Storage::TypeTraits &traits = arg;
|
const Storage::TypeTraits &traits = arg;
|
||||||
|
|
||||||
return traits.usesCustomParser == value;
|
return traits.usesCustomParser == value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MATCHER_P(IsSingleton, value, std::string(negation ? "isn't singleton " : "is singleton "))
|
||||||
|
{
|
||||||
|
const Storage::TypeTraits &traits = arg;
|
||||||
|
|
||||||
|
return traits.isSingleton == value;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename Matcher>
|
template<typename Matcher>
|
||||||
auto IsTypeTrait(const Matcher &matcher)
|
auto IsTypeTrait(const Matcher &matcher)
|
||||||
{
|
{
|
||||||
@@ -878,4 +885,39 @@ TEST_F(QmlTypesParser, skip_template_item)
|
|||||||
qmltypesFileSourceId)));
|
qmltypesFileSourceId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(QmlTypesParser, is_singleton)
|
||||||
|
{
|
||||||
|
QString source{R"(import QtQuick.tooling 1.2
|
||||||
|
Module{
|
||||||
|
Component { name: "QObject"
|
||||||
|
isSingleton: true}})"};
|
||||||
|
|
||||||
|
parser.parse(source, imports, types, directoryInfo);
|
||||||
|
|
||||||
|
ASSERT_THAT(types, ElementsAre(IsTypeTrait(IsSingleton(true))));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(QmlTypesParser, is_not_singleton)
|
||||||
|
{
|
||||||
|
QString source{R"(import QtQuick.tooling 1.2
|
||||||
|
Module{
|
||||||
|
Component { name: "QObject"
|
||||||
|
isSingleton: false}})"};
|
||||||
|
|
||||||
|
parser.parse(source, imports, types, directoryInfo);
|
||||||
|
|
||||||
|
ASSERT_THAT(types, ElementsAre(IsTypeTrait(IsSingleton(false))));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(QmlTypesParser, is_by_default_not_singleton)
|
||||||
|
{
|
||||||
|
QString source{R"(import QtQuick.tooling 1.2
|
||||||
|
Module{
|
||||||
|
Component { name: "QObject"}})"};
|
||||||
|
|
||||||
|
parser.parse(source, imports, types, directoryInfo);
|
||||||
|
|
||||||
|
ASSERT_THAT(types, ElementsAre(IsTypeTrait(IsSingleton(false))));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
Reference in New Issue
Block a user