Java Code Examples for com.google.googlejavaformat.Input.Token#getToksBefore()

The following examples show how to use com.google.googlejavaformat.Input.Token#getToksBefore() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaOutput.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * The earliest position of any Tok in the Token, including leading whitespace.
 */
public static int startPosition(Token token) {
    int min = token.getTok().getPosition();
    for (Input.Tok tok : token.getToksBefore()) {
        min = Math.min(min, tok.getPosition());
    }
    return min;
}
 
Example 2
Source File: JavaOutput.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * The earliest non-whitespace Tok in the Token.
 */
public static Input.Tok startTok(Token token) {
    for (Input.Tok tok : token.getToksBefore()) {
        if (tok.getIndex() >= 0) {
            return tok;
        }
    }
    return token.getTok();
}
 
Example 3
Source File: OpsBuilder.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
private static int getI(Token token) {
    for (Tok tok : token.getToksBefore()) {
        if (tok.getIndex() >= 0) {
            return tok.getIndex();
        }
    }
    return token.getTok().getIndex();
}
 
Example 4
Source File: OpsBuilder.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * @return the start column of the token at {@code position}, including leading comments.
 */
public Integer actualStartColumn(int position) {
    Token startToken = input.getPositionTokenMap().get(position);
    int start = startToken.getTok().getPosition();
    int line0 = input.getLineNumber(start);
    for (Tok tok : startToken.getToksBefore()) {
        if (line0 != input.getLineNumber(tok.getPosition())) {
            return start;
        }
        if (tok.isComment()) {
            start = Math.min(start, tok.getPosition());
        }
    }
    return start;
}
 
Example 5
Source File: JavaOutput.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * The earliest position of any Tok in the Token, including leading whitespace.
 */
public static int startPosition(Token token) {
    int min = token.getTok().getPosition();
    for (Input.Tok tok : token.getToksBefore()) {
        min = Math.min(min, tok.getPosition());
    }
    return min;
}
 
Example 6
Source File: JavaOutput.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * The earliest non-whitespace Tok in the Token.
 */
public static Input.Tok startTok(Token token) {
    for (Input.Tok tok : token.getToksBefore()) {
        if (tok.getIndex() >= 0) {
            return tok;
        }
    }
    return token.getTok();
}
 
Example 7
Source File: OpsBuilder.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
private static int getI(Token token) {
    for (Tok tok : token.getToksBefore()) {
        if (tok.getIndex() >= 0) {
            return tok.getIndex();
        }
    }
    return token.getTok().getIndex();
}
 
Example 8
Source File: OpsBuilder.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @return the start column of the token at {@code position}, including leading comments.
 */
public Integer actualStartColumn(int position) {
    Token startToken = input.getPositionTokenMap().get(position);
    int start = startToken.getTok().getPosition();
    int line0 = input.getLineNumber(start);
    for (Tok tok : startToken.getToksBefore()) {
        if (line0 != input.getLineNumber(tok.getPosition())) {
            return start;
        }
        if (tok.isComment()) {
            start = Math.min(start, tok.getPosition());
        }
    }
    return start;
}
 
Example 9
Source File: JavaOutput.java    From google-java-format with Apache License 2.0 5 votes vote down vote up
/** The earliest position of any Tok in the Token, including leading whitespace. */
public static int startPosition(Token token) {
  int min = token.getTok().getPosition();
  for (Input.Tok tok : token.getToksBefore()) {
    min = Math.min(min, tok.getPosition());
  }
  return min;
}
 
Example 10
Source File: JavaOutput.java    From google-java-format with Apache License 2.0 5 votes vote down vote up
/** The earliest non-whitespace Tok in the Token. */
public static Input.Tok startTok(Token token) {
  for (Input.Tok tok : token.getToksBefore()) {
    if (tok.getIndex() >= 0) {
      return tok;
    }
  }
  return token.getTok();
}
 
Example 11
Source File: OpsBuilder.java    From google-java-format with Apache License 2.0 5 votes vote down vote up
/** @return the start column of the token at {@code position}, including leading comments. */
public Integer actualStartColumn(int position) {
  Token startToken = input.getPositionTokenMap().get(position);
  int start = startToken.getTok().getPosition();
  int line0 = input.getLineNumber(start);
  for (Tok tok : startToken.getToksBefore()) {
    if (line0 != input.getLineNumber(tok.getPosition())) {
      return start;
    }
    if (tok.isComment()) {
      start = Math.min(start, tok.getPosition());
    }
  }
  return start;
}