summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/rewriter/rewriter.cpp
blob: ec504fa7afcca10eb69c8eb4ec47ecac3a36b2c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "rewriter_p.h"
#include "javascriptast_p.h"

QT_BEGIN_NAMESPACE

using namespace JavaScript;

void Rewriter::replace(const AST::SourceLocation &loc, const QString &text)
{ replace(loc.offset, loc.length, text); }

void Rewriter::remove(const AST::SourceLocation &loc)
{ return replace(loc.offset, loc.length, QString()); }

void Rewriter::remove(const AST::SourceLocation &firstLoc, const AST::SourceLocation &lastLoc)
{ return replace(firstLoc.offset, lastLoc.offset + lastLoc.length - firstLoc.offset, QString()); }

void Rewriter::insertTextBefore(const AST::SourceLocation &loc, const QString &text)
{ replace(loc.offset, 0, text); }

void Rewriter::insertTextAfter(const AST::SourceLocation &loc, const QString &text)
{ replace(loc.offset + loc.length, 0, text); }

void Rewriter::replace(int offset, int length, const QString &text)
{ textWriter.replace(offset, length, text); }

void Rewriter::insertText(int offset, const QString &text)
{ replace(offset, 0, text); }

void Rewriter::removeText(int offset, int length)
{ replace(offset, length, QString()); }

QString Rewriter::textAt(const AST::SourceLocation &loc) const
{ return _code.mid(loc.offset, loc.length); }

QString Rewriter::textAt(const AST::SourceLocation &firstLoc, const AST::SourceLocation &lastLoc) const
{ return _code.mid(firstLoc.offset, lastLoc.offset + lastLoc.length - firstLoc.offset); }

void Rewriter::accept(JavaScript::AST::Node *node)
{ JavaScript::AST::Node::acceptChild(node, this); }

void Rewriter::moveTextBefore(const AST::SourceLocation &firstLoc,
                              const AST::SourceLocation &lastLoc,
                              const AST::SourceLocation &loc)
{
    textWriter.move(firstLoc.offset, lastLoc.offset + lastLoc.length - firstLoc.offset, loc.offset);
}

void Rewriter::moveTextAfter(const AST::SourceLocation &firstLoc,
                             const AST::SourceLocation &lastLoc,
                             const AST::SourceLocation &loc)
{
    textWriter.move(firstLoc.offset, lastLoc.offset + lastLoc.length - firstLoc.offset, loc.offset + loc.length);
}

QT_END_NAMESPACE