diff --git a/.baseline/checkstyle/checkstyle.xml b/.baseline/checkstyle/checkstyle.xml index 0de6d7769..5d8bc6ef7 100644 --- a/.baseline/checkstyle/checkstyle.xml +++ b/.baseline/checkstyle/checkstyle.xml @@ -468,7 +468,6 @@ - diff --git a/build.gradle b/build.gradle index 40cb94deb..bf251b637 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ buildscript { classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' classpath 'com.netflix.nebula:nebula-publishing-plugin:14.1.1' classpath 'com.netflix.nebula:gradle-info-plugin:5.2.0' - classpath 'com.palantir.baseline:gradle-baseline-java:2.31.0' + classpath 'com.palantir.baseline:gradle-baseline-java:2.35.2' classpath 'gradle.plugin.org.inferred:gradle-processors:3.1.0' classpath 'com.palantir.gradle.gitversion:gradle-git-version:0.12.2' classpath 'com.palantir.gradle.consistentversions:gradle-consistent-versions:1.12.4' 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 9f22441a4..3450c5227 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 @@ -563,7 +563,8 @@ public OpsOutput build() { if (tokAfter.isComment()) { boolean breakAfter = tokAfter.isJavadocComment() || (tokAfter.isSlashStarComment() - && tokenOp.breakAndIndentTrailingComment().isPresent()); + && tokenOp.breakAndIndentTrailingComment() + .isPresent()); if (breakAfter) { tokOps.put(tokAfterPos, Break.make( FillMode.FORCED, @@ -636,7 +637,10 @@ public OpsOutput build() { afterForcedBreak = isForcedBreak(op); } } - return ImmutableOpsOutput.builder().ops(newOps.build()).inputMetadata(inputMetadataBuilder.build()).build(); + return ImmutableOpsOutput.builder() + .ops(newOps.build()) + .inputMetadata(inputMetadataBuilder.build()) + .build(); } private static boolean isNonNlsComment(Input.Tok tokAfter) { diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/doc/Break.java b/palantir-java-format/src/main/java/com/palantir/javaformat/doc/Break.java index e352860cf..2a7ac1aa1 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/doc/Break.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/doc/Break.java @@ -60,7 +60,12 @@ public static Break make(FillMode fillMode, String flat, Indent plusIndent) { * @return the new {@code Break} */ public static Break make(FillMode fillMode, String flat, Indent plusIndent, Optional optTag) { - return builder().fillMode(fillMode).flat(flat).plusIndent(plusIndent).optTag(optTag).build(); + return builder() + .fillMode(fillMode) + .flat(flat) + .plusIndent(plusIndent) + .optTag(optTag) + .build(); } /** @@ -69,7 +74,11 @@ public static Break make(FillMode fillMode, String flat, Indent plusIndent, Opti * @return the new forced {@code Break} */ public static Break makeForced() { - return builder().fillMode(FillMode.FORCED).flat("").plusIndent(Indent.Const.ZERO).build(); + return builder() + .fillMode(FillMode.FORCED) + .flat("") + .plusIndent(Indent.Const.ZERO) + .build(); } /** diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/doc/State.java b/palantir-java-format/src/main/java/com/palantir/javaformat/doc/State.java index 51a21bd20..83ce152a9 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/doc/State.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/doc/State.java @@ -114,7 +114,11 @@ State breakTaken(BreakTag breakTag, boolean broken) { * not commit to the indent just yet though, so lastIndent stays the same. */ State withIndentIncrementedBy(Indent plusIndent) { - return builder().from(this).indent(indent() + plusIndent.eval(this)).mustBreak(false).build(); + return builder() + .from(this) + .indent(indent() + plusIndent.eval(this)) + .mustBreak(false) + .build(); } /** Reset any accumulated indent to the same value as {@code lastIndent}. */ @@ -177,15 +181,24 @@ State withMustBreak(boolean mustBreak) { } State withNewBranch() { - return builder().from(this).branchingCoefficient(branchingCoefficient() + 1).build(); + return builder() + .from(this) + .branchingCoefficient(branchingCoefficient() + 1) + .build(); } State withLevelState(Level level, LevelState levelState) { - return builder().from(this).levelStates(levelStates().set(level, levelState)).build(); + return builder() + .from(this) + .levelStates(levelStates().set(level, levelState)) + .build(); } State withTokState(Comment comment, TokState tokState) { - return builder().from(this).tokStates(tokStates().set(comment, tokState)).build(); + return builder() + .from(this) + .tokStates(tokStates().set(comment, tokState)) + .build(); } public static class Builder extends ImmutableState.Builder {} 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 d8b8bfbe3..d43153054 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 @@ -561,8 +561,10 @@ Range characterRangeToTokenRange(int offset, int length) throws Formatt // 0 stands for "format the line under the cursor" length = 1; } - ImmutableCollection enclosed = - getPositionTokenMap().subRangeMap(Range.closedOpen(offset, offset + length)).asMapOfRanges().values(); + ImmutableCollection enclosed = getPositionTokenMap() + .subRangeMap(Range.closedOpen(offset, offset + length)) + .asMapOfRanges() + .values(); if (enclosed.isEmpty()) { return EMPTY_RANGE; } @@ -611,7 +613,10 @@ public ImmutableRangeMap getPositionTokenMap() { @Override public String toString() { - return MoreObjects.toStringHelper(this).add("tokens", tokens).add("super", super.toString()).toString(); + return MoreObjects.toStringHelper(this) + .add("tokens", tokens) + .add("super", super.toString()) + .toString(); } private JCCompilationUnit unit; 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 ee905d11c..7381c57ee 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 @@ -2403,7 +2403,9 @@ public Void visitModule(ModuleTree node, Void unused) { for (DirectiveTree directiveTree : node.getDirectives()) { markForPartialFormat(); builder.blankLineWanted( - previousDirective.map(k -> !k.equals(directiveTree.getKind())).orElse(false) + previousDirective + .map(k -> !k.equals(directiveTree.getKind())) + .orElse(false) ? BlankLineWanted.YES : BlankLineWanted.NO); builder.forcedBreak(); 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 25f6626cd..e8f0e8bb0 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 @@ -95,8 +95,9 @@ public int format(String... args) throws UsageException { } // TODO(someone): update this to always use Style.PALANTIR - JavaFormatterOptions options = - JavaFormatterOptions.builder().style(parameters.aosp() ? Style.AOSP : Style.GOOGLE).build(); + JavaFormatterOptions options = JavaFormatterOptions.builder() + .style(parameters.aosp() ? Style.AOSP : Style.GOOGLE) + .build(); if (parameters.stdin()) { return formatStdin(parameters, options); 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 841fa50c6..4b1dea7e8 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 @@ -247,7 +247,9 @@ private static RangeMap buildReplacements( endPosition = Math.max(CharMatcher.isNot(' ').indexIn(contents, endPosition), endPosition); String sep = Newlines.guessLineSeparator(contents); if (endPosition + sep.length() < contents.length() - && contents.subSequence(endPosition, endPosition + sep.length()).toString().equals(sep)) { + && contents.subSequence(endPosition, endPosition + sep.length()) + .toString() + .equals(sep)) { endPosition += sep.length(); } replacements.put(Range.closedOpen(importTree.getStartPosition(), endPosition), ""); @@ -258,7 +260,9 @@ private static RangeMap buildReplacements( private static String getSimpleName(JCImport importTree) { return importTree.getQualifiedIdentifier() instanceof JCIdent ? ((JCIdent) importTree.getQualifiedIdentifier()).getName().toString() - : ((JCFieldAccess) importTree.getQualifiedIdentifier()).getIdentifier().toString(); + : ((JCFieldAccess) importTree.getQualifiedIdentifier()) + .getIdentifier() + .toString(); } private static boolean isUnused( @@ -275,7 +279,9 @@ private static boolean isUnused( return true; } if (importTree.getQualifiedIdentifier() instanceof JCFieldAccess - && ((JCFieldAccess) importTree.getQualifiedIdentifier()).getIdentifier().contentEquals("*")) { + && ((JCFieldAccess) importTree.getQualifiedIdentifier()) + .getIdentifier() + .contentEquals("*")) { return false; } 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 efda0746e..8408a6962 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 @@ -56,7 +56,8 @@ static String getSourceForNode(Tree node, TreePath path) { } catch (IOException e) { throw new IOError(e); } - return source.subSequence(getStartPosition(node), getEndPosition(node, path)).toString(); + return source.subSequence(getStartPosition(node), getEndPosition(node, path)) + .toString(); } /** Returns the simple name of a (possibly qualified) method invocation expression. */ diff --git a/palantir-java-format/src/test/java/com/palantir/javaformat/NewlinesTest.java b/palantir-java-format/src/test/java/com/palantir/javaformat/NewlinesTest.java index 13a8125ab..1b41aa3de 100644 --- a/palantir-java-format/src/test/java/com/palantir/javaformat/NewlinesTest.java +++ b/palantir-java-format/src/test/java/com/palantir/javaformat/NewlinesTest.java @@ -26,27 +26,38 @@ public class NewlinesTest { @Test public void offsets() { - Truth.assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\nbar\n"))).containsExactly(0, 4, 8); - Truth.assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\nbar"))).containsExactly(0, 4); + Truth.assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\nbar\n"))) + .containsExactly(0, 4, 8); + Truth.assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\nbar"))) + .containsExactly(0, 4); - Truth.assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\rbar\r"))).containsExactly(0, 4, 8); - Truth.assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\rbar"))).containsExactly(0, 4); + Truth.assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\rbar\r"))) + .containsExactly(0, 4, 8); + Truth.assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\rbar"))) + .containsExactly(0, 4); - Truth.assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\r\nbar\r\n"))).containsExactly(0, 5, 10); - Truth.assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\r\nbar"))).containsExactly(0, 5); + Truth.assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\r\nbar\r\n"))) + .containsExactly(0, 5, 10); + Truth.assertThat(ImmutableList.copyOf(Newlines.lineOffsetIterator("foo\r\nbar"))) + .containsExactly(0, 5); } @Test public void lines() { - Truth.assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\nbar\n"))).containsExactly("foo\n", "bar\n"); - Truth.assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\nbar"))).containsExactly("foo\n", "bar"); + Truth.assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\nbar\n"))) + .containsExactly("foo\n", "bar\n"); + Truth.assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\nbar"))) + .containsExactly("foo\n", "bar"); - Truth.assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\rbar\r"))).containsExactly("foo\r", "bar\r"); - Truth.assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\rbar"))).containsExactly("foo\r", "bar"); + Truth.assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\rbar\r"))) + .containsExactly("foo\r", "bar\r"); + Truth.assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\rbar"))) + .containsExactly("foo\r", "bar"); Truth.assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\r\nbar\r\n"))) .containsExactly("foo\r\n", "bar\r\n"); - Truth.assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\r\nbar"))).containsExactly("foo\r\n", "bar"); + Truth.assertThat(ImmutableList.copyOf(Newlines.lineIterator("foo\r\nbar"))) + .containsExactly("foo\r\n", "bar"); } @Test diff --git a/palantir-java-format/src/test/java/com/palantir/javaformat/java/CommandLineOptionsParserTest.java b/palantir-java-format/src/test/java/com/palantir/javaformat/java/CommandLineOptionsParserTest.java index 6c6d19b82..7d3e1ef7f 100644 --- a/palantir-java-format/src/test/java/com/palantir/javaformat/java/CommandLineOptionsParserTest.java +++ b/palantir-java-format/src/test/java/com/palantir/javaformat/java/CommandLineOptionsParserTest.java @@ -71,12 +71,14 @@ public void stdin() { @Test public void aosp() { - assertThat(CommandLineOptionsParser.parse(Arrays.asList("-aosp")).aosp()).isTrue(); + assertThat(CommandLineOptionsParser.parse(Arrays.asList("-aosp")).aosp()) + .isTrue(); } @Test public void help() { - assertThat(CommandLineOptionsParser.parse(Arrays.asList("-help")).help()).isTrue(); + assertThat(CommandLineOptionsParser.parse(Arrays.asList("-help")).help()) + .isTrue(); } @Test @@ -104,17 +106,20 @@ public void offset() { @Test public void inPlace() { - assertThat(CommandLineOptionsParser.parse(Arrays.asList("-i", "A.java")).inPlace()).isTrue(); + assertThat(CommandLineOptionsParser.parse(Arrays.asList("-i", "A.java")).inPlace()) + .isTrue(); } @Test public void version() { - assertThat(CommandLineOptionsParser.parse(Arrays.asList("-v")).version()).isTrue(); + assertThat(CommandLineOptionsParser.parse(Arrays.asList("-v")).version()) + .isTrue(); } @Test public void skipSortingImports() { - assertThat(CommandLineOptionsParser.parse(Arrays.asList("--skip-sorting-imports")).sortImports()).isFalse(); + assertThat(CommandLineOptionsParser.parse(Arrays.asList("--skip-sorting-imports")).sortImports()) + .isFalse(); } @Test @@ -126,13 +131,15 @@ public void skipRemovingUnusedImports() { @Test public void dryRun() { - assertThat(CommandLineOptionsParser.parse(Arrays.asList("--dry-run")).dryRun()).isTrue(); + assertThat(CommandLineOptionsParser.parse(Arrays.asList("--dry-run")).dryRun()) + .isTrue(); assertThat(CommandLineOptionsParser.parse(Arrays.asList("-n")).dryRun()).isTrue(); } @Test public void setExitIfChanged() { - assertThat(CommandLineOptionsParser.parse(Arrays.asList("--set-exit-if-changed")).setExitIfChanged()).isTrue(); + assertThat(CommandLineOptionsParser.parse(Arrays.asList("--set-exit-if-changed")).setExitIfChanged()) + .isTrue(); } // TODO(cushon): consider handling this in the parser and reporting a more detailed error @@ -166,7 +173,8 @@ public void paramsFile() throws IOException { public void assumeFilename() { assertThat(CommandLineOptionsParser.parse(Arrays.asList("--assume-filename", "Foo.java")).assumeFilename()) .hasValue("Foo.java"); - assertThat(CommandLineOptionsParser.parse(Arrays.asList("Foo.java")).assumeFilename()).isEmpty(); + assertThat(CommandLineOptionsParser.parse(Arrays.asList("Foo.java")).assumeFilename()) + .isEmpty(); } @Test 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 46b316055..925b6cff4 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 @@ -103,7 +103,9 @@ public void preserveOriginalFile() throws Exception { @Test public void testMain() throws Exception { Process process = new ProcessBuilder(ImmutableList.of( - Paths.get(System.getProperty("java.home")).resolve("bin/java").toString(), + Paths.get(System.getProperty("java.home")) + .resolve("bin/java") + .toString(), "-cp", System.getProperty("java.class.path"), Main.class.getName())) @@ -400,7 +402,9 @@ public void exitIfChangedStdin() throws Exception { Path path = Files.createFile(testFolder.resolve("Test.java")); Files.write(path, "class Test {\n}\n".getBytes(UTF_8)); Process process = new ProcessBuilder(ImmutableList.of( - Paths.get(System.getProperty("java.home")).resolve("bin/java").toString(), + Paths.get(System.getProperty("java.home")) + .resolve("bin/java") + .toString(), "-cp", System.getProperty("java.class.path"), Main.class.getName(), @@ -423,7 +427,9 @@ public void exitIfChangedFiles() throws Exception { Path path = Files.createFile(testFolder.resolve("Test.java")); Files.write(path, "class Test {\n}\n".getBytes(UTF_8)); Process process = new ProcessBuilder(ImmutableList.of( - Paths.get(System.getProperty("java.home")).resolve("bin/java").toString(), + Paths.get(System.getProperty("java.home")) + .resolve("bin/java") + .toString(), "-cp", System.getProperty("java.class.path"), Main.class.getName(), diff --git a/palantir-java-format/src/test/java/com/palantir/javaformat/java/TypeNameClassifierTest.java b/palantir-java-format/src/test/java/com/palantir/javaformat/java/TypeNameClassifierTest.java index 793265181..f509159ab 100644 --- a/palantir-java-format/src/test/java/com/palantir/javaformat/java/TypeNameClassifierTest.java +++ b/palantir-java-format/src/test/java/com/palantir/javaformat/java/TypeNameClassifierTest.java @@ -65,9 +65,11 @@ public void typePrefixLength() { @Test public void ambiguousClass() { - assertThat(getPrefix("com.google.security.acl.proto2api.ACL.Entry.newBuilder")).hasValue(7); + assertThat(getPrefix("com.google.security.acl.proto2api.ACL.Entry.newBuilder")) + .hasValue(7); // A human would probably identify this as "class-shaped", but just looking // at the case we have to assume it could be something like `field1.field2.CONST`. - assertThat(getPrefix("com.google.security.acl.proto2api.ACL.newBuilder")).isEmpty(); + assertThat(getPrefix("com.google.security.acl.proto2api.ACL.newBuilder")) + .isEmpty(); } } 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 a85dc14ef..3494bb916 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 @@ -211,7 +211,9 @@ private static String findStringFormatTemplate(ExtensionContext extensionContext Method method = methods.get(0); - return AnnotationUtils.findAnnotation(method, Parameters.class).get().name(); + return AnnotationUtils.findAnnotation(method, Parameters.class) + .get() + .name(); }, String.class); }