forked from qt-creator/qt-creator
CppTools: Do not try to find definitions of generated symbols
This speeds up the quick fix InsertDefFromDecl on function declarations in classes containing Q_OBJECT. Task-number: QTCREATORBUG-9877 Change-Id: I0af16f17f40735040b7158a3191c13db3433edf9 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Lorenz Haas <lykurg@gmail.com> Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
@@ -163,6 +163,7 @@ private slots:
|
|||||||
void test_quickfix_InsertDefFromDecl_notTriggeringWhenDefinitionExists();
|
void test_quickfix_InsertDefFromDecl_notTriggeringWhenDefinitionExists();
|
||||||
void test_quickfix_InsertDefFromDecl_notTriggeringStatement();
|
void test_quickfix_InsertDefFromDecl_notTriggeringStatement();
|
||||||
void test_quickfix_InsertDefFromDecl_findRightImplementationFile();
|
void test_quickfix_InsertDefFromDecl_findRightImplementationFile();
|
||||||
|
void test_quickfix_InsertDefFromDecl_ignoreSurroundingGeneratedDeclarations();
|
||||||
void test_quickfix_InsertDefFromDecl_respectWsInOperatorNames1();
|
void test_quickfix_InsertDefFromDecl_respectWsInOperatorNames1();
|
||||||
void test_quickfix_InsertDefFromDecl_respectWsInOperatorNames2();
|
void test_quickfix_InsertDefFromDecl_respectWsInOperatorNames2();
|
||||||
|
|
||||||
|
|||||||
@@ -1180,6 +1180,63 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_findRightImplementationFil
|
|||||||
data.run(&factory);
|
data.run(&factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Ignore generated functions declarations when looking at the surrounding
|
||||||
|
/// functions declarations in order to find the right implementation file.
|
||||||
|
void CppEditorPlugin::test_quickfix_InsertDefFromDecl_ignoreSurroundingGeneratedDeclarations()
|
||||||
|
{
|
||||||
|
QList<TestDocumentPtr> testFiles;
|
||||||
|
|
||||||
|
QByteArray original;
|
||||||
|
QByteArray expected;
|
||||||
|
|
||||||
|
// Header File
|
||||||
|
original =
|
||||||
|
"#define DECLARE_HIDDEN_FUNCTION void hidden();\n"
|
||||||
|
"struct Foo\n"
|
||||||
|
"{\n"
|
||||||
|
" void a();\n"
|
||||||
|
" DECLARE_HIDDEN_FUNCTION\n"
|
||||||
|
" void b@();\n"
|
||||||
|
"};\n"
|
||||||
|
"}\n";
|
||||||
|
expected = original + '\n';
|
||||||
|
testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
|
||||||
|
|
||||||
|
// Source File #1
|
||||||
|
original =
|
||||||
|
"#include \"file.h\"\n"
|
||||||
|
"\n"
|
||||||
|
"void Foo::a()\n"
|
||||||
|
"{\n\n"
|
||||||
|
"}\n";
|
||||||
|
expected =
|
||||||
|
"#include \"file.h\"\n"
|
||||||
|
"\n"
|
||||||
|
"void Foo::a()\n"
|
||||||
|
"{\n\n"
|
||||||
|
"}\n"
|
||||||
|
"\n"
|
||||||
|
"void Foo::b()\n"
|
||||||
|
"{\n\n"
|
||||||
|
"}\n"
|
||||||
|
"\n";
|
||||||
|
testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
|
||||||
|
|
||||||
|
// Source File #2
|
||||||
|
original =
|
||||||
|
"#include \"file.h\"\n"
|
||||||
|
"\n"
|
||||||
|
"void Foo::hidden()\n"
|
||||||
|
"{\n\n"
|
||||||
|
"}\n";
|
||||||
|
expected = original + '\n';
|
||||||
|
testFiles << TestDocument::create(original, expected, QLatin1String("file2.cpp"));
|
||||||
|
|
||||||
|
InsertDefFromDecl factory;
|
||||||
|
TestCase data(testFiles);
|
||||||
|
data.run(&factory);
|
||||||
|
}
|
||||||
|
|
||||||
/// Check if whitespace is respected for operator functions
|
/// Check if whitespace is respected for operator functions
|
||||||
void CppEditorPlugin::test_quickfix_InsertDefFromDecl_respectWsInOperatorNames1()
|
void CppEditorPlugin::test_quickfix_InsertDefFromDecl_respectWsInOperatorNames1()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -498,8 +498,7 @@ static InsertionLocation nextToSurroundingDefinitions(Symbol *declaration,
|
|||||||
Declaration *surroundingFunctionDecl = 0;
|
Declaration *surroundingFunctionDecl = 0;
|
||||||
for (int i = declIndex - 1; i >= 0; --i) {
|
for (int i = declIndex - 1; i >= 0; --i) {
|
||||||
Symbol *s = klass->memberAt(i);
|
Symbol *s = klass->memberAt(i);
|
||||||
surroundingFunctionDecl = isNonVirtualFunctionDeclaration(s);
|
if (s->isGenerated() || !(surroundingFunctionDecl = isNonVirtualFunctionDeclaration(s)))
|
||||||
if (!surroundingFunctionDecl)
|
|
||||||
continue;
|
continue;
|
||||||
if ((definitionFunction = symbolFinder.findMatchingDefinition(surroundingFunctionDecl,
|
if ((definitionFunction = symbolFinder.findMatchingDefinition(surroundingFunctionDecl,
|
||||||
changes.snapshot())))
|
changes.snapshot())))
|
||||||
|
|||||||
Reference in New Issue
Block a user