-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1156 from eregon/more-newline-flags-visitor
Set newline flag using a visitor for both Ruby and Java nodes
- Loading branch information
Showing
9 changed files
with
272 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.yarp; | ||
|
||
// Keep in sync with Ruby MarkNewlinesVisitor | ||
final class MarkNewlinesVisitor extends AbstractNodeVisitor<Void> { | ||
|
||
private final Nodes.Source source; | ||
private boolean[] newlineMarked; | ||
|
||
MarkNewlinesVisitor(Nodes.Source source, boolean[] newlineMarked) { | ||
this.source = source; | ||
this.newlineMarked = newlineMarked; | ||
} | ||
|
||
@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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.