forked from qt-creator/qt-creator
CplusPlus: Fix minimal name construction
... when using declarations are involved. Fixes: QTCREATORBUG-14524 Change-Id: I0c391b88628f40973b6f601e60c64263f62a88a0 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -216,7 +216,14 @@ LookupContext &LookupContext::operator=(const LookupContext &other)
|
|||||||
QList<const Name *> LookupContext::fullyQualifiedName(Symbol *symbol, InlineNamespacePolicy policy)
|
QList<const Name *> LookupContext::fullyQualifiedName(Symbol *symbol, InlineNamespacePolicy policy)
|
||||||
{
|
{
|
||||||
QList<const Name *> qualifiedName = path(symbol->enclosingScope(), policy);
|
QList<const Name *> qualifiedName = path(symbol->enclosingScope(), policy);
|
||||||
addNames(symbol->name(), &qualifiedName, /*add all names*/ true);
|
QList<const Name *> symbolNames;
|
||||||
|
addNames(symbol->name(), &symbolNames, /*add all names*/ true);
|
||||||
|
if (const UsingDeclaration * const usingDecl = symbol->asUsingDeclaration()) {
|
||||||
|
if (!symbolNames.isEmpty())
|
||||||
|
qualifiedName << symbolNames.last();
|
||||||
|
} else {
|
||||||
|
qualifiedName << symbolNames;
|
||||||
|
}
|
||||||
return qualifiedName;
|
return qualifiedName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -811,7 +818,7 @@ void CreateBindings::lookupInScope(const Name *name, Scope *scope,
|
|||||||
continue; // skip using namespace directives
|
continue; // skip using namespace directives
|
||||||
else if (! id->match(s->identifier()))
|
else if (! id->match(s->identifier()))
|
||||||
continue;
|
continue;
|
||||||
else if (s->name() && s->name()->isQualifiedNameId())
|
else if (s->name() && s->name()->isQualifiedNameId() && !s->asUsingDeclaration())
|
||||||
continue; // skip qualified ids.
|
continue; // skip qualified ids.
|
||||||
|
|
||||||
if (Q_UNLIKELY(debug)) {
|
if (Q_UNLIKELY(debug)) {
|
||||||
|
@@ -155,6 +155,7 @@ private slots:
|
|||||||
void test_quickfix_InsertDefFromDecl_erroneousStatementAtEndOfFile();
|
void test_quickfix_InsertDefFromDecl_erroneousStatementAtEndOfFile();
|
||||||
void test_quickfix_InsertDefFromDecl_rvalueReference();
|
void test_quickfix_InsertDefFromDecl_rvalueReference();
|
||||||
void test_quickfix_InsertDefFromDecl_functionTryBlock();
|
void test_quickfix_InsertDefFromDecl_functionTryBlock();
|
||||||
|
void test_quickfix_InsertDefFromDecl_usingDecl();
|
||||||
void test_quickfix_InsertDefFromDecl_findImplementationFile();
|
void test_quickfix_InsertDefFromDecl_findImplementationFile();
|
||||||
void test_quickfix_InsertDefFromDecl_unicodeIdentifier();
|
void test_quickfix_InsertDefFromDecl_unicodeIdentifier();
|
||||||
void test_quickfix_InsertDefFromDecl_templateClass();
|
void test_quickfix_InsertDefFromDecl_templateClass();
|
||||||
|
@@ -4322,6 +4322,41 @@ void Foo::otherFunc()
|
|||||||
QuickFixOperationTest(testDocuments, &factory);
|
QuickFixOperationTest(testDocuments, &factory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CppEditorPlugin::test_quickfix_InsertDefFromDecl_usingDecl()
|
||||||
|
{
|
||||||
|
QList<QuickFixTestDocument::Ptr> testDocuments;
|
||||||
|
|
||||||
|
QByteArray original;
|
||||||
|
QByteArray expected;
|
||||||
|
|
||||||
|
// Header File
|
||||||
|
original = R"(
|
||||||
|
namespace N { struct S; }
|
||||||
|
using N::S;
|
||||||
|
|
||||||
|
void @func(const S &s);
|
||||||
|
)";
|
||||||
|
expected = original;
|
||||||
|
testDocuments << QuickFixTestDocument::create("file.h", original, expected);
|
||||||
|
|
||||||
|
// Source File
|
||||||
|
original = R"(
|
||||||
|
#include "file.h"
|
||||||
|
)";
|
||||||
|
expected = R"(
|
||||||
|
#include "file.h"
|
||||||
|
|
||||||
|
void func(const S &s)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
testDocuments << QuickFixTestDocument::create("file.cpp", original, expected);
|
||||||
|
|
||||||
|
InsertDefFromDecl factory;
|
||||||
|
QuickFixOperationTest(testDocuments, &factory);
|
||||||
|
}
|
||||||
|
|
||||||
/// Find right implementation file. (QTCREATORBUG-10728)
|
/// Find right implementation file. (QTCREATORBUG-10728)
|
||||||
void CppEditorPlugin::test_quickfix_InsertDefFromDecl_findImplementationFile()
|
void CppEditorPlugin::test_quickfix_InsertDefFromDecl_findImplementationFile()
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user