forked from qt-creator/qt-creator
QmlJSEditor: Adding and exporting helper function for usages
This patch adds and exports findUsageOfType() which can be used in e.g. the Qt Quick Desigener. Change-Id: I6e87df746bdb377485da052823f86b89d638ac2f Reviewed-by: Fawzi Mohamed <fawzi.mohamed@theqtcompany.com>
This commit is contained in:
committed by
Thomas Hartmann
parent
38609296d1
commit
ed49052f6a
@@ -920,6 +920,33 @@ void FindReferences::renameUsages(const QString &fileName, quint32 offset,
|
||||
m_watcher.setFuture(result);
|
||||
}
|
||||
|
||||
QList<FindReferences::Usage> FindReferences::findUsageOfType(const QString &fileName, const QString typeName)
|
||||
{
|
||||
QList<Usage> 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
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
#ifndef QMLJSFINDREFERENCES_H
|
||||
#define QMLJSFINDREFERENCES_H
|
||||
|
||||
#include "qmljseditor_global.h"
|
||||
|
||||
#include <QMutex>
|
||||
#include <QObject>
|
||||
#include <QFuture>
|
||||
@@ -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<Usage> findUsageOfType(const QString &fileName, const QString typeName);
|
||||
|
||||
private Q_SLOTS:
|
||||
void displayResults(int first, int last);
|
||||
void searchFinished();
|
||||
|
||||
Reference in New Issue
Block a user