Commit e9866469 authored by Lorenz Haas's avatar Lorenz Haas Committed by Nikolai Kosjar
Browse files

CppEditor: Resolve templates in AssignToLocalVariable



Task-number: QTCREATORBUG-9525

Change-Id: Ibe6c054c289f564a073a455f9b200bfffe5868eb
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent c56c63a8
......@@ -209,6 +209,7 @@ private slots:
void test_quickfix_AssignToLocalVariable_memberFunction();
void test_quickfix_AssignToLocalVariable_staticMemberFunction();
void test_quickfix_AssignToLocalVariable_newExpression();
void test_quickfix_AssignToLocalVariable_templates();
void test_quickfix_AssignToLocalVariable_noInitializationList();
void test_quickfix_AssignToLocalVariable_noVoidFunction();
void test_quickfix_AssignToLocalVariable_noVoidMemberFunction();
......
......@@ -2507,6 +2507,44 @@ void CppEditorPlugin::test_quickfix_AssignToLocalVariable_newExpression()
data.run(&factory);
}
void CppEditorPlugin::test_quickfix_AssignToLocalVariable_templates()
{
QList<TestDocumentPtr> testFiles;
QByteArray original;
QByteArray expected;
// Header File
original =
"template <typename T>\n"
"class List {\n"
"public:\n"
" T first();"
"};\n"
;
expected = original + "\n";
testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
// Source File
original =
"#include \"file.h\"\n"
"void foo() {\n"
" List<int> list;\n"
" li@st.first();\n"
"}";
expected =
"#include \"file.h\"\n"
"void foo() {\n"
" List<int> list;\n"
" int localFirst = list.first();\n"
"}\n";
testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
AssignToLocalVariable factory;
TestCase data(testFiles);
data.run(&factory);
}
/// Check: No trigger for function inside member initialization list.
void CppEditorPlugin::test_quickfix_AssignToLocalVariable_noInitializationList()
{
......
......@@ -4081,6 +4081,7 @@ public:
TypeOfExpression typeOfExpression;
typeOfExpression.init(assistInterface()->semanticInfo().doc, snapshot(),
assistInterface()->context().bindings());
typeOfExpression.setExpandTemplates(true);
Scope *scope = file->scopeAt(m_ast->firstToken());
const QList<LookupItem> result = typeOfExpression(file->textOf(m_ast).toUtf8(),
scope, TypeOfExpression::Preprocess);
......@@ -4220,6 +4221,7 @@ void AssignToLocalVariable::match(const CppQuickFixInterface &interface, QuickFi
TypeOfExpression typeOfExpression;
typeOfExpression.init(interface->semanticInfo().doc, interface->snapshot(),
interface->context().bindings());
typeOfExpression.setExpandTemplates(true);
// If items are empty, AssignToLocalVariableOperation will fail.
items = typeOfExpression(file->textOf(outerAST).toUtf8(),
......
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