Commit 27fe5df1 authored by Nikolai Kosjar's avatar Nikolai Kosjar

CppEditor: Skip also forward declarations of templates on F2

Task-number: QTCREATORBUG-20

Change-Id: If6349605e1f396e88c8e3e008328fc2cac8a4119
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
Reviewed-by: default avatarPrzemyslaw Gorszkowski <pgorszkowski@gmail.com>
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent 9fd38226
......@@ -242,6 +242,24 @@ Link findMacroLink(const QByteArray &name, const Document::Ptr &doc)
return Link();
}
/// Considers also forward declared templates.
static bool isForwardClassDeclaration(Type *type)
{
if (!type)
return false;
if (type->isForwardClassDeclarationType()) {
return true;
} else if (Template *templ = type->asTemplateType()) {
if (Symbol *declaration = templ->declaration()) {
if (declaration->isForwardClassDeclaration())
return true;
}
}
return false;
}
inline LookupItem skipForwardDeclarations(const QList<LookupItem> &resolvedSymbols)
{
QList<LookupItem> candidates = resolvedSymbols;
......@@ -249,11 +267,11 @@ inline LookupItem skipForwardDeclarations(const QList<LookupItem> &resolvedSymbo
LookupItem result = candidates.first();
const FullySpecifiedType ty = result.type().simplified();
if (ty->isForwardClassDeclarationType()) {
if (isForwardClassDeclaration(ty.type())) {
while (!candidates.isEmpty()) {
LookupItem r = candidates.takeFirst();
if (!r.type()->isForwardClassDeclarationType()) {
if (!isForwardClassDeclaration(r.type().type())) {
result = r;
break;
}
......@@ -676,8 +694,15 @@ BaseTextEditorWidget::Link FollowSymbolUnderCursor::findLink(const QTextCursor &
if (def == lastVisibleSymbol)
def = 0; // jump to declaration then.
if (symbol->isForwardClassDeclaration())
if (symbol->isForwardClassDeclaration()) {
def = symbolFinder->findMatchingClassDeclaration(symbol, snapshot);
} else if (Template *templ = symbol->asTemplate()) {
if (Symbol *declaration = templ->declaration()) {
if (declaration->isForwardClassDeclaration())
def = symbolFinder->findMatchingClassDeclaration(declaration, snapshot);
}
}
}
link = m_widget->linkToSymbol(def ? def : symbol);
......
......@@ -878,6 +878,12 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_data()
"@Foo foo;\n"
);
QTest::newRow("skipForwardDeclarationTemplates") << _(
"template <class E> class $Container {};\n"
"template <class E> class Container;\n"
"@Container<int> container;\n"
);
QTest::newRow("using_QTCREATORBUG7903_globalNamespace") << _(
"namespace NS {\n"
"class Foo {};\n"
......@@ -912,7 +918,6 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_data()
" @Foo foo;\n"
"}\n"
);
}
void CppEditorPlugin::test_FollowSymbolUnderCursor()
......@@ -933,6 +938,14 @@ void CppEditorPlugin::test_FollowSymbolUnderCursor_multipleDocuments_data()
"@Foo foo;\n",
QLatin1String("forwardDeclaredAndUsed.h"))
);
QTest::newRow("skipForwardDeclarationTemplates") << (QList<TestDocumentPtr>()
<< TestDocument::create("template <class E> class $Container {};\n",
QLatin1String("defined.h"))
<< TestDocument::create("template <class E> class Container;\n"
"@Container<int> container;\n",
QLatin1String("forwardDeclaredAndUsed.h"))
);
}
void CppEditorPlugin::test_FollowSymbolUnderCursor_multipleDocuments()
......
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