Skip to content

Commit

Permalink
Pull JavaInput.{getkN,getToken} up to Input so JavaOutput
Browse files Browse the repository at this point in the history
can be reused in formatters of other languages.

Fixes #412

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=278695343
  • Loading branch information
cgrushko authored and kluever committed Nov 6, 2019
1 parent a27c99c commit 1396e60
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
14 changes: 14 additions & 0 deletions core/src/main/java/com/google/googlejavaformat/Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ public interface Token {

public abstract String getText();

/**
* Get the number of toks.
*
* @return the number of toks, including the EOF tok
*/
public abstract int getkN();

/**
* Get the Token by index.
*
* @param k the token index
*/
public abstract Token getToken(int k);

@Override
public String toString() {
return MoreObjects.toStringHelper(this).add("super", super.toString()).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,8 @@ Range<Integer> characterRangeToTokenRange(int offset, int length) throws Formatt
*
* @return the number of toks, including the EOF tok
*/
int getkN() {
@Override
public int getkN() {
return kN;
}

Expand All @@ -603,7 +604,8 @@ int getkN() {
*
* @param k the token index
*/
Token getToken(int k) {
@Override
public Token getToken(int k) {
return kToToken[k];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
*/
public final class JavaOutput extends Output {
private final String lineSeparator;
private final JavaInput javaInput; // Used to follow along while emitting the output.
private final Input javaInput; // Used to follow along while emitting the output.
private final CommentsHelper commentsHelper; // Used to re-flow comments.
private final Map<Integer, BlankLineWanted> blankLines = new HashMap<>(); // Info on blank lines.
private final RangeSet<Integer> partialFormatRanges = TreeRangeSet.create();
Expand All @@ -62,10 +62,10 @@ public final class JavaOutput extends Output {
/**
* {@code JavaOutput} constructor.
*
* @param javaInput the {@link JavaInput}, used to match up blank lines in the output
* @param javaInput the {@link Input}, used to match up blank lines in the output
* @param commentsHelper the {@link CommentsHelper}, used to rewrite comments
*/
public JavaOutput(String lineSeparator, JavaInput javaInput, CommentsHelper commentsHelper) {
public JavaOutput(String lineSeparator, Input javaInput, CommentsHelper commentsHelper) {
this.lineSeparator = lineSeparator;
this.javaInput = javaInput;
this.commentsHelper = commentsHelper;
Expand Down

0 comments on commit 1396e60

Please sign in to comment.