forked from qt-creator/qt-creator
CppEditor: Fix "add definition" quickfix insertion string
... for the edge case of the insertion location being preceded by a function whose body is a try-catch clause. Fixes: QTCREATORBUG-14661 Change-Id: Icc7d5283ead81d644231479317214a8cc177493d Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -154,6 +154,7 @@ private slots:
|
||||
void test_quickfix_InsertDefFromDecl_macroUsesAtEndOfFile2();
|
||||
void test_quickfix_InsertDefFromDecl_erroneousStatementAtEndOfFile();
|
||||
void test_quickfix_InsertDefFromDecl_rvalueReference();
|
||||
void test_quickfix_InsertDefFromDecl_functionTryBlock();
|
||||
void test_quickfix_InsertDefFromDecl_findImplementationFile();
|
||||
void test_quickfix_InsertDefFromDecl_unicodeIdentifier();
|
||||
void test_quickfix_InsertDefFromDecl_templateClass();
|
||||
|
@@ -4283,6 +4283,45 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_rvalueReference()
|
||||
QuickFixOperationTest(testDocuments, &factory);
|
||||
}
|
||||
|
||||
void CppEditorPlugin::test_quickfix_InsertDefFromDecl_functionTryBlock()
|
||||
{
|
||||
QList<QuickFixTestDocument::Ptr> testDocuments;
|
||||
|
||||
QByteArray original;
|
||||
QByteArray expected;
|
||||
|
||||
// Header File
|
||||
original = R"(
|
||||
struct Foo {
|
||||
void tryCatchFunc();
|
||||
void @otherFunc();
|
||||
};
|
||||
)";
|
||||
expected = original;
|
||||
testDocuments << QuickFixTestDocument::create("file.h", original, expected);
|
||||
|
||||
// Source File
|
||||
original = R"(
|
||||
#include "file.h"
|
||||
|
||||
void Foo::tryCatchFunc() try {} catch (...) {}
|
||||
)";
|
||||
expected = R"(
|
||||
#include "file.h"
|
||||
|
||||
void Foo::tryCatchFunc() try {} catch (...) {}
|
||||
|
||||
void Foo::otherFunc()
|
||||
{
|
||||
|
||||
}
|
||||
)";
|
||||
testDocuments << QuickFixTestDocument::create("file.cpp", original, expected);
|
||||
|
||||
InsertDefFromDecl factory;
|
||||
QuickFixOperationTest(testDocuments, &factory);
|
||||
}
|
||||
|
||||
/// Find right implementation file. (QTCREATORBUG-10728)
|
||||
void CppEditorPlugin::test_quickfix_InsertDefFromDecl_findImplementationFile()
|
||||
{
|
||||
|
@@ -3111,6 +3111,15 @@ public:
|
||||
// make target lookup context
|
||||
Document::Ptr targetDoc = targetFile->cppDocument();
|
||||
Scope *targetScope = targetDoc->scopeAt(loc.line(), loc.column());
|
||||
|
||||
// Correct scope in case of a function try-block. See QTCREATORBUG-14661.
|
||||
if (targetScope && targetScope->asBlock()) {
|
||||
if (Class * const enclosingClass = targetScope->enclosingClass())
|
||||
targetScope = enclosingClass;
|
||||
else
|
||||
targetScope = targetScope->enclosingNamespace();
|
||||
}
|
||||
|
||||
LookupContext targetContext(targetDoc, op->snapshot());
|
||||
ClassOrNamespace *targetCoN = targetContext.lookupType(targetScope);
|
||||
if (!targetCoN)
|
||||
|
Reference in New Issue
Block a user