void QmlDirParser::reportError(quint16 line, quint16 column, const QString &description) { QmlError error; error.setLine(line); error.setColumn(column); error.setDescription(description); _errors.append(error); }
void QmlDirParser::reportError(int line, int column, const QString &description) { QmlError error; error.setUrl(_url); error.setLine(line); error.setColumn(column); error.setDescription(description); _errors.append(error); }
QList<QmlError> QmlDirParser::errors(const QString &uri) const { QUrl url(uri); QList<QmlError> errors; const int numErrors = _errors.size(); errors.reserve(numErrors); for (int i = 0; i < numErrors; ++i) { const QmlJS::DiagnosticMessage &msg = _errors.at(i); QmlError e; QString description = msg.message; description.replace(QLatin1String("$$URI$$"), uri); e.setDescription(description); e.setUrl(url); e.setLine(msg.loc.startLine); e.setColumn(msg.loc.startColumn); errors << e; } return errors; }
QDebug operator<<(QDebug debug, const QmlError &error) { debug << qPrintable(error.toString()); QUrl url = error.url(); if (error.line() > 0 && url.scheme() == QLatin1String("file")) { QString file = url.toLocalFile(); QFile f(file); if (f.open(QIODevice::ReadOnly)) { QByteArray data = f.readAll(); QTextStream stream(data, QIODevice::ReadOnly); #ifndef QT_NO_TEXTCODEC stream.setCodec("UTF-8"); #endif const QString code = stream.readAll(); const QStringList lines = code.split(QLatin1Char('\n')); if (lines.count() >= error.line()) { const QString &line = lines.at(error.line() - 1); debug << "\n " << qPrintable(line); if(error.column() > 0) { int column = qMax(0, error.column() - 1); column = qMin(column, line.length()); QByteArray ind; ind.reserve(column); for (int i = 0; i < column; ++i) { const QChar ch = line.at(i); if (ch.isSpace()) ind.append(ch.unicode()); else ind.append(' '); } ind.append('^'); debug << "\n " << ind.constData(); } } } } return debug; }
void QmlDirParser::setError(const QmlError &e) { _errors.clear(); reportError(e.line(), e.column(), e.description()); }