Skip to content

Commit bb45148

Browse files
committed
Break a cycle between javadoc and java packages
This makes GJF more jadep-friendly. MOE_MIGRATED_REVID=191617991
1 parent a268700 commit bb45148

File tree

4 files changed

+13
-17
lines changed

4 files changed

+13
-17
lines changed

core/src/main/java/com/google/googlejavaformat/java/JavaFormatterOptions.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package com.google.googlejavaformat.java;
1616

1717
import com.google.errorprone.annotations.Immutable;
18+
import com.google.googlejavaformat.java.javadoc.JavadocOptions;
1819

1920
/**
2021
* Options for a google-java-format invocation.
@@ -27,7 +28,7 @@
2728
* preferences, and in fact it would work directly against our primary goals.
2829
*/
2930
@Immutable
30-
public class JavaFormatterOptions {
31+
public class JavaFormatterOptions implements JavadocOptions {
3132

3233
static final int DEFAULT_MAX_LINE_LENGTH = 100;
3334

@@ -57,6 +58,7 @@ private JavaFormatterOptions(Style style) {
5758
}
5859

5960
/** Returns the maximum formatted width */
61+
@Override
6062
public int maxLineLength() {
6163
return DEFAULT_MAX_LINE_LENGTH;
6264
}

core/src/main/java/com/google/googlejavaformat/java/javadoc/JavadocFormatter.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import static java.util.regex.Pattern.compile;
2222

2323
import com.google.common.collect.ImmutableList;
24-
import com.google.googlejavaformat.java.JavaFormatterOptions;
2524
import com.google.googlejavaformat.java.javadoc.JavadocLexer.LexException;
2625
import java.util.List;
2726
import java.util.regex.Matcher;
@@ -40,7 +39,7 @@ public final class JavadocFormatter {
4039
* Formats the given Javadoc comment, which must start with ∕✱✱ and end with ✱∕. The output will
4140
* start and end with the same characters.
4241
*/
43-
public static String formatJavadoc(String input, int blockIndent, JavaFormatterOptions options) {
42+
public static String formatJavadoc(String input, int blockIndent, JavadocOptions options) {
4443
ImmutableList<Token> tokens;
4544
try {
4645
tokens = lex(input);
@@ -51,7 +50,7 @@ public static String formatJavadoc(String input, int blockIndent, JavaFormatterO
5150
return makeSingleLineIfPossible(blockIndent, result, options);
5251
}
5352

54-
private static String render(List<Token> input, int blockIndent, JavaFormatterOptions options) {
53+
private static String render(List<Token> input, int blockIndent, JavadocOptions options) {
5554
JavadocWriter output = new JavadocWriter(blockIndent, options);
5655
for (Token token : input) {
5756
switch (token.getType()) {
@@ -164,7 +163,7 @@ private static Token standardize(Token token, Token standardToken) {
164163
* fits on one line.
165164
*/
166165
private static String makeSingleLineIfPossible(
167-
int blockIndent, String input, JavaFormatterOptions options) {
166+
int blockIndent, String input, JavadocOptions options) {
168167
int oneLinerContentLength = options.maxLineLength() - "/** */".length() - blockIndent;
169168
Matcher matcher = ONE_CONTENT_LINE_PATTERN.matcher(input);
170169
if (matcher.matches() && matcher.group(1).isEmpty()) {

core/src/main/java/com/google/googlejavaformat/java/GoogleJavaFormatVersion.java.template renamed to core/src/main/java/com/google/googlejavaformat/java/javadoc/JavadocOptions.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015 Google Inc.
2+
* Copyright 2018 Google Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
55
* in compliance with the License. You may obtain a copy of the License at
@@ -12,13 +12,9 @@
1212
* the License.
1313
*/
1414

15-
package com.google.googlejavaformat.java;
15+
package com.google.googlejavaformat.java.javadoc;
1616

17-
import java.util.Optional;
18-
19-
class GoogleJavaFormatVersion {
20-
21-
static String version() {
22-
return "%VERSION%";
23-
}
17+
/** Options for javadoc formatting. */
18+
public interface JavadocOptions {
19+
int maxLineLength();
2420
}

core/src/main/java/com/google/googlejavaformat/java/javadoc/JavadocWriter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import com.google.common.base.Strings;
3030
import com.google.common.collect.ImmutableSet;
3131
import com.google.common.collect.Ordering;
32-
import com.google.googlejavaformat.java.JavaFormatterOptions;
3332
import com.google.googlejavaformat.java.javadoc.Token.Type;
3433

3534
/**
@@ -41,7 +40,7 @@
4140
*/
4241
final class JavadocWriter {
4342
private final int blockIndent;
44-
private final JavaFormatterOptions options;
43+
private final JavadocOptions options;
4544
private final StringBuilder output = new StringBuilder();
4645
/**
4746
* Whether we are inside an {@code <li>} element, excluding the case in which the {@code <li>}
@@ -61,7 +60,7 @@ final class JavadocWriter {
6160
private int indentForMoeEndStripComment;
6261
private boolean wroteAnythingSignificant;
6362

64-
JavadocWriter(int blockIndent, JavaFormatterOptions options) {
63+
JavadocWriter(int blockIndent, JavadocOptions options) {
6564
this.blockIndent = blockIndent;
6665
this.options = checkNotNull(options);
6766
}

0 commit comments

Comments
 (0)