forked from qt-creator/qt-creator
CppEditor: InsertDefFromDecl: Hide when definition already exists
"Add Definition Inside/Outside Class" was wrongly shown when there was already an definition outside the class. Change-Id: I6409080c6a1a3abdd4511f7db14ecb4f63458411 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
committed by
Nikolai Kosjar
parent
17a81ae106
commit
d25c5f35ca
@@ -157,6 +157,7 @@ private slots:
|
||||
void test_quickfix_InsertDefFromDecl_headerSource_namespace2();
|
||||
void test_quickfix_InsertDefFromDecl_freeFunction();
|
||||
void test_quickfix_InsertDefFromDecl_insideClass();
|
||||
void test_quickfix_InsertDefFromDecl_notTriggeringWhenDefinitionExists();
|
||||
|
||||
void test_quickfix_InsertDeclFromDef();
|
||||
|
||||
|
||||
@@ -893,6 +893,21 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_insideClass()
|
||||
data.run(&factory, 1);
|
||||
}
|
||||
|
||||
/// Check not triggering when definition exists
|
||||
void CppEditorPlugin::test_quickfix_InsertDefFromDecl_notTriggeringWhenDefinitionExists()
|
||||
{
|
||||
const QByteArray original =
|
||||
"class Foo {\n"
|
||||
" void b@ar();\n"
|
||||
"};\n"
|
||||
"void Foo::bar() {}\n";
|
||||
const QByteArray expected = original + "\n";
|
||||
|
||||
InsertDefFromDecl factory;
|
||||
TestCase data(original, expected);
|
||||
data.run(&factory, 1);
|
||||
}
|
||||
|
||||
// Function for one of InsertDeclDef section cases
|
||||
void insertToSectionDeclFromDef(const QByteArray §ion, int sectionIndex)
|
||||
{
|
||||
|
||||
@@ -2621,6 +2621,13 @@ void InsertDefFromDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
|
||||
const QString cppFileName = correspondingHeaderOrSource(
|
||||
interface->fileName(), &isHeaderFile);
|
||||
|
||||
// Check if there is already a definition
|
||||
CppTools::SymbolFinder symbolFinder;
|
||||
if (symbolFinder.findMatchingDefinition(decl, interface->snapshot(),
|
||||
true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Insert Position: Implementation File
|
||||
if (isHeaderFile && !cppFileName.isEmpty()) {
|
||||
CppRefactoringChanges refactoring(interface->snapshot());
|
||||
|
||||
Reference in New Issue
Block a user