forked from qt-creator/qt-creator
C++: fix highlighting type when there is using Namespace::Class
If type is not found we try to find 'using' declaration for this type. Task-number: QTCREATORBUG-7903 Change-Id: I569db9e1a8504a5da3115ebbed2e823d5924f6ca Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
committed by
Erik Verbruggen
parent
e245f2d5f9
commit
d14767a6af
@@ -210,7 +210,7 @@ bool FindUsages::checkCandidates(const QList<LookupItem> &candidates) const
|
||||
if (s->enclosingScope()->isTemplate()) {
|
||||
if (s->enclosingScope()->enclosingScope() != _declSymbol->enclosingScope())
|
||||
return false;
|
||||
} else if (s->enclosingScope() != _declSymbol->enclosingScope()) {
|
||||
} else if (! s->isUsingDeclaration() && s->enclosingScope() != _declSymbol->enclosingScope()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,6 +247,33 @@ const Name *LookupContext::minimalName(Symbol *symbol, ClassOrNamespace *target,
|
||||
return n;
|
||||
}
|
||||
|
||||
QList<LookupItem> LookupContext::lookupByUsing(const Name *name, Scope *scope) const
|
||||
{
|
||||
QList<LookupItem> candidates;
|
||||
// if it is a nameId there can be a using declaration for it
|
||||
if (name->isNameId()) {
|
||||
for (unsigned i = 0, count = scope->memberCount(); i < count; ++i) {
|
||||
if (UsingDeclaration *u = scope->memberAt(i)->asUsingDeclaration()) {
|
||||
if (const QualifiedNameId *q = u->name()->asQualifiedNameId()) {
|
||||
if (q->name()->isEqualTo(name)) {
|
||||
candidates = bindings()->globalNamespace()->find(q);
|
||||
|
||||
// if it is not a global scope(scope of scope is not equal 0)
|
||||
// then add current using declaration as a candidate
|
||||
if (scope->scope()) {
|
||||
LookupItem item;
|
||||
item.setDeclaration(u);
|
||||
item.setScope(scope);
|
||||
candidates.append(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return candidates;
|
||||
}
|
||||
|
||||
|
||||
QSharedPointer<CreateBindings> LookupContext::bindings() const
|
||||
{
|
||||
@@ -365,6 +392,10 @@ QList<LookupItem> LookupContext::lookup(const Name *name, Scope *scope) const
|
||||
}
|
||||
}
|
||||
|
||||
candidates = lookupByUsing(name, scope);
|
||||
if (! candidates.isEmpty())
|
||||
return candidates;
|
||||
|
||||
} else if (Function *fun = scope->asFunction()) {
|
||||
bindings()->lookupInScope(name, fun, &candidates, /*templateId = */ 0, /*binding=*/ 0);
|
||||
|
||||
@@ -390,7 +421,7 @@ QList<LookupItem> LookupContext::lookup(const Name *name, Scope *scope) const
|
||||
}
|
||||
}
|
||||
|
||||
// contunue, and look at the enclosing scope.
|
||||
// continue, and look at the enclosing scope.
|
||||
|
||||
} else if (ObjCMethod *method = scope->asObjCMethod()) {
|
||||
bindings()->lookupInScope(name, method, &candidates, /*templateId = */ 0, /*binding=*/ 0);
|
||||
@@ -416,8 +447,12 @@ QList<LookupItem> LookupContext::lookup(const Name *name, Scope *scope) const
|
||||
if (ClassOrNamespace *binding = bindings()->lookupType(scope))
|
||||
candidates = binding->find(name);
|
||||
|
||||
if (! candidates.isEmpty())
|
||||
return candidates;
|
||||
if (! candidates.isEmpty())
|
||||
return candidates;
|
||||
|
||||
candidates = lookupByUsing(name, scope);
|
||||
if (! candidates.isEmpty())
|
||||
return candidates;
|
||||
|
||||
} else if (scope->isObjCClass() || scope->isObjCProtocol()) {
|
||||
if (ClassOrNamespace *binding = bindings()->lookupType(scope))
|
||||
|
||||
@@ -311,6 +311,8 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
QList<LookupItem> lookupByUsing(const Name *name, Scope *scope) const;
|
||||
|
||||
// The current expression.
|
||||
Document::Ptr _expressionDocument;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user