Commit 22c3bd24 authored by Przemyslaw Gorszkowski's avatar Przemyslaw Gorszkowski Committed by Erik Verbruggen

C++: Fix code completion for Qt containers

This change solves only problem with Qt containers.
stl containers need separate change.
Problem was with predeclaration of template class after
declaration of this template class.
(there is unit test added which shows the problem).

Task-number: QTCREATORBUG-8228 (cover only Qt containers)

Change-Id: If1f76c88c955b7b55347d302b353f5cd52b244a4
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent 91889a9a
......@@ -726,7 +726,7 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac
return reference;
const TemplateNameId *templId = name->asTemplateNameId();
if (_alreadyConsideredClasses.contains(referenceClass) ||
if ((! templId && _alreadyConsideredClasses.contains(referenceClass)) ||
(templId &&
_alreadyConsideredTemplates.contains(templId))) {
return reference;
......
......@@ -370,6 +370,45 @@ void CppToolsPlugin::test_completion_template_5()
QVERIFY(completions.contains("b"));
}
void CppToolsPlugin::test_completion_template_6()
{
TestData data;
data.srcText = "\n"
"class Item\n"
"{\n"
" int i;\n"
"};\n"
"\n"
"template <typename T>\n"
"class Container\n"
"{\n"
" T get();\n"
"};\n"
"\n"
"template <typename T> class Container;\n"
"\n"
"class ItemContainer: public Container<Item>\n"
"{};\n"
"ItemContainer container;\n"
"@\n"
;
setup(&data);
Utils::ChangeSet change;
QString txt = QLatin1String("container.get().");
change.insert(data.pos, txt);
QTextCursor cursor(data.doc);
change.apply(&cursor);
data.pos += txt.length();
QStringList completions = getCompletions(data);
QCOMPARE(completions.size(), 2);
QVERIFY(completions.contains("Item"));
QVERIFY(completions.contains("i"));
}
void CppToolsPlugin::test_completion()
{
QFETCH(QByteArray, code);
......@@ -1013,4 +1052,6 @@ void CppToolsPlugin::test_completion_enclosing_template_class_data()
completions.append("Nested");
completions.append("int_nested");
QTest::newRow("case: nested template class with enclosing template class")
<< code << completions;}
<< code << completions;
}
......@@ -96,6 +96,7 @@ private slots:
void test_completion_template_3();
void test_completion_template_4();
void test_completion_template_5();
void test_completion_template_6();
void test_completion_template_as_base();
void test_completion_template_as_base_data();
void test_completion_use_global_identifier_as_base_class();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment