diff --git a/build.gradle b/build.gradle index dc6254db9..43ad9ad17 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ buildscript { dependencies { classpath 'com.palantir.jakartapackagealignment:jakarta-package-alignment:0.6.0' classpath 'com.gradle.publish:plugin-publish-plugin:1.3.1' - classpath 'com.palantir.baseline:gradle-baseline-java:6.32.0' + classpath 'com.palantir.baseline:gradle-baseline-java:6.34.0' classpath 'com.palantir.gradle.consistentversions:gradle-consistent-versions:2.34.0' classpath 'com.palantir.gradle.externalpublish:gradle-external-publish-plugin:1.19.0' classpath 'com.palantir.gradle.failure-reports:gradle-failure-reports:1.14.0' diff --git a/eclipse_plugin/src/main/java/com/palantir/javaformat/java/PalantirJavaFormatter.java b/eclipse_plugin/src/main/java/com/palantir/javaformat/java/PalantirJavaFormatter.java index 8e1d096d9..068cfecce 100644 --- a/eclipse_plugin/src/main/java/com/palantir/javaformat/java/PalantirJavaFormatter.java +++ b/eclipse_plugin/src/main/java/com/palantir/javaformat/java/PalantirJavaFormatter.java @@ -60,6 +60,7 @@ public String createIndentationString(int indentationLevel) { } /** Runs the Google Java formatter on the given source, with only the given ranges specified. */ + @SuppressWarnings({"for-rollout:DefaultLocale", "for-rollout:StatementSwitchToExpressionSwitch"}) @Nullable private TextEdit formatInternal(int kind, String source, IRegion[] regions, int initialIndent) { try { @@ -82,6 +83,7 @@ private TextEdit formatInternal(int kind, String source, IRegion[] regions, int default: throw new IllegalArgumentException(String.format("Unknown snippet kind: %d", kind)); } + @SuppressWarnings("for-rollout:PreferredInterfaceType") List replacements = new SnippetFormatter() .format(snippetKind, source, rangesFromRegions(regions), initialIndent, includeComments); if (idempotent(source, regions, replacements)) { diff --git a/eclipse_plugin/src/main/java/com/palantir/javaformat/java/SnippetFormatter.java b/eclipse_plugin/src/main/java/com/palantir/javaformat/java/SnippetFormatter.java index afc4635af..da06874c0 100644 --- a/eclipse_plugin/src/main/java/com/palantir/javaformat/java/SnippetFormatter.java +++ b/eclipse_plugin/src/main/java/com/palantir/javaformat/java/SnippetFormatter.java @@ -153,6 +153,7 @@ private static List toReplacements(String source, String replacemen return replacements; } + @SuppressWarnings({"for-rollout:StatementSwitchToExpressionSwitch", "for-rollout:UnnecessaryDefaultInEnumSwitch"}) private SnippetWrapper snippetWrapper(SnippetKind kind, String source, int initialIndent) { /* * Synthesize a dummy class around the code snippet provided by Eclipse. The diff --git a/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/ExecutableTransform.java b/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/ExecutableTransform.java index 2d61c98c2..31e3a9934 100644 --- a/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/ExecutableTransform.java +++ b/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/ExecutableTransform.java @@ -41,11 +41,13 @@ */ public abstract class ExecutableTransform implements TransformAction { + @SuppressWarnings("for-rollout:NonFinalStaticField") private static Logger logger = Logging.getLogger(ExecutableTransform.class); @InputArtifact public abstract Provider getInputArtifact(); + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") @Override public void transform(TransformOutputs outputs) { File inputFile = getInputArtifact().get().getAsFile(); @@ -58,6 +60,7 @@ public void transform(TransformOutputs outputs) { } } + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") private static void makeFileExecutable(Path pathToExe) { try { Set existingPermissions = Files.getPosixFilePermissions(pathToExe); diff --git a/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/FormatDiff.java b/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/FormatDiff.java index d12907dc7..75f6330eb 100644 --- a/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/FormatDiff.java +++ b/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/FormatDiff.java @@ -69,6 +69,7 @@ public static void formatDiff(Path dirToFormat, FormatterService formatter) } /** Parses the filenames and edited ranges out of `git diff -U0`. */ + @SuppressWarnings("for-rollout:SystemOut") @VisibleForTesting static Stream parseGitDiffOutput(String gitOutput) { return Streams.stream(Splitter.on(SEPARATOR).omitEmptyStrings().split(gitOutput)) @@ -96,6 +97,7 @@ static Stream parseGitDiffOutput(String gitOutput) { }); } + @SuppressWarnings("for-rollout:SystemOut") private static void format(FormatterService formatter, SingleFileDiff diff) { String input; try { @@ -161,6 +163,7 @@ private static RangeSet lineRangesToCharRanges(String input, RangeSet characterRanges = TreeRangeSet.create(); for (Range lineRange : lineRanges.subRangeSet(Range.closedOpen(0, lines.size() - 1)).asRanges()) { diff --git a/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/JavaFormatExtension.java b/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/JavaFormatExtension.java index 13e2dd00b..4da02cc02 100644 --- a/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/JavaFormatExtension.java +++ b/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/JavaFormatExtension.java @@ -41,6 +41,7 @@ public FormatterService serviceLoad() { @SuppressWarnings("for-rollout:NullAway") private FormatterService serviceLoadInternal() { + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") URL[] jarUris = configuration.getFiles().stream() .map(file -> { try { @@ -51,6 +52,7 @@ private FormatterService serviceLoadInternal() { }) .toArray(URL[]::new); + @SuppressWarnings("for-rollout:BanClassLoader") ClassLoader classLoader = new URLClassLoader(jarUris, FormatterService.class.getClassLoader()); return Iterables.getOnlyElement(ServiceLoader.load(FormatterService.class, classLoader)); } diff --git a/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/SpotlessInterop.java b/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/SpotlessInterop.java index 049b8074b..655ffc0fd 100644 --- a/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/SpotlessInterop.java +++ b/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/SpotlessInterop.java @@ -29,6 +29,7 @@ * {@link com.palantir.javaformat.gradle.PalantirJavaFormatSpotlessPlugin} even if spotless is not on the classpath. */ final class SpotlessInterop { + @SuppressWarnings("for-rollout:NonFinalStaticField") private static Logger logger = Logging.getLogger(SpotlessInterop.class); private SpotlessInterop() {} diff --git a/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/spotless/NativePalantirJavaFormatStep.java b/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/spotless/NativePalantirJavaFormatStep.java index cc92dd1d3..129c43939 100644 --- a/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/spotless/NativePalantirJavaFormatStep.java +++ b/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/spotless/NativePalantirJavaFormatStep.java @@ -30,6 +30,7 @@ import org.gradle.api.logging.Logging; public final class NativePalantirJavaFormatStep { + @SuppressWarnings("for-rollout:NonFinalStaticField") private static Logger logger = Logging.getLogger(NativePalantirJavaFormatStep.class); private NativePalantirJavaFormatStep() {} diff --git a/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/spotless/PalantirJavaFormatStep.java b/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/spotless/PalantirJavaFormatStep.java index c18b15d0e..9d92fb783 100644 --- a/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/spotless/PalantirJavaFormatStep.java +++ b/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/spotless/PalantirJavaFormatStep.java @@ -73,6 +73,7 @@ FormatterFunc createFormat() { } } + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") private static void ensureImplementationNotDirectlyLoadable() { try { PalantirJavaFormatStep.class.getClassLoader().loadClass(IMPL_CLASS); diff --git a/idea-plugin/src/main/java/com/palantir/javaformat/intellij/FormatterProvider.java b/idea-plugin/src/main/java/com/palantir/javaformat/intellij/FormatterProvider.java index e30306b13..78fb53401 100644 --- a/idea-plugin/src/main/java/com/palantir/javaformat/intellij/FormatterProvider.java +++ b/idea-plugin/src/main/java/com/palantir/javaformat/intellij/FormatterProvider.java @@ -100,6 +100,7 @@ private static Optional createFormatter(FormatterCacheKey cach // Use "in-process" formatter service log.info("Using in-process formatter for jdk version {}", jdkMajorVersion); URL[] implementationUrls = toUrlsUnchecked(implementationClasspath); + @SuppressWarnings("for-rollout:BanClassLoader") ClassLoader classLoader = new URLClassLoader(implementationUrls, FormatterService.class.getClassLoader()); return ServiceLoader.load(FormatterService.class, classLoader).findFirst(); } @@ -195,6 +196,7 @@ private static Optional getProjectJdk(Project project) { return Optional.ofNullable(ProjectRootManager.getInstance(project).getProjectSdk()); } + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") private static URL[] toUrlsUnchecked(List paths) { return paths.stream() .map(path -> { @@ -207,6 +209,7 @@ private static URL[] toUrlsUnchecked(List paths) { .toArray(URL[]::new); } + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") private static List listDirAsUrlsUnchecked(Path dir) { try (Stream list = Files.list(dir)) { return list.collect(Collectors.toList()); diff --git a/idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatFormattingService.java b/idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatFormattingService.java index 6c3d8631f..3e8ef8b76 100644 --- a/idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatFormattingService.java +++ b/idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatFormattingService.java @@ -101,6 +101,7 @@ public void run() { request.getDocumentText().length(), request.getFormattingRanges())); } + @SuppressWarnings("for-rollout:PreferredInterfaceType") List replacements = formatterService.get().getFormatReplacements(request.getDocumentText(), toRanges(request)); if (logger.isDebugEnabled()) { @@ -140,6 +141,7 @@ public static String applyReplacements(String input, Collection rep return writer.toString(); } + @SuppressWarnings("for-rollout:PreferredInterfaceType") private static Collection> toRanges(AsyncFormattingRequest request) { if (isWholeFile(request)) { // The IDE sometimes passes invalid ranges when the file is unsaved before invoking the diff --git a/idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatSettings.java b/idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatSettings.java index 55a02eb41..eea3f352f 100644 --- a/idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatSettings.java +++ b/idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatSettings.java @@ -113,6 +113,7 @@ Optional getImplementationVersion() { return Optional.ofNullable(FormatterProvider.getPluginDescriptor().getVersion()); } + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") Optional computeFormatterVersion() { return getImplementationClassPath().map(classpath -> classpath.stream() .flatMap(uri -> { @@ -179,7 +180,7 @@ public void setEnabled(@Nullable String enabledStr) { } } - @SuppressWarnings("for-rollout:NullAway") + @SuppressWarnings({"for-rollout:NullAway", "for-rollout:StatementSwitchToExpressionSwitch"}) public String getEnabled() { switch (enabled) { case ENABLED: diff --git a/idea-plugin/src/main/java/com/palantir/javaformat/intellij/UiFormatterStyle.java b/idea-plugin/src/main/java/com/palantir/javaformat/intellij/UiFormatterStyle.java index 3fc1bb7c7..f37a0b9b6 100644 --- a/idea-plugin/src/main/java/com/palantir/javaformat/intellij/UiFormatterStyle.java +++ b/idea-plugin/src/main/java/com/palantir/javaformat/intellij/UiFormatterStyle.java @@ -27,9 +27,13 @@ enum UiFormatterStyle { ; private final String description; + + @SuppressWarnings("for-rollout:DifferentNameButSame") private final JavaFormatterOptions.Style style; - UiFormatterStyle(String description, JavaFormatterOptions.Style style) { + UiFormatterStyle( + String description, + @SuppressWarnings("for-rollout:DifferentNameButSame") JavaFormatterOptions.Style style) { this.description = description; this.style = style; } @@ -39,11 +43,13 @@ public String toString() { return description; } + @SuppressWarnings("for-rollout:DifferentNameButSame") public JavaFormatterOptions.Style convert() { return style; } - static UiFormatterStyle convert(JavaFormatterOptions.Style style) { + static UiFormatterStyle convert( + @SuppressWarnings("for-rollout:DifferentNameButSame") JavaFormatterOptions.Style style) { return Arrays.stream(UiFormatterStyle.values()) .filter(value -> Objects.equals(value.style, style)) .findFirst() diff --git a/palantir-java-format-benchmarks/src/jmh/java/com/palantir/javaformat/BenchmarkMultiFiles.java b/palantir-java-format-benchmarks/src/jmh/java/com/palantir/javaformat/BenchmarkMultiFiles.java index c27c38791..2f3aec23e 100644 --- a/palantir-java-format-benchmarks/src/jmh/java/com/palantir/javaformat/BenchmarkMultiFiles.java +++ b/palantir-java-format-benchmarks/src/jmh/java/com/palantir/javaformat/BenchmarkMultiFiles.java @@ -47,6 +47,7 @@ public static class BenchmarkState { final List filesToFormat = getFilesToFormat(); + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") private static List getFilesToFormat() { Path srcJavaFormatFiles = Paths.get(".") .toAbsolutePath() diff --git a/palantir-java-format-jdk-bootstrap/src/main/java/com/palantir/javaformat/bootstrap/BootstrappingFormatterService.java b/palantir-java-format-jdk-bootstrap/src/main/java/com/palantir/javaformat/bootstrap/BootstrappingFormatterService.java index 34c49721f..5e9538f09 100644 --- a/palantir-java-format-jdk-bootstrap/src/main/java/com/palantir/javaformat/bootstrap/BootstrappingFormatterService.java +++ b/palantir-java-format-jdk-bootstrap/src/main/java/com/palantir/javaformat/bootstrap/BootstrappingFormatterService.java @@ -50,6 +50,7 @@ public BootstrappingFormatterService(Path jdkPath, Integer jdkMajorVersion, List this.implementationClassPath = implementationClassPath; } + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") @Override public ImmutableList getFormatReplacements(String input, Collection> ranges) { try { @@ -59,6 +60,7 @@ public ImmutableList getFormatReplacements(String input, Collection } } + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") @Override public String formatSourceReflowStringsAndFixImports(String input) { try { @@ -68,6 +70,7 @@ public String formatSourceReflowStringsAndFixImports(String input) { } } + @SuppressWarnings({"for-rollout:CheckedExceptionNotThrown", "for-rollout:ThrowSpecificExceptions"}) @Override public String fixImports(String input) throws FormatterException { try { diff --git a/palantir-java-format-jdk-bootstrap/src/main/java/com/palantir/javaformat/bootstrap/FormatterCommandRunner.java b/palantir-java-format-jdk-bootstrap/src/main/java/com/palantir/javaformat/bootstrap/FormatterCommandRunner.java index e8b63d221..8781e08d1 100644 --- a/palantir-java-format-jdk-bootstrap/src/main/java/com/palantir/javaformat/bootstrap/FormatterCommandRunner.java +++ b/palantir-java-format-jdk-bootstrap/src/main/java/com/palantir/javaformat/bootstrap/FormatterCommandRunner.java @@ -28,6 +28,7 @@ final class FormatterCommandRunner { private static final Pattern SYNTAX_ERROR_PATTERN = Pattern.compile(":\\d+:\\d+:\\serror:\\s"); + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") static Optional runWithStdin(List command, String input, Optional workingDirectory) throws IOException { ProcessBuilder processBuilder = new ProcessBuilder().command(command); diff --git a/palantir-java-format-jdk-bootstrap/src/main/java/com/palantir/javaformat/bootstrap/NativeImageFormatterService.java b/palantir-java-format-jdk-bootstrap/src/main/java/com/palantir/javaformat/bootstrap/NativeImageFormatterService.java index 54158d915..6686d17c8 100644 --- a/palantir-java-format-jdk-bootstrap/src/main/java/com/palantir/javaformat/bootstrap/NativeImageFormatterService.java +++ b/palantir-java-format-jdk-bootstrap/src/main/java/com/palantir/javaformat/bootstrap/NativeImageFormatterService.java @@ -42,6 +42,7 @@ public NativeImageFormatterService(Path nativeImagePath) { this.nativeImagePath = nativeImagePath; } + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") @Override public ImmutableList getFormatReplacements(String input, Collection> ranges) { try { @@ -63,6 +64,7 @@ public ImmutableList getFormatReplacements(String input, Collection } } + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") @Override public String formatSourceReflowStringsAndFixImports(String input) { try { @@ -72,6 +74,7 @@ public String formatSourceReflowStringsAndFixImports(String input) { } } + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") @Override public String fixImports(String input) { try { diff --git a/palantir-java-format-spi/src/main/java/com/palantir/javaformat/java/FormatterDiagnostic.java b/palantir-java-format-spi/src/main/java/com/palantir/javaformat/java/FormatterDiagnostic.java index 3f4794ab5..0abfa229c 100644 --- a/palantir-java-format-spi/src/main/java/com/palantir/javaformat/java/FormatterDiagnostic.java +++ b/palantir-java-format-spi/src/main/java/com/palantir/javaformat/java/FormatterDiagnostic.java @@ -29,6 +29,7 @@ public static FormatterDiagnostic create(String message) { return new FormatterDiagnostic(-1, -1, message); } + @SuppressWarnings("for-rollout:InconsistentOverloads") public static FormatterDiagnostic create(int lineNumber, int column, String message) { checkArgument(lineNumber >= 0); checkArgument(column >= 0); diff --git a/palantir-java-format-spi/src/main/java/com/palantir/javaformat/java/FormatterException.java b/palantir-java-format-spi/src/main/java/com/palantir/javaformat/java/FormatterException.java index 94c6b2674..6d144cf49 100644 --- a/palantir-java-format-spi/src/main/java/com/palantir/javaformat/java/FormatterException.java +++ b/palantir-java-format-spi/src/main/java/com/palantir/javaformat/java/FormatterException.java @@ -37,6 +37,7 @@ public FormatterException(Iterable diagnostics) { this.diagnostics = ImmutableList.copyOf(diagnostics); } + @SuppressWarnings("for-rollout:PreferredInterfaceType") public List diagnostics() { return diagnostics; } diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/BreakBehaviour.java b/palantir-java-format/src/main/java/com/palantir/javaformat/BreakBehaviour.java index 7ab0751b0..cb09ce1e4 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/BreakBehaviour.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/BreakBehaviour.java @@ -73,6 +73,7 @@ public interface Cases { */ static class Json extends JsonSerializer { + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") @Override public void serialize(BreakBehaviour value, JsonGenerator gen, SerializerProvider serializers) throws IOException { diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/OpenOp.java b/palantir-java-format/src/main/java/com/palantir/javaformat/OpenOp.java index ba25f077c..f09d2d419 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/OpenOp.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/OpenOp.java @@ -98,6 +98,7 @@ public PartialInlineability partialInlineability() { * ...)); // long arguments * */ + @SuppressWarnings("for-rollout:UnescapedEntity") @Default public Complexity complexity() { return Complexity.SIMPLE; @@ -140,6 +141,7 @@ public static Builder builder() { } public static class Builder extends ImmutableOpenOp.Builder { + @SuppressWarnings("for-rollout:BuilderReturnThis") public Builder isSimple(boolean isSimple) { return complexity(isSimple ? Complexity.SIMPLE : Complexity.COMPLEX); } diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/OpsBuilder.java b/palantir-java-format/src/main/java/com/palantir/javaformat/OpsBuilder.java index 322242c8a..53bf47aa6 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/OpsBuilder.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/OpsBuilder.java @@ -52,7 +52,7 @@ 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()) { + for (@SuppressWarnings("for-rollout:DifferentNameButSame") Input.Tok tok : startToken.getToksBefore()) { if (tok.isComment()) { start = Math.min(start, tok.getPosition()); } @@ -60,7 +60,7 @@ 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()) { + for (@SuppressWarnings("for-rollout:DifferentNameButSame") Input.Tok tok : endToken.getToksAfter()) { if (tok.isComment()) { end = Math.max(end, tok.getPosition() + tok.length()); } @@ -74,7 +74,7 @@ public Integer actualStartColumn(int position) { @SuppressWarnings("for-rollout:NullAway") int start = startToken.getTok().getPosition(); int line0 = input.getLineNumber(start); - for (Input.Tok tok : startToken.getToksBefore()) { + for (@SuppressWarnings("for-rollout:DifferentNameButSame") Input.Tok tok : startToken.getToksBefore()) { if (line0 != input.getLineNumber(tok.getPosition())) { return start; } @@ -214,6 +214,7 @@ public int depth() { * * @throws FormattingError if any ops were unclosed */ + @SuppressWarnings("for-rollout:DefaultLocale") public void checkClosed(int previous) { if (depth != previous) { throw new FormattingError(diagnostic(String.format("saw %d unclosed ops", depth))); @@ -246,6 +247,7 @@ public void sync(int inputPosition) { } /** Output any remaining tokens from the input stream (e.g. terminal whitespace). */ + @SuppressWarnings("for-rollout:DifferentNameButSame") public void drain() { int inputPosition = input.getText().length() + 1; if (inputPosition > this.inputPosition) { @@ -280,6 +282,7 @@ public void open(Indent plusIndent) { * @param debugName a representative name for this lambda * @param plusIndent the extra indent for the new level */ + @SuppressWarnings("for-rollout:InconsistentOverloads") public void open(String debugName, Indent plusIndent) { add(OpenOp.builder().plusIndent(plusIndent).debugName(debugName).build()); } @@ -332,13 +335,15 @@ public Optional peekToken(int skip) { * * @param token the optional token */ + @SuppressWarnings("for-rollout:DifferentNameButSame") public void guessToken(String token) { token(token, Token.RealOrImaginary.IMAGINARY, ZERO, /* breakAndIndentTrailingComment= */ Optional.empty()); } + @SuppressWarnings("for-rollout:DifferentNameButSame") public void token( String token, - Token.RealOrImaginary realOrImaginary, + @SuppressWarnings("for-rollout:DifferentNameButSame") Token.RealOrImaginary realOrImaginary, Indent plusIndentCommentsBefore, Optional breakAndIndentTrailingComment) { ImmutableList tokens = input.getTokens(); @@ -366,6 +371,7 @@ public void token( * * @param op the operator to emit */ + @SuppressWarnings("for-rollout:DifferentNameButSame") public void op(String op) { int opN = op.length(); for (int i = 0; i < opN; i++) { @@ -440,6 +446,7 @@ public void breakToFill(String flat) { * @param flat the {@link Break} when not broken * @param plusIndent extra indent if taken */ + @SuppressWarnings("for-rollout:InconsistentOverloads") public void breakOp(FillMode fillMode, String flat, Indent plusIndent) { breakOp(fillMode, flat, plusIndent, /* optionalTag= */ Optional.empty()); } @@ -452,6 +459,7 @@ public void breakOp(FillMode fillMode, String flat, Indent plusIndent) { * @param plusIndent extra indent if taken * @param optionalTag an optional tag for remembering whether the break was taken */ + @SuppressWarnings("for-rollout:InconsistentOverloads") public void breakOp(FillMode fillMode, String flat, Indent plusIndent, Optional optionalTag) { add(Break.make(fillMode, flat, plusIndent, optionalTag)); } @@ -491,7 +499,7 @@ public void blankLineWanted(BlankLineWanted wanted) { } private static int getI(Input.Token token) { - for (Input.Tok tok : token.getToksBefore()) { + for (@SuppressWarnings("for-rollout:DifferentNameButSame") Input.Tok tok : token.getToksBefore()) { if (tok.getIndex() >= 0) { return tok.getIndex(); } @@ -515,9 +523,11 @@ public interface OpsOutput { } /** Build a list of {@link Op}s from the {@code OpsBuilder}. */ + @SuppressWarnings("for-rollout:DifferentNameButSame") public OpsOutput build() { markForPartialFormat(); // Rewrite the ops to insert comments. + @SuppressWarnings("for-rollout:PreferredInterfaceType") Multimap tokOps = ArrayListMultimap.create(); int opsN = ops.size(); for (int i = 0; i < opsN; i++) { @@ -547,7 +557,8 @@ public OpsOutput build() { boolean space = false; // Do we need an extra space after a previous "/*" comment? boolean lastWasComment = false; // Was the last thing we output a comment? boolean allowBlankAfterLastComment = false; - for (Input.Tok tokBefore : token.getToksBefore()) { + for (@SuppressWarnings("for-rollout:DifferentNameButSame") + Input.Tok tokBefore : token.getToksBefore()) { if (tokBefore.isNewline()) { newlines++; } else if (tokBefore.isComment()) { @@ -589,7 +600,8 @@ public OpsOutput build() { int tokAfterPos = nonNlsCommentsAfterPlus ? k - 1 : k + 1; - for (Input.Tok tokAfter : token.getToksAfter()) { + for (@SuppressWarnings("for-rollout:DifferentNameButSame") + Input.Tok tokAfter : token.getToksAfter()) { if (tokAfter.isComment()) { boolean breakAfter = tokAfter.isJavadocComment() || (tokAfter.isSlashStarComment() @@ -620,7 +632,8 @@ public OpsOutput build() { */ int newlines = 0; boolean lastWasComment = false; - for (Input.Tok tokBefore : token.getToksBefore()) { + for (@SuppressWarnings("for-rollout:DifferentNameButSame") + Input.Tok tokBefore : token.getToksBefore()) { if (tokBefore.isNewline()) { newlines++; } else if (tokBefore.isComment()) { @@ -632,7 +645,8 @@ public OpsOutput build() { } tokOps.put(j, Comment.make(tokBefore)); } - for (Input.Tok tokAfter : token.getToksAfter()) { + for (@SuppressWarnings("for-rollout:DifferentNameButSame") + Input.Tok tokAfter : token.getToksAfter()) { tokOps.put(k + 1, Comment.make(tokAfter)); } } @@ -676,7 +690,7 @@ public OpsOutput build() { .build(); } - private static boolean isNonNlsComment(Input.Tok tokAfter) { + private static boolean isNonNlsComment(@SuppressWarnings("for-rollout:DifferentNameButSame") Input.Tok tokAfter) { return tokAfter.isSlashSlashComment() && tokAfter.getText().contains("$NON-NLS"); } @@ -684,7 +698,7 @@ private static boolean isForcedBreak(Op op) { return op instanceof Break && ((Break) op).isForced(); } - private static List makeComment(Input.Tok comment) { + private static List makeComment(@SuppressWarnings("for-rollout:DifferentNameButSame") Input.Tok comment) { return comment.isSlashStarComment() ? ImmutableList.of(Comment.make(comment)) : ImmutableList.of(Comment.make(comment), Break.makeForced()); diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/Utils.java b/palantir-java-format/src/main/java/com/palantir/javaformat/Utils.java index 66f3f9616..368a49fff 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/Utils.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/Utils.java @@ -50,6 +50,7 @@ public static RangeSet lineRangesToCharRanges(String input, RangeSet characterRanges = TreeRangeSet.create(); for (Range lineRange : lineRanges.subRangeSet(Range.closedOpen(0, lines.size() - 1)).asRanges()) { diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/doc/DocVisitor.java b/palantir-java-format/src/main/java/com/palantir/javaformat/doc/DocVisitor.java index 3d2d6ade7..3f7702b86 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/doc/DocVisitor.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/doc/DocVisitor.java @@ -17,6 +17,7 @@ package com.palantir.javaformat.doc; public interface DocVisitor { + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") default T visit(Doc doc) { if (doc instanceof Level) { return visitLevel((Level) doc); diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/doc/Level.java b/palantir-java-format/src/main/java/com/palantir/javaformat/doc/Level.java index c87ac969c..10fbbc7c1 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/doc/Level.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/doc/Level.java @@ -113,10 +113,15 @@ protected Range computeRange() { } @Override - public State computeBreaks(CommentsHelper commentsHelper, int maxWidth, State state, Obs.ExplorationNode observer) { + public State computeBreaks( + CommentsHelper commentsHelper, + int maxWidth, + State state, + @SuppressWarnings("for-rollout:DifferentNameButSame") Obs.ExplorationNode observer) { return tryToFitOnOneLine(maxWidth, state, docs) .map(newWidth -> state.withColumn(newWidth).withLevelState(this, ImmutableLevelState.of(true))) .orElseGet(() -> { + @SuppressWarnings("for-rollout:DifferentNameButSame") Obs.LevelNode childLevel = observer.newChildNode(this, state); State newState = getBreakBehaviour().match(new BreakImpl(commentsHelper, maxWidth, state, childLevel)); @@ -168,9 +173,15 @@ class BreakImpl implements BreakBehaviour.Cases { private final CommentsHelper commentsHelper; private final int maxWidth; private final State state; + + @SuppressWarnings("for-rollout:DifferentNameButSame") private final Obs.LevelNode levelNode; - public BreakImpl(CommentsHelper commentsHelper, int maxWidth, State state, Obs.LevelNode levelNode) { + public BreakImpl( + CommentsHelper commentsHelper, + int maxWidth, + State state, + @SuppressWarnings("for-rollout:DifferentNameButSame") Obs.LevelNode levelNode) { this.commentsHelper = commentsHelper; this.maxWidth = maxWidth; this.state = state; @@ -192,10 +203,12 @@ public State preferBreakingLastInnerLevel(boolean _keepIndentWhenInlined) { // breaks if the outcome is the same. State state = this.state.withNewBranch(); + @SuppressWarnings("for-rollout:DifferentNameButSame") Obs.Exploration broken = breakNormally(state); if (state.branchingCoefficient() < MAX_BRANCHING_COEFFICIENT) { State state1 = state.withNoIndent(); + @SuppressWarnings("for-rollout:DifferentNameButSame") Optional lastLevelBroken = levelNode.maybeExplore( "tryBreakLastLevel", state1, @@ -230,6 +243,7 @@ public State breakOnlyIfInnerLevelsThenFitOnOneLine(boolean keepIndentWhenInline @Override public State inlineSuffix() { + @SuppressWarnings("for-rollout:DifferentNameButSame") Optional lastLevelBroken = levelNode.maybeExplore( "inlineSuffix", state, @@ -265,7 +279,7 @@ private Optional handle_breakOnlyIfInnerLevelsThenFitOnOneLine( State state, State brokenState, boolean keepIndent, - Obs.ExplorationNode explorationNode) { + @SuppressWarnings("for-rollout:DifferentNameButSame") Obs.ExplorationNode explorationNode) { // Note: we are not checking if the brokenState produced one extra line compared to state, as this can be // misleading if there is no level but a single comment that got reflowed onto multiple lines (see palantir-11). @@ -302,7 +316,7 @@ private Optional tryInlinePrefixOntoCurrentLine( int maxWidth, State state, boolean keepIndent, - Obs.ExplorationNode explorationNode) { + @SuppressWarnings("for-rollout:DifferentNameButSame") Obs.ExplorationNode explorationNode) { // Find the last level, skipping empty levels (that contain nothing, or are made up // entirely of other empty levels). // Last level because there might be other in-between levels after the initial break like `new @@ -376,6 +390,7 @@ private Optional tryInlineSuffix( commentsHelper, maxWidth, state, explorationNode, lastLevelBeforeSuffix, isSimpleInliningSoFar); } + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") private Optional tryBreakInnerLevel( CommentsHelper commentsHelper, int maxWidth, @@ -472,7 +487,11 @@ private static Optional tryBreakInnerLevel_acceptInlineChain( .markAccepted()); } - @SuppressWarnings("for-rollout:NullAway") + @SuppressWarnings({ + "for-rollout:NullAway", + "for-rollout:ThrowSpecificExceptions", + "for-rollout:UnnecessaryDefaultInEnumSwitch" + }) private static Optional tryBreakInnerLevel_checkInner( CommentsHelper commentsHelper, int maxWidth, @@ -570,13 +589,14 @@ private State tryToLayOutLevelOnOneLine( int maxWidth, State state, SplitsBreaks splitsBreaks, - Obs.ExplorationNode explorationNode) { + @SuppressWarnings("for-rollout:DifferentNameButSame") Obs.ExplorationNode explorationNode) { for (int i = 0; i < splitsBreaks.splits().size(); ++i) { if (i > 0) { state = splitsBreaks.breaks().get(i - 1).computeBreaks(state, false); } + @SuppressWarnings("for-rollout:PreferredInterfaceType") List split = splitsBreaks.splits().get(i); float splitWidth = getWidth(split); boolean enoughRoom = state.column() + splitWidth <= maxWidth; @@ -606,7 +626,10 @@ private static SplitsBreaks splitByBreaks(List docs) { /** Compute breaks for a {@link Level} that spans multiple lines. */ private State computeBroken( - CommentsHelper commentsHelper, int maxWidth, State state, Obs.ExplorationNode explorationNode) { + CommentsHelper commentsHelper, + int maxWidth, + State state, + @SuppressWarnings("for-rollout:DifferentNameButSame") Obs.ExplorationNode explorationNode) { SplitsBreaks splitsBreaks = memoizedSplitsBreaks.get(); if (!splitsBreaks.breaks().isEmpty()) { @@ -637,7 +660,7 @@ private State computeBreakAndSplit( State state, Optional optBreakDoc, List split, - Obs.ExplorationNode explorationNode) { + @SuppressWarnings("for-rollout:DifferentNameButSame") Obs.ExplorationNode explorationNode) { float breakWidth = optBreakDoc.isPresent() ? optBreakDoc.get().getWidth() : 0.0F; float splitWidth = getWidth(split); @@ -663,7 +686,7 @@ private static State computeSplit( int maxWidth, List docs, State state, - Obs.ExplorationNode explorationNode) { + @SuppressWarnings("for-rollout:DifferentNameButSame") Obs.ExplorationNode explorationNode) { for (Doc doc : docs) { state = doc.computeBreaks(commentsHelper, maxWidth, state, explorationNode); } diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/doc/NoopSink.java b/palantir-java-format/src/main/java/com/palantir/javaformat/doc/NoopSink.java index 42e25296c..eafe97e26 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/doc/NoopSink.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/doc/NoopSink.java @@ -37,6 +37,7 @@ public FinishLevelNode writeLevelNode(int levelNodeId, int parentExplorationId, return acceptedExplorationId -> {}; } + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") @Override public String getOutput() { throw new RuntimeException("Not supposed to get the output"); diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/DebugRenderer.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/DebugRenderer.java index 9dc276e98..61a9ab9cc 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/DebugRenderer.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/DebugRenderer.java @@ -44,12 +44,15 @@ public class DebugRenderer { private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + + @SuppressWarnings("for-rollout:NonFinalStaticField") private static Path publicDir = Paths.get("../debugger/public"); static Path getOutputFile() { return publicDir.resolve("output.js"); } + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") static void render( JavaInput javaInput, OpsOutput opsOutput, @@ -83,6 +86,7 @@ private static String outputAsString(JavaOutput javaOutput) { return output.toString(); } + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") private static String opsJson(OpsOutput opsOutput) { ArrayNode arrayNode = OBJECT_MAPPER.createArrayNode(); @@ -144,6 +148,7 @@ private static String opsJson(OpsOutput opsOutput) { } } + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") private static String jsonEscapedString(String javaInput) { try { return OBJECT_MAPPER.writeValueAsString(javaInput); diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/DimensionHelpers.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/DimensionHelpers.java index a03983b42..5721fe463 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/DimensionHelpers.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/DimensionHelpers.java @@ -101,6 +101,7 @@ private static Iterable> reorderBySourcePosition(DequeGiven {@code int @A @B [][] @C []}, adds {@code [[@A, @B], [@C]]} to dims and returns {@code int}. */ + @SuppressWarnings("for-rollout:InconsistentOverloads") private static Tree extractDims(Deque> dims, Tree node) { switch (node.getKind()) { case ARRAY_TYPE: diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/FormatFileCallable.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/FormatFileCallable.java index d73ad787c..04a522351 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/FormatFileCallable.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/FormatFileCallable.java @@ -53,6 +53,7 @@ public String call() throws FormatterException { return formatFile(formatter); } + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") private String formatReplacements(Formatter formatter) throws FormatterException { ImmutableList replacements = formatter.getFormatReplacements(input, characterRanges(input).asRanges()); @@ -83,6 +84,7 @@ private String fixImports(String input) throws FormatterException { } private RangeSet characterRanges(String input) { + @SuppressWarnings("for-rollout:UnnecessaryFinal") final RangeSet characterRanges = TreeRangeSet.create(); if (parameters.characterRanges().isEmpty() diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/Formatter.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/Formatter.java index 561d74895..22577e6bb 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/Formatter.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/Formatter.java @@ -118,7 +118,10 @@ public static Formatter createFormatter(JavaFormatterOptions options) { * @return javaOutput the output produced */ static JavaOutput format( - final JavaInput javaInput, JavaFormatterOptions options, CommentsHelper commentsHelper, boolean debugMode) + @SuppressWarnings("for-rollout:UnnecessaryFinal") final JavaInput javaInput, + JavaFormatterOptions options, + CommentsHelper commentsHelper, + boolean debugMode) throws FormatterException { Context context = new Context(); @@ -163,10 +166,12 @@ static JavaOutput format( return javaOutput; } + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") static JCCompilationUnit parseJcCompilationUnit(Context context, String sourceText) throws FormatterException { DiagnosticCollector diagnostics = new DiagnosticCollector<>(); context.put(DiagnosticListener.class, diagnostics); Options.instance(context).put("--enable-preview", "true"); + @SuppressWarnings("for-rollout:InitializeInline") JCCompilationUnit unit; JavacFileManager fileManager = new JavacFileManager(context, true, UTF_8); try { @@ -176,6 +181,7 @@ static JCCompilationUnit parseJcCompilationUnit(Context context, String sourceTe throw new RuntimeException(e); } SimpleJavaFileObject source = new SimpleJavaFileObject(URI.create("source"), JavaFileObject.Kind.SOURCE) { + @SuppressWarnings({"for-rollout:CheckedExceptionNotThrown", "for-rollout:PreferredInterfaceType"}) @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { return sourceText; @@ -203,7 +209,9 @@ static int getRuntimeVersion() { @SuppressWarnings("for-rollout:ThrowError") private static JavaInputAstVisitor createVisitor( - final String className, final OpsBuilder builder, final JavaFormatterOptions options) { + @SuppressWarnings("for-rollout:UnnecessaryFinal") final String className, + @SuppressWarnings("for-rollout:UnnecessaryFinal") final OpsBuilder builder, + @SuppressWarnings("for-rollout:UnnecessaryFinal") final JavaFormatterOptions options) { try { return Class.forName(className) .asSubclass(JavaInputAstVisitor.class) diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/ImportOrderer.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/ImportOrderer.java index 1ba037e11..a9ff306ff 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/ImportOrderer.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/ImportOrderer.java @@ -63,6 +63,7 @@ public static String reorderImports(String text) throws FormatterException { } private String reorderImports() throws FormatterException { + @SuppressWarnings("for-rollout:InitializeInline") int firstImportStart; Optional maybeFirstImport = findIdentifier(0, IMPORT_OR_CLASS_START); if (!maybeFirstImport.isPresent() || !tokenAt(maybeFirstImport.get()).equals("import")) { diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInput.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInput.java index e13aaa0f3..58c8ff6ba 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInput.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInput.java @@ -359,6 +359,7 @@ static ImmutableList buildToks(String text, ImmutableSet stopTok context.put(DiagnosticListener.class, diagnosticCollector); Log log = Log.instance(context); log.useSource(new SimpleJavaFileObject(URI.create("Source.java"), Kind.SOURCE) { + @SuppressWarnings({"for-rollout:CheckedExceptionNotThrown", "for-rollout:PreferredInterfaceType"}) @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { return text; @@ -384,7 +385,9 @@ public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOExcept ? t.stringVal() // Unicode escapes removed. : originalTokText; char tokText0 = tokText.charAt(0); // The token's first character. + @SuppressWarnings("for-rollout:UnnecessaryFinal") final boolean isToken; // Is this tok a token? + @SuppressWarnings("for-rollout:UnnecessaryFinal") final boolean isNumbered; // Is this tok numbered? (tokens and comments) String extraNewline = null; // Extra newline at end? List strings = new ArrayList<>(); @@ -558,7 +561,7 @@ private static boolean isParamComment(Tok tok) { * @return the {@code 0}-based {@link Range} of tokens * @throws FormatterException on formatting errors */ - @SuppressWarnings("for-rollout:NullAway") + @SuppressWarnings({"for-rollout:DefaultLocale", "for-rollout:NullAway"}) Range characterRangeToTokenRange(int offset, int length) throws FormatterException { int requiredLength = offset + length; if (requiredLength > text.length()) { diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java index e94d81221..c9a98fa3c 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaInputAstVisitor.java @@ -919,6 +919,7 @@ public boolean visitEnumDeclaration(ClassTree node) { return false; } + @SuppressWarnings("for-rollout:UnnecessaryDefaultInEnumSwitch") @Override public Void visitMemberReference(MemberReferenceTree node, Void unused) { sync(node); @@ -1749,6 +1750,7 @@ private boolean ambiguousUnaryOperator(UnaryTree node, String operatorName) { return true; } + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") @Override public Void visitPrimitiveType(PrimitiveTypeTree node, Void unused) { sync(node); @@ -2222,6 +2224,7 @@ protected List visitModifiers( return visitModifiers(modifiersTree.getAnnotations(), annotationsDirection, declarationAnnotationBreak); } + @SuppressWarnings("for-rollout:PreferredInterfaceType") private List visitModifiers( List annotationTrees, Direction annotationsDirection, @@ -2943,6 +2946,7 @@ private boolean shouldHaveColumnLimit(ExpressionTree expr) { } /** Returns the simple names of expressions in a "." chain. */ + @SuppressWarnings("for-rollout:PreferredInterfaceType") private List simpleNames(Deque stack) { ImmutableList.Builder simpleNames = ImmutableList.builder(); OUTER: @@ -3206,6 +3210,7 @@ private boolean isFormatMethod(List arguments) { private static final Pattern FORMAT_SPECIFIER = Pattern.compile("%|\\{[0-9]\\}"); private boolean isStringConcat(ExpressionTree first) { + @SuppressWarnings("for-rollout:UnnecessaryFinal") final boolean[] stringConcat = {false}; new TreeScanner() { @Override @@ -3229,7 +3234,9 @@ public void scan(JCTree tree) { } private boolean isFormatString(ExpressionTree first) { + @SuppressWarnings("for-rollout:UnnecessaryFinal") final boolean[] stringLiteral = {true}; + @SuppressWarnings("for-rollout:UnnecessaryFinal") final boolean[] formatString = {false}; new TreeScanner() { @Override @@ -3343,6 +3350,7 @@ static int rowLength(List row) { @SuppressWarnings("for-rollout:NullAway") private Integer actualColumn(ExpressionTree expression) { + @SuppressWarnings("for-rollout:PreferredInterfaceType") Map positionToColumnMap = builder.getInput().getPositionToColumnMap(); return positionToColumnMap.get(builder.actualStartColumn(getStartPosition(expression))); } @@ -3536,6 +3544,7 @@ private void maybeAddDims(Deque> annotations) { * @param annotations an ordered list of type annotations grouped by dimension (e.g. {@code [[@A, @B], [@C]]} for * {@code int @A [] @B @C []} */ + @SuppressWarnings("for-rollout:InconsistentOverloads") private void maybeAddDims(Deque dimExpressions, Deque> annotations) { boolean lastWasAnnotation = false; while (builder.peekToken().isPresent()) { diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaOutput.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaOutput.java index 44c6c8b3e..b311adcec 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaOutput.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavaOutput.java @@ -307,6 +307,7 @@ private Range expandToBreakableRegions(Range iRange) { return Range.closedOpen(loTok, hiTok + 1); } + @SuppressWarnings("for-rollout:PreferredInterfaceType") private RangeSet partialFormatRanges() { return inputMetadata.partialFormatRanges(); } diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavacTokens.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavacTokens.java index 705837412..de3d587a5 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavacTokens.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JavacTokens.java @@ -34,6 +34,7 @@ class JavacTokens { /** The lexer eats terminal comments, so feed it one we don't care about. */ // TODO(b/33103797): fix javac and remove the work-around + @SuppressWarnings("for-rollout:PreferredInterfaceType") private static final CharSequence EOF_COMMENT = "\n//EOF"; /** An unprocessed input token, including whitespace and comments. */ @@ -130,6 +131,7 @@ protected Comment processComment(int pos, int endPos, CommentStyle style) { return new CommentWithTextAndPosition(pos, endPos, new AccessibleReader(fac, buf, buf.length), style); } + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") private char[] getRawCharactersReflectively(int beginIndex, int endIndex) { Object instance; try { diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JsonSink.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JsonSink.java index 7ef3d7afc..8b3034840 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/JsonSink.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/JsonSink.java @@ -86,6 +86,7 @@ public FinishLevelNode writeLevelNode(int levelNodeId, int parentExplorationId, return acceptedExplorationId -> json.put("acceptedExplorationId", acceptedExplorationId); } + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") @Override public String getOutput() { try { diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/Main.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/Main.java index 169bb962d..cf4e29010 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/Main.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/Main.java @@ -63,7 +63,9 @@ public Main(PrintWriter outWriter, PrintWriter errWriter, InputStream inStream) */ public static void main(String[] args) { int result; + @SuppressWarnings("for-rollout:SystemOut") PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out, UTF_8)); + @SuppressWarnings("for-rollout:SystemOut") PrintWriter err = new PrintWriter(new OutputStreamWriter(System.err, UTF_8)); try { Main formatter = new Main(out, err, System.in); @@ -183,6 +185,7 @@ private int formatFiles(CommandLineOptions parameters, JavaFormatterOptions opti return allOk ? 0 : 1; } + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") private int formatStdin(CommandLineOptions parameters, JavaFormatterOptions options) { String input; try { @@ -216,6 +219,7 @@ private int formatStdin(CommandLineOptions parameters, JavaFormatterOptions opti } /** Parses and validates command-line flags. */ + @SuppressWarnings("for-rollout:SystemOut") public static CommandLineOptions processArgs(String... args) throws UsageException { CommandLineOptions parameters; try { diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/RemoveUnusedImports.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/RemoveUnusedImports.java index aac2dd165..f947a0a9a 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/RemoveUnusedImports.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/RemoveUnusedImports.java @@ -76,7 +76,10 @@ public class RemoveUnusedImports { private static final class UnusedImportScanner extends TreePathScanner { private final Set usedNames = new LinkedHashSet<>(); + + @SuppressWarnings("for-rollout:PreferredInterfaceType") private final Multimap> usedInJavadoc = HashMultimap.create(); + final JavacTrees trees; final DocTreeScanner docTreeSymbolScanner; @@ -102,7 +105,7 @@ 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 + @SuppressWarnings({"unchecked", "for-rollout:ThrowSpecificExceptions"}) // reflection @Override public Void visitCase(CaseTree tree, Void unused) { if (CASE_TREE_GET_LABELS != null) { @@ -200,7 +203,8 @@ public Void visitIdentifier(IdentifierTree node, Void aVoid) { } } - public static String removeUnusedImports(final String contents) throws FormatterException { + public static String removeUnusedImports(@SuppressWarnings("for-rollout:UnnecessaryFinal") final String contents) + throws FormatterException { Context context = new Context(); JCCompilationUnit unit = parse(context, contents); if (unit == null) { diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/StringWrapper.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/StringWrapper.java index 945bf8e0f..bd4804980 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/StringWrapper.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/StringWrapper.java @@ -48,7 +48,9 @@ /** Wraps string literals that exceed the column limit. */ public final class StringWrapper { /** Reflows string literals in the given Java source code that extend past the given column limit. */ - static String wrap(final int columnLimit, String input, Formatter formatter) throws FormatterException { + static String wrap( + @SuppressWarnings("for-rollout:UnnecessaryFinal") final int columnLimit, String input, Formatter formatter) + throws FormatterException { if (!longLines(columnLimit, input)) { // fast path return input; @@ -113,14 +115,16 @@ private static ImmutableSet> rangesAfterAppliedReplacements( return outputRanges.build(); } - @SuppressWarnings("for-rollout:NullAway") - private static TreeRangeMap getReflowReplacements(int columnLimit, final String input) + @SuppressWarnings({"for-rollout:DifferentNameButSame", "for-rollout:NullAway"}) + private static TreeRangeMap getReflowReplacements( + int columnLimit, @SuppressWarnings("for-rollout:UnnecessaryFinal") final String input) throws FormatterException { JCTree.JCCompilationUnit unit = parse(input, /* allowStringFolding= */ false); String separator = Newlines.guessLineSeparator(input); // Paths to string literals that extend past the column limit. List toFix = new ArrayList<>(); + @SuppressWarnings({"for-rollout:DifferentNameButSame", "for-rollout:UnnecessaryFinal"}) final Position.LineMap lineMap = unit.getLineMap(); new TreePathScanner() { @Override @@ -326,6 +330,7 @@ private static String reflow( * Flattens the given binary expression tree, and extracts the subset that contains the given path and any adjacent * nodes that are also string literals. */ + @SuppressWarnings({"for-rollout:DifferentNameButSame", "for-rollout:PreferredInterfaceType"}) private static List flatten( String input, JCTree.JCCompilationUnit unit, TreePath path, TreePath parent, AtomicBoolean firstInChain) { List flat = new ArrayList<>(); diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/Trees.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/Trees.java index 8b3b5646a..aead55e4b 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/Trees.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/Trees.java @@ -48,6 +48,7 @@ static int getEndPosition(Tree expression, TreePath path) { } /** Returns the source text for the node. */ + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") static String getSourceForNode(Tree node, TreePath path) { CharSequence source; try { diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/java14/Java14InputAstVisitor.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/java14/Java14InputAstVisitor.java index 9c2e0f706..d7c696d7a 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/java14/Java14InputAstVisitor.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/java14/Java14InputAstVisitor.java @@ -96,7 +96,7 @@ protected List getPermitsClause(ClassTree node) { } } - @SuppressWarnings("for-rollout:NullAway") + @SuppressWarnings({"for-rollout:NullAway", "for-rollout:ThrowSpecificExceptions"}) @Override public Void visitBindingPattern(BindingPatternTree node, Void unused) { sync(node); @@ -221,6 +221,7 @@ public void visitRecordDeclaration(ClassTree node) { if (node.getMembers() == null) { token(";"); } else { + @SuppressWarnings("for-rollout:PreferredInterfaceType") List members = node.getMembers().stream() .filter(t -> (TreeInfo.flags((JCTree) t) & Flags.GENERATED_MEMBER) == 0) .collect(toImmutableList()); @@ -229,6 +230,7 @@ public void visitRecordDeclaration(ClassTree node) { dropEmptyDeclarations(); } + @SuppressWarnings("for-rollout:DifferentNameButSame") private static ImmutableList recordVariables(ClassTree node) { return node.getMembers().stream() .filter(JCTree.JCVariableDecl.class::isInstance) @@ -256,7 +258,7 @@ public Void visitInstanceOf(InstanceOfTree node, Void unused) { return null; } - @SuppressWarnings("for-rollout:NullAway") + @SuppressWarnings({"for-rollout:NullAway", "for-rollout:UnnecessaryDefaultInEnumSwitch"}) @Override public Void visitCase(CaseTree node, Void unused) { sync(node); @@ -290,6 +292,7 @@ public Void visitCase(CaseTree node, Void unused) { builder.close(); } + @SuppressWarnings("for-rollout:UnnecessaryFinal") final ExpressionTree guard = getGuard(node); if (guard != null) { builder.breakToFill(" "); @@ -362,6 +365,7 @@ private static Method maybeGetMethod(Class c, String name) { } } + @SuppressWarnings("for-rollout:ThrowSpecificExceptions") private static Object invoke(Method m, Object target) { try { return m.invoke(target); @@ -371,7 +375,7 @@ private static Object invoke(Method m, Object target) { } @SuppressWarnings({"NullableProblems", "for-rollout:NullAway"}) - protected ExpressionTree getGuard(final CaseTree node) { + protected ExpressionTree getGuard(@SuppressWarnings("for-rollout:UnnecessaryFinal") final CaseTree node) { return null; } } diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/java21/Java21InputAstVisitor.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/java21/Java21InputAstVisitor.java index e9911ae31..bb72562e7 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/java21/Java21InputAstVisitor.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/java21/Java21InputAstVisitor.java @@ -37,7 +37,7 @@ public Java21InputAstVisitor(OpsBuilder builder, int indentMultiplier) { } @Override - protected ExpressionTree getGuard(final CaseTree node) { + protected ExpressionTree getGuard(@SuppressWarnings("for-rollout:UnnecessaryFinal") final CaseTree node) { return node.getGuard(); } diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocFormatter.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocFormatter.java index 4c4aefe15..623630b20 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocFormatter.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocFormatter.java @@ -56,6 +56,7 @@ public String formatJavadoc(String input, int blockIndent) { return makeSingleLineIfPossible(blockIndent, result); } + @SuppressWarnings("for-rollout:UnnecessaryDefaultInEnumSwitch") private String render(List input, int blockIndent) { JavadocWriter output = new JavadocWriter(blockIndent, maxLineLength); for (Token token : input) { diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocLexer.java b/palantir-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocLexer.java index 0c86a8da3..21c336a97 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocLexer.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/java/javadoc/JavadocLexer.java @@ -554,6 +554,7 @@ private static boolean hasMultipleNewlines(String s) { */ private static final Pattern LITERAL_PATTERN = compile("^.[^ \t\n@<{}*]*", DOTALL); + @SuppressWarnings("for-rollout:ConstantPatternCompile") private static Pattern fullCommentPattern() { return compile("^", DOTALL); } diff --git a/palantir-java-format/src/test/java/com/palantir/javaformat/java/AospImportStyleTest.java b/palantir-java-format/src/test/java/com/palantir/javaformat/java/AospImportStyleTest.java index 9401b1299..273952fc1 100644 --- a/palantir-java-format/src/test/java/com/palantir/javaformat/java/AospImportStyleTest.java +++ b/palantir-java-format/src/test/java/com/palantir/javaformat/java/AospImportStyleTest.java @@ -41,6 +41,7 @@ public AospImportStyleTest(String input, String reordered) { this.reordered = reordered; } + @SuppressWarnings("for-rollout:PreferredInterfaceType") @ParameterizedClass.Parameters(name = "{index}: {0}") public static List parameters() { // Inputs are provided as three-dimensional arrays. Each element of the outer array is a test diff --git a/palantir-java-format/src/test/java/com/palantir/javaformat/java/ArrayDimensionTest.java b/palantir-java-format/src/test/java/com/palantir/javaformat/java/ArrayDimensionTest.java index d57bf396c..e24e1b926 100644 --- a/palantir-java-format/src/test/java/com/palantir/javaformat/java/ArrayDimensionTest.java +++ b/palantir-java-format/src/test/java/com/palantir/javaformat/java/ArrayDimensionTest.java @@ -30,6 +30,7 @@ @Execution(ExecutionMode.CONCURRENT) @ExtendWith(ParameterizedClass.class) public class ArrayDimensionTest { + @SuppressWarnings("for-rollout:PreferredInterfaceType") @ParameterizedClass.Parameters public static Iterable parameters() { String[] inputs = { diff --git a/palantir-java-format/src/test/java/com/palantir/javaformat/java/DiagnosticTest.java b/palantir-java-format/src/test/java/com/palantir/javaformat/java/DiagnosticTest.java index 86f07b19c..f402056a8 100644 --- a/palantir-java-format/src/test/java/com/palantir/javaformat/java/DiagnosticTest.java +++ b/palantir-java-format/src/test/java/com/palantir/javaformat/java/DiagnosticTest.java @@ -54,6 +54,7 @@ public void restoreLocale() throws Exception { @Test public void parseError() throws Exception { + @SuppressWarnings("for-rollout:StringConcatToTextBlock") String input = Joiner.on('\n') .join( "public class InvalidSyntax {", diff --git a/palantir-java-format/src/test/java/com/palantir/javaformat/java/FileBasedTests.java b/palantir-java-format/src/test/java/com/palantir/javaformat/java/FileBasedTests.java index e0daff88f..f03b97293 100644 --- a/palantir-java-format/src/test/java/com/palantir/javaformat/java/FileBasedTests.java +++ b/palantir-java-format/src/test/java/com/palantir/javaformat/java/FileBasedTests.java @@ -77,6 +77,7 @@ public FileBasedTests(Class testClass, String testDirName) { this.fullTestPath = Paths.get("src/test/resources").resolve(resourcePrefix); } + @SuppressWarnings("for-rollout:DefaultLocale") public static void assumeJavaVersionForTest(String testName) { Optional maybeJavaVersion = VERSIONED_TESTS.inverse().get(testName).stream().collect(toOptional()); @@ -84,6 +85,7 @@ public static void assumeJavaVersionForTest(String testName) { Formatter.getRuntimeVersion() >= version, String.format("Not running on jdk %d or later", version))); } + @SuppressWarnings({"for-rollout:MissingDefault", "for-rollout:StatementSwitchToExpressionSwitch"}) public List paramsAsNameInputOutput() throws IOException { ClassLoader classLoader = testClass.getClassLoader(); Map inputs = new TreeMap<>(); diff --git a/palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java b/palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java index 397bd1528..21f0a186c 100644 --- a/palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java +++ b/palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java @@ -32,6 +32,7 @@ @Execution(ExecutionMode.CONCURRENT) public class FormatterIntegrationTest { + @SuppressWarnings("for-rollout:NonFinalStaticField") private static FileBasedTests tests = new FileBasedTests(FormatterIntegrationTest.class, "testdata"); @ParameterizedClass.Parameters(name = "{0}") diff --git a/palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterTest.java b/palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterTest.java index 1f2da75ac..7bf54dc38 100644 --- a/palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterTest.java +++ b/palantir-java-format/src/test/java/com/palantir/javaformat/java/FormatterTest.java @@ -47,6 +47,7 @@ public void testFormatAosp() throws Exception { // don't forget to misspell "long", or you will be mystified for a while String input = "class A{void b(){while(true){weCanBeCertainThatThisWillEndUpGettingWrapped(" + "because, it, is, just, so, very, very, very, very, looong);}}}"; + @SuppressWarnings("for-rollout:StringConcatToTextBlock") String expectedOutput = Joiner.on("\n") .join( "class A {", @@ -88,7 +89,9 @@ public void testFormatNonJavaFiles() throws Exception { @Test public void testFormatStdinStdoutWithDashFlag() 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)); @@ -107,7 +110,9 @@ public void testFormatStdinStdoutWithDashFlag() throws Exception { @Test public void testFormatLengthUpToEOF() 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"); @@ -219,6 +224,7 @@ public void voidMethod() 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;", @@ -249,6 +255,7 @@ public void importsFixedIfRequested() throws FormatterException { + " @Nullable List xs;\n" + "}\n"; String output = Formatter.create().formatSourceAndFixImports(input); + @SuppressWarnings("for-rollout:StringConcatToTextBlock") String expect = "package com.google.example;\n\n" + "import java.util.List;\n" + "import javax.annotations.Nullable;\n\n" @@ -394,6 +401,7 @@ public void throwsFormatterException() throws Exception { @Test public void blankLinesImportComment() throws FormatterException { + @SuppressWarnings("for-rollout:StringConcatToTextBlock") String withBlank = "package p;\n" + "\n" + "/** test */\n" @@ -403,6 +411,7 @@ public 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"; diff --git a/palantir-java-format/src/test/java/com/palantir/javaformat/java/GoogleImportStyleTest.java b/palantir-java-format/src/test/java/com/palantir/javaformat/java/GoogleImportStyleTest.java index e3b0cb412..32530841b 100644 --- a/palantir-java-format/src/test/java/com/palantir/javaformat/java/GoogleImportStyleTest.java +++ b/palantir-java-format/src/test/java/com/palantir/javaformat/java/GoogleImportStyleTest.java @@ -41,6 +41,7 @@ public GoogleImportStyleTest(String input, String reordered) { this.reordered = reordered; } + @SuppressWarnings("for-rollout:PreferredInterfaceType") @ParameterizedClass.Parameters(name = "{index}: {0}") public static List parameters() { // Inputs are provided as three-dimensional arrays. Each element of the outer array is a test diff --git a/palantir-java-format/src/test/java/com/palantir/javaformat/java/ImportOrdererUtils.java b/palantir-java-format/src/test/java/com/palantir/javaformat/java/ImportOrdererUtils.java index deaad4108..9f4529490 100644 --- a/palantir-java-format/src/test/java/com/palantir/javaformat/java/ImportOrdererUtils.java +++ b/palantir-java-format/src/test/java/com/palantir/javaformat/java/ImportOrdererUtils.java @@ -19,7 +19,8 @@ import com.google.common.base.Joiner; public final class ImportOrdererUtils { - public static Object[] createRow(String[][] inputAndOutput) { + @SuppressWarnings("for-rollout:AvoidObjectArrays") + public static Object[] createRow(@SuppressWarnings("for-rollout:AvoidObjectArrays") String[][] inputAndOutput) { assertThat(inputAndOutput).hasLength(2); String[] input = inputAndOutput[0]; String[] output = inputAndOutput[1]; diff --git a/palantir-java-format/src/test/java/com/palantir/javaformat/java/MainTest.java b/palantir-java-format/src/test/java/com/palantir/javaformat/java/MainTest.java index f97717ca3..c9acb95f4 100644 --- a/palantir-java-format/src/test/java/com/palantir/javaformat/java/MainTest.java +++ b/palantir-java-format/src/test/java/com/palantir/javaformat/java/MainTest.java @@ -100,6 +100,7 @@ public void preserveOriginalFile() throws Exception { } catch (UnsupportedOperationException e) { return; } + @SuppressWarnings("for-rollout:SystemOut") Main main = new Main( new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out, UTF_8)), true), new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.err, UTF_8)), true), @@ -155,6 +156,7 @@ public void javadoc() throws Exception { }; InputStream in = new ByteArrayInputStream(joiner.join(input).getBytes(UTF_8)); StringWriter out = new StringWriter(); + @SuppressWarnings("for-rollout:SystemOut") Main main = new Main( new PrintWriter(out, true), new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.err, UTF_8)), true), @@ -190,6 +192,7 @@ public void imports() throws Exception { }; InputStream in = new ByteArrayInputStream(joiner.join(input).getBytes(UTF_8)); StringWriter out = new StringWriter(); + @SuppressWarnings("for-rollout:SystemOut") Main main = new Main( new PrintWriter(out, true), new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.err, UTF_8)), true), @@ -230,6 +233,7 @@ public void optimizeImportsDoesNotLeaveEmptyLines() throws Exception { InputStream in = new ByteArrayInputStream(joiner.join(input).getBytes(UTF_8)); StringWriter out = new StringWriter(); + @SuppressWarnings("for-rollout:SystemOut") Main main = new Main( new PrintWriter(out, true), new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.err, UTF_8)), true), @@ -258,6 +262,7 @@ public void importRemovalLines() throws Exception { "}", }; StringWriter out = new StringWriter(); + @SuppressWarnings("for-rollout:SystemOut") Main main = new Main( new PrintWriter(out, true), new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.err, UTF_8)), true), @@ -484,6 +489,7 @@ public void reflowLongStrings() throws Exception { }; InputStream in = new ByteArrayInputStream(joiner.join(input).getBytes(UTF_8)); StringWriter out = new StringWriter(); + @SuppressWarnings("for-rollout:SystemOut") Main main = new Main( new PrintWriter(out, true), new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.err, UTF_8)), true), @@ -510,6 +516,7 @@ public void noReflowLongStrings() throws Exception { }; InputStream in = new ByteArrayInputStream(joiner.join(input).getBytes(UTF_8)); StringWriter out = new StringWriter(); + @SuppressWarnings("for-rollout:SystemOut") Main main = new Main( new PrintWriter(out, true), new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.err, UTF_8)), true), diff --git a/palantir-java-format/src/test/java/com/palantir/javaformat/java/PartialFormattingTest.java b/palantir-java-format/src/test/java/com/palantir/javaformat/java/PartialFormattingTest.java index 689296134..29f244117 100644 --- a/palantir-java-format/src/test/java/com/palantir/javaformat/java/PartialFormattingTest.java +++ b/palantir-java-format/src/test/java/com/palantir/javaformat/java/PartialFormattingTest.java @@ -42,6 +42,7 @@ @ExtendWith(ParameterizedClass.class) public final class PartialFormattingTest { + @SuppressWarnings("for-rollout:PreferredInterfaceType") @ParameterizedClass.Parameters public static List parameters() { return ImmutableList.copyOf(new Object[][] {{"\n"}, {"\r"}, {"\r\n"}}); diff --git a/palantir-java-format/src/test/java/com/palantir/javaformat/java/RemoveUnusedImportsCaseLabelsTest.java b/palantir-java-format/src/test/java/com/palantir/javaformat/java/RemoveUnusedImportsCaseLabelsTest.java index 0d6a194af..d855d7d85 100644 --- a/palantir-java-format/src/test/java/com/palantir/javaformat/java/RemoveUnusedImportsCaseLabelsTest.java +++ b/palantir-java-format/src/test/java/com/palantir/javaformat/java/RemoveUnusedImportsCaseLabelsTest.java @@ -28,6 +28,7 @@ final class RemoveUnusedImportsCaseLabelsTest { @Test void preserveTypesInCaseLabels() throws FormatterException { Assumptions.assumeTrue(Formatter.getRuntimeVersion() >= 17, "Not running on jdk 17 or later"); + @SuppressWarnings("for-rollout:StringConcatToTextBlock") String input = Joiner.on('\n') .join( "package example;", diff --git a/palantir-java-format/src/test/java/com/palantir/javaformat/java/RemoveUnusedImportsTest.java b/palantir-java-format/src/test/java/com/palantir/javaformat/java/RemoveUnusedImportsTest.java index cdea6fe04..6f8fd94ea 100644 --- a/palantir-java-format/src/test/java/com/palantir/javaformat/java/RemoveUnusedImportsTest.java +++ b/palantir-java-format/src/test/java/com/palantir/javaformat/java/RemoveUnusedImportsTest.java @@ -31,6 +31,7 @@ @ExtendWith(ParameterizedClass.class) public class RemoveUnusedImportsTest { + @SuppressWarnings("for-rollout:PreferredInterfaceType") @ParameterizedClass.Parameters(name = "{index}: {0}") public static List parameters() { String[][][] inputsOutputs = { diff --git a/palantir-java-format/src/test/java/com/palantir/javaformat/java/StringWrapperIntegrationTest.java b/palantir-java-format/src/test/java/com/palantir/javaformat/java/StringWrapperIntegrationTest.java index f5fa126b0..f60a13ce5 100644 --- a/palantir-java-format/src/test/java/com/palantir/javaformat/java/StringWrapperIntegrationTest.java +++ b/palantir-java-format/src/test/java/com/palantir/javaformat/java/StringWrapperIntegrationTest.java @@ -31,6 +31,7 @@ @Execution(ExecutionMode.CONCURRENT) public class StringWrapperIntegrationTest { + @SuppressWarnings("for-rollout:NonFinalStaticField") private static FileBasedTests tests = new FileBasedTests(StringWrapperIntegrationTest.class); @ParameterizedClass.Parameters(name = "{0}") diff --git a/palantir-java-format/src/test/java/com/palantir/javaformat/jupiter/ParameterizedClass.java b/palantir-java-format/src/test/java/com/palantir/javaformat/jupiter/ParameterizedClass.java index ee28d5436..4e49ab28e 100644 --- a/palantir-java-format/src/test/java/com/palantir/javaformat/jupiter/ParameterizedClass.java +++ b/palantir-java-format/src/test/java/com/palantir/javaformat/jupiter/ParameterizedClass.java @@ -44,6 +44,7 @@ import org.junit.platform.commons.util.ReflectionUtils; public final class ParameterizedClass implements TestTemplateInvocationContextProvider { + @SuppressWarnings("for-rollout:NonFinalStaticField") private static ExtensionContext.Namespace namespace = ExtensionContext.Namespace.create(ParameterizedClass.class); /** @@ -193,8 +194,8 @@ private static List allParameters(Method method) { result.add(entry); } return result; - } else if (parameters instanceof Object[]) { - return Arrays.asList((Object[]) parameters); + } else if (parameters instanceof Object[] array) { + return Arrays.asList(array); } else { throw new TestInstantiationException("Invalid return type. Must be iterable of arrays"); }