forked from qt-creator/qt-creator
C++ editor: support nested class of enclosing template
Fixing: * highlighting * tooltips * find usage * selecting Task-number: QTCREATORBUG-8245 Change-Id: I6e900799e43126706125b7e424567fca2b2c223e Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
committed by
Nikolai Kosjar
parent
bc137f36a7
commit
23844410fd
@@ -260,6 +260,8 @@ void FindUsages::checkExpression(unsigned startToken, unsigned endToken, Scope *
|
|||||||
if (! scope)
|
if (! scope)
|
||||||
scope = _currentScope;
|
scope = _currentScope;
|
||||||
|
|
||||||
|
// make possible to instantiate templates
|
||||||
|
typeofExpression.setExpandTemplates(true);
|
||||||
const QList<LookupItem> results = typeofExpression(expression, scope, TypeOfExpression::Preprocess);
|
const QList<LookupItem> results = typeofExpression(expression, scope, TypeOfExpression::Preprocess);
|
||||||
reportResult(endToken, results);
|
reportResult(endToken, results);
|
||||||
}
|
}
|
||||||
|
@@ -281,7 +281,11 @@ public:
|
|||||||
static const Name *minimalName(Symbol *symbol, ClassOrNamespace *target, Control *control);
|
static const Name *minimalName(Symbol *symbol, ClassOrNamespace *target, Control *control);
|
||||||
|
|
||||||
void setExpandTemplates(bool expandTemplates)
|
void setExpandTemplates(bool expandTemplates)
|
||||||
{ m_expandTemplates = expandTemplates; }
|
{
|
||||||
|
if (_bindings)
|
||||||
|
_bindings->setExpandTemplates(expandTemplates);
|
||||||
|
m_expandTemplates = expandTemplates;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// The current expression.
|
// The current expression.
|
||||||
|
@@ -819,6 +819,8 @@ static QList<int> lazyFindReferences(Scope *scope, QString code, Document::Ptr d
|
|||||||
TypeOfExpression typeOfExpression;
|
TypeOfExpression typeOfExpression;
|
||||||
snapshot.insert(doc);
|
snapshot.insert(doc);
|
||||||
typeOfExpression.init(doc, snapshot);
|
typeOfExpression.init(doc, snapshot);
|
||||||
|
// make possible to instantiate templates
|
||||||
|
typeOfExpression.setExpandTemplates(true);
|
||||||
if (Symbol *canonicalSymbol = CanonicalSymbol::canonicalSymbol(scope, code, typeOfExpression))
|
if (Symbol *canonicalSymbol = CanonicalSymbol::canonicalSymbol(scope, code, typeOfExpression))
|
||||||
return CppModelManagerInterface::instance()->references(canonicalSymbol, typeOfExpression.context());
|
return CppModelManagerInterface::instance()->references(canonicalSymbol, typeOfExpression.context());
|
||||||
return QList<int>();
|
return QList<int>();
|
||||||
@@ -1522,6 +1524,8 @@ CPPEditorWidget::Link CPPEditorWidget::findLinkAt(const QTextCursor &cursor,
|
|||||||
|
|
||||||
TypeOfExpression typeOfExpression;
|
TypeOfExpression typeOfExpression;
|
||||||
typeOfExpression.init(doc, snapshot);
|
typeOfExpression.init(doc, snapshot);
|
||||||
|
// make possible to instantiate templates
|
||||||
|
typeOfExpression.setExpandTemplates(true);
|
||||||
const QList<LookupItem> resolvedSymbols =
|
const QList<LookupItem> resolvedSymbols =
|
||||||
typeOfExpression.reference(expression.toUtf8(), scope, TypeOfExpression::Preprocess);
|
typeOfExpression.reference(expression.toUtf8(), scope, TypeOfExpression::Preprocess);
|
||||||
|
|
||||||
|
@@ -118,6 +118,8 @@ void CppElementEvaluator::execute()
|
|||||||
|
|
||||||
TypeOfExpression typeOfExpression;
|
TypeOfExpression typeOfExpression;
|
||||||
typeOfExpression.init(doc, snapshot);
|
typeOfExpression.init(doc, snapshot);
|
||||||
|
// make possible to instantiate templates
|
||||||
|
typeOfExpression.setExpandTemplates(true);
|
||||||
const QList<LookupItem> &lookupItems = typeOfExpression(expression.toUtf8(), scope);
|
const QList<LookupItem> &lookupItems = typeOfExpression(expression.toUtf8(), scope);
|
||||||
if (lookupItems.isEmpty())
|
if (lookupItems.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
@@ -324,6 +324,8 @@ CheckSymbols::CheckSymbols(Document::Ptr doc, const LookupContext &context, cons
|
|||||||
_potentialStatics = collectTypes.statics();
|
_potentialStatics = collectTypes.statics();
|
||||||
|
|
||||||
typeOfExpression.init(_doc, _context.snapshot(), _context.bindings());
|
typeOfExpression.init(_doc, _context.snapshot(), _context.bindings());
|
||||||
|
// make possible to instantiate templates
|
||||||
|
typeOfExpression.setExpandTemplates(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
CheckSymbols::~CheckSymbols()
|
CheckSymbols::~CheckSymbols()
|
||||||
|
@@ -90,6 +90,9 @@ private Q_SLOTS:
|
|||||||
// void objc_methods();
|
// void objc_methods();
|
||||||
// void objc_fields();
|
// void objc_fields();
|
||||||
// void objc_classes();
|
// void objc_classes();
|
||||||
|
|
||||||
|
// templates
|
||||||
|
void instantiateTemplateWithNestedClass();
|
||||||
};
|
};
|
||||||
|
|
||||||
void tst_FindUsages::inlineMethod()
|
void tst_FindUsages::inlineMethod()
|
||||||
@@ -351,5 +354,48 @@ void tst_FindUsages::qproperty_1()
|
|||||||
QCOMPARE(findUsages.references().size(), 2);
|
QCOMPARE(findUsages.references().size(), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_FindUsages::instantiateTemplateWithNestedClass()
|
||||||
|
{
|
||||||
|
const QByteArray src = "\n"
|
||||||
|
"struct Foo\n"
|
||||||
|
"{ int bar; };\n"
|
||||||
|
"template <typename T>\n"
|
||||||
|
"struct Template\n"
|
||||||
|
"{\n"
|
||||||
|
" struct Nested\n"
|
||||||
|
" {\n"
|
||||||
|
" T t;\n"
|
||||||
|
" }nested;\n"
|
||||||
|
"};\n"
|
||||||
|
"void f()\n"
|
||||||
|
"{\n"
|
||||||
|
" Template<Foo> templateFoo;\n"
|
||||||
|
" templateFoo.nested.t.bar;\n"
|
||||||
|
"}\n"
|
||||||
|
;
|
||||||
|
|
||||||
|
Document::Ptr doc = Document::create("simpleTemplate");
|
||||||
|
doc->setUtf8Source(src);
|
||||||
|
doc->parse();
|
||||||
|
doc->check();
|
||||||
|
|
||||||
|
QVERIFY(doc->diagnosticMessages().isEmpty());
|
||||||
|
QCOMPARE(doc->globalSymbolCount(), 3U);
|
||||||
|
|
||||||
|
Snapshot snapshot;
|
||||||
|
snapshot.insert(doc);
|
||||||
|
|
||||||
|
Class *classFoo = doc->globalSymbolAt(0)->asClass();
|
||||||
|
QVERIFY(classFoo);
|
||||||
|
QCOMPARE(classFoo->memberCount(), 1U);
|
||||||
|
Declaration *barDeclaration = classFoo->memberAt(0)->asDeclaration();
|
||||||
|
QVERIFY(barDeclaration);
|
||||||
|
QCOMPARE(barDeclaration->name()->identifier()->chars(), "bar");
|
||||||
|
|
||||||
|
FindUsages findUsages(src, doc, snapshot);
|
||||||
|
findUsages(barDeclaration);
|
||||||
|
QCOMPARE(findUsages.usages().size(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_APPLESS_MAIN(tst_FindUsages)
|
QTEST_APPLESS_MAIN(tst_FindUsages)
|
||||||
#include "tst_findusages.moc"
|
#include "tst_findusages.moc"
|
||||||
|
Reference in New Issue
Block a user