Exemple #1
0
QDeclarativeJS::AST::SourceLocation QmlDocVisitor::precedingComment(quint32 offset) const
{
    QListIterator<QDeclarativeJS::AST::SourceLocation> it(engine->comments());
    it.toBack();

    while (it.hasPrevious()) {

        QDeclarativeJS::AST::SourceLocation loc = it.previous();

        if (loc.begin() <= lastEndOffset)
            // Return if we reach the end of the preceding structure.
            break;

        else if (usedComments.contains(loc.begin()))
            // Return if we encounter a previously used comment.
            break;

        else if (loc.begin() > lastEndOffset && loc.end() < offset) {

            // Only examine multiline comments in order to avoid snippet markers.
            if (document.mid(loc.offset - 1, 1) == "*") {
                QString comment = document.mid(loc.offset, loc.length);
                if (comment.startsWith("!") || comment.startsWith("*"))
                    return loc;
            }
        }
    }

    return QDeclarativeJS::AST::SourceLocation();
}
Exemple #2
0
QDeclarativeJS::AST::SourceLocation QmlDocVisitor::precedingComment(unsigned offset) const
{
    QDeclarativeJS::AST::SourceLocation currentLoc;

    foreach (const QDeclarativeJS::AST::SourceLocation &loc, engine->comments()) {
        if (loc.begin() > lastEndOffset && loc.end() < offset)
            currentLoc = loc;
        else
            break;
    }
    if (currentLoc.isValid()) {
        QString comment = document.mid(currentLoc.offset, currentLoc.length);
        if (comment.startsWith("!") || comment.startsWith("*"))
            return currentLoc;
    }

    return QDeclarativeJS::AST::SourceLocation();
}
Exemple #3
0
void QmlDocVisitor::applyDocumentation(QDeclarativeJS::AST::SourceLocation location,
                                    Node *node)
{
    QDeclarativeJS::AST::SourceLocation loc = precedingComment(location.begin());

    if (loc.isValid()) {
        QString source = document.mid(loc.offset, loc.length);

        Location start(filePath);
        start.setLineNo(loc.startLine);
        start.setColumnNo(loc.startColumn);
        Location finish(filePath);
        finish.setLineNo(loc.startLine);
        finish.setColumnNo(loc.startColumn);

        Doc doc(start, finish, source.mid(1), commands);
        node->setDoc(doc);

        usedComments.insert(loc.offset);
    }
}
void QmlMarkupVisitor::addVerbatim(QDeclarativeJS::AST::SourceLocation first,
                                   QDeclarativeJS::AST::SourceLocation last)
{
    if (!first.isValid())
        return;

    quint32 start = first.begin();
    quint32 finish;
    if (last.isValid())
        finish = last.end();
    else
        finish = first.end();

    if (cursor < start)
        addExtra(cursor, start);
    else if (cursor > start)
        return;

    QString text = source.mid(start, finish - start);
    output += protect(text);
    cursor = finish;
}
Exemple #5
0
void QmlDocVisitor::applyDocumentation(QDeclarativeJS::AST::SourceLocation location,
                                       Node *node)
{
    QDeclarativeJS::AST::SourceLocation loc = precedingComment(location.begin());

    if (loc.isValid()) {
        QString source = document.mid(loc.offset, loc.length);
        if (source.startsWith(QLatin1String("!")) ||
                (source.startsWith(QLatin1String("*")) &&
                 source[1] != QLatin1Char('*'))) {

            Location start(filePath);
            start.setLineNo(loc.startLine);
            start.setColumnNo(loc.startColumn);
            Location finish(filePath);
            finish.setLineNo(loc.startLine);
            finish.setColumnNo(loc.startColumn);

            Doc doc(start, finish, source.mid(1), commands);
            node->setDoc(doc);
        }
    }
}
void QmlMarkupVisitor::addMarkedUpToken(
    QDeclarativeJS::AST::SourceLocation &location, const QString &tagName,
    const QHash<QString, QString> &attributes)
{
    if (!location.isValid())
        return;

    if (cursor < location.offset)
        addExtra(cursor, location.offset);
    else if (cursor > location.offset)
        return;

    output += QString(QLatin1String("<@%1")).arg(tagName);
    foreach (const QString &key, attributes)
        output += QString(QLatin1String(" %1=\"%2\"")).arg(key).arg(attributes[key]);
    output += QString(QLatin1String(">%2</@%3>")).arg(protect(sourceText(location)), tagName);
    cursor += location.length;
}