Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<Replacement> replacements = new SnippetFormatter()
.format(snippetKind, source, rangesFromRegions(regions), initialIndent, includeComments);
if (idempotent(source, regions, replacements)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ private static List<Replacement> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@
*/
public abstract class ExecutableTransform implements TransformAction<TransformParameters.None> {

@SuppressWarnings("for-rollout:NonFinalStaticField")
private static Logger logger = Logging.getLogger(ExecutableTransform.class);

@InputArtifact
public abstract Provider<FileSystemLocation> getInputArtifact();

@SuppressWarnings("for-rollout:ThrowSpecificExceptions")
@Override
public void transform(TransformOutputs outputs) {
File inputFile = getInputArtifact().get().getAsFile();
Expand All @@ -58,6 +60,7 @@ public void transform(TransformOutputs outputs) {
}
}

@SuppressWarnings("for-rollout:ThrowSpecificExceptions")
private static void makeFileExecutable(Path pathToExe) {
try {
Set<PosixFilePermission> existingPermissions = Files.getPosixFilePermissions(pathToExe);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SingleFileDiff> parseGitDiffOutput(String gitOutput) {
return Streams.stream(Splitter.on(SEPARATOR).omitEmptyStrings().split(gitOutput))
Expand Down Expand Up @@ -96,6 +97,7 @@ static Stream<SingleFileDiff> parseGitDiffOutput(String gitOutput) {
});
}

@SuppressWarnings("for-rollout:SystemOut")
private static void format(FormatterService formatter, SingleFileDiff diff) {
String input;
try {
Expand Down Expand Up @@ -161,6 +163,7 @@ private static RangeSet<Integer> lineRangesToCharRanges(String input, RangeSet<I
Iterators.addAll(lines, new LineOffsetIterator(input));
lines.add(input.length() + 1);

@SuppressWarnings("for-rollout:UnnecessaryFinal")
final RangeSet<Integer> characterRanges = TreeRangeSet.create();
for (Range<Integer> lineRange :
lineRanges.subRangeSet(Range.closedOpen(0, lines.size() - 1)).asRanges()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ FormatterFunc createFormat() {
}
}

@SuppressWarnings("for-rollout:ThrowSpecificExceptions")
private static void ensureImplementationNotDirectlyLoadable() {
try {
PalantirJavaFormatStep.class.getClassLoader().loadClass(IMPL_CLASS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ private static Optional<FormatterService> 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();
}
Expand Down Expand Up @@ -195,6 +196,7 @@ private static Optional<Sdk> getProjectJdk(Project project) {
return Optional.ofNullable(ProjectRootManager.getInstance(project).getProjectSdk());
}

@SuppressWarnings("for-rollout:ThrowSpecificExceptions")
private static URL[] toUrlsUnchecked(List<Path> paths) {
return paths.stream()
.map(path -> {
Expand All @@ -207,6 +209,7 @@ private static URL[] toUrlsUnchecked(List<Path> paths) {
.toArray(URL[]::new);
}

@SuppressWarnings("for-rollout:ThrowSpecificExceptions")
private static List<Path> listDirAsUrlsUnchecked(Path dir) {
try (Stream<Path> list = Files.list(dir)) {
return list.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public void run() {
request.getDocumentText().length(),
request.getFormattingRanges()));
}
@SuppressWarnings("for-rollout:PreferredInterfaceType")
List<Replacement> replacements =
formatterService.get().getFormatReplacements(request.getDocumentText(), toRanges(request));
if (logger.isDebugEnabled()) {
Expand Down Expand Up @@ -140,6 +141,7 @@ public static String applyReplacements(String input, Collection<Replacement> rep
return writer.toString();
}

@SuppressWarnings("for-rollout:PreferredInterfaceType")
private static Collection<Range<Integer>> toRanges(AsyncFormattingRequest request) {
if (isWholeFile(request)) {
// The IDE sometimes passes invalid ranges when the file is unsaved before invoking the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Optional<String> getImplementationVersion() {
return Optional.ofNullable(FormatterProvider.getPluginDescriptor().getVersion());
}

@SuppressWarnings("for-rollout:ThrowSpecificExceptions")
Optional<String> computeFormatterVersion() {
return getImplementationClassPath().map(classpath -> classpath.stream()
.flatMap(uri -> {
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static class BenchmarkState {

final List<String> filesToFormat = getFilesToFormat();

@SuppressWarnings("for-rollout:ThrowSpecificExceptions")
private static List<String> getFilesToFormat() {
Path srcJavaFormatFiles = Paths.get(".")
.toAbsolutePath()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public BootstrappingFormatterService(Path jdkPath, Integer jdkMajorVersion, List
this.implementationClassPath = implementationClassPath;
}

@SuppressWarnings("for-rollout:ThrowSpecificExceptions")
@Override
public ImmutableList<Replacement> getFormatReplacements(String input, Collection<Range<Integer>> ranges) {
try {
Expand All @@ -59,6 +60,7 @@ public ImmutableList<Replacement> getFormatReplacements(String input, Collection
}
}

@SuppressWarnings("for-rollout:ThrowSpecificExceptions")
@Override
public String formatSourceReflowStringsAndFixImports(String input) {
try {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> runWithStdin(List<String> command, String input, Optional<Path> workingDirectory)
throws IOException {
ProcessBuilder processBuilder = new ProcessBuilder().command(command);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public NativeImageFormatterService(Path nativeImagePath) {
this.nativeImagePath = nativeImagePath;
}

@SuppressWarnings("for-rollout:ThrowSpecificExceptions")
@Override
public ImmutableList<Replacement> getFormatReplacements(String input, Collection<Range<Integer>> ranges) {
try {
Expand All @@ -63,6 +64,7 @@ public ImmutableList<Replacement> getFormatReplacements(String input, Collection
}
}

@SuppressWarnings("for-rollout:ThrowSpecificExceptions")
@Override
public String formatSourceReflowStringsAndFixImports(String input) {
try {
Expand All @@ -72,6 +74,7 @@ public String formatSourceReflowStringsAndFixImports(String input) {
}
}

@SuppressWarnings("for-rollout:ThrowSpecificExceptions")
@Override
public String fixImports(String input) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public FormatterException(Iterable<FormatterDiagnostic> diagnostics) {
this.diagnostics = ImmutableList.copyOf(diagnostics);
}

@SuppressWarnings("for-rollout:PreferredInterfaceType")
public List<FormatterDiagnostic> diagnostics() {
return diagnostics;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public interface Cases<R> {
*/
static class Json extends JsonSerializer<BreakBehaviour> {

@SuppressWarnings("for-rollout:ThrowSpecificExceptions")
@Override
public void serialize(BreakBehaviour value, JsonGenerator gen, SerializerProvider serializers)
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public PartialInlineability partialInlineability() {
* ...)); // long arguments
* </pre>
*/
@SuppressWarnings("for-rollout:UnescapedEntity")
@Default
public Complexity complexity() {
return Complexity.SIMPLE;
Expand Down Expand Up @@ -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);
}
Expand Down
Loading