MCPcopy Index your code
hub / github.com/google/google-java-format / Tok

Class Tok

core/src/main/java/com/google/googlejavaformat/Doc.java:698–771  ·  view source on GitHub ↗

A leaf node in a Doc for a non-token.

Source from the content-addressed store, hash-verified

696
697 /** A leaf node in a {@link Doc} for a non-token. */
698 static final class Tok extends Doc implements Op {
699 private final Input.Tok tok;
700
701 private Tok(Input.Tok tok) {
702 this.tok = tok;
703 }
704
705 /**
706 * Factory method for a {@code Tok}.
707 *
708 * @param tok the {@link Input.Tok} to wrap
709 * @return the new {@code Tok}
710 */
711 static Tok make(Input.Tok tok) {
712 return new Tok(tok);
713 }
714
715 @Override
716 public void add(DocBuilder builder) {
717 builder.add(this);
718 }
719
720 @Override
721 int computeWidth() {
722 int idx = Newlines.firstBreak(tok.getOriginalText());
723 // only count the first line of multi-line block comments
724 if (tok.isComment()) {
725 if (idx > 0) {
726 return idx;
727 } else if (tok.isSlashSlashComment() && !tok.getOriginalText().startsWith("// ")) {
728 // Account for line comments with missing spaces, see computeFlat.
729 return tok.length() + 1;
730 } else {
731 return reformatParameterComment(tok).map(String::length).orElse(tok.length());
732 }
733 }
734 return idx != -1 ? MAX_LINE_WIDTH : tok.length();
735 }
736
737 @Override
738 String computeFlat() {
739 // TODO(cushon): commentsHelper.rewrite doesn't get called for spans that fit in a single
740 // line. That's fine for multi-line comment reflowing, but problematic for adding missing
741 // spaces in line comments.
742 if (tok.isSlashSlashComment() && !tok.getOriginalText().startsWith("// ")) {
743 return "// " + tok.getOriginalText().substring("//".length());
744 }
745 return reformatParameterComment(tok).orElse(tok.getOriginalText());
746 }
747
748 @Override
749 Range<Integer> computeRange() {
750 return Range.singleton(tok.getIndex()).canonical(INTEGERS);
751 }
752
753 String text;
754
755 @Override

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected