forked from ruby/prism
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMarkNewlinesVisitor.java
More file actions
62 lines (52 loc) · 1.76 KB
/
Copy pathMarkNewlinesVisitor.java
File metadata and controls
62 lines (52 loc) · 1.76 KB
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
56
57
58
59
60
61
62
package org.ruby_lang.prism;
// Keep in sync with Ruby MarkNewlinesVisitor
final class MarkNewlinesVisitor extends AbstractNodeVisitor<Void> {
private final Nodes.Source source;
private boolean[] newlineMarked;
MarkNewlinesVisitor(Nodes.Source source) {
this.source = source;
this.newlineMarked = new boolean[1 + source.getLineCount()];
}
@Override
public Void visitBlockNode(Nodes.BlockNode node) {
boolean[] oldNewlineMarked = this.newlineMarked;
this.newlineMarked = new boolean[oldNewlineMarked.length];
try {
return super.visitBlockNode(node);
} finally {
this.newlineMarked = oldNewlineMarked;
}
}
@Override
public Void visitLambdaNode(Nodes.LambdaNode node) {
boolean[] oldNewlineMarked = this.newlineMarked;
this.newlineMarked = new boolean[oldNewlineMarked.length];
try {
return super.visitLambdaNode(node);
} finally {
this.newlineMarked = oldNewlineMarked;
}
}
@Override
public Void visitIfNode(Nodes.IfNode node) {
node.setNewLineFlag(this.source, this.newlineMarked);
return super.visitIfNode(node);
}
@Override
public Void visitUnlessNode(Nodes.UnlessNode node) {
node.setNewLineFlag(this.source, this.newlineMarked);
return super.visitUnlessNode(node);
}
@Override
public Void visitStatementsNode(Nodes.StatementsNode node) {
for (Nodes.Node child : node.body) {
child.setNewLineFlag(this.source, this.newlineMarked);
}
return super.visitStatementsNode(node);
}
@Override
protected Void defaultVisit(Nodes.Node node) {
node.visitChildNodes(this);
return null;
}
}