forked from qt-creator/qt-creator
C++: fix support for nested anonymous class
The case when anonymous class is inside function. Fixed: * highlighting * completion Task-number: QTCREATORBUG-11711 Change-Id: Ic8fc5fdfb1aed62a74bf148ab7ed449d08214dda Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com> Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
committed by
Erik Verbruggen
parent
31cad45c0e
commit
6bf75acac7
@@ -1630,7 +1630,8 @@ bool CreateBindings::visit(Block *block)
|
||||
// nested ClassOrNamespaces)
|
||||
if (! _currentClassOrNamespace->_blocks.empty()
|
||||
|| ! _currentClassOrNamespace->_classOrNamespaces.empty()
|
||||
|| ! _currentClassOrNamespace->_enums.empty()) {
|
||||
|| ! _currentClassOrNamespace->_enums.empty()
|
||||
|| ! _currentClassOrNamespace->_anonymouses.empty()) {
|
||||
previous->_blocks[block] = binding;
|
||||
_entities.append(binding);
|
||||
} else {
|
||||
|
||||
@@ -1513,6 +1513,20 @@ void CppToolsPlugin::test_completion_data()
|
||||
) << _("nestedOfNestedAnonymousClass.") << (QStringList()
|
||||
<< QLatin1String("memberOfNestedOfNestedAnonymousClass"));
|
||||
|
||||
QTest::newRow("nested_anonymous_class_inside_function") << _(
|
||||
"void fun()\n"
|
||||
"{\n"
|
||||
" union\n"
|
||||
" {\n"
|
||||
" int foo1;\n"
|
||||
" int foo2;\n"
|
||||
" };\n"
|
||||
" @\n"
|
||||
"};\n"
|
||||
) << _("foo") << (QStringList()
|
||||
<< QLatin1String("foo1")
|
||||
<< QLatin1String("foo2"));
|
||||
|
||||
QTest::newRow("crash_cloning_template_class_QTCREATORBUG9329") << _(
|
||||
"struct A {};\n"
|
||||
"template <typename T>\n"
|
||||
|
||||
@@ -1344,6 +1344,11 @@ void CppCompletionAssistProcessor::globalCompletion(CPlusPlus::Scope *currentSco
|
||||
if (UsingNamespaceDirective *u = member->asUsingNamespaceDirective()) {
|
||||
if (ClassOrNamespace *b = binding->lookupType(u->name()))
|
||||
usingBindings.append(b);
|
||||
} else if (Class *c = member->asClass()) {
|
||||
if (c->name()->isAnonymousNameId()) {
|
||||
if (ClassOrNamespace *b = binding->findBlock(block))
|
||||
completeClass(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1539,6 +1544,8 @@ void CppCompletionAssistProcessor::completeClass(CPlusPlus::ClassOrNamespace *b,
|
||||
foreach (Symbol *bb, binding->symbols()) {
|
||||
if (Class *k = bb->asClass())
|
||||
scopesToVisit.append(k);
|
||||
else if (Block *b = bb->asBlock())
|
||||
scopesToVisit.append(b);
|
||||
}
|
||||
|
||||
foreach (Enum *e, binding->unscopedEnums())
|
||||
|
||||
@@ -193,6 +193,7 @@ private slots:
|
||||
void test_checksymbols_QTCREATORBUG9098();
|
||||
void test_checksymbols_AnonymousClass();
|
||||
void test_checksymbols_AnonymousClass_insideNamespace();
|
||||
void test_checksymbols_AnonymousClass_insideFunction();
|
||||
void test_checksymbols_AnonymousClass_QTCREATORBUG8963();
|
||||
void test_checksymbols_class_declaration_with_object_name_nested_in_function();
|
||||
void test_checksymbols_highlightingTypeWhenUsingNamespaceClass_QTCREATORBUG7903_globalNamespace();
|
||||
@@ -1548,6 +1549,27 @@ void tst_CheckSymbols::test_checksymbols_AnonymousClass_insideNamespace()
|
||||
TestData::check(source, expectedUses);
|
||||
}
|
||||
|
||||
void tst_CheckSymbols::test_checksymbols_AnonymousClass_insideFunction()
|
||||
{
|
||||
const QByteArray source =
|
||||
"int foo()\n"
|
||||
"{\n"
|
||||
" union\n"
|
||||
" {\n"
|
||||
" int foo1;\n"
|
||||
" int foo2;\n"
|
||||
" };\n"
|
||||
"}\n"
|
||||
;
|
||||
const QList<Use> expectedUses = QList<Use>()
|
||||
<< Use(1, 5, 3, CppHighlightingSupport::FunctionUse)
|
||||
<< Use(5, 13, 4, CppHighlightingSupport::FieldUse)
|
||||
<< Use(6, 13, 4, CppHighlightingSupport::FieldUse)
|
||||
;
|
||||
|
||||
TestData::check(source, expectedUses);
|
||||
}
|
||||
|
||||
void tst_CheckSymbols::test_checksymbols_AnonymousClass_QTCREATORBUG8963()
|
||||
{
|
||||
const QByteArray source =
|
||||
|
||||
Reference in New Issue
Block a user