diff --git a/src/plugins/qmljseditor/qmljsfindreferences.cpp b/src/plugins/qmljseditor/qmljsfindreferences.cpp index c3ad1ec7d13..2c518ca52ed 100644 --- a/src/plugins/qmljseditor/qmljsfindreferences.cpp +++ b/src/plugins/qmljseditor/qmljsfindreferences.cpp @@ -920,6 +920,33 @@ void FindReferences::renameUsages(const QString &fileName, quint32 offset, m_watcher.setFuture(result); } +QList FindReferences::findUsageOfType(const QString &fileName, const QString typeName) +{ + QList usages; + ModelManagerInterface *modelManager = ModelManagerInterface::instance(); + + Document::Ptr doc = modelManager->snapshot().document(fileName); + if (!doc) + return usages; + + Link link(modelManager->snapshot(), modelManager->defaultVContext(doc->language(), doc), modelManager->builtins(doc)); + ContextPtr context = link(); + ScopeChain scopeChain(doc, context); + + const ObjectValue *targetValue = scopeChain.context()->lookupType(doc.data(), QStringList(typeName)); + + QmlJS::Snapshot snapshot = modelManager->snapshot(); + + foreach (const QmlJS::Document::Ptr &doc, snapshot) { + FindTypeUsages findUsages(doc, context); + FindTypeUsages::Result results = findUsages(typeName, targetValue); + foreach (const AST::SourceLocation &loc, results) { + usages.append(Usage(doc->fileName(), matchingLine(loc.offset, doc->source()), loc.startLine, loc.startColumn - 1, loc.length)); + } + } + return usages; +} + void FindReferences::displayResults(int first, int last) { // the first usage is always a dummy to indicate we now start searching diff --git a/src/plugins/qmljseditor/qmljsfindreferences.h b/src/plugins/qmljseditor/qmljsfindreferences.h index c05a2c42777..1435c40395f 100644 --- a/src/plugins/qmljseditor/qmljsfindreferences.h +++ b/src/plugins/qmljseditor/qmljsfindreferences.h @@ -31,6 +31,8 @@ #ifndef QMLJSFINDREFERENCES_H #define QMLJSFINDREFERENCES_H +#include "qmljseditor_global.h" + #include #include #include @@ -48,7 +50,7 @@ class SearchResult; namespace QmlJSEditor { -class FindReferences: public QObject +class QMLJSEDITOR_EXPORT FindReferences: public QObject { Q_OBJECT public: @@ -81,6 +83,8 @@ public: void renameUsages(const QString &fileName, quint32 offset, const QString &replacement = QString()); + static QList findUsageOfType(const QString &fileName, const QString typeName); + private Q_SLOTS: void displayResults(int first, int last); void searchFinished();