Commit e1a0f5ab authored by Christian Kamm's avatar Christian Kamm
Browse files

C++: Make 'follow symbol' work with forward declared classes.

If it encounters a forward declaration, it tries to find the class
declaration globally now.

Task-number: QTCREATORBUG-20
parent 2deae8c8
...@@ -793,3 +793,26 @@ Symbol *Snapshot::findMatchingDefinition(Symbol *symbol) const ...@@ -793,3 +793,26 @@ Symbol *Snapshot::findMatchingDefinition(Symbol *symbol) const
return 0; return 0;
} }
Class *Snapshot::findMatchingClassDeclaration(Symbol *declaration) const
{
if (! declaration->identifier())
return 0;
foreach (Document::Ptr doc, *this) {
if (! doc->control()->findIdentifier(declaration->identifier()->chars(),
declaration->identifier()->size()))
continue;
LookupContext context(doc, *this);
ClassOrNamespace *type = context.lookupType(declaration);
if (!type || type->symbols().count() != 1)
continue;
if (Class *c = type->symbols().first()->asClass())
return c;
}
return 0;
}
...@@ -372,6 +372,7 @@ public: ...@@ -372,6 +372,7 @@ public:
const QString &fileName) const; const QString &fileName) const;
Symbol *findMatchingDefinition(Symbol *symbol) const; Symbol *findMatchingDefinition(Symbol *symbol) const;
Class *findMatchingClassDeclaration(Symbol *symbol) const;
private: private:
void simplified_helper(Document::Ptr doc, Snapshot *snapshot) const; void simplified_helper(Document::Ptr doc, Snapshot *snapshot) const;
......
...@@ -64,7 +64,8 @@ static void fullyQualifiedName_helper(Symbol *symbol, QList<const Name *> *names ...@@ -64,7 +64,8 @@ static void fullyQualifiedName_helper(Symbol *symbol, QList<const Name *> *names
names->append(symbol->name()); names->append(symbol->name());
} }
} else if (symbol->isObjCClass() || symbol->isObjCBaseClass() || symbol->isObjCProtocol() } else if (symbol->isObjCClass() || symbol->isObjCBaseClass() || symbol->isObjCProtocol()
|| symbol->isObjCForwardClassDeclaration() || symbol->isObjCForwardProtocolDeclaration()) { || symbol->isObjCForwardClassDeclaration() || symbol->isObjCForwardProtocolDeclaration()
|| symbol->isForwardClassDeclaration()) {
if (symbol->name()) if (symbol->name())
names->append(symbol->name()); names->append(symbol->name());
} else if (symbol->isFunction()) { } else if (symbol->isFunction()) {
......
...@@ -1315,6 +1315,10 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor, ...@@ -1315,6 +1315,10 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
def = 0; // jump to declaration then. def = 0; // jump to declaration then.
} }
if (symbol->isForwardClassDeclaration()) {
def = snapshot.findMatchingClassDeclaration(symbol);
}
link = linkToSymbol(def ? def : symbol); link = linkToSymbol(def ? def : symbol);
link.begin = beginOfToken; link.begin = beginOfToken;
link.end = endOfToken; link.end = endOfToken;
......
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