com.google.googlejavaformat.Input Java Examples

The following examples show how to use com.google.googlejavaformat.Input. 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 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 #2
Source File: JavaInputAstVisitor.java    From google-java-format with Apache License 2.0 5 votes vote down vote up
/** Does this list of trees end with the specified token? */
private boolean hasTrailingToken(Input input, List<? extends Tree> nodes, String token) {
  if (nodes.isEmpty()) {
    return false;
  }
  Tree lastNode = getLast(nodes);
  Optional<? extends Input.Token> nextToken =
      getNextToken(input, getEndPosition(lastNode, getCurrentPath()));
  return nextToken.isPresent() && nextToken.get().getTok().getText().equals(token);
}
 
Example #3
Source File: JavaInputAstVisitor.java    From google-java-format with Apache License 2.0 5 votes vote down vote up
/** Does this declaration have javadoc preceding it? */
private boolean hasJavaDoc(Tree bodyDeclaration) {
  int position = ((JCTree) bodyDeclaration).getStartPosition();
  Input.Token token = builder.getInput().getPositionTokenMap().get(position);
  if (token != null) {
    for (Input.Tok tok : token.getToksBefore()) {
      if (tok.getText().startsWith("/**")) {
        return true;
      }
    }
  }
  return false;
}
 
Example #4
Source File: JavaOutput.java    From google-java-format with Apache License 2.0 5 votes vote down vote up
/** The last non-whitespace Tok in the Token. */
public static Input.Tok endTok(Token token) {
  for (int i = token.getToksAfter().size() - 1; i >= 0; i--) {
    Input.Tok tok = token.getToksAfter().get(i);
    if (tok.getIndex() >= 0) {
      return tok;
    }
  }
  return token.getTok();
}
 
Example #5
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 #6
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 #7
Source File: JavaOutput.java    From google-java-format with Apache License 2.0 5 votes vote down vote up
/**
 * {@code JavaOutput} constructor.
 *
 * @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, Input javaInput, CommentsHelper commentsHelper) {
  this.lineSeparator = lineSeparator;
  this.javaInput = javaInput;
  this.commentsHelper = commentsHelper;
  kN = javaInput.getkN();
}
 
Example #8
Source File: JavaInputAstVisitor.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Does this list of trees end with the specified token?
 */
private boolean hasTrailingToken(Input input, List<? extends Tree> nodes, String token) {
    if (nodes.isEmpty()) {
        return false;
    }
    Tree lastNode = getLast(nodes);
    Optional<? extends Input.Token> nextToken =
            getNextToken(input, getEndPosition(lastNode, getCurrentPath()));
    return nextToken.isPresent() && nextToken.get().getTok().getText().equals(token);
}
 
Example #9
Source File: JavaInputAstVisitor.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Does this declaration have javadoc preceding it?
 */
private boolean hasJavaDoc(Tree bodyDeclaration) {
    int position = ((JCTree) bodyDeclaration).getStartPosition();
    Input.Token token = builder.getInput().getPositionTokenMap().get(position);
    if (token != null) {
        for (Input.Tok tok : token.getToksBefore()) {
            if (tok.getText().startsWith("/**")) {
                return true;
            }
        }
    }
    return false;
}
 
Example #10
Source File: JavaOutput.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * The last non-whitespace Tok in the Token.
 */
public static Input.Tok endTok(Token token) {
    for (int i = token.getToksAfter().size() - 1; i >= 0; i--) {
        Input.Tok tok = token.getToksAfter().get(i);
        if (tok.getIndex() >= 0) {
            return tok;
        }
    }
    return token.getTok();
}
 
Example #11
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 #12
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 #13
Source File: JavaOutput.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * The last non-whitespace Tok in the Token.
 */
public static Input.Tok endTok(Token token) {
    for (int i = token.getToksAfter().size() - 1; i >= 0; i--) {
        Input.Tok tok = token.getToksAfter().get(i);
        if (tok.getIndex() >= 0) {
            return tok;
        }
    }
    return token.getTok();
}
 
Example #14
Source File: JavaInputAstVisitor.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Does this declaration have javadoc preceding it?
 */
private boolean hasJavaDoc(Tree bodyDeclaration) {
    int position = ((JCTree) bodyDeclaration).getStartPosition();
    Input.Token token = builder.getInput().getPositionTokenMap().get(position);
    if (token != null) {
        for (Input.Tok tok : token.getToksBefore()) {
            if (tok.getText().startsWith("/**")) {
                return true;
            }
        }
    }
    return false;
}
 
Example #15
Source File: JavaInputAstVisitor.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Does this list of trees end with the specified token?
 */
private boolean hasTrailingToken(Input input, List<? extends Tree> nodes, String token) {
    if (nodes.isEmpty()) {
        return false;
    }
    Tree lastNode = getLast(nodes);
    Optional<? extends Input.Token> nextToken =
            getNextToken(input, getEndPosition(lastNode, getCurrentPath()));
    return nextToken.isPresent() && nextToken.get().getTok().getText().equals(token);
}
 
Example #16
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 #17
Source File: JavaInputAstVisitor.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
private static Optional<? extends Input.Token> getNextToken(Input input, int position) {
    return Optional.fromNullable(input.getPositionTokenMap().get(position));
}
 
Example #18
Source File: JavaInputAstVisitor.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
private static Optional<? extends Input.Token> getNextToken(Input input, int position) {
    return Optional.fromNullable(input.getPositionTokenMap().get(position));
}
 
Example #19
Source File: JavaInputAstVisitor.java    From google-java-format with Apache License 2.0 4 votes vote down vote up
private static Optional<? extends Input.Token> getNextToken(Input input, int position) {
  return Optional.ofNullable(input.getPositionTokenMap().get(position));
}
 
Example #20
Source File: JavaInput.java    From javaide with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Get the input tokens.
 *
 * @return the input tokens
 */
@Override
public ImmutableList<? extends Input.Token> getTokens() {
    return tokens;
}
 
Example #21
Source File: JavaInput.java    From javaide with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Get the earlier {@link Tok}s assigned to this {@code Token}.
 *
 * @return the earlier {@link Tok}s assigned to this {@code Token}
 */
@Override
public ImmutableList<? extends Input.Tok> getToksBefore() {
    return toksBefore;
}
 
Example #22
Source File: JavaInput.java    From javaide with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Get the later {@link Tok}s assigned to this {@code Token}.
 *
 * @return the later {@link Tok}s assigned to this {@code Token}
 */
@Override
public ImmutableList<? extends Input.Tok> getToksAfter() {
    return toksAfter;
}
 
Example #23
Source File: JavaInput.java    From java-n-IDE-for-Android with Apache License 2.0 2 votes vote down vote up
/**
 * Get the input tokens.
 *
 * @return the input tokens
 */
@Override
public ImmutableList<? extends Input.Token> getTokens() {
    return tokens;
}
 
Example #24
Source File: JavaInput.java    From java-n-IDE-for-Android with Apache License 2.0 2 votes vote down vote up
/**
 * Get the earlier {@link Tok}s assigned to this {@code Token}.
 *
 * @return the earlier {@link Tok}s assigned to this {@code Token}
 */
@Override
public ImmutableList<? extends Input.Tok> getToksBefore() {
    return toksBefore;
}
 
Example #25
Source File: JavaInput.java    From java-n-IDE-for-Android with Apache License 2.0 2 votes vote down vote up
/**
 * Get the later {@link Tok}s assigned to this {@code Token}.
 *
 * @return the later {@link Tok}s assigned to this {@code Token}
 */
@Override
public ImmutableList<? extends Input.Tok> getToksAfter() {
    return toksAfter;
}
 
Example #26
Source File: JavaInput.java    From google-java-format with Apache License 2.0 2 votes vote down vote up
/**
 * Get the earlier {@link Tok}s assigned to this {@code Token}.
 *
 * @return the earlier {@link Tok}s assigned to this {@code Token}
 */
@Override
public ImmutableList<? extends Input.Tok> getToksBefore() {
  return toksBefore;
}
 
Example #27
Source File: JavaInput.java    From google-java-format with Apache License 2.0 2 votes vote down vote up
/**
 * Get the later {@link Tok}s assigned to this {@code Token}.
 *
 * @return the later {@link Tok}s assigned to this {@code Token}
 */
@Override
public ImmutableList<? extends Input.Tok> getToksAfter() {
  return toksAfter;
}
 
Example #28
Source File: JavaInput.java    From google-java-format with Apache License 2.0 2 votes vote down vote up
/**
 * Get the input tokens.
 *
 * @return the input tokens
 */
@Override
public ImmutableList<? extends Input.Token> getTokens() {
  return tokens;
}