Commit 701b3e0a authored by Erik Verbruggen's avatar Erik Verbruggen

Added more tracing information in case rewriting the QML source failed.

parent 4fb2a9fd
......@@ -79,7 +79,8 @@ bool QmlRefactoring::changeImports(const QSet<QmlDesigner::Import> &/*addedImpor
bool QmlRefactoring::addToArrayMemberList(int parentLocation, const QString &propertyName, const QString &content)
{
Q_ASSERT(parentLocation >= 0);
if (parentLocation < 0)
return false;
AddArrayMemberVisitor visit(*textModifier, (quint32) parentLocation, propertyName, content);
visit.setConvertObjectBindingIntoArrayBinding(true);
......@@ -88,7 +89,8 @@ bool QmlRefactoring::addToArrayMemberList(int parentLocation, const QString &pro
bool QmlRefactoring::addToObjectMemberList(int parentLocation, const QString &content)
{
Q_ASSERT(parentLocation >= 0);
if (parentLocation < 0)
return false;
AddObjectVisitor visit(*textModifier, (quint32) parentLocation, content, m_propertyOrder);
return visit(qmlDocument->qmlProgram());
......@@ -96,7 +98,8 @@ bool QmlRefactoring::addToObjectMemberList(int parentLocation, const QString &co
bool QmlRefactoring::addProperty(int parentLocation, const QString &name, const QString &value, PropertyType propertyType)
{
Q_ASSERT(parentLocation >= 0);
if(parentLocation < 0)
return false;
AddPropertyVisitor visit(*textModifier, (quint32) parentLocation, name, value, propertyType, m_propertyOrder);
return visit(qmlDocument->qmlProgram());
......@@ -104,7 +107,8 @@ bool QmlRefactoring::addProperty(int parentLocation, const QString &name, const
bool QmlRefactoring::changeProperty(int parentLocation, const QString &name, const QString &value, PropertyType propertyType)
{
Q_ASSERT(parentLocation >= 0);
if (parentLocation < 0)
return false;
ChangePropertyVisitor visit(*textModifier, (quint32) parentLocation, name, value, propertyType);
return visit(qmlDocument->qmlProgram());
......@@ -112,8 +116,8 @@ bool QmlRefactoring::changeProperty(int parentLocation, const QString &name, con
bool QmlRefactoring::changeObjectType(int nodeLocation, const QString &newType)
{
Q_ASSERT(nodeLocation >= 0);
Q_ASSERT(!newType.isEmpty());
if (nodeLocation < 0 || newType.isEmpty())
return false;
ChangeObjectTypeVisitor visit(*textModifier, (quint32) nodeLocation, newType);
return visit(qmlDocument->qmlProgram());
......@@ -121,8 +125,8 @@ bool QmlRefactoring::changeObjectType(int nodeLocation, const QString &newType)
bool QmlRefactoring::moveObject(int objectLocation, const QString &targetPropertyName, bool targetIsArrayBinding, int targetParentObjectLocation)
{
Q_ASSERT(objectLocation >= 0);
Q_ASSERT(targetParentObjectLocation >= 0);
if (objectLocation < 0 || targetParentObjectLocation < 0)
return false;
MoveObjectVisitor visit(*textModifier, (quint32) objectLocation, targetPropertyName, targetIsArrayBinding, (quint32) targetParentObjectLocation, m_propertyOrder);
return visit(qmlDocument->qmlProgram());
......@@ -130,8 +134,8 @@ bool QmlRefactoring::moveObject(int objectLocation, const QString &targetPropert
bool QmlRefactoring::moveObjectBeforeObject(int movingObjectLocation, int beforeObjectLocation)
{
Q_ASSERT(movingObjectLocation >= 0);
Q_ASSERT(beforeObjectLocation >= -1);
if (movingObjectLocation < 0 || beforeObjectLocation < -1)
return false;
if (beforeObjectLocation == -1) {
MoveObjectBeforeObjectVisitor visit(*textModifier, movingObjectLocation);
......@@ -145,7 +149,8 @@ bool QmlRefactoring::moveObjectBeforeObject(int movingObjectLocation, int before
bool QmlRefactoring::removeObject(int nodeLocation)
{
Q_ASSERT(nodeLocation >= 0);
if (nodeLocation < 0)
return false;
RemoveUIObjectMemberVisitor visit(*textModifier, (quint32) nodeLocation);
return visit(qmlDocument->qmlProgram());
......@@ -153,8 +158,8 @@ bool QmlRefactoring::removeObject(int nodeLocation)
bool QmlRefactoring::removeProperty(int parentLocation, const QString &name)
{
Q_ASSERT(parentLocation >= 0);
Q_ASSERT(!name.isEmpty());
if (parentLocation < 0 || name.isEmpty())
return false;
RemovePropertyVisitor visit(*textModifier, (quint32) parentLocation, name);
return visit(qmlDocument->qmlProgram());
......
......@@ -78,7 +78,7 @@ public:
public:
Error();
Error(const QmlError &qmlError);
Error(const Exception &exception);
Error(Exception *exception);
Type type() const
{ return m_type; }
......
......@@ -230,6 +230,13 @@ void ModelToTextMerger::applyChanges()
#endif // DUMP_REWRITE_ACTIONS
ModelNodePositionStorage *positionStore = m_rewriterView->positionStorage();
const bool success = action->execute(refactoring, *positionStore);
if (!success) {
qDebug() << "*** QML source code: ***";
qDebug() << qPrintable(textModifier->text());
qDebug() << "*** End of QML source code. ***";
}
Q_ASSERT(success);
}
qDeleteAll(m_rewriteActions);
......
......@@ -39,10 +39,10 @@ using namespace QmlDesigner;
static inline QString toString(QmlRefactoring::PropertyType type)
{
switch (type) {
case QmlRefactoring::ArrayBinding: return QLatin1String("array binding");
case QmlRefactoring::ObjectBinding: return QLatin1String("object binding");
case QmlRefactoring::ScriptBinding: return QLatin1String("script binding");
default: return QLatin1String("UNKNOWN");
case QmlRefactoring::ArrayBinding: return QLatin1String("array binding");
case QmlRefactoring::ObjectBinding: return QLatin1String("object binding");
case QmlRefactoring::ScriptBinding: return QLatin1String("script binding");
default: return QLatin1String("UNKNOWN");
}
}
......@@ -51,21 +51,27 @@ bool AddPropertyRewriteAction::execute(QmlRefactoring &refactoring, ModelNodePos
const int nodeLocation = positionStore.nodeOffset(m_property.parentModelNode());
bool result = false;
if (m_property.isDefaultProperty())
if (m_property.isDefaultProperty()) {
result = refactoring.addToObjectMemberList(nodeLocation, m_valueText);
else {
if (!result) {
qDebug() << "*** AddPropertyRewriteAction::execute failed in addToObjectMemberList("
<< nodeLocation << ","
<< m_valueText << ") **"
<< info();
}
} else {
result = refactoring.addProperty(nodeLocation, m_property.name(), m_valueText, m_propertyType);
if (!result) {
qDebug() << "*** AddPropertyRewriteAction::execute failed in addProperty("
<< nodeLocation << ","
<< m_property.name() << ","
<< m_valueText << ", ScriptBinding)"
<< m_valueText << ", ScriptBinding) **"
<< info();
}
}
Q_ASSERT(result);
return result;
}
......@@ -87,15 +93,30 @@ bool ChangeIdRewriteAction::execute(QmlDesigner::QmlRefactoring &refactoring, Mo
qDebug() << "*** ChangeIdRewriteAction::execute failed in addProperty("
<< nodeLocation << ","
<< idPropertyName << ","
<< m_newId << ", ScriptBinding)"
<< m_newId << ", ScriptBinding) **"
<< info();
}
} else if (m_newId.isEmpty())
} else if (m_newId.isEmpty()) {
result = refactoring.removeProperty(nodeLocation, idPropertyName);
else
if (!result) {
qDebug() << "*** ChangeIdRewriteAction::execute failed in removeProperty("
<< nodeLocation << ","
<< idPropertyName << ") **"
<< info();
}
} else {
result = refactoring.changeProperty(nodeLocation, idPropertyName, m_newId, QmlRefactoring::ScriptBinding);
Q_ASSERT(result);
if (!result) {
qDebug() << "*** ChangeIdRewriteAction::execute failed in changeProperty("
<< nodeLocation << ","
<< idPropertyName << ","
<< m_newId << ", ScriptBinding) **"
<< info();
}
}
return result;
}
......@@ -109,14 +130,38 @@ bool ChangePropertyRewriteAction::execute(QmlDesigner::QmlRefactoring &refactori
const int nodeLocation = positionStore.nodeOffset(m_property.parentModelNode());
bool result = false;
if (m_property.isDefaultProperty())
if (m_property.isDefaultProperty()) {
result = refactoring.addToObjectMemberList(nodeLocation, m_valueText);
else if (m_propertyType == QmlRefactoring::ArrayBinding)
if (!result) {
qDebug() << "*** ChangePropertyRewriteAction::execute failed in addToObjectMemberList("
<< nodeLocation << ","
<< m_valueText << ") **"
<< info();
}
} else if (m_propertyType == QmlRefactoring::ArrayBinding) {
result = refactoring.addToArrayMemberList(nodeLocation, m_property.name(), m_valueText);
else
if (!result) {
qDebug() << "*** ChangePropertyRewriteAction::execute failed in addToArrayMemberList("
<< nodeLocation << ","
<< m_property.name() << ","
<< m_valueText << ") **"
<< info();
}
} else {
result = refactoring.changeProperty(nodeLocation, m_property.name(), m_valueText, m_propertyType);
Q_ASSERT(result);
if (!result) {
qDebug() << "*** ChangePropertyRewriteAction::execute failed in changeProperty("
<< nodeLocation << ","
<< m_property.name() << ","
<< m_valueText << ","
<< qPrintable(toString(m_propertyType)) << ") **"
<< info();
}
}
return result;
}
......@@ -141,8 +186,13 @@ bool ChangeTypeRewriteAction::execute(QmlDesigner::QmlRefactoring &refactoring,
newNodeType = newNodeType.mid(slashIdx + 1);
result = refactoring.changeObjectType(nodeLocation, newNodeType);
if (!result) {
qDebug() << "*** ChangeTypeRewriteAction::execute failed in changeObjectType("
<< nodeLocation << ","
<< newNodeType << ") **"
<< info();
}
Q_ASSERT(result);
return result;
}
......@@ -154,11 +204,13 @@ QString ChangeTypeRewriteAction::info() const
bool RemoveNodeRewriteAction::execute(QmlDesigner::QmlRefactoring &refactoring, ModelNodePositionStorage &positionStore)
{
const int nodeLocation = positionStore.nodeOffset(m_node);
bool result = false;
result = refactoring.removeObject(nodeLocation);
bool result = refactoring.removeObject(nodeLocation);
if (!result) {
qDebug() << "*** RemoveNodeRewriteAction::execute failed in removeObject("
<< nodeLocation << ") **"
<< info();
}
Q_ASSERT(result);
return result;
}
......@@ -170,11 +222,14 @@ QString RemoveNodeRewriteAction::info() const
bool RemovePropertyRewriteAction::execute(QmlDesigner::QmlRefactoring &refactoring, ModelNodePositionStorage &positionStore)
{
const int nodeLocation = positionStore.nodeOffset(m_property.parentModelNode());
bool result = false;
result = refactoring.removeProperty(nodeLocation, m_property.name());
bool result = refactoring.removeProperty(nodeLocation, m_property.name());
if (!result) {
qDebug() << "*** RemovePropertyRewriteAction::execute failed in removeProperty("
<< nodeLocation << ","
<< m_property.name() << ") **"
<< info();
}
Q_ASSERT(result);
return result;
}
......@@ -195,8 +250,15 @@ bool ReparentNodeRewriteAction::execute(QmlDesigner::QmlRefactoring &refactoring
targetPropertyName = m_targetProperty.name();
result = refactoring.moveObject(nodeLocation, targetPropertyName, isArrayBinding, targetParentObjectLocation);
if (!result) {
qDebug() << "*** ReparentNodeRewriteAction::execute failed in moveObject("
<< nodeLocation << ","
<< targetPropertyName << ","
<< isArrayBinding << ","
<< targetParentObjectLocation << ") **"
<< info();
}
Q_ASSERT(result);
return result;
}
......@@ -219,8 +281,13 @@ bool MoveNodeRewriteAction::execute(QmlRefactoring &refactoring,
bool result = false;
result = refactoring.moveObjectBeforeObject(movingNodeLocation, newTrailingNodeLocation);
if (!result) {
qDebug() << "*** MoveNodeRewriteAction::execute failed in moveObjectBeforeObject("
<< movingNodeLocation << ","
<< newTrailingNodeLocation << ") **"
<< info();
}
Q_ASSERT(result);
return result;
}
......
......@@ -52,12 +52,12 @@ RewriterView::Error::Error():
{
}
RewriterView::Error::Error(const Exception &exception):
RewriterView::Error::Error(Exception *exception):
m_type(InternalError),
m_line(exception.line()),
m_line(exception->line()),
m_column(-1),
m_description(exception.description()),
m_url(exception.file())
m_description(exception->description()),
m_url(exception->file())
{
}
......@@ -74,13 +74,33 @@ QString RewriterView::Error::toString() const
{
QString str;
if (url().isValid())
str = url().toString() + QLatin1Char(':');
if (line() != -1)
str += QString::number(line()) + QLatin1Char(':');
if(column() != -1)
str += QString::number(column()) + QLatin1Char(':');
if (m_type == ParseError)
str += tr("Error parsing");
else if (m_type == InternalError)
str += tr("Internal error while parsing");
if (url().isValid()) {
if (!str.isEmpty())
str += QLatin1Char(' ');
str += tr("\"%1\"").arg(url().toString());
}
if (line() != -1) {
if (!str.isEmpty())
str += QLatin1Char(' ');
str += tr("line %1").arg(line());
}
if(column() != -1) {
if (!str.isEmpty())
str += QLatin1Char(' ');
str += tr("column %1").arg(column());
}
if (!str.isEmpty())
QLatin1String(": ");
str += description();
return str;
......
......@@ -110,7 +110,7 @@ bool TextToModelMerger::load(const QByteArray &data, DifferenceHandler &differen
setActive(false);
return success;
} catch (Exception &e) {
m_rewriterView->addError(RewriterView::Error(e));
m_rewriterView->addError(RewriterView::Error(&e));
setActive(false);
......
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