forked from qt-creator/qt-creator
ObjC++: also index ObjC symbols.
@classes, @protocols, @properties and -methods (and +methods) will now show up in the locator. Change-Id: I33f904c456c321fc80b8aba7ff52d5f1207c58be Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
committed by
Nikolai Kosjar
parent
b8adc78615
commit
3a242495fe
2
src/libs/3rdparty/cplusplus/Bind.cpp
vendored
2
src/libs/3rdparty/cplusplus/Bind.cpp
vendored
@@ -2567,6 +2567,8 @@ bool Bind::visit(ObjCMethodDeclarationAST *ast)
|
|||||||
this->statement(ast->function_body);
|
this->statement(ast->function_body);
|
||||||
(void) switchScope(previousScope);
|
(void) switchScope(previousScope);
|
||||||
_scope->addMember(method);
|
_scope->addMember(method);
|
||||||
|
} else if (method) {
|
||||||
|
_scope->addMember(method);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -168,7 +168,9 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data()
|
|||||||
|
|
||||||
MyTestDataDir testDirectory(QLatin1String("testdata_basic"));
|
MyTestDataDir testDirectory(QLatin1String("testdata_basic"));
|
||||||
const QString testFile = testDirectory.file(QLatin1String("file1.cpp"));
|
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 testFileShort = FileUtils::shortNativePath(FileName::fromString(testFile));
|
||||||
|
const QString objTestFileShort = FileUtils::shortNativePath(FileName::fromString(objTestFile));
|
||||||
|
|
||||||
QTest::newRow("CppFunctionsFilter")
|
QTest::newRow("CppFunctionsFilter")
|
||||||
<< testFile
|
<< testFile
|
||||||
@@ -247,6 +249,27 @@ void CppToolsPlugin::test_cpplocatorfilters_CppLocatorFilter_data()
|
|||||||
<< ResultData(_("MyNamespace::myFunction"), _("(bool, int)"))
|
<< ResultData(_("MyNamespace::myFunction"), _("(bool, int)"))
|
||||||
<< ResultData(_("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()
|
void CppToolsPlugin::test_cpplocatorfilters_CppCurrentDocumentFilter()
|
||||||
|
|||||||
@@ -105,11 +105,7 @@ bool SearchSymbols::visit(Enum *symbol)
|
|||||||
|
|
||||||
bool SearchSymbols::visit(Function *symbol)
|
bool SearchSymbols::visit(Function *symbol)
|
||||||
{
|
{
|
||||||
if (!(symbolsToSearchFor & SymbolSearcher::Functions) || !symbol->name())
|
processFunction(symbol);
|
||||||
return false;
|
|
||||||
QString name = overview.prettyName(symbol->name());
|
|
||||||
QString type = overview.prettyType(symbol->type());
|
|
||||||
addChildItem(name, type, _scope, IndexItem::Function, symbol);
|
|
||||||
return false;
|
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 we're searching for functions, still allow signal declarations to show up.
|
||||||
if (symbolsToSearchFor & SymbolSearcher::Functions) {
|
if (symbolsToSearchFor & SymbolSearcher::Functions) {
|
||||||
Function *funTy = symbol->type()->asFunctionType();
|
Function *funTy = symbol->type()->asFunctionType();
|
||||||
if (!funTy)
|
if (!funTy) {
|
||||||
|
if (!symbol->type()->asObjCMethodType())
|
||||||
return false;
|
return false;
|
||||||
if (!funTy->isSignal())
|
} else if (!funTy->isSignal()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -153,19 +151,7 @@ bool SearchSymbols::visit(Declaration *symbol)
|
|||||||
|
|
||||||
bool SearchSymbols::visit(Class *symbol)
|
bool SearchSymbols::visit(Class *symbol)
|
||||||
{
|
{
|
||||||
QString name = overview.prettyName(symbol->name());
|
processClass(symbol);
|
||||||
|
|
||||||
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));
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -225,8 +211,10 @@ bool SearchSymbols::visit(CPlusPlus::ObjCBaseProtocol *)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SearchSymbols::visit(CPlusPlus::ObjCClass *)
|
bool SearchSymbols::visit(CPlusPlus::ObjCClass *symbol)
|
||||||
{
|
{
|
||||||
|
processClass(symbol);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,8 +223,10 @@ bool SearchSymbols::visit(CPlusPlus::ObjCForwardClassDeclaration *)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SearchSymbols::visit(CPlusPlus::ObjCProtocol *)
|
bool SearchSymbols::visit(CPlusPlus::ObjCProtocol *symbol)
|
||||||
{
|
{
|
||||||
|
processClass(symbol);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,13 +235,15 @@ bool SearchSymbols::visit(CPlusPlus::ObjCForwardProtocolDeclaration *)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SearchSymbols::visit(CPlusPlus::ObjCMethod *)
|
bool SearchSymbols::visit(CPlusPlus::ObjCMethod *symbol)
|
||||||
{
|
{
|
||||||
|
processFunction(symbol);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SearchSymbols::visit(CPlusPlus::ObjCPropertyDeclaration *)
|
bool SearchSymbols::visit(CPlusPlus::ObjCPropertyDeclaration *symbol)
|
||||||
{
|
{
|
||||||
|
processFunction(symbol);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,3 +307,31 @@ IndexItem::Ptr SearchSymbols::addChildItem(const QString &symbolName, const QStr
|
|||||||
_parent->addChild(newItem);
|
_parent->addChild(newItem);
|
||||||
return 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
|
// Objective-C
|
||||||
virtual bool visit(CPlusPlus::ObjCBaseClass *);
|
virtual bool visit(CPlusPlus::ObjCBaseClass *);
|
||||||
virtual bool visit(CPlusPlus::ObjCBaseProtocol *);
|
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::ObjCForwardClassDeclaration *);
|
||||||
virtual bool visit(CPlusPlus::ObjCProtocol *);
|
virtual bool visit(CPlusPlus::ObjCProtocol *symbol);
|
||||||
virtual bool visit(CPlusPlus::ObjCForwardProtocolDeclaration *);
|
virtual bool visit(CPlusPlus::ObjCForwardProtocolDeclaration *);
|
||||||
virtual bool visit(CPlusPlus::ObjCMethod *);
|
virtual bool visit(CPlusPlus::ObjCMethod *symbol);
|
||||||
virtual bool visit(CPlusPlus::ObjCPropertyDeclaration *);
|
virtual bool visit(CPlusPlus::ObjCPropertyDeclaration *symbol);
|
||||||
|
|
||||||
QString scopedSymbolName(const QString &symbolName, const CPlusPlus::Symbol *symbol) const;
|
QString scopedSymbolName(const QString &symbolName, const CPlusPlus::Symbol *symbol) const;
|
||||||
QString scopedSymbolName(const CPlusPlus::Symbol *symbol) const;
|
QString scopedSymbolName(const CPlusPlus::Symbol *symbol) const;
|
||||||
@@ -99,6 +99,10 @@ protected:
|
|||||||
const QString &symbolScope, IndexItem::ItemType type,
|
const QString &symbolScope, IndexItem::ItemType type,
|
||||||
CPlusPlus::Symbol *symbol);
|
CPlusPlus::Symbol *symbol);
|
||||||
|
|
||||||
|
private:
|
||||||
|
template<class T> void processClass(T *clazz);
|
||||||
|
template<class T> void processFunction(T *func);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString findOrInsert(const QString &s)
|
QString findOrInsert(const QString &s)
|
||||||
{ return strings.insert(s); }
|
{ return strings.insert(s); }
|
||||||
|
|||||||
23
tests/cpplocators/testdata_basic/file1.mm
Normal file
23
tests/cpplocators/testdata_basic/file1.mm
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
// 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
|
||||||
Reference in New Issue
Block a user