com.google.googlejavaformat.Input.Tok Java Examples

The following examples show how to use com.google.googlejavaformat.Input.Tok. 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: JavaCommentsHelper.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
@Override
public String rewrite(Tok tok, int maxWidth, int column0) {
    if (!tok.isComment()) {
        return tok.getOriginalText();
    }
    String text = tok.getOriginalText();
    if (tok.isJavadocComment()) {
        text = JavadocFormatter.formatJavadoc(text, column0, options);
    }
    List<String> lines = new ArrayList<>();
    Iterator<String> it = Newlines.lineIterator(text);
    while (it.hasNext()) {
        lines.add(CharMatcher.whitespace().trimTrailingFrom(it.next()));
    }
    if (tok.isSlashSlashComment()) {
        return indentLineComments(lines, column0);
    } else if (javadocShaped(lines)) {
        return indentJavadoc(lines, column0);
    } else {
        return preserveIndentation(lines, column0);
    }
}
 
Example #2
Source File: JavaCommentsHelper.java    From google-java-format with Apache License 2.0 6 votes vote down vote up
@Override
public String rewrite(Tok tok, int maxWidth, int column0) {
  if (!tok.isComment()) {
    return tok.getOriginalText();
  }
  String text = tok.getOriginalText();
  if (tok.isJavadocComment() && options.formatJavadoc()) {
    text = JavadocFormatter.formatJavadoc(text, column0);
  }
  List<String> lines = new ArrayList<>();
  Iterator<String> it = Newlines.lineIterator(text);
  while (it.hasNext()) {
    lines.add(CharMatcher.whitespace().trimTrailingFrom(it.next()));
  }
  if (tok.isSlashSlashComment()) {
    return indentLineComments(lines, column0);
  } else if (javadocShaped(lines)) {
    return indentJavadoc(lines, column0);
  } else {
    return preserveIndentation(lines, column0);
  }
}
 
Example #3
Source File: JavaCommentsHelper.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public String rewrite(Tok tok, int maxWidth, int column0) {
    if (!tok.isComment()) {
        return tok.getOriginalText();
    }
    String text = tok.getOriginalText();
    if (tok.isJavadocComment()) {
        text = JavadocFormatter.formatJavadoc(text, column0, options);
    }
    List<String> lines = new ArrayList<>();
    Iterator<String> it = Newlines.lineIterator(text);
    while (it.hasNext()) {
        lines.add(CharMatcher.whitespace().trimTrailingFrom(it.next()));
    }
    if (tok.isSlashSlashComment()) {
        return indentLineComments(lines, column0);
    } else if (javadocShaped(lines)) {
        return indentJavadoc(lines, column0);
    } else {
        return preserveIndentation(lines, column0);
    }
}
 
Example #4
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 #5
Source File: OpsBuilder.java    From google-java-format with Apache License 2.0 5 votes vote down vote up
private static int getI(Input.Token token) {
  for (Input.Tok tok : token.getToksBefore()) {
    if (tok.getIndex() >= 0) {
      return tok.getIndex();
    }
  }
  return token.getTok().getIndex();
}
 
Example #6
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 #7
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;
}
 
Example #8
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 #9
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 #10
Source File: OpsBuilder.java    From google-java-format with Apache License 2.0 4 votes vote down vote up
private static List<Op> makeComment(Input.Tok comment) {
  return comment.isSlashStarComment()
      ? ImmutableList.of(Doc.Tok.make(comment))
      : ImmutableList.of(Doc.Tok.make(comment), Doc.Break.makeForced());
}
 
Example #11
Source File: ModifierOrderer.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
private static void addTrivia(StringBuilder replacement, ImmutableList<? extends Tok> toks) {
    for (Tok tok : toks) {
        replacement.append(tok.getText());
    }
}
 
Example #12
Source File: ModifierOrderer.java    From google-java-format with Apache License 2.0 4 votes vote down vote up
private static void addTrivia(StringBuilder replacement, ImmutableList<? extends Tok> toks) {
  for (Tok tok : toks) {
    replacement.append(tok.getText());
  }
}
 
Example #13
Source File: OpsBuilder.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
private static List<Op> makeComment(Tok comment) {
    return comment.isSlashStarComment()
            ? ImmutableList.<Op>of(Doc.Tok.make(comment))
            : ImmutableList.<Op>of(Doc.Tok.make(comment), Doc.Break.makeForced());
}
 
Example #14
Source File: ModifierOrderer.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
private static void addTrivia(StringBuilder replacement, ImmutableList<? extends Tok> toks) {
    for (Tok tok : toks) {
        replacement.append(tok.getText());
    }
}
 
Example #15
Source File: OpsBuilder.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
private static List<Op> makeComment(Tok comment) {
    return comment.isSlashStarComment()
            ? ImmutableList.<Op>of(Doc.Tok.make(comment))
            : ImmutableList.<Op>of(Doc.Tok.make(comment), Doc.Break.makeForced());
}
 
Example #16
Source File: ModifierOrderer.java    From google-java-format with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the given token as a {@link javax.lang.model.element.Modifier}, or {@code null} if it
 * is not a modifier.
 */
private static Modifier asModifier(Token token) {
  return getModifier(((JavaInput.Tok) token.getTok()).kind());
}
 
Example #17
Source File: ModifierOrderer.java    From javaide with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Returns the given token as a {@link Modifier}, or {@code null} if it
 * is not a modifier.
 */
private static Modifier asModifier(Token token) {
    return getModifier(((JavaInput.Tok) token.getTok()).kind());
}
 
Example #18
Source File: ModifierOrderer.java    From java-n-IDE-for-Android with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the given token as a {@link Modifier}, or {@code null} if it
 * is not a modifier.
 */
private static Modifier asModifier(Token token) {
    return getModifier(((JavaInput.Tok) token.getTok()).kind());
}