CppEditor: Prevent "Add Declaration" for existing template functions

class Foo
{
    template<class T>
    void func();
};

template<class T>
void Foo::func() {} // Add Declaration should not be triggered at all

Change-Id: Ifff733d8381177300dae017ae419200cfdf5c425
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
Orgad Shaneh
2016-07-31 22:29:39 +03:00
committed by Orgad Shaneh
parent 65dc6d0fc2
commit 2890966ec3
3 changed files with 28 additions and 1 deletions

View File

@@ -147,6 +147,7 @@ private slots:
void test_quickfix_InsertDefFromDecl_unicodeIdentifier(); void test_quickfix_InsertDefFromDecl_unicodeIdentifier();
void test_quickfix_InsertDeclFromDef(); void test_quickfix_InsertDeclFromDef();
void test_quickfix_InsertDeclFromDef_notTriggeredForTemplateFunc();
void test_quickfix_AddIncludeForUndefinedIdentifier_data(); void test_quickfix_AddIncludeForUndefinedIdentifier_data();
void test_quickfix_AddIncludeForUndefinedIdentifier(); void test_quickfix_AddIncludeForUndefinedIdentifier();

View File

@@ -2715,6 +2715,22 @@ void CppEditorPlugin::test_quickfix_InsertDeclFromDef()
insertToSectionDeclFromDef("private slots", 5); insertToSectionDeclFromDef("private slots", 5);
} }
void CppEditorPlugin::test_quickfix_InsertDeclFromDef_notTriggeredForTemplateFunc()
{
QByteArray contents =
"class Foo\n"
"{\n"
" template<class T>\n"
" void func();\n"
"};\n"
"\n"
"template<class T>\n"
"void Foo::fu@nc() {}\n";
InsertDeclFromDef factory;
QuickFixOperationTest(singleDocument(contents, ""), &factory);
}
void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_data() void CppEditorPlugin::test_quickfix_AddIncludeForUndefinedIdentifier_data()
{ {
QTest::addColumn<QString>("headerPath"); QTest::addColumn<QString>("headerPath");

View File

@@ -2465,7 +2465,17 @@ void InsertDeclFromDef::match(const CppQuickFixInterface &interface, QuickFixOpe
Function *fun = funDef->symbol; Function *fun = funDef->symbol;
if (Class *matchingClass = isMemberFunction(interface.context(), fun)) { if (Class *matchingClass = isMemberFunction(interface.context(), fun)) {
const QualifiedNameId *qName = fun->name()->asQualifiedNameId(); const QualifiedNameId *qName = fun->name()->asQualifiedNameId();
for (Symbol *s = matchingClass->find(qName->identifier()); s; s = s->next()) { for (Symbol *symbol = matchingClass->find(qName->identifier());
symbol; symbol = symbol->next()) {
Symbol *s = symbol;
if (fun->enclosingScope()->isTemplate()) {
if (const Template *templ = s->type()->asTemplateType()) {
if (Symbol *decl = templ->declaration()) {
if (decl->type()->isFunctionType())
s = decl;
}
}
}
if (!s->name() if (!s->name()
|| !qName->identifier()->match(s->identifier()) || !qName->identifier()->match(s->identifier())
|| !s->type()->isFunctionType()) || !s->type()->isFunctionType())