Skip to content

Commit e6a7af7

Browse files
eamonnmcmanusgoogle-java-format Team
authored andcommitted
Reduce member visibility where possible.
Remove some unused code discovered during this exercise. Implement a TODO about using the javac `Flags` API directly. PiperOrigin-RevId: 891844799
1 parent c4dedd5 commit e6a7af7

14 files changed

+90
-165
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.util.List;
2323
import java.util.Map;
2424

25-
/** This interface defines methods common to an {@link Input} or an {@link Output}. */
25+
/** This class defines methods common to an {@link Input} or an {@link Output}. */
2626
public abstract class InputOutput {
2727
private ImmutableList<String> lines = ImmutableList.of();
2828

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static Result create(
5656
private final CommandLineOptions parameters;
5757
private final JavaFormatterOptions options;
5858

59-
public FormatFileCallable(
59+
FormatFileCallable(
6060
CommandLineOptions parameters, Path path, String input, JavaFormatterOptions options) {
6161
this.path = path;
6262
this.input = input;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,12 @@ public static String reorderImports(String text) throws FormatterException {
6363
}
6464

6565
private String reorderImports() throws FormatterException {
66-
int firstImportStart;
6766
Optional<Integer> maybeFirstImport = findIdentifier(0, IMPORT_OR_CLASS_START);
6867
if (!maybeFirstImport.isPresent() || !tokenAt(maybeFirstImport.get()).equals("import")) {
6968
// No imports, so nothing to do.
7069
return text;
7170
}
72-
firstImportStart = maybeFirstImport.get();
71+
int firstImportStart = maybeFirstImport.get();
7372
int unindentedFirstImportStart = unindent(firstImportStart);
7473

7574
ImportsAndIndex imports = scanImports(firstImportStart);
@@ -189,7 +188,7 @@ private ImportOrderer(String text, ImmutableList<Tok> toks, Style style) {
189188
}
190189
}
191190

192-
enum ImportType {
191+
private enum ImportType {
193192
STATIC,
194193
MODULE,
195194
NORMAL
@@ -206,7 +205,8 @@ enum ImportType {
206205
* @param importType the {@link ImportType} of the import.
207206
* @param lineSeparator the line separator to use when formatting the import.
208207
*/
209-
record Import(String imported, String trailing, ImportType importType, String lineSeparator) {
208+
private record Import(
209+
String imported, String trailing, ImportType importType, String lineSeparator) {
210210
/** The top-level package of the import. */
211211
String topLevel() {
212212
return DOT_SPLITTER.split(imported).iterator().next();
@@ -227,7 +227,7 @@ boolean isJava() {
227227
}
228228

229229
/** True if this is a third-party import per AOSP style. */
230-
public boolean isThirdParty() {
230+
boolean isThirdParty() {
231231
return !(isAndroid() || isJava());
232232
}
233233

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727
import java.util.regex.Pattern;
2828

2929
/** {@code JavaCommentsHelper} extends {@link CommentsHelper} to rewrite Java comments. */
30-
public final class JavaCommentsHelper implements CommentsHelper {
30+
final class JavaCommentsHelper implements CommentsHelper {
3131

3232
private final String lineSeparator;
3333
private final JavaFormatterOptions options;
3434

35-
public JavaCommentsHelper(String lineSeparator, JavaFormatterOptions options) {
35+
JavaCommentsHelper(String lineSeparator, JavaFormatterOptions options) {
3636
this.lineSeparator = lineSeparator;
3737
this.options = options;
3838
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
import org.jspecify.annotations.Nullable;
6060

6161
/** {@code JavaInput} extends {@link Input} to represent a Java input document. */
62-
public final class JavaInput extends Input {
62+
final class JavaInput extends Input {
6363
/**
6464
* A {@code JavaInput} is a sequence of {@link Tok}s that cover the Java input. A {@link Tok} is
6565
* either a token (if {@code isToken()}), or a non-token, which is a comment (if {@code
@@ -275,7 +275,7 @@ public String toString() {
275275
* @param text the input text
276276
* @throws FormatterException if the input cannot be parsed
277277
*/
278-
public JavaInput(String text) throws FormatterException {
278+
JavaInput(String text) throws FormatterException {
279279
this.text = checkNotNull(text);
280280
setLines(ImmutableList.copyOf(Newlines.lineIterator(text)));
281281
ImmutableList<Tok> toks = buildToks(text);
@@ -608,7 +608,7 @@ private static boolean isParamComment(Tok tok) {
608608
* @return the {@code 0}-based {@link Range} of tokens
609609
* @throws FormatterException if the upper endpoint of the range is outside the file
610610
*/
611-
Range<Integer> characterRangeToTokenRange(Range<Integer> characterRange)
611+
private Range<Integer> characterRangeToTokenRange(Range<Integer> characterRange)
612612
throws FormatterException {
613613
if (characterRange.upperEndpoint() > text.length()) {
614614
throw new FormatterException(
@@ -699,11 +699,11 @@ public int getColumnNumber(int inputPosition) {
699699

700700
// TODO(cushon): refactor JavaInput so the CompilationUnit can be passed into
701701
// the constructor.
702-
public void setCompilationUnit(JCCompilationUnit unit) {
702+
void setCompilationUnit(JCCompilationUnit unit) {
703703
this.unit = unit;
704704
}
705705

706-
public RangeSet<Integer> characterRangesToTokenRanges(Collection<Range<Integer>> characterRanges)
706+
RangeSet<Integer> characterRangesToTokenRanges(Collection<Range<Integer>> characterRanges)
707707
throws FormatterException {
708708
RangeSet<Integer> tokenRangeSet = TreeRangeSet.create();
709709
for (Range<Integer> characterRange : characterRanges) {

0 commit comments

Comments
 (0)