Commit 3a242495 authored by Erik Verbruggen's avatar Erik Verbruggen Committed by Nikolai Kosjar

ObjC++: also index ObjC symbols.

@classes, @protocols, @properties and -methods (and +methods) will now
show up in the locator.

Change-Id: I33f904c456c321fc80b8aba7ff52d5f1207c58be
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent b8adc786
......@@ -2567,6 +2567,8 @@ bool Bind::visit(ObjCMethodDeclarationAST *ast)
this->statement(ast->function_body);
(void) switchScope(previousScope);
_scope->addMember(method);
} else if (method) {
_scope->addMember(method);
}
return false;
......
......@@ -168,7 +168,9 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data()
MyTestDataDir testDirectory(QLatin1String("testdata_basic"));
const QString testFile = testDirectory.file(QLatin1String("file1.cpp"));
const QString objTestFile = testDirectory.file(QLatin1String("file1.mm"));
const QString testFileShort = FileUtils::shortNativePath(FileName::fromString(testFile));
const QString objTestFileShort = FileUtils::shortNativePath(FileName::fromString(objTestFile));
QTest::newRow("CppFunctionsFilter")
<< testFile
......@@ -247,6 +249,27 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data()
<< ResultData(_("MyNamespace::myFunction"), _("(bool, int)"))
<< ResultData(_("myFunction"), _("(bool, int)"))
);
QTest::newRow("CppClassesFilter-ObjC")
<< objTestFile
<< cppClassesFilter
<< _("M")
<< (QList<ResultData>()
<< ResultData(_("MyClass"), objTestFileShort)
<< ResultData(_("MyClass"), objTestFileShort)
<< ResultData(_("MyClass"), objTestFileShort)
<< ResultData(_("MyProtocol"), objTestFileShort)
);
QTest::newRow("CppFunctionsFilter-ObjC")
<< objTestFile
<< cppFunctionsFilter
<< _("M")
<< (QList<ResultData>()
<< ResultData(_("anotherMethod"), _("MyClass"))
<< ResultData(_("anotherMethod:"), _("MyClass"))
<< ResultData(_("someMethod"), _("MyClass"))
);
}
void CppToolsPlugin::test_cpplocatorfilters_CppCurrentDocumentFilter()
......
......@@ -105,11 +105,7 @@ bool SearchSymbols::visit(Enum *symbol)
bool SearchSymbols::visit(Function *symbol)
{
if (!(symbolsToSearchFor & SymbolSearcher::Functions) || !symbol->name())
return false;
QString name = overview.prettyName(symbol->name());
QString type = overview.prettyType(symbol->type());
addChildItem(name, type, _scope, IndexItem::Function, symbol);
processFunction(symbol);
return false;
}
......@@ -130,10 +126,12 @@ bool SearchSymbols::visit(Declaration *symbol)
// if we're searching for functions, still allow signal declarations to show up.
if (symbolsToSearchFor & SymbolSearcher::Functions) {
Function *funTy = symbol->type()->asFunctionType();
if (!funTy)
return false;
if (!funTy->isSignal())
if (!funTy) {
if (!symbol->type()->asObjCMethodType())
return false;
} else if (!funTy->isSignal()) {
return false;
}
} else {
return false;
}
......@@ -153,19 +151,7 @@ bool SearchSymbols::visit(Declaration *symbol)
bool SearchSymbols::visit(Class *symbol)
{
QString name = overview.prettyName(symbol->name());
IndexItem::Ptr newParent;
if (symbolsToSearchFor & SymbolSearcher::Classes)
newParent = addChildItem(name, QString(), _scope, IndexItem::Class, symbol);
if (!newParent)
newParent = _parent;
ScopedIndexItemPtr parentRaii(_parent, newParent);
QString newScope = scopedSymbolName(name, symbol);
ScopedScope scopeRaii(_scope, newScope);
for (unsigned i = 0, ei = symbol->memberCount(); i != ei; ++i)
accept(symbol->memberAt(i));
processClass(symbol);
return false;
}
......@@ -225,8 +211,10 @@ bool SearchSymbols::visit(CPlusPlus::ObjCBaseProtocol *)
return false;
}
bool SearchSymbols::visit(CPlusPlus::ObjCClass *)
bool SearchSymbols::visit(CPlusPlus::ObjCClass *symbol)
{
processClass(symbol);
return false;
}
......@@ -235,8 +223,10 @@ bool SearchSymbols::visit(CPlusPlus::ObjCForwardClassDeclaration *)
return false;
}
bool SearchSymbols::visit(CPlusPlus::ObjCProtocol *)
bool SearchSymbols::visit(CPlusPlus::ObjCProtocol *symbol)
{
processClass(symbol);
return false;
}
......@@ -245,13 +235,15 @@ bool SearchSymbols::visit(CPlusPlus::ObjCForwardProtocolDeclaration *)
return false;
}
bool SearchSymbols::visit(CPlusPlus::ObjCMethod *)
bool SearchSymbols::visit(CPlusPlus::ObjCMethod *symbol)
{
processFunction(symbol);
return false;
}
bool SearchSymbols::visit(CPlusPlus::ObjCPropertyDeclaration *)
bool SearchSymbols::visit(CPlusPlus::ObjCPropertyDeclaration *symbol)
{
processFunction(symbol);
return false;
}
......@@ -315,3 +307,31 @@ IndexItem::Ptr SearchSymbols::addChildItem(const QString &symbolName, const QStr
_parent->addChild(newItem);
return newItem;
}
template<class T>
void SearchSymbols::processClass(T *clazz)
{
QString name = overview.prettyName(clazz->name());
IndexItem::Ptr newParent;
if (symbolsToSearchFor & SymbolSearcher::Classes)
newParent = addChildItem(name, QString(), _scope, IndexItem::Class, clazz);
if (!newParent)
newParent = _parent;
ScopedIndexItemPtr parentRaii(_parent, newParent);
QString newScope = scopedSymbolName(name, clazz);
ScopedScope scopeRaii(_scope, newScope);
for (unsigned i = 0, ei = clazz->memberCount(); i != ei; ++i)
accept(clazz->memberAt(i));
}
template<class T>
void SearchSymbols::processFunction(T *func)
{
if (!(symbolsToSearchFor & SymbolSearcher::Functions) || !func->name())
return;
QString name = overview.prettyName(func->name());
QString type = overview.prettyType(func->type());
addChildItem(name, type, _scope, IndexItem::Function, func);
}
......@@ -85,12 +85,12 @@ protected:
// Objective-C
virtual bool visit(CPlusPlus::ObjCBaseClass *);
virtual bool visit(CPlusPlus::ObjCBaseProtocol *);
virtual bool visit(CPlusPlus::ObjCClass *);
virtual bool visit(CPlusPlus::ObjCClass *symbol);
virtual bool visit(CPlusPlus::ObjCForwardClassDeclaration *);
virtual bool visit(CPlusPlus::ObjCProtocol *);
virtual bool visit(CPlusPlus::ObjCProtocol *symbol);
virtual bool visit(CPlusPlus::ObjCForwardProtocolDeclaration *);
virtual bool visit(CPlusPlus::ObjCMethod *);
virtual bool visit(CPlusPlus::ObjCPropertyDeclaration *);
virtual bool visit(CPlusPlus::ObjCMethod *symbol);
virtual bool visit(CPlusPlus::ObjCPropertyDeclaration *symbol);
QString scopedSymbolName(const QString &symbolName, const CPlusPlus::Symbol *symbol) const;
QString scopedSymbolName(const CPlusPlus::Symbol *symbol) const;
......@@ -99,6 +99,10 @@ protected:
const QString &symbolScope, IndexItem::ItemType type,
CPlusPlus::Symbol *symbol);
private:
template<class T> void processClass(T *clazz);
template<class T> void processFunction(T *func);
private:
QString findOrInsert(const QString &s)
{ return strings.insert(s); }
......
// Copyright header to keep the Qt Insanity Bot happy.
@protocol NSObject
@end
@interface NSObject<NSObject>
@end
@protocol MyProtocol <NSObject>
- (void) someMethod;
@end
@interface MyClass: NSObject <MyProtocol>
@end
@implementation MyClass
- (void) someMethod {}
@end
@implementation MyClass(MyCategory)
- (void) anotherMethod;{}
- (void) anotherMethod:(NSObject*)withAnObject{}
@end
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