Skip to content

Commit db6dfa4

Browse files
committed
Make EffectivelyPrivate an error
Twelve members of private nested classes were public or protected, which reaches no further than the file a private class is in. They have no access modifier now: - the constructors of Obs's two nodes, of ReferenceScanner, and of the test's DelegatingFormatter; - the IntelliJ formatting task's constructor and applyReplacements; - SnippetWrapper's three methods and StringWrapper's getReflowReplacements; - TypeNameClassifier's TyParseState.isSingleUnit and next(), with the five overrides of next() in its constants.
1 parent a02443e commit db6dfa4

8 files changed

Lines changed: 18 additions & 18 deletions

File tree

‎buildSrc/src/main/groovy/open-java-format.error-prone-conventions.gradle‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ tasks.withType(JavaCompile).configureEach {
2828
error('CanonicalAnnotationSyntax')
2929
error('CollectorMutability')
3030
error('DirectReturn')
31+
error('EffectivelyPrivate')
3132
error('FormatStringConcatenation')
3233
error('JUnitClassModifiers')
3334
error('JUnitMethodDeclaration')

‎open-java-format-eclipse-plugin/src/main/java/com/palantir/javaformat/java/SnippetFormatter.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,18 @@ private final class SnippetWrapper {
4242
int offset;
4343
final StringBuilder contents = new StringBuilder();
4444

45-
public SnippetWrapper append(String str) {
45+
SnippetWrapper append(String str) {
4646
contents.append(str);
4747
return this;
4848
}
4949

50-
public SnippetWrapper appendSource(String source) {
50+
SnippetWrapper appendSource(String source) {
5151
this.offset = contents.length();
5252
contents.append(source);
5353
return this;
5454
}
5555

56-
public void closeBraces(int initialIndent) {
56+
void closeBraces(int initialIndent) {
5757
for (int i = initialIndent; --i >= 0; ) {
5858
contents.append("\n").append(createIndentationString(i)).append("}");
5959
}

‎open-java-format-idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatFormattingService.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ private static final class PalantirJavaFormatFormattingTask implements Formattin
108108
private final AsyncFormattingRequest request;
109109
private final Optional<FormatterService> formatterService;
110110

111-
public PalantirJavaFormatFormattingTask(
112-
AsyncFormattingRequest request, Optional<FormatterService> formatterService) {
111+
PalantirJavaFormatFormattingTask(AsyncFormattingRequest request, Optional<FormatterService> formatterService) {
113112
this.request = request;
114113
this.formatterService = formatterService;
115114
}
@@ -174,7 +173,7 @@ public void run() {
174173
}
175174
}
176175

177-
public static String applyReplacements(String input, Collection<Replacement> replacementsCollection) {
176+
static String applyReplacements(String input, Collection<Replacement> replacementsCollection) {
178177
List<Replacement> replacements = new ArrayList<>(replacementsCollection);
179178
replacements.sort(comparing((Replacement r) -> r.getReplaceRange().lowerEndpoint())
180179
.reversed());

‎open-java-format-idea-plugin/src/test/java/com/palantir/javaformat/intellij/PalantirJavaFormatFormattingServiceTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private PsiFile createPsiFile(String path, String... contents) throws IOExceptio
126126
}
127127

128128
private static final class DelegatingFormatter extends PalantirJavaFormatFormattingService {
129-
public DelegatingFormatter() {
129+
DelegatingFormatter() {
130130
this.setPluginDescriptor(
131131
requireNonNull(FormattingService.EP_NAME.findExtension(PalantirJavaFormatFormattingService.class))
132132
.getPluginDescriptor()

‎open-java-format/src/main/java/com/palantir/javaformat/doc/Obs.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private static class LevelNodeImpl extends HasUniqueId implements LevelNode {
9595
private final FinishLevelNode finisher;
9696
private final int startColumn;
9797

98-
public LevelNodeImpl(Level level, State incomingState, int parentExplorationId, Sink sink) {
98+
LevelNodeImpl(Level level, State incomingState, int parentExplorationId, Sink sink) {
9999
this.level = level;
100100
this.sink = sink;
101101
this.finisher = sink.writeLevelNode(id(), parentExplorationId, incomingState, level);
@@ -170,7 +170,7 @@ private static class ExplorationNodeImpl extends HasUniqueId implements Explorat
170170
private final FinishExplorationNode finishExplorationNode;
171171
private final Optional<Level> parentLevel;
172172

173-
public ExplorationNodeImpl(
173+
ExplorationNodeImpl(
174174
@Nullable LevelNodeImpl parent,
175175
String humanDescription,
176176
Sink sink,

‎open-java-format/src/main/java/com/palantir/javaformat/java/RemoveUnusedImports.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public Void visitReference(ReferenceTree referenceTree, Void unused) {
181181
private class ReferenceScanner extends TreeScanner<Void, Void> {
182182
private final long basePos;
183183

184-
public ReferenceScanner(long basePos) {
184+
ReferenceScanner(long basePos) {
185185
this.basePos = basePos;
186186
}
187187

‎open-java-format/src/main/java/com/palantir/javaformat/java/StringWrapper.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ private static class Reflower {
173173
this.lineMap = unit.getLineMap();
174174
}
175175

176-
protected TreeRangeMap<Integer, String> getReflowReplacements() {
176+
TreeRangeMap<Integer, String> getReflowReplacements() {
177177
// Paths to string literals that extend past the column limit.
178178
List<TreePath> longStringLiterals = new ArrayList<>();
179179
// Paths to text blocks to be re-indented.

‎open-java-format/src/main/java/com/palantir/javaformat/java/TypeNameClassifier.java‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private enum TyParseState {
2929
/** The start state. */
3030
START(false) {
3131
@Override
32-
public TyParseState next(JavaCaseFormat n) {
32+
TyParseState next(JavaCaseFormat n) {
3333
return switch (n) {
3434
case UPPERCASE ->
3535
// if we see an UpperCamel later, assume this was a class
@@ -47,7 +47,7 @@ public TyParseState next(JavaCaseFormat n) {
4747
/** The current prefix is a type. */
4848
TYPE(true) {
4949
@Override
50-
public TyParseState next(JavaCaseFormat n) {
50+
TyParseState next(JavaCaseFormat n) {
5151
return switch (n) {
5252
case UPPERCASE, LOWER_CAMEL, LOWERCASE -> TyParseState.FIRST_STATIC_MEMBER;
5353
case UPPER_CAMEL -> TyParseState.TYPE;
@@ -58,23 +58,23 @@ public TyParseState next(JavaCaseFormat n) {
5858
/** The current prefix is a type, followed by a single static member access. */
5959
FIRST_STATIC_MEMBER(true) {
6060
@Override
61-
public TyParseState next(JavaCaseFormat n) {
61+
TyParseState next(JavaCaseFormat n) {
6262
return TyParseState.REJECT;
6363
}
6464
},
6565

6666
/** Anything not represented by one of the other states. */
6767
REJECT(false) {
6868
@Override
69-
public TyParseState next(JavaCaseFormat n) {
69+
TyParseState next(JavaCaseFormat n) {
7070
return TyParseState.REJECT;
7171
}
7272
},
7373

7474
/** An ambiguous type prefix. */
7575
AMBIGUOUS(false) {
7676
@Override
77-
public TyParseState next(JavaCaseFormat n) {
77+
TyParseState next(JavaCaseFormat n) {
7878
return switch (n) {
7979
case UPPERCASE -> AMBIGUOUS;
8080
case LOWER_CAMEL, LOWERCASE -> TyParseState.REJECT;
@@ -89,12 +89,12 @@ public TyParseState next(JavaCaseFormat n) {
8989
this.isSingleUnit = isSingleUnit;
9090
}
9191

92-
public boolean isSingleUnit() {
92+
boolean isSingleUnit() {
9393
return isSingleUnit;
9494
}
9595

9696
/** Transition function. */
97-
public abstract TyParseState next(JavaCaseFormat n);
97+
abstract TyParseState next(JavaCaseFormat n);
9898
}
9999

100100
/**

0 commit comments

Comments
 (0)