aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@digia.com>2013-07-24 14:41:01 +0200
committerNikolai Kosjar <nikolai.kosjar@digia.com>2013-08-08 11:49:42 +0200
commit83bbd534e52437d665b250fe27c3c61e02252e91 (patch)
tree7670c7b6411792e31d05d77ad8ff24dc3d7d2d32
parent11d2d7447671c5aaf8e8b718df0fdf8e58f76c80 (diff)
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>
-rw-r--r--src/plugins/cppeditor/cppeditorplugin.h1
-rw-r--r--src/plugins/cppeditor/cppquickfix_test.cpp57
-rw-r--r--src/plugins/cpptools/insertionpointlocator.cpp3
3 files changed, 59 insertions, 2 deletions
diff --git a/src/plugins/cppeditor/cppeditorplugin.h b/src/plugins/cppeditor/cppeditorplugin.h
index 356677038a..93bc4368b2 100644
--- a/src/plugins/cppeditor/cppeditorplugin.h
+++ b/src/plugins/cppeditor/cppeditorplugin.h
@@ -163,6 +163,7 @@ private slots:
void test_quickfix_InsertDefFromDecl_notTriggeringWhenDefinitionExists();
void test_quickfix_InsertDefFromDecl_notTriggeringStatement();
void test_quickfix_InsertDefFromDecl_findRightImplementationFile();
+ void test_quickfix_InsertDefFromDecl_ignoreSurroundingGeneratedDeclarations();
void test_quickfix_InsertDefFromDecl_respectWsInOperatorNames1();
void test_quickfix_InsertDefFromDecl_respectWsInOperatorNames2();
diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp
index 351536db42..0d1bf885fa 100644
--- a/src/plugins/cppeditor/cppquickfix_test.cpp
+++ b/src/plugins/cppeditor/cppquickfix_test.cpp
@@ -1180,6 +1180,63 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_findRightImplementationFil
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
void CppEditorPlugin::test_quickfix_InsertDefFromDecl_respectWsInOperatorNames1()
{
diff --git a/src/plugins/cpptools/insertionpointlocator.cpp b/src/plugins/cpptools/insertionpointlocator.cpp
index 5170203463..48fc824f15 100644
--- a/src/plugins/cpptools/insertionpointlocator.cpp
+++ b/src/plugins/cpptools/insertionpointlocator.cpp
@@ -498,8 +498,7 @@ static InsertionLocation nextToSurroundingDefinitions(Symbol *declaration,
Declaration *surroundingFunctionDecl = 0;
for (int i = declIndex - 1; i >= 0; --i) {
Symbol *s = klass->memberAt(i);
- surroundingFunctionDecl = isNonVirtualFunctionDeclaration(s);
- if (!surroundingFunctionDecl)
+ if (s->isGenerated() || !(surroundingFunctionDecl = isNonVirtualFunctionDeclaration(s)))
continue;
if ((definitionFunction = symbolFinder.findMatchingDefinition(surroundingFunctionDecl,
changes.snapshot())))