Commit f24216bd authored by Olivier Goffart's avatar Olivier Goffart
Browse files

QmlJsDelta: moved to the QMLJS library

Also used 'int' instead of QDeclarativeDebugObjectReference for
the debug id in order not to use the private API from QMLJS
parent 31949f18
......@@ -27,7 +27,8 @@ HEADERS += \
$$PWD/qmljsicontextpane.h \
$$PWD/qmljspropertyreader.h \
$$PWD/qmljsrewriter.h \
$$PWD/qmljsicons.h
$$PWD/qmljsicons.h \
$$PWD/qmljsdelta.h
SOURCES += \
$$PWD/qmljsbind.cpp \
......@@ -45,7 +46,8 @@ SOURCES += \
$$PWD/qmljsmodelmanagerinterface.cpp \
$$PWD/qmljspropertyreader.cpp \
$$PWD/qmljsrewriter.cpp \
$$PWD/qmljsicons.cpp
$$PWD/qmljsicons.cpp \
$$PWD/qmljsdelta.cpp
RESOURCES += \
$$PWD/qmljs.qrc
......
......@@ -28,12 +28,14 @@
**************************************************************************/
#include "qmljsdelta.h"
#include "qmljsclientproxy.h"
#include <qmljs/parser/qmljsast_p.h>
#include <qmljs/parser/qmljsastvisitor_p.h>
#include <typeinfo>
#include <QtCore/QDebug>
#include <QtCore/QStringList>
using namespace QmlJS::AST;
......@@ -314,7 +316,7 @@ static QHash<QString, UiObjectMember*> extractProperties(UiObjectDefinition *obj
namespace QmlJS {
void Delta::insert(UiObjectMember *member, UiObjectMember *parentMember, const QList<QDeclarativeDebugObjectReference > &debugReferences, const Document::Ptr &doc)
void Delta::insert(UiObjectMember *member, UiObjectMember *parentMember, const QList<DebugId> &debugReferences, const Document::Ptr &doc)
{
if (!member || !parentMember)
return;
......@@ -337,9 +339,9 @@ void Delta::insert(UiObjectMember *member, UiObjectMember *parentMember, const Q
QString filename = doc->fileName() + QLatin1Char('_') + QString::number(doc->editorRevision())
+ QLatin1Char(':') + QString::number(uiObjectDef->firstSourceLocation().startLine-importList.count());
foreach(const QDeclarativeDebugObjectReference &ref, debugReferences) {
if (ref.debugId() != -1) {
createObject(qmlText, ref, importList, filename);
foreach(DebugId debugId, debugReferences) {
if (debugId != -1) {
createObject(qmlText, debugId, importList, filename);
}
}
newObjects += member;
......@@ -349,7 +351,7 @@ void Delta::insert(UiObjectMember *member, UiObjectMember *parentMember, const Q
void Delta::update(UiObjectDefinition* oldObject, const QmlJS::Document::Ptr& oldDoc,
UiObjectDefinition* newObject, const QmlJS::Document::Ptr& newDoc,
const QList< QDeclarativeDebugObjectReference >& debugReferences)
const QList<DebugId>& debugReferences)
{
Q_ASSERT (oldObject && newObject);
QSet<QString> presentBinding;
......@@ -366,8 +368,8 @@ void Delta::update(UiObjectDefinition* oldObject, const QmlJS::Document::Ptr& ol
const QString scriptCode = _scriptCode(script, newDoc);
UiScriptBinding *previousScript = cast<UiScriptBinding *>(oldMember);
if (!previousScript || _scriptCode(previousScript, oldDoc) != scriptCode) {
foreach (const QDeclarativeDebugObjectReference &ref, debugReferences) {
if (ref.debugId() != -1)
foreach (DebugId ref, debugReferences) {
if (ref != -1)
updateScriptBinding(ref, script, property, scriptCode);
}
}
......@@ -377,8 +379,8 @@ void Delta::update(UiObjectDefinition* oldObject, const QmlJS::Document::Ptr& ol
UiSourceElement *previousSource = cast<UiSourceElement*>(oldMember);
if (!previousSource || _methodCode(previousSource, oldDoc) != methodCode) {
foreach (const QDeclarativeDebugObjectReference &ref, debugReferences) {
if (ref.debugId() != -1)
foreach (DebugId ref, debugReferences) {
if (ref != -1)
updateMethodBody(ref, script, methodName, methodCode);
}
}
......@@ -391,20 +393,20 @@ void Delta::update(UiObjectDefinition* oldObject, const QmlJS::Document::Ptr& ol
if (!newProperties.contains(it2.key())) {
if (cast<UiScriptBinding *>(*it2)) {
foreach (const QDeclarativeDebugObjectReference &ref, debugReferences) {
if (ref.debugId() != -1)
resetBindingForObject(ref.debugId(), it2.key());
foreach (DebugId ref, debugReferences) {
if (ref != -1)
resetBindingForObject(ref, it2.key());
}
}
}
}
}
void Delta::remove(const QList< QDeclarativeDebugObjectReference >& debugReferences)
void Delta::remove(const QList<DebugId>& debugReferences)
{
foreach (const QDeclarativeDebugObjectReference &ref, debugReferences) {
if (ref.debugId() != -1)
removeObject(ref.debugId());
foreach (DebugId ref, debugReferences) {
if (ref != -1)
removeObject(ref);
}
}
......@@ -414,7 +416,7 @@ Delta::DebugIdMap Delta::operator()(const Document::Ptr &doc1, const Document::P
Q_ASSERT(doc1->qmlProgram());
Q_ASSERT(doc2->qmlProgram());
QHash< UiObjectMember*, QList<QDeclarativeDebugObjectReference > > newDebuggIds;
Delta::DebugIdMap newDebuggIds;
Map M = Mapping(doc1, doc2);
......@@ -445,7 +447,7 @@ Delta::DebugIdMap Delta::operator()(const Document::Ptr &doc1, const Document::P
Q_ASSERT(cast<UiObjectDefinition *>(x));
if (debugIds.contains(x)) {
QList< QDeclarativeDebugObjectReference > ids = debugIds[x];
QList<DebugId> ids = debugIds[x];
newDebuggIds[y] = ids;
update(cast<UiObjectDefinition *>(x), doc1, cast<UiObjectDefinition *>(y), doc2, ids);
}
......@@ -467,7 +469,7 @@ Delta::DebugIdMap Delta::operator()(const Document::Ptr &doc1, const Document::P
continue;
if (!M.way1.contains(x)) {
qDebug () << "Delta::operator(): remove " << label(x, doc1);
QList< QDeclarativeDebugObjectReference > ids = debugIds.value(x);
QList<DebugId> ids = debugIds.value(x);
if (!ids.isEmpty())
remove(ids);
continue;
......@@ -486,19 +488,16 @@ Document::Ptr Delta::previousDocument() const
return m_previousDoc;
}
void Delta::createObject(const QString &, const QDeclarativeDebugObjectReference &,
const QStringList &, const QString&)
void Delta::createObject(const QString &, DebugId, const QStringList &, const QString&)
{}
void Delta::removeObject(int)
{}
void Delta::resetBindingForObject(int, const QString &)
{}
void Delta::updateMethodBody(const QDeclarativeDebugObjectReference &,
UiScriptBinding *, const QString &, const QString &)
void Delta::updateMethodBody(DebugId, UiScriptBinding *, const QString &, const QString &)
{}
void Delta::updateScriptBinding(const QDeclarativeDebugObjectReference &,
UiScriptBinding *, const QString &, const QString &)
void Delta::updateScriptBinding(DebugId, UiScriptBinding *, const QString &, const QString &)
{}
} //namespace QmlJs
......
......@@ -30,48 +30,44 @@
#ifndef QMLJSDELTA_H
#define QMLJSDELTA_H
#include "qmljsprivateapi.h"
#include <qmljs/qmljsdocument.h>
#include <qmljs/parser/qmljsastvisitor_p.h>
#include <qmljs/parser/qmljsastfwd_p.h>
#include <qmljs/parser/qmljsast_p.h>
#include <qmljs/qmljs_global.h>
namespace QmlJS {
class Delta
class QMLJS_EXPORT Delta
{
public:
QSet<AST::UiObjectMember *> newObjects;
typedef QHash<AST::UiObjectMember*, QList<QDeclarativeDebugObjectReference > > DebugIdMap;
typedef int DebugId;
typedef QHash<AST::UiObjectMember*, QList<DebugId> > DebugIdMap;
DebugIdMap operator()(const QmlJS::Document::Ptr &doc1, const QmlJS::Document::Ptr &doc2, const DebugIdMap &debugIds);
QSet<AST::UiObjectMember *> newObjects;
QmlJS::Document::Ptr document() const;
QmlJS::Document::Ptr previousDocument() const;
private:
void insert(AST::UiObjectMember *member, AST::UiObjectMember *parentMember,
const QList<QDeclarativeDebugObjectReference> &debugReferences, const Document::Ptr &doc);
const QList<DebugId> &debugReferences, const Document::Ptr &doc);
void update(AST::UiObjectDefinition* oldObject, const QmlJS::Document::Ptr& oldDoc,
AST::UiObjectDefinition* newObject, const QmlJS::Document::Ptr& newDoc,
const QList<QDeclarativeDebugObjectReference >& debugReferences);
void remove(const QList< QDeclarativeDebugObjectReference > &debugReferences);
const QList<DebugId>& debugReferences);
void remove(const QList<DebugId> &debugReferences);
protected:
virtual void updateScriptBinding(const QDeclarativeDebugObjectReference &objectReference,
virtual void updateScriptBinding(DebugId objectReference,
AST::UiScriptBinding *scriptBinding,
const QString &propertyName,
const QString &scriptCode);
virtual void updateMethodBody(const QDeclarativeDebugObjectReference &objectReference,
virtual void updateMethodBody(DebugId objectReference,
AST::UiScriptBinding *scriptBinding,
const QString &methodName,
const QString &methodBody);
virtual void resetBindingForObject(int debugId, const QString &propertyName);
virtual void removeObject(int debugId);
virtual void createObject(const QString &qmlText, const QDeclarativeDebugObjectReference &ref,
const QStringList &importList, const QString &filename);
virtual void createObject(const QString &qmlText, DebugId ref,
const QStringList &importList, const QString &filename);
private:
QmlJS::Document::Ptr m_currentDoc;
......
......@@ -445,11 +445,11 @@ void ClientProxy::changeToSelectMarqueeTool()
m_designClient->changeToSelectMarqueeTool();
}
void ClientProxy::createQmlObject(const QString &qmlText, const QDeclarativeDebugObjectReference &parentRef,
void ClientProxy::createQmlObject(const QString &qmlText, int parentDebugId,
const QStringList &imports, const QString &filename)
{
if (isDesignClientConnected())
m_designClient->createQmlObject(qmlText, parentRef, imports, filename);
m_designClient->createQmlObject(qmlText, parentDebugId, imports, filename);
}
void QmlJSInspector::Internal::ClientProxy::destroyQmlObject(int debugId)
......
......@@ -106,7 +106,7 @@ public slots:
void changeToZoomTool();
void changeToSelectTool();
void changeToSelectMarqueeTool();
void createQmlObject(const QString &qmlText, const QDeclarativeDebugObjectReference &parent,
void createQmlObject(const QString &qmlText, int parentDebugId,
const QStringList &imports, const QString &filename = QString());
void destroyQmlObject(int debugId);
......
......@@ -215,7 +215,7 @@ void QmlJSDesignDebugClient::changeToZoomTool()
sendMessage(message);
}
void QmlJSDesignDebugClient::createQmlObject(const QString &qmlText, const QDeclarativeDebugObjectReference &parentRef,
void QmlJSDesignDebugClient::createQmlObject(const QString &qmlText, int parentDebugId,
const QStringList &imports, const QString &filename)
{
if (!m_connection || !m_connection->isConnected())
......@@ -226,7 +226,7 @@ void QmlJSDesignDebugClient::createQmlObject(const QString &qmlText, const QDecl
ds << QByteArray("CREATE_OBJECT")
<< qmlText
<< parentRef.debugId()
<< parentDebugId
<< imports
<< filename;
......
......@@ -64,7 +64,7 @@ public:
void changeToSelectMarqueeTool();
void changeToZoomTool();
void createQmlObject(const QString &qmlText, const QDeclarativeDebugObjectReference &parentRef,
void createQmlObject(const QString &qmlText, int parentDebugId,
const QStringList &imports, const QString &filename);
void destroyQmlObject(int debugId);
......
......@@ -30,7 +30,6 @@
#include "qmljsinspector.h"
#include "qmljsclientproxy.h"
#include "qmljsinspectorcontext.h"
#include "qmljsdelta.h"
#include "qmljslivetextpreview.h"
#include "qmljsprivateapi.h"
......@@ -38,6 +37,7 @@
#include <qmljs/qmljsmodelmanagerinterface.h>
#include <qmljs/qmljsdocument.h>
#include <qmljs/qmljsdelta.h>
#include <debugger/debuggerrunner.h>
#include <debugger/debuggerconstants.h>
......
......@@ -17,7 +17,6 @@ qmljsinspectorcontext.h \
qmljsinspectorplugin.h \
qmljsclientproxy.h \
qmljsinspector.h \
qmljsdelta.h \
qmlinspectortoolbar.h \
qmljslivetextpreview.h \
qmljsdesigndebugclient.h
......@@ -28,7 +27,6 @@ qmljsinspectorcontext.cpp \
qmljsinspectorplugin.cpp \
qmljsclientproxy.cpp \
qmljsinspector.cpp \
qmljsdelta.cpp \
qmlinspectortoolbar.cpp \
qmljslivetextpreview.cpp \
qmljsdesigndebugclient.cpp
......
......@@ -31,11 +31,12 @@
#include "qmljsclientproxy.h"
#include "qmljslivetextpreview.h"
#include "qmljsdelta.h"
#include "qmljsprivateapi.h"
#include <qmljseditor/qmljseditorconstants.h>
#include <qmljseditor/qmljseditor.h>
#include <qmljs/qmljsdelta.h>
#include <qmljs/parser/qmljsast_p.h>
#include <extensionsystem/pluginmanager.h>
#include <coreplugin/icore.h>
......@@ -59,6 +60,7 @@ namespace Internal {
class MapObjectWithDebugReference : public Visitor
{
public:
typedef QList<int> DebugIdList;
MapObjectWithDebugReference() : activated(0) {}
virtual void endVisit(UiObjectDefinition *ast) ;
virtual void endVisit(UiObjectBinding *ast) ;
......@@ -67,7 +69,7 @@ class MapObjectWithDebugReference : public Visitor
QDeclarativeDebugObjectReference root;
QString filename;
QHash<UiObjectMember *, QList<QDeclarativeDebugObjectReference> > result;
QHash<UiObjectMember *, DebugIdList> result;
QSet<QmlJS::AST::UiObjectMember *> lookupObjects;
Document::Ptr doc;
private:
......@@ -115,12 +117,12 @@ void MapObjectWithDebugReference::processRecursive(const QDeclarativeDebugObject
if (object.source().columnNumber() == int(loc.startColumn)) {
QString objectFileName = object.source().url().toLocalFile();
if (object.source().lineNumber() == int(loc.startLine) && objectFileName == filename) {
result[ast] += object;
result[ast] += object.debugId();
} else if (doc && objectFileName.startsWith(filename + QLatin1Char('_') + QString::number(doc->editorRevision()) + QLatin1Char(':'))) {
bool ok;
int line = objectFileName.mid(objectFileName.lastIndexOf(':') + 1).toInt(&ok);
if (ok && int(loc.startLine) == line + object.source().lineNumber() - 1)
result[ast] += object;
result[ast] += object.debugId();
}
}
......@@ -185,10 +187,10 @@ void QmlJSLiveTextPreview::resetInitialDoc(const QmlJS::Document::Ptr &doc)
}
QList<QDeclarativeDebugObjectReference > QmlJSLiveTextPreview::objectReferencesForOffset(quint32 offset) const
QList<int> QmlJSLiveTextPreview::objectReferencesForOffset(quint32 offset) const
{
QList<QDeclarativeDebugObjectReference > result;
QHashIterator<QmlJS::AST::UiObjectMember*, QList<QDeclarativeDebugObjectReference > > iter(m_debugIds);
QList<int> result;
QHashIterator<QmlJS::AST::UiObjectMember*, QList<int> > iter(m_debugIds);
while(iter.hasNext()) {
iter.next();
QmlJS::AST::UiObjectMember *member = iter.key();
......@@ -217,16 +219,16 @@ void QmlJSLiveTextPreview::changeSelectedElements(QList<int> offsets, const QStr
}
}
QList<QDeclarativeDebugObjectReference> selectedReferences;
QList<int> selectedReferences;
bool containsReference = false;
foreach(int offset, offsets) {
if (offset >= 0) {
QList<QDeclarativeDebugObjectReference> list = objectReferencesForOffset(offset);
QList<int> list = objectReferencesForOffset(offset);
if (!containsReference && objectRefUnderCursor.debugId() != -1) {
foreach(const QDeclarativeDebugObjectReference &ref, list) {
if (ref.debugId() == objectRefUnderCursor.debugId()) {
foreach(int id, list) {
if (id == objectRefUnderCursor.debugId()) {
containsReference = true;
break;
}
......@@ -237,17 +239,21 @@ void QmlJSLiveTextPreview::changeSelectedElements(QList<int> offsets, const QStr
}
if (!containsReference && objectRefUnderCursor.debugId() != -1)
selectedReferences << objectRefUnderCursor;
selectedReferences << objectRefUnderCursor.debugId();
if (!selectedReferences.isEmpty())
emit selectedItemsChanged(selectedReferences);
if (!selectedReferences.isEmpty()) {
QList<QDeclarativeDebugObjectReference> refs;
foreach(int i, selectedReferences)
refs << QDeclarativeDebugObjectReference(i);
emit selectedItemsChanged(refs);
}
}
static QList<QDeclarativeDebugObjectReference> findRootObjectRecursive(const QDeclarativeDebugObjectReference &object, const Document::Ptr &doc)
static QList<int> findRootObjectRecursive(const QDeclarativeDebugObjectReference &object, const Document::Ptr &doc)
{
QList<QDeclarativeDebugObjectReference> result;
QList<int> result;
if (object.className() == doc->componentName())
result += object;
result += object.debugId();
foreach (const QDeclarativeDebugObjectReference &it, object.children()) {
result += findRootObjectRecursive(it, doc);
......@@ -281,7 +287,7 @@ void QmlJSLiveTextPreview::updateDebugIds(const QDeclarativeDebugObjectReference
// Map the root nodes of the document.
if(doc->qmlProgram()->members && doc->qmlProgram()->members->member) {
UiObjectMember* root = doc->qmlProgram()->members->member;
QList< QDeclarativeDebugObjectReference > r = findRootObjectRecursive(rootReference, doc);
QList<int> r = findRootObjectRecursive(rootReference, doc);
if (!r.isEmpty())
m_debugIds[root] += r;
}
......@@ -406,21 +412,21 @@ private:
}
protected:
virtual void updateMethodBody(const QDeclarativeDebugObjectReference& objectReference,
UiScriptBinding* scriptBinding, const QString& methodName, const QString& methodBody)
virtual void updateMethodBody(DebugId debugId, UiScriptBinding* scriptBinding,
const QString& methodName, const QString& methodBody)
{
Q_UNUSED(scriptBinding);
ClientProxy::instance()->setMethodBodyForObject(objectReference.debugId(), methodName, methodBody);
ClientProxy::instance()->setMethodBodyForObject(debugId, methodName, methodBody);
}
virtual void updateScriptBinding(const QDeclarativeDebugObjectReference& objectReference,
UiScriptBinding* scriptBinding, const QString& propertyName, const QString& scriptCode)
virtual void updateScriptBinding(DebugId debugId, UiScriptBinding* scriptBinding,
const QString& propertyName, const QString& scriptCode)
{
QVariant expr = scriptCode;
const bool isLiteral = isLiteralValue(scriptBinding);
if (isLiteral)
expr = castToLiteral(scriptCode, scriptBinding);
ClientProxy::instance()->setBindingForObject(objectReference.debugId(), propertyName, expr, isLiteral);
ClientProxy::instance()->setBindingForObject(debugId, propertyName, expr, isLiteral);
}
virtual void resetBindingForObject(int debugId, const QString &propertyName)
......@@ -433,7 +439,7 @@ protected:
ClientProxy::instance()->destroyQmlObject(debugId);
}
virtual void createObject(const QString& qmlText, const QDeclarativeDebugObjectReference& ref,
virtual void createObject(const QString& qmlText, DebugId ref,
const QStringList& importList, const QString& filename)
{
referenceRefreshRequired = true;
......
......@@ -82,11 +82,11 @@ public slots:
void updateDebugIds(const QDeclarativeDebugObjectReference &rootReference);
private:
QList<QDeclarativeDebugObjectReference > objectReferencesForOffset(quint32 offset) const;
QList<int> objectReferencesForOffset(quint32 offset) const;
QVariant castToLiteral(const QString &expression, QmlJS::AST::UiScriptBinding *scriptBinding);
private:
QHash<QmlJS::AST::UiObjectMember*, QList<QDeclarativeDebugObjectReference> > m_debugIds;
QHash<QmlJS::AST::UiObjectMember*, QList<int> > m_debugIds;
QHash<QmlJS::Document::Ptr, QSet<QmlJS::AST::UiObjectMember *> > m_createdObjects;
QmlJS::Document::Ptr m_previousDoc;
......
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