diff --git a/buildSrc/src/main/groovy/open-java-format.error-prone-conventions.gradle b/buildSrc/src/main/groovy/open-java-format.error-prone-conventions.gradle index 9bb1278d3..5d3f6595a 100644 --- a/buildSrc/src/main/groovy/open-java-format.error-prone-conventions.gradle +++ b/buildSrc/src/main/groovy/open-java-format.error-prone-conventions.gradle @@ -18,6 +18,12 @@ tasks.withType(JavaCompile).configureEach { options.errorprone { // Annotation processor output (Immutables) is not ours to fix. excludedPaths = '.*/build/generated/.*' + error('FormatStringConcatenation') + error('JUnitClassModifiers') + error('JUnitMethodDeclaration') + error('RefactorSwitch') + error('SameNameButDifferent') + error('UnusedVariable') } } @@ -27,27 +33,3 @@ pluginManager.withPlugin('java-gradle-plugin') { options.errorprone.disable('JavaxInjectOnAbstractMethod') } } - -// The checks vfs-s3 makes build-breaking. The commented ones stay off until the code is fixed, one check at a -// time: StaticImport 84, LexicographicalAnnotationListing 46, RedundantStringConversion 6, AlmostJavadoc 3 -// findings; the rest have none. -tasks.withType(JavaCompile).configureEach { - options.errorprone { - //error('StaticImport') - //error('UnnecessarilyFullyQualified') - //error('EmptyBlockTag') - //error('OperatorPrecedence') - //error('RedundantStringConversion') - //error('PatternMatchingInstanceof') - //error('UnnecessaryParentheses') - //error('LexicographicalAnnotationListing') - error('JUnitMethodDeclaration') - error('JUnitClassModifiers') - //error('MissingSummary') - //error('AlmostJavadoc') - //error('BadImport') - //error('JdkObsolete') - // NonStaticImport (Picnic) is the inverse of StaticImport and would give contradictory advice. - //disable('NonStaticImport') - } -} diff --git a/gradle-open-java-format/src/main/java/com/palantir/javaformat/gradle/FormatDiff.java b/gradle-open-java-format/src/main/java/com/palantir/javaformat/gradle/FormatDiff.java index 6ac871250..ec4fb6abd 100644 --- a/gradle-open-java-format/src/main/java/com/palantir/javaformat/gradle/FormatDiff.java +++ b/gradle-open-java-format/src/main/java/com/palantir/javaformat/gradle/FormatDiff.java @@ -129,7 +129,6 @@ private static Path gitTopLevelDir(Path dir) throws IOException, InterruptedExce return Paths.get(gitCommand(dir, "git", "rev-parse", "--show-toplevel")); } - @SuppressWarnings("for-rollout:DefaultCharset") private static String gitCommand(Path dir, String... args) throws IOException, InterruptedException { Process process = new ProcessBuilder().command(args).directory(dir.toFile()).start(); diff --git a/gradle-open-java-format/src/main/java/com/palantir/javaformat/gradle/FormatterServiceLoader.java b/gradle-open-java-format/src/main/java/com/palantir/javaformat/gradle/FormatterServiceLoader.java index 233e6b0ef..ca01b2630 100644 --- a/gradle-open-java-format/src/main/java/com/palantir/javaformat/gradle/FormatterServiceLoader.java +++ b/gradle-open-java-format/src/main/java/com/palantir/javaformat/gradle/FormatterServiceLoader.java @@ -69,7 +69,6 @@ public static synchronized FormatterService load(Collection jars) { return LOADED.computeIfAbsent(key, _key -> loadUncached(jars)); } - @SuppressWarnings("for-rollout:NullAway") private static FormatterService loadUncached(Collection jars) { URL[] jarUris = jars.stream() .map(file -> { diff --git a/gradle-open-java-format/src/main/java/com/palantir/javaformat/gradle/PalantirJavaFormatProviderPlugin.java b/gradle-open-java-format/src/main/java/com/palantir/javaformat/gradle/PalantirJavaFormatProviderPlugin.java index 39d219a21..e8305c486 100644 --- a/gradle-open-java-format/src/main/java/com/palantir/javaformat/gradle/PalantirJavaFormatProviderPlugin.java +++ b/gradle-open-java-format/src/main/java/com/palantir/javaformat/gradle/PalantirJavaFormatProviderPlugin.java @@ -25,7 +25,6 @@ public final class PalantirJavaFormatProviderPlugin implements Plugin { static final String CONFIGURATION_NAME = "palantirJavaFormat"; - @SuppressWarnings({"for-rollout:GradleTypesAsFields", "for-rollout:NonAbstractGradleType"}) @Override public void apply(Project rootProject) { Preconditions.checkState( @@ -34,7 +33,6 @@ public void apply(Project rootProject) { rootProject.getPluginManager().apply(NativeImageFormatProviderPlugin.class); - @SuppressWarnings("for-rollout:ConfigurationAvoidanceRegistration") Configuration configuration = rootProject.getConfigurations().create(CONFIGURATION_NAME, conf -> { // Empty unless the build declares a formatter: the plugin carries its own, and needs no repository. conf.setDescription("Overrides the open-java-format implementation that comes inside the plugin"); diff --git a/gradle-open-java-format/src/main/java/com/palantir/javaformat/gradle/spotless/PalantirJavaFormatStep.java b/gradle-open-java-format/src/main/java/com/palantir/javaformat/gradle/spotless/PalantirJavaFormatStep.java index d56ecbea1..9cff43b4d 100644 --- a/gradle-open-java-format/src/main/java/com/palantir/javaformat/gradle/spotless/PalantirJavaFormatStep.java +++ b/gradle-open-java-format/src/main/java/com/palantir/javaformat/gradle/spotless/PalantirJavaFormatStep.java @@ -84,8 +84,7 @@ Signature sign() throws IOException { static final class Signature implements Serializable { private static final long serialVersionUID = 1L; - // Spotless compares the signature in its serialized form, and reads nothing out of it. - @SuppressWarnings("UnusedVariable") + /** The hash of the plugin's own jars, or empty when the build declared its own. */ private final String bundled; private final FileSignature override; @@ -100,7 +99,7 @@ static final class Signature implements Serializable { } List jars() { - return BundledFormatter.jarsUnlessOverridden(override.files(), gradleUserHome); + return bundled.isEmpty() ? List.copyOf(override.files()) : BundledFormatter.jars(gradleUserHome); } } diff --git a/gradle-open-java-format/src/test/java/com/palantir/javaformat/gradle/FormatDiffTest.java b/gradle-open-java-format/src/test/java/com/palantir/javaformat/gradle/FormatDiffTest.java index ba6e08ea5..406baf76d 100644 --- a/gradle-open-java-format/src/test/java/com/palantir/javaformat/gradle/FormatDiffTest.java +++ b/gradle-open-java-format/src/test/java/com/palantir/javaformat/gradle/FormatDiffTest.java @@ -104,7 +104,7 @@ private void runCommandInRepo(String... args) throws IOException, InterruptedExc process.getErrorStream().transferTo(baos); String stderr = baos.toString(UTF_8); - Preconditions.checkState(process.exitValue() == 0, "Expected return code of 0: " + stderr); + Preconditions.checkState(process.exitValue() == 0, "Expected return code of 0: %s", stderr); } private static Stream getFormatters() throws IOException { diff --git a/open-java-format-eclipse-plugin/src/main/java/com/palantir/javaformat/java/SnippetFormatter.java b/open-java-format-eclipse-plugin/src/main/java/com/palantir/javaformat/java/SnippetFormatter.java index b1457c261..51d1e3410 100644 --- a/open-java-format-eclipse-plugin/src/main/java/com/palantir/javaformat/java/SnippetFormatter.java +++ b/open-java-format-eclipse-plugin/src/main/java/com/palantir/javaformat/java/SnippetFormatter.java @@ -159,7 +159,7 @@ private SnippetWrapper snippetWrapper(SnippetKind kind, String source, int initi * dummy class is correctly formatted -- the blocks use correct indentation, * etc. */ - switch (kind) { + return switch (kind) { case COMPILATION_UNIT -> { SnippetWrapper wrapper = new SnippetWrapper(); for (int i = 1; i <= initialIndent; i++) { @@ -167,7 +167,7 @@ private SnippetWrapper snippetWrapper(SnippetKind kind, String source, int initi } wrapper.appendSource(source); wrapper.closeBraces(initialIndent); - return wrapper; + yield wrapper; } case CLASS_BODY_DECLARATIONS -> { SnippetWrapper wrapper = new SnippetWrapper(); @@ -176,7 +176,7 @@ private SnippetWrapper snippetWrapper(SnippetKind kind, String source, int initi } wrapper.appendSource(source); wrapper.closeBraces(initialIndent); - return wrapper; + yield wrapper; } case STATEMENTS -> { SnippetWrapper wrapper = new SnippetWrapper(); @@ -186,7 +186,7 @@ private SnippetWrapper snippetWrapper(SnippetKind kind, String source, int initi } wrapper.appendSource(source); wrapper.closeBraces(initialIndent); - return wrapper; + yield wrapper; } case EXPRESSION -> { SnippetWrapper wrapper = new SnippetWrapper(); @@ -198,9 +198,9 @@ private SnippetWrapper snippetWrapper(SnippetKind kind, String source, int initi wrapper.appendSource(source); wrapper.append(";"); wrapper.closeBraces(initialIndent); - return wrapper; + yield wrapper; } default -> throw new IllegalArgumentException("Unknown snippet kind: " + kind); - } + }; } } diff --git a/open-java-format-idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatSettings.java b/open-java-format-idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatSettings.java index 48420169d..83ea2e716 100644 --- a/open-java-format-idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatSettings.java +++ b/open-java-format-idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatSettings.java @@ -37,28 +37,25 @@ import static java.util.Optional.ofNullable; -@SuppressWarnings("for-rollout:SameNameButDifferent") @State( name = "PalantirJavaFormatSettings", storages = {@Storage("open-java-format.xml")}) -public class PalantirJavaFormatSettings implements PersistentStateComponent { +public class PalantirJavaFormatSettings implements PersistentStateComponent { - @SuppressWarnings("for-rollout:SameNameButDifferent") - private State state = new State(); + private StoredSettings state = new StoredSettings(); static PalantirJavaFormatSettings getInstance(Project project) { return project.getService(PalantirJavaFormatSettings.class); } - @SuppressWarnings("for-rollout:SameNameButDifferent") @Nullable @Override - public State getState() { + public StoredSettings getState() { return state; } @Override - public void loadState(@SuppressWarnings("for-rollout:SameNameButDifferent") State state) { + public void loadState(StoredSettings state) { this.state = state; } @@ -152,7 +149,7 @@ enum EnabledState { DISABLED } - static class State { + static class StoredSettings { private EnabledState enabled = EnabledState.UNKNOWN; private Optional> implementationClassPath = Optional.empty(); @@ -167,7 +164,6 @@ public void setImplementationClassPath(@Nullable List value) { .map(strings -> strings.stream().map(URI::create).collect(Collectors.toList())); } - @SuppressWarnings("for-rollout:NullAway") public List getImplementationClassPath() { return implementationClassPath .map(paths -> paths.stream().map(URI::toString).collect(Collectors.toList())) @@ -185,7 +181,6 @@ public void setEnabled(@Nullable String enabledStr) { } } - @SuppressWarnings("for-rollout:NullAway") public String getEnabled() { return switch (enabled) { case ENABLED -> "true"; diff --git a/open-java-format-idea-plugin/src/test/java/com/palantir/javaformat/intellij/FormatterProviderTest.java b/open-java-format-idea-plugin/src/test/java/com/palantir/javaformat/intellij/FormatterProviderTest.java index 0bfa7dbd6..1dc3d138b 100644 --- a/open-java-format-idea-plugin/src/test/java/com/palantir/javaformat/intellij/FormatterProviderTest.java +++ b/open-java-format-idea-plugin/src/test/java/com/palantir/javaformat/intellij/FormatterProviderTest.java @@ -22,7 +22,7 @@ import com.intellij.testFramework.fixtures.JavaTestFixtureFactory; import com.palantir.javaformat.bootstrap.BootstrappingFormatterService; import com.palantir.javaformat.bootstrap.NativeImageFormatterService; -import com.palantir.javaformat.intellij.PalantirJavaFormatSettings.State; +import com.palantir.javaformat.intellij.PalantirJavaFormatSettings.StoredSettings; import java.nio.file.Path; import java.util.Optional; import java.util.concurrent.atomic.AtomicReference; @@ -45,7 +45,7 @@ void setUp() throws Exception { fixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(projectBuilder.getFixture()); fixture.setUp(); settings = PalantirJavaFormatSettings.getInstance(fixture.getProject()); - settings.loadState(new State()); + settings.loadState(new StoredSettings()); } @AfterEach diff --git a/open-java-format-idea-plugin/src/test/java/com/palantir/javaformat/intellij/PalantirJavaFormatConfigurableTest.java b/open-java-format-idea-plugin/src/test/java/com/palantir/javaformat/intellij/PalantirJavaFormatConfigurableTest.java index 177201dc5..c74d18bf6 100644 --- a/open-java-format-idea-plugin/src/test/java/com/palantir/javaformat/intellij/PalantirJavaFormatConfigurableTest.java +++ b/open-java-format-idea-plugin/src/test/java/com/palantir/javaformat/intellij/PalantirJavaFormatConfigurableTest.java @@ -34,7 +34,7 @@ import com.palantir.javaformat.intellij.EmbeddedNativeImage.Installed; import com.palantir.javaformat.intellij.EmbeddedNativeImage.Status; import com.palantir.javaformat.intellij.PalantirJavaFormatConfigurable.StatusLine; -import com.palantir.javaformat.intellij.PalantirJavaFormatSettings.State; +import com.palantir.javaformat.intellij.PalantirJavaFormatSettings.StoredSettings; import java.awt.Component; import java.awt.Container; import java.io.IOException; @@ -74,7 +74,7 @@ void setUp() throws Exception { fixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(projectBuilder.getFixture()); fixture.setUp(); settings = PalantirJavaFormatSettings.getInstance(fixture.getProject()); - settings.loadState(new State()); + settings.loadState(new StoredSettings()); settings.setEnabled(true); // Nothing downloaded, and nowhere to download from. var embedded = new EmbeddedNativeImage( @@ -104,7 +104,7 @@ void hasNoChoiceOfCodeStyle() { @Test void readsAndWritesTheEnabledSetting() throws Throwable { - State disabled = new State(); + var disabled = new StoredSettings(); disabled.setEnabled("false"); settings.loadState(disabled); @@ -176,7 +176,7 @@ void showsTheActiveFormatterAsThePageStands() throws Throwable { useNativeImage.setSelected(true); assertThat(activeFormatter().getText()) - .isEqualTo("Need to download version " + pluginVersion + " from Maven Central"); + .isEqualTo("Need to download version %s from Maven Central", pluginVersion); path.setText("/opt/open-java-format"); assertThat(activeFormatter().getText()).isEqualTo("/opt/open-java-format"); @@ -268,7 +268,7 @@ void refusesAPathThatIsNotAnExecutableFile() throws Throwable { assertThatThrownBy(configurable::apply) .isInstanceOf(ConfigurationException.class) - .hasMessage(missing + " is not an executable file"); + .hasMessage("%s is not an executable file", missing); }); } diff --git a/open-java-format-idea-plugin/src/test/java/com/palantir/javaformat/intellij/PalantirJavaFormatFormattingServiceTest.java b/open-java-format-idea-plugin/src/test/java/com/palantir/javaformat/intellij/PalantirJavaFormatFormattingServiceTest.java index 64050f4d5..2401d64e6 100644 --- a/open-java-format-idea-plugin/src/test/java/com/palantir/javaformat/intellij/PalantirJavaFormatFormattingServiceTest.java +++ b/open-java-format-idea-plugin/src/test/java/com/palantir/javaformat/intellij/PalantirJavaFormatFormattingServiceTest.java @@ -35,7 +35,7 @@ import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture; import com.intellij.testFramework.fixtures.JavaTestFixtureFactory; import com.intellij.testFramework.fixtures.TestFixtureBuilder; -import com.palantir.javaformat.intellij.PalantirJavaFormatSettings.State; +import com.palantir.javaformat.intellij.PalantirJavaFormatSettings.StoredSettings; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -70,7 +70,7 @@ void setUp() throws Exception { settings = PalantirJavaFormatSettings.getInstance(fixture.getProject()); - State resetState = new State(); + var resetState = new StoredSettings(); resetState.setEnabled("true"); settings.loadState(resetState); } @@ -127,7 +127,6 @@ private PsiFile createPsiFile(String path, String... contents) throws IOExceptio } private static final class DelegatingFormatter extends PalantirJavaFormatFormattingService { - @SuppressWarnings("DataFlowIssue") public DelegatingFormatter() { this.setPluginDescriptor(FormattingService.EP_NAME .findExtension(PalantirJavaFormatFormattingService.class) diff --git a/open-java-format-idea-plugin/src/test/java/com/palantir/javaformat/intellij/PalantirJavaFormatSettingsTest.java b/open-java-format-idea-plugin/src/test/java/com/palantir/javaformat/intellij/PalantirJavaFormatSettingsTest.java index d3d574b4b..8596c2e1f 100644 --- a/open-java-format-idea-plugin/src/test/java/com/palantir/javaformat/intellij/PalantirJavaFormatSettingsTest.java +++ b/open-java-format-idea-plugin/src/test/java/com/palantir/javaformat/intellij/PalantirJavaFormatSettingsTest.java @@ -18,7 +18,7 @@ import com.intellij.openapi.util.JDOMUtil; import com.intellij.util.xmlb.XmlSerializer; -import com.palantir.javaformat.intellij.PalantirJavaFormatSettings.State; +import com.palantir.javaformat.intellij.PalantirJavaFormatSettings.StoredSettings; import java.nio.file.Path; import java.util.Optional; import org.intellij.lang.annotations.Language; @@ -42,7 +42,7 @@ void loadsAFileThatStillHasTheCodeStyle() throws Exception { @Test void doesNotWriteACodeStyle() { - var xml = JDOMUtil.write(XmlSerializer.serialize(new State())); + var xml = JDOMUtil.write(XmlSerializer.serialize(new StoredSettings())); assertThat(xml).doesNotContain("style"); } @@ -78,7 +78,7 @@ void ignoresTheNativeImageTheGradlePluginUsedToWrite() throws Exception { @Test void takesABlankPathForNone() { - var state = new State(); + var state = new StoredSettings(); state.nativeImagePath = " "; var settings = new PalantirJavaFormatSettings(); settings.loadState(state); @@ -86,7 +86,7 @@ void takesABlankPathForNone() { assertThat(settings.getNativeImagePath()).isEmpty(); } - private static State deserialize(@Language("xml") String xml) throws Exception { - return XmlSerializer.deserialize(JDOMUtil.load(xml), State.class); + private static StoredSettings deserialize(@Language("xml") String xml) throws Exception { + return XmlSerializer.deserialize(JDOMUtil.load(xml), StoredSettings.class); } } diff --git a/open-java-format-jdk-bootstrap/src/main/java/com/palantir/javaformat/bootstrap/BootstrappingFormatterService.java b/open-java-format-jdk-bootstrap/src/main/java/com/palantir/javaformat/bootstrap/BootstrappingFormatterService.java index e46312c6b..f5b13f314 100644 --- a/open-java-format-jdk-bootstrap/src/main/java/com/palantir/javaformat/bootstrap/BootstrappingFormatterService.java +++ b/open-java-format-jdk-bootstrap/src/main/java/com/palantir/javaformat/bootstrap/BootstrappingFormatterService.java @@ -86,7 +86,6 @@ private ImmutableList getFormatReplacementsInternal(String input, C /* outputReplacements= */ true, ranges.stream().map(RangeUtils::toStringRange).collect(Collectors.toList())); - @SuppressWarnings("for-rollout:NullAway") Optional output = FormatterCommandRunner.runWithStdin(command.toArgs(), input, Optional.of(jdkPath.getParent())); if (output.isEmpty() || output.get().isEmpty()) { diff --git a/open-java-format/src/main/java/com/palantir/javaformat/Newlines.java b/open-java-format/src/main/java/com/palantir/javaformat/Newlines.java index 73b03ce73..05bb595d2 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/Newlines.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/Newlines.java @@ -53,7 +53,6 @@ public static int hasNewlineAt(String input, int idx) { } /** Returns the terminating line break in the input, or {@code null} if the input does not end in a break. */ - @SuppressWarnings("for-rollout:NullAway") public static String getLineEnding(String input) { for (String b : BREAKS) { if (input.endsWith(b)) { @@ -160,7 +159,6 @@ private static final class LineIterator implements Iterator { private final String input; private final Iterator indices; - @SuppressWarnings("for-rollout:NullAway") private LineIterator(String input) { this.input = input; this.indices = lineOffsetIterator(input); diff --git a/open-java-format/src/main/java/com/palantir/javaformat/OpsBuilder.java b/open-java-format/src/main/java/com/palantir/javaformat/OpsBuilder.java index 7ff81101e..837c9fb87 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/OpsBuilder.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/OpsBuilder.java @@ -50,7 +50,6 @@ public final class OpsBuilder { /** Return the actual size of the AST node at position, including comments. */ public int actualSize(int position, int length) { Input.Token startToken = input.getPositionTokenMap().get(position); - @SuppressWarnings("for-rollout:NullAway") int start = startToken.getTok().getPosition(); for (Input.Tok tok : startToken.getToksBefore()) { if (tok.isComment()) { @@ -58,7 +57,6 @@ public int actualSize(int position, int length) { } } Input.Token endToken = input.getPositionTokenMap().get(position + length - 1); - @SuppressWarnings("for-rollout:NullAway") int end = endToken.getTok().getPosition() + endToken.getTok().length(); for (Input.Tok tok : endToken.getToksAfter()) { if (tok.isComment()) { @@ -71,7 +69,6 @@ public int actualSize(int position, int length) { /** Return the start column of the token at {@code position}, including leading comments. */ public Integer actualStartColumn(int position) { Input.Token startToken = input.getPositionTokenMap().get(position); - @SuppressWarnings("for-rollout:NullAway") int start = startToken.getTok().getPosition(); int line0 = input.getLineNumber(start); for (Input.Tok tok : startToken.getToksBefore()) { diff --git a/open-java-format/src/main/java/com/palantir/javaformat/doc/Comment.java b/open-java-format/src/main/java/com/palantir/javaformat/doc/Comment.java index 37742b128..8297503a4 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/doc/Comment.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/doc/Comment.java @@ -157,7 +157,6 @@ protected Range computeRange() { public State computeBreaks( CommentsHelper commentsHelper, int maxWidth, State state, Obs.ExplorationNode observationNode) { String text = commentsHelper.rewrite(tok, maxWidth, state.column()); - @SuppressWarnings("for-rollout:NullAway") int lastLineStart = Iterators.getLast(Newlines.lineOffsetIterator(text)); int lastLineLength = text.length() - lastLineStart; // rewrite() indents every line after the first to state.column(), so after a comment that spans lines the diff --git a/open-java-format/src/main/java/com/palantir/javaformat/doc/Level.java b/open-java-format/src/main/java/com/palantir/javaformat/doc/Level.java index 2824bdb9d..ce78867d6 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/doc/Level.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/doc/Level.java @@ -402,7 +402,6 @@ private Optional tryInlinePrefixOntoCurrentLine( commentsHelper, maxWidth, newState, memoizedSplitsBreaks.get(), explorationNode)); } - @SuppressWarnings("for-rollout:NullAway") private Optional tryBreakLastLevel( CommentsHelper commentsHelper, int maxWidth, @@ -429,7 +428,6 @@ private Optional tryBreakLastLevel( /** A call of {@link #tryBreakLastLevel}, by everything besides this level that decides its outcome. */ private record LastLevelAttempt(int maxWidth, boolean isSimpleInliningSoFar, State.LayoutInputs inputs) {} - @SuppressWarnings("for-rollout:NullAway") private Optional tryInlineSuffix( CommentsHelper commentsHelper, int maxWidth, @@ -549,7 +547,6 @@ private static Optional tryBreakInnerLevel_acceptInlineChain( .markAccepted()); } - @SuppressWarnings("for-rollout:NullAway") private static Optional tryBreakInnerLevel_checkInner( CommentsHelper commentsHelper, int maxWidth, diff --git a/open-java-format/src/main/java/com/palantir/javaformat/doc/LevelDelimitedFlatValueDocVisitor.java b/open-java-format/src/main/java/com/palantir/javaformat/doc/LevelDelimitedFlatValueDocVisitor.java index 5ef16ab9b..8de02dac4 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/doc/LevelDelimitedFlatValueDocVisitor.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/doc/LevelDelimitedFlatValueDocVisitor.java @@ -53,7 +53,6 @@ public String visitBreak(Break doc) { return sb.toString(); } - @SuppressWarnings("for-rollout:NullAway") @Override public String visitLevel(Level level) { if (level.getFlat().isEmpty()) { diff --git a/open-java-format/src/main/java/com/palantir/javaformat/doc/Obs.java b/open-java-format/src/main/java/com/palantir/javaformat/doc/Obs.java index 457351e08..0fcbf7ede 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/doc/Obs.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/doc/Obs.java @@ -64,7 +64,6 @@ FinishExplorationNode startExplorationNode( String getOutput(); } - @SuppressWarnings("for-rollout:NullAway") public static ExplorationNode createRoot(Sink sink) { return new ExplorationNodeImpl(null, "(initial node)", sink, 0, Optional.empty()); } diff --git a/open-java-format/src/main/java/com/palantir/javaformat/doc/State.java b/open-java-format/src/main/java/com/palantir/javaformat/doc/State.java index d5b53f13b..02b523d78 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/doc/State.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/doc/State.java @@ -26,8 +26,6 @@ import org.immutables.value.Value; /** State for writing. */ -// Automatically suppressed to unblock enforcement in new code -@SuppressWarnings("ImmutablesStyle") @Value.Immutable @Value.Style(overshadowImplementation = true) @JsonSerialize(as = ImmutableState.class) diff --git a/open-java-format/src/main/java/com/palantir/javaformat/java/CommandLineOptionsParser.java b/open-java-format/src/main/java/com/palantir/javaformat/java/CommandLineOptionsParser.java index 7a1dd0a36..06088b223 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/java/CommandLineOptionsParser.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/java/CommandLineOptionsParser.java @@ -55,7 +55,6 @@ final class CommandLineOptionsParser { ); /** Parses {@link CommandLineOptions}. */ - @SuppressWarnings("for-rollout:NullAway") static CommandLineOptions parse(Iterable options) { CommandLineOptions.Builder optionsBuilder = CommandLineOptions.builder(); List expandedOptions = new ArrayList<>(); @@ -142,18 +141,18 @@ private static void parseCharacterRanges(ImmutableRangeSet.Builder resu */ private static Range parseCharacterRange(String range) { List args = COLON_SPLITTER.splitToList(range); - switch (args.size()) { + return switch (args.size()) { case 1 -> { int lowerUpperRange = Integer.parseInt(args.get(0)); - return Range.closed(lowerUpperRange, lowerUpperRange); + yield Range.closed(lowerUpperRange, lowerUpperRange); } case 2 -> { int lower = Integer.parseInt(args.get(0)); int higher = Integer.parseInt(args.get(1)); - return Range.closed(lower, higher); + yield Range.closed(lower, higher); } default -> throw new IllegalArgumentException(range); - } + }; } /** @@ -173,18 +172,18 @@ private static void parseRangeSet(RangeSet result, String ranges) { */ private static Range parseRange(String arg) { List args = COLON_SPLITTER.splitToList(arg); - switch (args.size()) { + return switch (args.size()) { case 1 -> { int line = Integer.parseInt(args.get(0)) - 1; - return Range.closedOpen(line, line + 1); + yield Range.closedOpen(line, line + 1); } case 2 -> { int line0 = Integer.parseInt(args.get(0)) - 1; int line1 = Integer.parseInt(args.get(1)) - 1; - return Range.closedOpen(line0, line1 + 1); + yield Range.closedOpen(line0, line1 + 1); } default -> throw new IllegalArgumentException(arg); - } + }; } /** diff --git a/open-java-format/src/main/java/com/palantir/javaformat/java/DimensionHelpers.java b/open-java-format/src/main/java/com/palantir/javaformat/java/DimensionHelpers.java index 965be309f..dba0d5582 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/java/DimensionHelpers.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/java/DimensionHelpers.java @@ -102,22 +102,18 @@ private static Iterable> reorderBySourcePosition(DequeGiven {@code int @A @B [][] @C []}, adds {@code [[@A, @B], [@C]]} to dims and returns {@code int}. */ private static Tree extractDims(Deque> dims, Tree node) { - switch (node.getKind()) { - case ARRAY_TYPE -> { - return extractDims(dims, ((ArrayTypeTree) node).getType()); - } + return switch (node.getKind()) { + case ARRAY_TYPE -> extractDims(dims, ((ArrayTypeTree) node).getType()); case ANNOTATED_TYPE -> { AnnotatedTypeTree annotatedTypeTree = (AnnotatedTypeTree) node; if (!(annotatedTypeTree.getUnderlyingType() instanceof ArrayTypeTree)) { - return node; + yield node; } node = extractDims(dims, annotatedTypeTree.getUnderlyingType()); dims.addFirst(ImmutableList.copyOf(annotatedTypeTree.getAnnotations())); - return node; - } - default -> { - return node; + yield node; } - } + default -> node; + }; } } diff --git a/open-java-format/src/main/java/com/palantir/javaformat/java/Formatter.java b/open-java-format/src/main/java/com/palantir/javaformat/java/Formatter.java index ebc10209d..ed2549241 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/java/Formatter.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/java/Formatter.java @@ -243,7 +243,6 @@ static int getRuntimeVersion() { return Runtime.version().feature(); } - @SuppressWarnings("for-rollout:ThrowError") private static JavaInputAstVisitor createVisitor( final String className, final OpsBuilder builder, final JavaFormatterOptions options) { try { diff --git a/open-java-format/src/main/java/com/palantir/javaformat/java/ImportOrderer.java b/open-java-format/src/main/java/com/palantir/javaformat/java/ImportOrderer.java index 3478db685..7d58138b3 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/java/ImportOrderer.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/java/ImportOrderer.java @@ -93,7 +93,6 @@ private String reorderImports() throws FormatterException { tail.add(CharMatcher.whitespace().trimLeadingFrom(tokString(afterLastImport, toks.size()))); if (!toks.isEmpty()) { Tok lastTok = getLast(toks); - @SuppressWarnings("for-rollout:NullAway") int tailStart = lastTok.getPosition() + lastTok.length(); tail.add(text.substring(tailStart)); } diff --git a/open-java-format/src/main/java/com/palantir/javaformat/java/JavaInput.java b/open-java-format/src/main/java/com/palantir/javaformat/java/JavaInput.java index de951b0ca..950ae3ac7 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/java/JavaInput.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/java/JavaInput.java @@ -59,7 +59,6 @@ import javax.tools.SimpleJavaFileObject; /** {@code JavaInput} extends {@link Input} to represent a Java input document. */ -@SuppressWarnings("for-rollout:ThrowError") public final class JavaInput extends Input { /** * A {@code JavaInput} is a sequence of {@link Tok}s that cover the Java input. A {@link Tok} is either a token (if @@ -258,7 +257,6 @@ public String toString() { * output. */ - @SuppressWarnings("for-rollout:AlmostJavadoc") private final ImmutableMap positionToColumnMap; // Map Tok position to column. private final ImmutableList tokens; // The Tokens for this input. @@ -273,7 +271,6 @@ public String toString() { * @param text the input text * @throws FormatterException if the input cannot be parsed */ - @SuppressWarnings("for-rollout:NullAway") public JavaInput(String text) throws FormatterException { this.text = checkNotNull(text); setLines(ImmutableList.copyOf(Newlines.lineIterator(text))); @@ -338,7 +335,6 @@ public String getLineSeparator() { } /** Lex the input and build the list of toks. */ - @SuppressWarnings("for-rollout:NullAway") private ImmutableList buildToks(String text) throws FormatterException { ImmutableList toks = buildToks(text, ImmutableSet.of()); kN = getLast(toks).getIndex(); @@ -353,7 +349,6 @@ private ImmutableList buildToks(String text) throws FormatterException { * @param stopTokens a set of tokens which should cause lexing to stop. If one of these is found, the returned list * will include tokens up to but not including that token. */ - @SuppressWarnings("for-rollout:NullAway") static ImmutableList buildToks(String text, ImmutableSet stopTokens) throws FormatterException { stopTokens = ImmutableSet.builder() .addAll(stopTokens) @@ -481,7 +476,6 @@ public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOExcept * @param handler the diagnostic handler * @return a collection of diagnostics */ - @SuppressWarnings({"unchecked", "for-rollout:ThrowError"}) private static Collection getDiagnostics(DeferredDiagnosticHandler handler) { try { return (Collection) GET_DIAGNOSTICS.invoke(handler); @@ -549,7 +543,6 @@ private static boolean isSpaces(Tok tok) { return !tok.isToken() && !tok.isNewline() && !tok.isComment(); } - @SuppressWarnings("for-rollout:NullAway") private static int updateColumn(int columnI, String originalTokText) { Integer last = Iterators.getLast(Newlines.lineOffsetIterator(originalTokText)); if (last > 0) { @@ -642,7 +635,6 @@ private static boolean isParamComment(Tok tok) { * @return the {@code 0}-based {@link Range} of tokens * @throws FormatterException on formatting errors */ - @SuppressWarnings("for-rollout:NullAway") Range characterRangeToTokenRange(int offset, int length) throws FormatterException { int requiredLength = offset + length; if (requiredLength > text.length()) { diff --git a/open-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java b/open-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java index ad0f8df96..2c374113b 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java @@ -991,7 +991,6 @@ void visitVariables(List fragments, DeclarationKind declarationKin } } - @SuppressWarnings("for-rollout:NullAway") private TypeWithDims variableFragmentDims(boolean first, int leadingDims, Tree type) { if (type == null) { return null; @@ -1004,7 +1003,6 @@ private TypeWithDims variableFragmentDims(boolean first, int leadingDims, Tree t null, leadingDims > 0 ? dims.dims.subList(0, dims.dims.size() - leadingDims) : dims.dims); } - @SuppressWarnings("for-rollout:NullAway") @Override public Void visitForLoop(ForLoopTree node, Void unused) { sync(node); @@ -1406,7 +1404,6 @@ private static boolean isCompactSourceFile(Tree type) { && (classDecl.mods.flags & IMPLICIT_CLASS) == IMPLICIT_CLASS; } - @SuppressWarnings("for-rollout:NullAway") @Override public Void visitMethod(MethodTree node, Void unused) { sync(node); @@ -1649,7 +1646,6 @@ private static List handleStream(List parts) { .collect(toList()); } - @SuppressWarnings("for-rollout:NullAway") private static Stream indexes(Stream stream, Predicate predicate) { return Streams.mapWithIndex(stream, (x, i) -> predicate.apply(x) ? i : -1) .filter(x -> x != -1); @@ -1825,7 +1821,6 @@ public Void visitReturn(ReturnTree node, Void unused) { } // TODO(cushon): is this worth special-casing? - @SuppressWarnings("for-rollout:NullAway") boolean visitSingleMemberAnnotation(AnnotationTree node) { if (node.getArguments().size() != 1) { return false; @@ -1851,7 +1846,6 @@ boolean visitSingleMemberAnnotation(AnnotationTree node) { return true; } - @SuppressWarnings("for-rollout:deprecation") @Override public Void visitCase(CaseTree node, Void unused) { sync(node); @@ -2204,7 +2198,6 @@ private void visitStatement( } } - @SuppressWarnings("for-rollout:NullAway") protected void visitStatements(List statements, boolean inlineFirst) { boolean first = true; PeekingIterator it = Iterators.peekingIterator(statements.iterator()); @@ -2219,7 +2212,6 @@ protected void visitStatements(List statements, boolean } markForPartialFormat(); first = false; - @SuppressWarnings("for-rollout:NullAway") List fragments = variableFragments(it, tree); if (!fragments.isEmpty()) { visitVariables( @@ -2944,7 +2936,6 @@ private void visitRegularDot(List items, boolean needDot) { // .happens()) // .thenReturn(result); // - @SuppressWarnings("for-rollout:NullAway") private boolean fillFirstArgument(ExpressionTree e, List items, Indent indent) { // is there a trailing dereference? if (items.size() < 2) { @@ -2984,7 +2975,6 @@ private boolean fillFirstArgument(ExpressionTree e, List items, private void visitDotWithPrefix( List items, boolean needDot, Collection prefixes, FillMode prefixFillMode) { // Are there method invocations or field accesses after the prefix? - @SuppressWarnings("for-rollout:NullAway") boolean trailingDereferences = !prefixes.isEmpty() && getLast(prefixes) < items.size() - 1; boolean hasMethodInvocations = items.stream().anyMatch(expr -> expr instanceof MethodInvocationTree); @@ -3120,7 +3110,6 @@ private ExpressionTree getArrayBase(ExpressionTree node) { return node; } - @SuppressWarnings("for-rollout:NullAway") private ExpressionTree getMethodReceiver(MethodInvocationTree methodInvocation) { ExpressionTree select = methodInvocation.getMethodSelect(); return select instanceof MemberSelectTree memberSelectTree ? memberSelectTree.getExpression() : null; @@ -3364,14 +3353,12 @@ public void scan(JCTree tree) { } /** Returns the number of columns if the arguments arg laid out in a grid, or else {@code -1}. */ - @SuppressWarnings("for-rollout:NullAway") private int argumentsAreTabular(List arguments) { if (arguments.isEmpty()) { return -1; } List> rows = new ArrayList<>(); PeekingIterator it = Iterators.peekingIterator(arguments.iterator()); - @SuppressWarnings("for-rollout:NullAway") int start0 = actualColumn(it.peek()); { List row = new ArrayList<>(); @@ -3389,7 +3376,6 @@ private int argumentsAreTabular(List arguments) { } while (it.hasNext()) { List row = new ArrayList<>(); - @SuppressWarnings("for-rollout:NullAway") int start = actualColumn(it.peek()); if (start != start0) { return -1; @@ -3444,14 +3430,12 @@ static int rowLength(List row) { return size; } - @SuppressWarnings("for-rollout:NullAway") private Integer actualColumn(ExpressionTree expression) { Map positionToColumnMap = builder.getInput().getPositionToColumnMap(); return positionToColumnMap.get(builder.actualStartColumn(getStartPosition(expression))); } /** How many lines does this node take up in the input. Returns at least 1. */ - @SuppressWarnings("for-rollout:NullAway") int lineSpan(Tree node) { ImmutableRangeMap positionTokenMap = builder.getInput().getPositionTokenMap(); @@ -3505,7 +3489,6 @@ enum DeclarationKind { } /** Declare one variable or variable-like thing. */ - @SuppressWarnings("TooManyArguments") int declareOne( DeclarationKind kind, Direction annotationsDirection, @@ -3534,7 +3517,6 @@ int declareOne( } /** Declare one variable or variable-like thing. */ - @SuppressWarnings("TooManyArguments") int declareOne( DeclarationKind kind, Direction annotationsDirection, @@ -3792,7 +3774,6 @@ protected void addBodyDeclarations( * class/interface/enum bodies (indented by {@link #plusTwo}) and for the bare top-level member list of a * compact source file (JEP 512), which is indented by {@link Indent.Const#ZERO}. */ - @SuppressWarnings("for-rollout:NullAway") private void addBodyDeclarations( List bodyDeclarations, BracesOrNot braces, @@ -3931,7 +3912,6 @@ private boolean hasTrailingToken(Input input, List nodes, String return false; } Tree lastNode = getLast(nodes); - @SuppressWarnings("for-rollout:NullAway") Optional nextToken = getNextToken(input, getEndPosition(lastNode, getCurrentPath())); return nextToken.isPresent() && nextToken.get().getTok().getText().equals(token); } @@ -4025,7 +4005,6 @@ protected void sync(Tree node) { * have it. Used with {@link #invoke} to reach AST accessors that are newer than the compiler this module builds * with, such as {@code ImportTree#isModule()} (JDK 23). */ - @SuppressWarnings("for-rollout:NullAway") protected static Method maybeGetMethod(Class c, String name) { try { return c.getMethod(name); diff --git a/open-java-format/src/main/java/com/palantir/javaformat/java/JavaOutput.java b/open-java-format/src/main/java/com/palantir/javaformat/java/JavaOutput.java index 1b254f680..9466bd12b 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/java/JavaOutput.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/java/JavaOutput.java @@ -242,7 +242,6 @@ void flush() { * * @return a list of {@link Replacement}s, sorted by start index, without overlaps */ - @SuppressWarnings("for-rollout:NullAway") public ImmutableList getFormatReplacements(RangeSet iRangeSet0) { ImmutableList.Builder result = ImmutableList.builder(); Map> kToJ = JavaOutput.makeKToIJ(this); @@ -278,7 +277,6 @@ public ImmutableList getFormatReplacements(RangeSet iRange replaceFrom--; } - @SuppressWarnings("for-rollout:NullAway") int i = kToJ.get(startTok.getIndex()).lowerEndpoint(); // Include leading blank lines from the formatted output, unless the formatted range // starts at the beginning of the file. @@ -357,7 +355,6 @@ public ImmutableList getFormatReplacements(RangeSet iRange * @param iRange the {@link Range} of tokens * @return the expanded token range */ - @SuppressWarnings("for-rollout:NullAway") private Range expandToBreakableRegions(Range iRange) { // The original line range. int loTok = iRange.lowerEndpoint(); diff --git a/open-java-format/src/main/java/com/palantir/javaformat/java/JavacTokens.java b/open-java-format/src/main/java/com/palantir/javaformat/java/JavacTokens.java index 705837412..9cc61d20a 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/java/JavacTokens.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/java/JavacTokens.java @@ -72,7 +72,6 @@ public String stringVal() { } /** Lex the input and return a list of {@link RawTok}s. */ - @SuppressWarnings("for-rollout:NullAway") public static ImmutableList getTokens(String source, Context context, Set stopTokens) { if (source == null) { return ImmutableList.of(); @@ -155,7 +154,6 @@ static class CommentWithTextAndPosition implements Comment { private final AccessibleReader reader; private final CommentStyle style; - @SuppressWarnings("for-rollout:NullAway") private String text = null; public CommentWithTextAndPosition(int pos, int endPos, AccessibleReader reader, CommentStyle style) { diff --git a/open-java-format/src/main/java/com/palantir/javaformat/java/JsonSink.java b/open-java-format/src/main/java/com/palantir/javaformat/java/JsonSink.java index 6aa69eac2..edb40b3a0 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/java/JsonSink.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/java/JsonSink.java @@ -37,10 +37,8 @@ public final class JsonSink implements Sink { private final Map childrenMap = new HashMap<>(); - @SuppressWarnings("for-rollout:NullAway") private ObjectNode rootNode; - @SuppressWarnings("for-rollout:NullAway") @Override public FinishExplorationNode startExplorationNode( int exporationId, @@ -72,7 +70,6 @@ public FinishExplorationNode startExplorationNode( @Override public FinishLevelNode writeLevelNode(int levelNodeId, int parentExplorationId, State incomingState, Level level) { - @SuppressWarnings("for-rollout:NullAway") ObjectNode json = childrenMap.get(parentExplorationId).addObject(); json.put("type", "level"); json.put("id", levelNodeId); diff --git a/open-java-format/src/main/java/com/palantir/javaformat/java/Main.java b/open-java-format/src/main/java/com/palantir/javaformat/java/Main.java index 5551b325d..903dfc6e3 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/java/Main.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/java/Main.java @@ -129,7 +129,6 @@ private int formatFiles(CommandLineOptions parameters, JavaFormatterOptions opti } } - @SuppressWarnings("for-rollout:RedundantControlFlow") private int formatFiles( CommandLineOptions parameters, JavaFormatterOptions options, ExecutorService executorService) { Map inputs = new LinkedHashMap<>(); diff --git a/open-java-format/src/main/java/com/palantir/javaformat/java/ModifierOrderer.java b/open-java-format/src/main/java/com/palantir/javaformat/java/ModifierOrderer.java index fe97403ac..3fa532e6e 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/java/ModifierOrderer.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/java/ModifierOrderer.java @@ -71,7 +71,6 @@ boolean isEmpty() { return tokens.isEmpty() || modifier == null; } - @SuppressWarnings("for-rollout:NullAway") Modifier modifier() { return modifier; } @@ -105,7 +104,6 @@ ImmutableList getToksAfter() { } @Override - @SuppressWarnings("for-rollout:NullAway") public int compareTo(ModifierTokens o) { checkState(!isEmpty()); // empty ModifierTokens are filtered out prior to sorting return modifier.compareTo(o.modifier); @@ -209,7 +207,6 @@ private static Modifier asModifier(ImmutableList tokens) { * Returns the given token as a {@link javax.lang.model.element.Modifier}, or {@code null} if it is not a modifier. */ @Nullable - @SuppressWarnings("for-rollout:NullAway") private static Modifier asModifier(Token token) { TokenKind kind = ((JavaInput.Tok) token.getTok()).kind(); if (kind != null) { diff --git a/open-java-format/src/main/java/com/palantir/javaformat/java/RemoveUnusedImports.java b/open-java-format/src/main/java/com/palantir/javaformat/java/RemoveUnusedImports.java index a42aee5ec..c27745e4f 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/java/RemoveUnusedImports.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/java/RemoveUnusedImports.java @@ -103,7 +103,6 @@ public Void visitIdentifier(IdentifierTree tree, Void unused) { // TODO(fwindheuser): remove this override when pattern matching in switch is no longer a preview // feature, and TreePathScanner visits CaseTree#getLabels instead of CaseTree#getExpressions - @SuppressWarnings("unchecked") // reflection @Override public Void visitCase(CaseTree tree, Void unused) { if (CASE_TREE_GET_LABELS != null) { @@ -118,7 +117,6 @@ public Void visitCase(CaseTree tree, Void unused) { private static final Method CASE_TREE_GET_LABELS = caseTreeGetLabels(); - @SuppressWarnings("for-rollout:NullAway") private static Method caseTreeGetLabels() { try { return CaseTree.class.getMethod("getLabels"); @@ -127,7 +125,6 @@ private static Method caseTreeGetLabels() { } } - @SuppressWarnings("for-rollout:VoidUsed") @Override public Void scan(Tree tree, Void unused) { if (tree == null) { @@ -185,7 +182,6 @@ public ReferenceScanner(long basePos) { this.basePos = basePos; } - @SuppressWarnings("for-rollout:VoidUsed") @Override public Void visitIdentifier(IdentifierTree node, Void aVoid) { usedInJavadoc.put( diff --git a/open-java-format/src/main/java/com/palantir/javaformat/java/StringWrapper.java b/open-java-format/src/main/java/com/palantir/javaformat/java/StringWrapper.java index d5472baa8..6034b35a1 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/java/StringWrapper.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/java/StringWrapper.java @@ -130,7 +130,6 @@ private static String wrapOnce(final int columnLimit, String input, Formatter fo return result; } - @SuppressWarnings("ResultOfMethodCallIgnored") private static ImmutableSet> rangesAfterAppliedReplacements( TreeRangeMap replacements) { ImmutableSet.Builder> outputRanges = ImmutableSet.builder(); @@ -449,7 +448,6 @@ private String computePrefixIndentation( int startLine = lineMap.getLineNumber(startingPos); int lineStartPosition = lineMap.getStartPosition(startLine); int endPos = getEndPosition(unit, expression); - int endLine = lineMap.getLineNumber(endPos); int parentLine = shouldUseStartLineParent ? startParentLine : endParentLine; // ignore indentation if the current argument is on the same line as the parent if (startLine == parentLine) { @@ -482,7 +480,6 @@ private record Chain( int firstLineColumn, List plain) {} - @SuppressWarnings("for-rollout:NullAway") private void wrapLongStrings( TreeRangeMap replacements, List longStringLiterals, @@ -516,7 +513,6 @@ private void wrapLongStrings( // Handling leaving trailing non-string tokens at the end of the literal, // e.g. the trailing `);` in `foo("...");`. - @SuppressWarnings("for-rollout:NullAway") int end = getEndPosition(unit, getLast(flat)); int lineEnd = end; while (Newlines.hasNewlineAt(input, lineEnd) == -1) { diff --git a/open-java-format/src/main/java/com/palantir/javaformat/java/Trees.java b/open-java-format/src/main/java/com/palantir/javaformat/java/Trees.java index d7fd65e2b..9d573102a 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/java/Trees.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/java/Trees.java @@ -142,7 +142,6 @@ static Name getMethodName(MethodInvocationTree methodInvocation) { } /** Returns the receiver of a qualified method invocation expression, or {@code null}. */ - @SuppressWarnings("for-rollout:NullAway") static ExpressionTree getMethodReceiver(MethodInvocationTree methodInvocation) { ExpressionTree select = methodInvocation.getMethodSelect(); return select instanceof MemberSelectTree memberSelectTree ? memberSelectTree.getExpression() : null; diff --git a/open-java-format/src/main/java/com/palantir/javaformat/java/java14/Java14InputAstVisitor.java b/open-java-format/src/main/java/com/palantir/javaformat/java/java14/Java14InputAstVisitor.java index 746a8e2be..178fd0987 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/java/java14/Java14InputAstVisitor.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/java/java14/Java14InputAstVisitor.java @@ -51,7 +51,6 @@ /** * Extends {@link JavaInputAstVisitor} with support for AST nodes that were added or modified for Java 14. */ -@SuppressWarnings("Since15") public class Java14InputAstVisitor extends JavaInputAstVisitor { private static final Method COMPILATION_UNIT_TREE_GET_MODULE = maybeGetMethod(CompilationUnitTree.class, "getModule"); @@ -94,7 +93,6 @@ protected List getPermitsClause(ClassTree node) { } } - @SuppressWarnings("for-rollout:NullAway") @Override public Void visitBindingPattern(BindingPatternTree node, Void unused) { sync(node); @@ -252,7 +250,6 @@ public Void visitInstanceOf(InstanceOfTree node, Void unused) { return null; } - @SuppressWarnings("for-rollout:NullAway") @Override public Void visitCase(CaseTree node, Void unused) { sync(node); @@ -347,7 +344,6 @@ public Void visitLambdaExpression(LambdaExpressionTree node, Void unused) { return null; } - @SuppressWarnings({"NullableProblems", "for-rollout:NullAway"}) protected ExpressionTree getGuard(final CaseTree node) { return null; } diff --git a/open-java-format/src/main/java/com/palantir/javaformat/java/java21/Java21InputAstVisitor.java b/open-java-format/src/main/java/com/palantir/javaformat/java/java21/Java21InputAstVisitor.java index f6f586ee7..703b3ac10 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/java/java21/Java21InputAstVisitor.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/java/java21/Java21InputAstVisitor.java @@ -32,7 +32,6 @@ * Extends {@link Java14InputAstVisitor} with support for AST nodes that were added or modified in * Java 21. */ -@SuppressWarnings("Since21") public class Java21InputAstVisitor extends Java14InputAstVisitor { // AnyPatternTree (the unnamed pattern `_`, JEP 456) is still a preview API on JDK 21, which this // module compiles with, so match it by Tree.Kind name instead of by type. diff --git a/open-java-format/src/main/java/com/palantir/javaformat/java/javadoc/CharStream.java b/open-java-format/src/main/java/com/palantir/javaformat/java/javadoc/CharStream.java index 2664aa3aa..f74d8eccf 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/java/javadoc/CharStream.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/java/javadoc/CharStream.java @@ -45,7 +45,6 @@ boolean tryConsume(String expected) { /* * @param pattern the pattern to search for, which must be anchored to match only at position 0 */ - @SuppressWarnings("for-rollout:AlmostJavadoc") boolean tryConsumeRegex(Pattern pattern) { Matcher matcher = pattern.matcher(remaining); if (!matcher.find()) { diff --git a/open-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocLexer.java b/open-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocLexer.java index c67b0f1ae..f0fa8c663 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocLexer.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocLexer.java @@ -320,7 +320,6 @@ private void checkMatchingTags() throws LexException { * *

Note that we do not merge a literal token and a whitespace token together. */ - @SuppressWarnings("for-rollout:NullAway") private static ImmutableList joinAdjacentLiteralsAndAdjacentWhitespace(List input) { /* * Note: Our final token is always END_JAVADOC. This saves us some trouble: @@ -335,7 +334,6 @@ private static ImmutableList joinAdjacentLiteralsAndAdjacentWhitespace(Li boolean lastTagWasInlineTagStart = false; for (PeekingIterator tokens = peekingIterator(input.iterator()); tokens.hasNext(); ) { - @SuppressWarnings("for-rollout:NullAway") Token.Type nextType = tokens.peek().getType(); if (nextType == INLINE_TAG_OPEN) { inlineTagDepth.increment(); @@ -429,7 +427,6 @@ private static boolean isSuspendedHyphenConjunction(String s) { *

This method must be called after {@link #joinAdjacentLiteralsAndAdjacentWhitespace}, as it assumes that * adjacent whitespace tokens have already been joined. */ - @SuppressWarnings("for-rollout:NullAway") private static ImmutableList inferParagraphTags(List input) { ImmutableList.Builder output = ImmutableList.builder(); @@ -468,7 +465,6 @@ && hasMultipleNewlines(tokens.peek().getValue())) { *

This method must be called after {@link #joinAdjacentLiteralsAndAdjacentWhitespace}, as it assumes that * adjacent whitespace tokens have already been joined. */ - @SuppressWarnings("for-rollout:NullAway") private static ImmutableList optionalizeSpacesAfterLinks(List input) { ImmutableList.Builder output = ImmutableList.builder(); @@ -498,7 +494,6 @@ private static ImmutableList optionalizeSpacesAfterLinks(List inpu * *

Also trim leading and trailing blank lines, and move the trailing `}` to its own line. */ - @SuppressWarnings("for-rollout:NullAway") private static ImmutableList deindentPreCodeBlocks(List input) { ImmutableList.Builder output = ImmutableList.builder(); for (PeekingIterator tokens = peekingIterator(input.iterator()); tokens.hasNext(); ) { @@ -523,7 +518,6 @@ private static ImmutableList deindentPreCodeBlocks(List input) { return output.build(); } - @SuppressWarnings("for-rollout:NullAway") private static void deindentPreCodeBlock(ImmutableList.Builder output, PeekingIterator tokens) { Deque saved = new ArrayDeque<>(); output.add(new Token(LITERAL, tokens.next().getValue().trim())); @@ -635,7 +629,6 @@ private static boolean hasMultipleNewlines(String s) { * with matching only one character here. That would eliminate the need for the regex entirely. * That might be faster or slower than what we do now. */ - @SuppressWarnings("for-rollout:AlmostJavadoc") private static final Pattern LITERAL_PATTERN = compile("^.[^ \t\n@<{}*]*", DOTALL); private static Pattern fullCommentPattern() { diff --git a/open-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocWriter.java b/open-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocWriter.java index 47be68fdb..b9071173a 100644 --- a/open-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocWriter.java +++ b/open-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocWriter.java @@ -280,7 +280,6 @@ private void requestNewline() { requestWhitespace(NEWLINE); } - @SuppressWarnings("for-rollout:NullAway") private void requestWhitespace(RequestedWhitespace requestedWhitespace) { this.requestedWhitespace = Ordering.natural().max(requestedWhitespace, this.requestedWhitespace); } diff --git a/open-java-format/src/test/java/com/palantir/javaformat/java/DiagnosticTest.java b/open-java-format/src/test/java/com/palantir/javaformat/java/DiagnosticTest.java index 5961a4335..6d83af8aa 100644 --- a/open-java-format/src/test/java/com/palantir/javaformat/java/DiagnosticTest.java +++ b/open-java-format/src/test/java/com/palantir/javaformat/java/DiagnosticTest.java @@ -54,7 +54,6 @@ void restoreLocale() throws Exception { @Test void parseError() throws Exception { - @SuppressWarnings("for-rollout:StringConcatToTextBlock") String input = Joiner.on('\n') .join( "public class InvalidSyntax {", diff --git a/open-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java b/open-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java index ae644be92..efa7b6288 100644 --- a/open-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java +++ b/open-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java @@ -79,7 +79,7 @@ public void format() { tests.writeFormatterOutput(name, output); return; } - assertThat(output).describedAs("bad output for " + name).isEqualTo(expected); + assertThat(output).describedAs("bad output for %s", name).isEqualTo(expected); } catch (FormatterException e) { throw new RuntimeException(String.format("Formatter crashed on %s", name), e); } @@ -100,7 +100,7 @@ public void idempotentLF() { try { String mangled = expected.replace(separator, "\n"); String output = createFormatter().formatSource(mangled); - assertThat(output).describedAs("bad output for " + name).isEqualTo(mangled); + assertThat(output).describedAs("bad output for %s", name).isEqualTo(mangled); } catch (FormatterException e) { throw new RuntimeException(String.format("Formatter crashed on %s", name), e); } @@ -113,7 +113,7 @@ public void idempotentCR() { try { String mangled = expected.replace(separator, "\r"); String output = createFormatter().formatSource(mangled); - assertThat(output).describedAs("bad output for " + name).isEqualTo(mangled); + assertThat(output).describedAs("bad output for %s", name).isEqualTo(mangled); } catch (FormatterException e) { throw new RuntimeException(String.format("Formatter crashed on %s", name), e); } @@ -126,7 +126,7 @@ public void idempotentCRLF() { try { String mangled = expected.replace(separator, "\r\n"); String output = createFormatter().formatSource(mangled); - assertThat(output).describedAs("bad output for " + name).isEqualTo(mangled); + assertThat(output).describedAs("bad output for %s", name).isEqualTo(mangled); } catch (FormatterException e) { throw new RuntimeException(String.format("Formatter crashed on %s", name), e); } diff --git a/open-java-format/src/test/java/com/palantir/javaformat/java/FormatterTest.java b/open-java-format/src/test/java/com/palantir/javaformat/java/FormatterTest.java index 68f462e27..aec3257ab 100644 --- a/open-java-format/src/test/java/com/palantir/javaformat/java/FormatterTest.java +++ b/open-java-format/src/test/java/com/palantir/javaformat/java/FormatterTest.java @@ -69,9 +69,7 @@ void formatNonJavaFiles() throws Exception { @Test void formatStdinStdoutWithDashFlag() throws Exception { - @SuppressWarnings("for-rollout:StringConcatToTextBlock") String input = "class Foo{\n" + "void f\n" + "() {\n" + "}\n" + "}\n"; - @SuppressWarnings("for-rollout:StringConcatToTextBlock") String expectedOutput = "class Foo {\n" + " void f() {}\n" + "}\n"; InputStream in = new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)); @@ -90,9 +88,7 @@ void formatStdinStdoutWithDashFlag() throws Exception { @Test void formatLengthUpToEOF() throws Exception { - @SuppressWarnings("for-rollout:StringConcatToTextBlock") String input = "class Foo{\n" + "void f\n" + "() {\n" + "}\n" + "}\n\n\n\n\n\n"; - @SuppressWarnings("for-rollout:StringConcatToTextBlock") String expectedOutput = "class Foo {\n" + " void f() {}\n" + "}\n"; Path path = testFolder.resolve("Foo.java"); @@ -131,7 +127,6 @@ void blankInClassBodyNoTrailing() throws FormatterException { assertThat(output).isEqualTo(expect); } - @SuppressWarnings("for-rollout:StringConcatToTextBlock") private static final String UNORDERED_IMPORTS = Joiner.on('\n') .join( "import com.google.common.base.Preconditions;", @@ -220,7 +215,6 @@ void throwsFormatterException() throws Exception { @Test void blankLinesImportComment() throws FormatterException { - @SuppressWarnings("for-rollout:StringConcatToTextBlock") String withBlank = "package p;\n" + "\n" + "/** test */\n" @@ -230,7 +224,6 @@ void blankLinesImportComment() throws FormatterException { + "class T {\n" + " A a;\n" + "}\n"; - @SuppressWarnings("for-rollout:StringConcatToTextBlock") String withoutBlank = "package p;\n" + "\n" + "/** test */\n" + "import a.A;\n" + "\n" + "class T {\n" + " A a;\n" + "}\n"; @@ -259,7 +252,6 @@ void canParse_java9_private_interface_methods() { @Test void producesFormattingChangesOnAlreadyFormattedFiles() throws FormatterException { Formatter formatter = FORMATTER; - @SuppressWarnings("for-rollout:StringConcatToTextBlock") String simpleClass = "package com.palantir;\n" + "\n" + "public final class Formatted {\n" diff --git a/open-java-format/src/test/java/com/palantir/javaformat/java/JavaCommentsHelperTest.java b/open-java-format/src/test/java/com/palantir/javaformat/java/JavaCommentsHelperTest.java index 59e564baf..f5d2202a2 100644 --- a/open-java-format/src/test/java/com/palantir/javaformat/java/JavaCommentsHelperTest.java +++ b/open-java-format/src/test/java/com/palantir/javaformat/java/JavaCommentsHelperTest.java @@ -96,6 +96,7 @@ void anUnbreakableTokenIsLeftLong() throws Exception { assertThat(rewritten).contains("/// " + url); } + @SuppressWarnings("FormatStringConcatenation") // Written out like the input, not as a template @Test void theMissingSpaceRuleAppliesToEveryLineOfTheRun() throws Exception { // Otherwise the same source formats differently depending on whether the running JDK hands the run diff --git a/open-java-format/src/test/java/com/palantir/javaformat/java/JavadocFormattingTest.java b/open-java-format/src/test/java/com/palantir/javaformat/java/JavadocFormattingTest.java index 80394ce20..0643bfce0 100644 --- a/open-java-format/src/test/java/com/palantir/javaformat/java/JavadocFormattingTest.java +++ b/open-java-format/src/test/java/com/palantir/javaformat/java/JavadocFormattingTest.java @@ -1147,7 +1147,6 @@ void unicodeEscapesNotReplaced() { } @Test - @SuppressWarnings("UnicodeEscape") void unicodeEscapesNotInterpretedBug() { /* * In theory, "\u003C" should be treated exactly like <, and so too should the escaped versions of diff --git a/open-java-format/src/test/java/com/palantir/javaformat/java/MainTest.java b/open-java-format/src/test/java/com/palantir/javaformat/java/MainTest.java index 3f675eac5..800f25998 100644 --- a/open-java-format/src/test/java/com/palantir/javaformat/java/MainTest.java +++ b/open-java-format/src/test/java/com/palantir/javaformat/java/MainTest.java @@ -483,7 +483,6 @@ void exitIfChangedStdin() throws Exception { Files.write(path, "class Test {\n}\n".getBytes(UTF_8)); Process process = formatterMain("-").redirectInput(path.toFile()).start(); process.waitFor(); - String err = new String(ByteStreams.toByteArray(process.getErrorStream()), UTF_8); String out = new String(ByteStreams.toByteArray(process.getInputStream()), UTF_8); assertThat(out).isEqualTo("" + System.lineSeparator()); assertThat(process.exitValue()).isEqualTo(1); @@ -495,7 +494,6 @@ void exitIfChangedFiles() throws Exception { Files.write(path, "class Test {\n}\n".getBytes(UTF_8)); Process process = formatterMain(path.toAbsolutePath().toString()).start(); process.waitFor(); - String err = new String(ByteStreams.toByteArray(process.getErrorStream()), UTF_8); String out = new String(ByteStreams.toByteArray(process.getInputStream()), UTF_8); assertThat(out).isEqualTo(path.toAbsolutePath().toString() + System.lineSeparator()); assertThat(process.exitValue()).isEqualTo(1); diff --git a/open-java-format/src/test/java/com/palantir/javaformat/jupiter/ParameterizedClass.java b/open-java-format/src/test/java/com/palantir/javaformat/jupiter/ParameterizedClass.java index 6bd5cf22f..fc3540ac7 100644 --- a/open-java-format/src/test/java/com/palantir/javaformat/jupiter/ParameterizedClass.java +++ b/open-java-format/src/test/java/com/palantir/javaformat/jupiter/ParameterizedClass.java @@ -167,7 +167,6 @@ public boolean supportsTestTemplate(ExtensionContext _value) { } /** Users must provide a public static Object[][] method, and this invokes it *once*, caching the result. */ - @SuppressWarnings("for-rollout:deprecation") private static List invokeUserParametersMethod(ExtensionContext extensionContext, Class testClass) { List methods = AnnotationUtils.findAnnotatedMethods( testClass, Parameters.class, ReflectionUtils.HierarchyTraversalMode.BOTTOM_UP); @@ -180,7 +179,6 @@ private static List invokeUserParametersMethod(ExtensionContext extens "invokeUserParametersMethod", unused -> allParameters(userParametersMethod), List.class); } - @SuppressWarnings("unchecked") private static List allParameters(Method method) { try { Object parameters = method.invoke(null); @@ -204,7 +202,6 @@ private static List allParameters(Method method) { } } - @SuppressWarnings("for-rollout:deprecation") private static String findStringFormatTemplate(ExtensionContext extensionContext, Class testClass) { return extensionContext .getStore(namespace)