Commit da077c36 authored by Marco Bubke's avatar Marco Bubke

QmlDesigner.Rewriter: Use the QmlJS Parser instead of the QDeclarativeEngine

The QmlJS Parser is checking the source file so we don't need to use the QmlEngine anymore.
parent 4c9724fc
......@@ -43,6 +43,10 @@
#include <modelnode.h>
#include <QScopedPointer>
namespace QmlJS {
class DiagnosticMessage;
}
namespace QmlDesigner {
......@@ -77,7 +81,7 @@ public:
public:
Error();
Error(const QDeclarativeError &qmlError);
Error(const QmlJS::DiagnosticMessage &qmlError, const QUrl &document);
Error(const QString &shortDescription);
Error(Exception *exception);
......
......@@ -32,6 +32,8 @@
#include <filemanager/firstdefinitionfinder.h>
#include <customnotifications.h>
#include <qmljs/parser/qmljsengine_p.h>
#include "rewriterview.h"
#include "rewritingexception.h"
#include "textmodifier.h"
......@@ -42,6 +44,8 @@
#include "nodeproperty.h"
#include "invalidmodelnodeexception.h"
using namespace QmlDesigner::Internal;
namespace QmlDesigner {
......@@ -62,12 +66,12 @@ RewriterView::Error::Error(Exception *exception):
{
}
RewriterView::Error::Error(const QDeclarativeError &qmlError):
RewriterView::Error::Error(const QmlJS::DiagnosticMessage &qmlError, const QUrl &document):
m_type(ParseError),
m_line(qmlError.line()),
m_column(qmlError.column()),
m_description(qmlError.description()),
m_url(qmlError.url())
m_line(qmlError.loc.startLine),
m_column(qmlError.loc.startColumn),
m_description(qmlError.message),
m_url(document)
{
}
......
......@@ -46,8 +46,6 @@
#include <qmljs/qmljsscopebuilder.h>
#include <qmljs/parser/qmljsast_p.h>
#include <QtDeclarative/QDeclarativeComponent>
#include <QtDeclarative/QDeclarativeEngine>
#include <QtCore/QSet>
#include <QtGui/QMessageBox>
......@@ -564,27 +562,6 @@ bool TextToModelMerger::load(const QString &data, DifferenceHandler &differenceH
const QStringList importPaths = m_rewriterView->textModifier()->importPaths();
setActive(true);
{ // Have the QML engine check if the document is valid:
QDeclarativeEngine engine;
engine.setOutputWarningsToStandardError(false);
QDeclarativeComponent comp(&engine);
comp.setData(data.toUtf8(), url);
if (comp.status() == QDeclarativeComponent::Error) {
QList<RewriterView::Error> errors;
foreach (const QDeclarativeError &error, comp.errors())
errors.append(RewriterView::Error(error));
m_rewriterView->setErrors(errors);
setActive(false);
return false;
} else if (comp.status() == QDeclarativeComponent::Loading) {
// Probably loading remote components. Previous DOM behaviour was:
QList<RewriterView::Error> errors;
errors.append(RewriterView::Error());
m_rewriterView->setErrors(errors);
setActive(false);
return false;
}
}
try {
Snapshot snapshot = m_rewriterView->textModifier()->getSnapshot();
......@@ -592,6 +569,16 @@ bool TextToModelMerger::load(const QString &data, DifferenceHandler &differenceH
Document::Ptr doc = Document::create(fileName.isEmpty() ? QLatin1String("<internal>") : fileName);
doc->setSource(data);
doc->parseQml();
if (!doc->isParsedCorrectly()) {
QList<RewriterView::Error> errors;
foreach (const QmlJS::DiagnosticMessage &message, doc->diagnosticMessages())
errors.append(RewriterView::Error(message, QUrl::fromLocalFile(doc->fileName())));
m_rewriterView->setErrors(errors);
setActive(false);
return false;
}
snapshot.insert(doc);
ReadingContext ctxt(snapshot, doc, importPaths);
......
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