forked from qt-creator/qt-creator
CppEditor: Properly handle function types as template arguments
... when creating getters and setters. Fixes: QTCREATORBUG-27133 Change-Id: Ia77147a270fb1229c765ff9d5f03aa243d51fe97 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -84,10 +84,13 @@ void NamePrettyPrinter::visit(const TemplateNameId *name)
|
|||||||
|
|
||||||
TemplateArgument templArg = name->templateArgumentAt(index);
|
TemplateArgument templArg = name->templateArgumentAt(index);
|
||||||
QString arg;
|
QString arg;
|
||||||
if (templArg.type().isValid())
|
if (templArg.type().isValid()) {
|
||||||
arg = overview()->prettyType(templArg.type());
|
Overview o = *_overview;
|
||||||
else if (const NumericLiteral *num = templArg.numericLiteral())
|
o.showReturnTypes = true;
|
||||||
|
arg = o.prettyType(templArg.type());
|
||||||
|
} else if (const NumericLiteral *num = templArg.numericLiteral()) {
|
||||||
arg = QString::fromLatin1(num->chars(), num->size());
|
arg = QString::fromLatin1(num->chars(), num->size());
|
||||||
|
}
|
||||||
|
|
||||||
if (arg.isEmpty())
|
if (arg.isEmpty())
|
||||||
_name += QString::fromLatin1("_Tp%1").arg(index + 1);
|
_name += QString::fromLatin1("_Tp%1").arg(index + 1);
|
||||||
|
|||||||
@@ -3362,6 +3362,43 @@ void QuickfixTest::testGenerateGetterSetterOnlySetterHeaderFileWithIncludeGuard(
|
|||||||
QuickFixOperationTest(testDocuments, &factory, ProjectExplorer::HeaderPaths(), 0);
|
QuickFixOperationTest(testDocuments, &factory, ProjectExplorer::HeaderPaths(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QuickfixTest::testGenerateGetterFunctionAsTemplateArg()
|
||||||
|
{
|
||||||
|
QList<TestDocumentPtr> testDocuments;
|
||||||
|
const QByteArray original = R"(
|
||||||
|
template<typename T> class TS {};
|
||||||
|
template<typename T, typename U> class TS<T(U)> {};
|
||||||
|
|
||||||
|
class S2 {
|
||||||
|
TS<int(int)> @member;
|
||||||
|
};
|
||||||
|
)";
|
||||||
|
const QByteArray expected = R"(
|
||||||
|
template<typename T> class TS {};
|
||||||
|
template<typename T, typename U> class TS<T(U)> {};
|
||||||
|
|
||||||
|
class S2 {
|
||||||
|
TS<int(int)> member;
|
||||||
|
|
||||||
|
public:
|
||||||
|
const TS<int (int)> &getMember() const
|
||||||
|
{
|
||||||
|
return member;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
)";
|
||||||
|
|
||||||
|
testDocuments << CppTestDocument::create("file.h", original, expected);
|
||||||
|
|
||||||
|
QuickFixSettings s;
|
||||||
|
s->getterOutsideClassFrom = 0;
|
||||||
|
s->getterInCppFileFrom = 0;
|
||||||
|
s->getterNameTemplate = "get<Name>";
|
||||||
|
|
||||||
|
GenerateGetterSetter factory;
|
||||||
|
QuickFixOperationTest(testDocuments, &factory, ProjectExplorer::HeaderPaths(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
class CppCodeStyleSettingsChanger {
|
class CppCodeStyleSettingsChanger {
|
||||||
public:
|
public:
|
||||||
CppCodeStyleSettingsChanger(const CppCodeStyleSettings &settings);
|
CppCodeStyleSettingsChanger(const CppCodeStyleSettings &settings);
|
||||||
|
|||||||
@@ -115,6 +115,7 @@ private slots:
|
|||||||
void testGenerateGetterSetterOnlySetter();
|
void testGenerateGetterSetterOnlySetter();
|
||||||
void testGenerateGetterSetterInlineInHeaderFile();
|
void testGenerateGetterSetterInlineInHeaderFile();
|
||||||
void testGenerateGetterSetterOnlySetterHeaderFileWithIncludeGuard();
|
void testGenerateGetterSetterOnlySetterHeaderFileWithIncludeGuard();
|
||||||
|
void testGenerateGetterFunctionAsTemplateArg();
|
||||||
void testGenerateGettersSetters_data();
|
void testGenerateGettersSetters_data();
|
||||||
void testGenerateGettersSetters();
|
void testGenerateGettersSetters();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user