Commit 31ce303e authored by Przemyslaw Gorszkowski's avatar Przemyslaw Gorszkowski Committed by Erik Verbruggen

C++: fix code completion: casting inside parentheses

Included unit tests.

Task-number: QTCREATORBUG-8368

Change-Id: I1b04124bc2c9eac050cfb2e6d3a5c1aca5311f4b
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent d9571f2e
......@@ -157,6 +157,8 @@ int ExpressionUnderCursor::startOfExpression_helper(BackwardsScanner &tk, int in
return index - 1;
} else if (tk[index - 1].is(T_RPAREN)) {
int matchingBraceIndex = tk.startOfMatchingBrace(index);
if (! matchingBraceIndex)
return matchingBraceIndex;
if (matchingBraceIndex != index) {
if (tk[matchingBraceIndex - 1].is(T_GREATER)) {
int lessIndex = tk.startOfMatchingBrace(matchingBraceIndex);
......
......@@ -152,6 +152,87 @@ void CppToolsPlugin::test_completion_forward_declarations_present()
QCOMPARE(completions, expected);
}
void CppToolsPlugin::test_completion_inside_parentheses_c_style_conversion()
{
TestData data;
data.srcText = "\n"
"class Base\n"
"{\n"
" int i_base;\n"
"};\n"
"\n"
"class Derived : public Base\n"
"{\n"
" int i_derived;\n"
"};\n"
"\n"
"void fun()\n"
"{\n"
" Base *b = new Derived;\n"
" if (1)\n"
" @\n"
"}\n"
;
setup(&data);
Utils::ChangeSet change;
QString txt = QLatin1String("((Derived *)b)->");
change.insert(data.pos, txt);
QTextCursor cursor(data.doc);
change.apply(&cursor);
data.pos += txt.length();
QStringList completions = getCompletions(data);
QCOMPARE(completions.size(), 4);
QVERIFY(completions.contains(QLatin1String("Derived")));
QVERIFY(completions.contains(QLatin1String("Base")));
QVERIFY(completions.contains(QLatin1String("i_derived")));
QVERIFY(completions.contains(QLatin1String("i_base")));
}
void CppToolsPlugin::test_completion_inside_parentheses_cast_operator_conversion()
{
TestData data;
data.srcText = "\n"
"class Base\n"
"{\n"
" int i_base;\n"
"};\n"
"\n"
"class Derived : public Base\n"
"{\n"
" int i_derived;\n"
"};\n"
"\n"
"void fun()\n"
"{\n"
" Base *b = new Derived;\n"
" if (1)\n"
" @\n"
"}\n"
;
setup(&data);
Utils::ChangeSet change;
QString txt = QLatin1String("(static_cast<Derived *>(b))->");
change.insert(data.pos, txt);
QTextCursor cursor(data.doc);
change.apply(&cursor);
data.pos += txt.length();
QStringList completions = getCompletions(data);
QCOMPARE(completions.size(), 4);
QVERIFY(completions.contains(QLatin1String("Derived")));
QVERIFY(completions.contains(QLatin1String("Base")));
QVERIFY(completions.contains(QLatin1String("i_derived")));
QVERIFY(completions.contains(QLatin1String("i_base")));
}
void CppToolsPlugin::test_completion_basic_1()
{
TestData data;
......
......@@ -90,6 +90,8 @@ private slots:
void test_codegen_definition_middle_member();
void test_completion_forward_declarations_present();
void test_completion_inside_parentheses_c_style_conversion();
void test_completion_inside_parentheses_cast_operator_conversion();
void test_completion_basic_1();
void test_completion_template_1();
void test_completion_template_2();
......
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