From 799fc18bd753d8cdbc312b00f9cf8d75513a5103 Mon Sep 17 00:00:00 2001 From: Aurindam Jana Date: Fri, 25 May 2012 17:43:56 +0200 Subject: [PATCH] QmlJSInspector: Remove dependency on QmlJSTools As Location information is already cached, there is no need to fetch the information from the QmlJS Semantic info. Task-number: QTCREATORBUG-7409 Change-Id: I9cc3dce0910632cfe517f7697d74691e6675793b Reviewed-by: Christiaan Janssen --- src/libs/qmldebug/baseenginedebugclient.h | 15 +++- src/plugins/debugger/Debugger.pluginspec.in | 1 - .../debugger/debugger_dependencies.pri | 1 - .../debugger/qml/qmlinspectoradapter.cpp | 75 +++---------------- .../debugger/qml/qmlinspectoradapter.h | 5 +- .../debugger/qml/qmlinspectoragent.cpp | 36 ++++++++- src/plugins/debugger/qml/qmlinspectoragent.h | 5 +- .../debugger/qml/qmllivetextpreview.cpp | 2 +- 8 files changed, 64 insertions(+), 76 deletions(-) diff --git a/src/libs/qmldebug/baseenginedebugclient.h b/src/libs/qmldebug/baseenginedebugclient.h index 4f050c26302..1abcaa2820e 100644 --- a/src/libs/qmldebug/baseenginedebugclient.h +++ b/src/libs/qmldebug/baseenginedebugclient.h @@ -140,8 +140,19 @@ private: class ObjectReference { public: - ObjectReference() : m_debugId(-1), m_parentId(-1), m_contextDebugId(-1), m_needsMoreData(false) {} - explicit ObjectReference(int id) : m_debugId(id), m_parentId(-1), m_contextDebugId(-1), m_needsMoreData(false) {} + ObjectReference() + : m_debugId(-1), m_parentId(-1), m_contextDebugId(-1), m_needsMoreData(false) + { + } + explicit ObjectReference(int id) + : m_debugId(id), m_parentId(-1), m_contextDebugId(-1), m_needsMoreData(false) + { + } + ObjectReference(int id, int parentId, const FileReference &source) + : m_debugId(id), m_parentId(parentId), m_source(source), + m_contextDebugId(-1), m_needsMoreData(false) + { + } int debugId() const { return m_debugId; } int parentId() const { return m_parentId; } diff --git a/src/plugins/debugger/Debugger.pluginspec.in b/src/plugins/debugger/Debugger.pluginspec.in index a2b6521ae6d..77d13834f8a 100644 --- a/src/plugins/debugger/Debugger.pluginspec.in +++ b/src/plugins/debugger/Debugger.pluginspec.in @@ -18,7 +18,6 @@ Alternatively, this plugin may be used under the terms of the GNU Lesser General - diff --git a/src/plugins/debugger/debugger_dependencies.pri b/src/plugins/debugger/debugger_dependencies.pri index e99a0c39f53..d6cb1671060 100644 --- a/src/plugins/debugger/debugger_dependencies.pri +++ b/src/plugins/debugger/debugger_dependencies.pri @@ -3,7 +3,6 @@ include(../../plugins/cpptools/cpptools.pri) include(../../plugins/find/find.pri) include(../../plugins/projectexplorer/projectexplorer.pri) include(../../plugins/texteditor/texteditor.pri) -include(../../plugins/qmljstools/qmljstools.pri) include(../../libs/cplusplus/cplusplus.pri) include(../../libs/utils/utils.pri) include(../../libs/symbianutils/symbianutils.pri) diff --git a/src/plugins/debugger/qml/qmlinspectoradapter.cpp b/src/plugins/debugger/qml/qmlinspectoradapter.cpp index 70a7020deca..5a5b5294c5c 100644 --- a/src/plugins/debugger/qml/qmlinspectoradapter.cpp +++ b/src/plugins/debugger/qml/qmlinspectoradapter.cpp @@ -49,7 +49,6 @@ #include #include #include -#include #include #include @@ -57,24 +56,6 @@ using namespace QmlDebug; namespace Debugger { namespace Internal { - -// Get semantic info from QmlJSTextEditorWidget -// (we use the meta object system here to avoid having to link -// against qmljseditor) -static QmlJSTools::SemanticInfo getSemanticInfo(QPlainTextEdit *qmlJSTextEdit) -{ - QmlJSTools::SemanticInfo info; - QTC_ASSERT(QLatin1String(qmlJSTextEdit->metaObject()->className()) - == QLatin1String("QmlJSEditor::QmlJSTextEditorWidget"), - return info); - QTC_ASSERT(qmlJSTextEdit->metaObject()->indexOfProperty("semanticInfo") - != -1, return info); - - info = qmlJSTextEdit->property("semanticInfo") - .value(); - return info; -} - /*! * QmlInspectorAdapter manages the clients for the inspector, and the * integration with the text editor. @@ -281,7 +262,7 @@ void QmlInspectorAdapter::selectObjectsFromEditor(const QList &debugIds) m_cursorPositionChangedExternally = true; m_targetToSync = ToolTarget; m_debugIdToSelect = debugIds.first(); - selectObject(ObjectReference(m_debugIdToSelect), ToolTarget); + selectObject(agent()->objectForId(m_debugIdToSelect), ToolTarget); } void QmlInspectorAdapter::selectObjectsFromToolsClient(const QList &debugIds) @@ -291,7 +272,7 @@ void QmlInspectorAdapter::selectObjectsFromToolsClient(const QList &debugId m_targetToSync = EditorTarget; m_debugIdToSelect = debugIds.first(); - selectObject(ObjectReference(m_debugIdToSelect), EditorTarget); + selectObject(agent()->objectForId(m_debugIdToSelect), EditorTarget); } void QmlInspectorAdapter::onObjectFetched(const ObjectReference &ref) @@ -477,16 +458,14 @@ void QmlInspectorAdapter::showConnectionStatusMessage(const QString &message) } void QmlInspectorAdapter::gotoObjectReferenceDefinition( - const ObjectReference &obj) + const FileReference &objSource) { if (m_cursorPositionChangedExternally) { m_cursorPositionChangedExternally = false; return; } - FileReference source = obj.source(); - - const QString fileName = m_engine->toFileInProject(source.url()); + const QString fileName = m_engine->toFileInProject(objSource.url()); Core::EditorManager *editorManager = Core::EditorManager::instance(); Core::IEditor *currentEditor = editorManager->currentEditor(); @@ -498,46 +477,13 @@ void QmlInspectorAdapter::gotoObjectReferenceDefinition( m_selectionCallbackExpected = true; if (textEditor) { - if (objectIdForLocation(fileName) != obj.debugId()) { - m_selectionCallbackExpected = true; - editorManager->addCurrentPositionToNavigationHistory(); - textEditor->gotoLine(source.lineNumber()); - textEditor->widget()->setFocus(); - } + m_selectionCallbackExpected = true; + editorManager->addCurrentPositionToNavigationHistory(); + textEditor->gotoLine(objSource.lineNumber()); + textEditor->widget()->setFocus(); } } -int QmlInspectorAdapter::objectIdForLocation( - const QString &fileName, int cursorPosition) const -{ - Core::IEditor *editor = Core::EditorManager::openEditor(fileName); - TextEditor::ITextEditor *textEditor - = qobject_cast(editor); - - if (textEditor - && textEditor->id() == QmlJSEditor::Constants::C_QMLJSEDITOR_ID) { - if (cursorPosition == -1) - cursorPosition = textEditor->position(); - TextEditor::BaseTextEditor *baseTextEditor = - static_cast(editor); - QPlainTextEdit *editWidget - = qobject_cast(baseTextEditor->widget()); - - QmlJSTools::SemanticInfo semanticInfo = getSemanticInfo(editWidget); - - if (QmlJS::AST::Node *node - = semanticInfo.declaringMemberNoProperties(cursorPosition)) { - if (QmlJS::AST::UiObjectMember *objMember - = node->uiObjectMemberCast()) { - return agent()->objectIdForLocation( - objMember->firstSourceLocation().startLine, - objMember->firstSourceLocation().startColumn); - } - } - } - return -1; -} - void QmlInspectorAdapter::selectObject(const ObjectReference &obj, SelectionTarget target) { @@ -546,9 +492,10 @@ void QmlInspectorAdapter::selectObject(const ObjectReference &obj, QList() << obj); if (target == EditorTarget) - gotoObjectReferenceDefinition(obj); + gotoObjectReferenceDefinition(obj.source()); - agent()->selectObjectInTree(obj.debugId()); + if (!agent()->selectObjectInTree(obj.debugId())) + return; m_currentSelectedDebugId = obj.debugId(); m_currentSelectedDebugName = agent()->displayName(obj.debugId()); diff --git a/src/plugins/debugger/qml/qmlinspectoradapter.h b/src/plugins/debugger/qml/qmlinspectoradapter.h index 2e1f99b39fc..e6ed0dd4f7a 100644 --- a/src/plugins/debugger/qml/qmlinspectoradapter.h +++ b/src/plugins/debugger/qml/qmlinspectoradapter.h @@ -48,6 +48,7 @@ namespace QmlDebug { class BaseEngineDebugClient; class BaseToolsClient; class ObjectReference; +class FileReference; } namespace Debugger { @@ -106,9 +107,7 @@ private: void initializePreviews(); void showConnectionStatusMessage(const QString &message); - void gotoObjectReferenceDefinition(const QmlDebug::ObjectReference &obj); - int objectIdForLocation( - const QString &fileName, int cursorPosition = -1) const; + void gotoObjectReferenceDefinition(const QmlDebug::FileReference &objSource); enum SelectionTarget { NoTarget, ToolTarget, EditorTarget }; void selectObject( diff --git a/src/plugins/debugger/qml/qmlinspectoragent.cpp b/src/plugins/debugger/qml/qmlinspectoragent.cpp index d3755c323be..d2c49ac07e9 100644 --- a/src/plugins/debugger/qml/qmlinspectoragent.cpp +++ b/src/plugins/debugger/qml/qmlinspectoragent.cpp @@ -110,7 +110,7 @@ void QmlInspectorAgent::updateWatchData(const WatchData &data) } } -void QmlInspectorAgent::selectObjectInTree(int debugId) +bool QmlInspectorAgent::selectObjectInTree(int debugId) { if (debug) { qDebug() << __FUNCTION__ << "(" << debugId << ")"; @@ -125,10 +125,12 @@ void QmlInspectorAgent::selectObjectInTree(int debugId) qDebug() << " selecting" << iname << "in tree"; m_debuggerEngine->watchHandler()->setCurrentItem(iname); m_objectToSelect = 0; + return true; } else { // we've to fetch it m_objectToSelect = debugId; fetchObject(debugId); + return false; } } @@ -220,7 +222,7 @@ quint32 QmlInspectorAgent::resetBindingForObject(int objectDebugId, return queryId; } -ObjectReference QmlInspectorAgent::objectForId( +ObjectReference QmlInspectorAgent::objectForName( const QString &objectId) const { if (!objectId.isEmpty() && objectId[0].isLower()) { @@ -234,6 +236,36 @@ ObjectReference QmlInspectorAgent::objectForId( return ObjectReference(); } +ObjectReference QmlInspectorAgent::objectForId(int objectDebugId) const +{ + if (!m_debugIdToIname.contains(objectDebugId)) + return ObjectReference(objectDebugId); + + int line = -1; + int column = -1; + QString file; + QHashIterator, QHash, QList > > iter(m_debugIdHash); + while (iter.hasNext()) { + iter.next(); + QHashIterator, QList > i(iter.value()); + while (i.hasNext()) { + i.next(); + if (i.value().contains(objectDebugId)) { + line = i.key().first; + column = i.key().second; + break; + } + } + if (line != -1) { + file = iter.key().first; + break; + } + } + // TODO: Set correct parentId + return ObjectReference(objectDebugId, -1, + FileReference(QUrl::fromLocalFile(file), line, column)); +} + int QmlInspectorAgent::objectIdForLocation( int line, int column) const { diff --git a/src/plugins/debugger/qml/qmlinspectoragent.h b/src/plugins/debugger/qml/qmlinspectoragent.h index f71484f4294..5b63b85a9b5 100644 --- a/src/plugins/debugger/qml/qmlinspectoragent.h +++ b/src/plugins/debugger/qml/qmlinspectoragent.h @@ -64,7 +64,7 @@ public: void assignValue(const WatchData *data, const QString &expression, const QVariant &valueV); void updateWatchData(const WatchData &data); - void selectObjectInTree(int debugId); + bool selectObjectInTree(int debugId); quint32 setBindingForObject(int objectDebugId, const QString &propertyName, @@ -77,7 +77,8 @@ public: quint32 resetBindingForObject(int objectDebugId, const QString &propertyName); - QmlDebug::ObjectReference objectForId(const QString &objectId) const; + QmlDebug::ObjectReference objectForName(const QString &objectId) const; + QmlDebug::ObjectReference objectForId(int objectDebugId) const; int objectIdForLocation(int line, int column) const; QHash rootObjectIds() const; DebugIdHash debugIdHash() const { return m_debugIdHash; } diff --git a/src/plugins/debugger/qml/qmllivetextpreview.cpp b/src/plugins/debugger/qml/qmllivetextpreview.cpp index f3995e8fa9f..012d0d7a529 100644 --- a/src/plugins/debugger/qml/qmllivetextpreview.cpp +++ b/src/plugins/debugger/qml/qmllivetextpreview.cpp @@ -540,7 +540,7 @@ bool QmlLiveTextPreview::changeSelectedElements(const QList offsets, m_lastOffsets = offsets; ObjectReference objectRefUnderCursor; objectRefUnderCursor - = m_inspectorAdapter->agent()->objectForId(wordAtCursor); + = m_inspectorAdapter->agent()->objectForName(wordAtCursor); QList selectedReferences; bool containsReferenceUnderCursor = false;