forked from qt-creator/qt-creator
C++: nested class in function
Case when nested class declaration contains object name for this class.
Example:
void fun()
{
struct S
{
int i;
} s;
s.i;
}
Fixes:
* highlighting
* completion
* tests
Task-number: QTCREATORBUG-11710
Change-Id: I32e234f57655c388a87a199edc8be750d7bf823f
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Przemyslaw Gorszkowski <pgorszkowski@gmail.com>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
committed by
Nikolai Kosjar
parent
46c083c2eb
commit
e3f5977311
@@ -866,8 +866,12 @@ ClassOrNamespace *ResolveExpression::findClass(const FullySpecifiedType &origina
|
|||||||
FullySpecifiedType ty = originalTy.simplified();
|
FullySpecifiedType ty = originalTy.simplified();
|
||||||
ClassOrNamespace *binding = 0;
|
ClassOrNamespace *binding = 0;
|
||||||
|
|
||||||
if (Class *klass = ty->asClassType())
|
if (Class *klass = ty->asClassType()) {
|
||||||
binding = _context.lookupType(klass, enclosingTemplateInstantiation);
|
if (scope->isBlock())
|
||||||
|
binding = _context.lookupType(klass->name(), scope, enclosingTemplateInstantiation);
|
||||||
|
if (!binding)
|
||||||
|
binding = _context.lookupType(klass, enclosingTemplateInstantiation);
|
||||||
|
}
|
||||||
|
|
||||||
else if (NamedType *namedTy = ty->asNamedType())
|
else if (NamedType *namedTy = ty->asNamedType())
|
||||||
binding = _context.lookupType(namedTy->name(), scope, enclosingTemplateInstantiation);
|
binding = _context.lookupType(namedTy->name(), scope, enclosingTemplateInstantiation);
|
||||||
|
|||||||
@@ -1441,6 +1441,19 @@ void CppToolsPlugin::test_completion_data()
|
|||||||
<< QLatin1String("A")
|
<< QLatin1String("A")
|
||||||
<< QLatin1String("a"));
|
<< QLatin1String("a"));
|
||||||
|
|
||||||
|
QTest::newRow("nested_class_declaration_with_object_name_inside_function") << _(
|
||||||
|
"int foo()\n"
|
||||||
|
"{\n"
|
||||||
|
" struct Nested\n"
|
||||||
|
" {\n"
|
||||||
|
" int i;\n"
|
||||||
|
" } n;\n"
|
||||||
|
" @;\n"
|
||||||
|
"}\n"
|
||||||
|
) << _("n.") << (QStringList()
|
||||||
|
<< QLatin1String("Nested")
|
||||||
|
<< QLatin1String("i"));
|
||||||
|
|
||||||
QTest::newRow("nested_anonymous_class_QTCREATORBUG10876_1") << _(
|
QTest::newRow("nested_anonymous_class_QTCREATORBUG10876_1") << _(
|
||||||
"struct EnclosingStruct\n"
|
"struct EnclosingStruct\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|||||||
@@ -194,6 +194,7 @@ private slots:
|
|||||||
void test_checksymbols_AnonymousClass();
|
void test_checksymbols_AnonymousClass();
|
||||||
void test_checksymbols_AnonymousClass_insideNamespace();
|
void test_checksymbols_AnonymousClass_insideNamespace();
|
||||||
void test_checksymbols_AnonymousClass_QTCREATORBUG8963();
|
void test_checksymbols_AnonymousClass_QTCREATORBUG8963();
|
||||||
|
void test_checksymbols_class_declaration_with_object_name_nested_in_function();
|
||||||
void test_checksymbols_highlightingTypeWhenUsingNamespaceClass_QTCREATORBUG7903_globalNamespace();
|
void test_checksymbols_highlightingTypeWhenUsingNamespaceClass_QTCREATORBUG7903_globalNamespace();
|
||||||
void test_checksymbols_highlightingTypeWhenUsingNamespaceClass_QTCREATORBUG7903_namespace();
|
void test_checksymbols_highlightingTypeWhenUsingNamespaceClass_QTCREATORBUG7903_namespace();
|
||||||
void test_checksymbols_highlightingTypeWhenUsingNamespaceClass_QTCREATORBUG7903_insideFunction();
|
void test_checksymbols_highlightingTypeWhenUsingNamespaceClass_QTCREATORBUG7903_insideFunction();
|
||||||
@@ -1585,6 +1586,31 @@ void tst_CheckSymbols::test_checksymbols_AnonymousClass_QTCREATORBUG8963()
|
|||||||
TestData::check(source, expectedUses);
|
TestData::check(source, expectedUses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_CheckSymbols::test_checksymbols_class_declaration_with_object_name_nested_in_function()
|
||||||
|
{
|
||||||
|
const QByteArray source =
|
||||||
|
"int foo()\n"
|
||||||
|
"{\n"
|
||||||
|
" struct Nested\n"
|
||||||
|
" {\n"
|
||||||
|
" int i;\n"
|
||||||
|
" } n;\n"
|
||||||
|
" n.i = 42;\n"
|
||||||
|
"}\n"
|
||||||
|
;
|
||||||
|
|
||||||
|
const QList<Use> expectedUses = QList<Use>()
|
||||||
|
<< Use(1, 5, 3, CppHighlightingSupport::FunctionUse)
|
||||||
|
<< Use(3, 12, 6, CppHighlightingSupport::TypeUse)
|
||||||
|
<< Use(5, 13, 1, CppHighlightingSupport::FieldUse)
|
||||||
|
<< Use(6, 7, 1, CppHighlightingSupport::LocalUse)
|
||||||
|
<< Use(7, 5, 1, CppHighlightingSupport::LocalUse)
|
||||||
|
<< Use(7, 7, 1, CppHighlightingSupport::FieldUse)
|
||||||
|
;
|
||||||
|
|
||||||
|
TestData::check(source, expectedUses);
|
||||||
|
}
|
||||||
|
|
||||||
void tst_CheckSymbols::test_checksymbols_highlightingTypeWhenUsingNamespaceClass_QTCREATORBUG7903_globalNamespace()
|
void tst_CheckSymbols::test_checksymbols_highlightingTypeWhenUsingNamespaceClass_QTCREATORBUG7903_globalNamespace()
|
||||||
{
|
{
|
||||||
const QByteArray source =
|
const QByteArray source =
|
||||||
|
|||||||
Reference in New Issue
Block a user