From 2bd3849b1f94d9fa887937a2976327d71140aed8 Mon Sep 17 00:00:00 2001 From: svc-excavator-bot Date: Mon, 9 Dec 2019 13:43:03 +0000 Subject: [PATCH] Excavator: Upgrades Baseline to the latest version --- build.gradle | 2 +- .../javaformat/gradle/FormatDiff.java | 40 ++++++++++--------- .../PalantirJavaFormatProviderPlugin.java | 10 +++-- .../javaformat/gradle/FormatDiffTest.java | 3 +- .../intellij/PalantirCodeStyleManager.java | 9 +++-- .../java/com/palantir/javaformat/Indent.java | 11 +++-- .../com/palantir/javaformat/OpsBuilder.java | 25 +++++++----- .../javaformat/doc/JsonDocVisitor.java | 5 ++- .../com/palantir/javaformat/doc/Level.java | 16 ++++---- .../javaformat/java/DebugRenderer.java | 8 +++- .../palantir/javaformat/java/JavaInput.java | 4 +- .../javaformat/java/JavaInputAstVisitor.java | 3 +- .../javaformat/java/StringWrapper.java | 15 ++++--- .../java/CommandLineOptionsParserTest.java | 9 +++-- .../javaformat/java/DiagnosticTest.java | 3 +- .../javaformat/java/FormatterTest.java | 3 +- .../palantir/javaformat/java/MainTest.java | 3 +- .../java/PartialFormattingTest.java | 10 ++--- 18 files changed, 104 insertions(+), 75 deletions(-) diff --git a/build.gradle b/build.gradle index 12d51f3fd..0341d609d 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.39.0' + classpath 'com.palantir.baseline:gradle-baseline-java:2.41.0' 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.13.1' 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 76f7dd47f..a5acfe725 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 @@ -72,25 +72,27 @@ public static void formatDiff(Path dirToFormat, FormatterService formatter) /** Parses the filenames and edited ranges out of `git diff -U0`. */ @VisibleForTesting static Stream parseGitDiffOutput(String gitOutput) { - return Streams.stream(Splitter.on(SEPARATOR).omitEmptyStrings().split(gitOutput)).flatMap(singleFileDiff -> { - Matcher filenameMatcher = FILENAME.matcher(singleFileDiff); - if (!filenameMatcher.find()) { - System.err.println("Failed to find filename"); - return Stream.empty(); - } - Path path = Paths.get(filenameMatcher.group("filename")); - - RangeSet lineRanges = TreeRangeSet.create(); - Matcher hunk = HUNK.matcher(singleFileDiff); - while (hunk.find()) { - int firstLineOfHunk = Integer.parseInt(hunk.group("startLineOneIndexed")) - 1; - int hunkLength = Optional.ofNullable(hunk.group("numLines")).map(Integer::parseInt).orElse(1); - Range rangeZeroIndexed = Range.closedOpen(firstLineOfHunk, firstLineOfHunk + hunkLength); - lineRanges.add(rangeZeroIndexed); - } - - return Stream.of(new SingleFileDiff(path, lineRanges)); - }); + return Streams.stream(Splitter.on(SEPARATOR).omitEmptyStrings().split(gitOutput)) + .flatMap(singleFileDiff -> { + Matcher filenameMatcher = FILENAME.matcher(singleFileDiff); + if (!filenameMatcher.find()) { + System.err.println("Failed to find filename"); + return Stream.empty(); + } + Path path = Paths.get(filenameMatcher.group("filename")); + + RangeSet lineRanges = TreeRangeSet.create(); + Matcher hunk = HUNK.matcher(singleFileDiff); + while (hunk.find()) { + int firstLineOfHunk = Integer.parseInt(hunk.group("startLineOneIndexed")) - 1; + int hunkLength = Optional.ofNullable(hunk.group("numLines")).map(Integer::parseInt).orElse(1); + Range rangeZeroIndexed = + Range.closedOpen(firstLineOfHunk, firstLineOfHunk + hunkLength); + lineRanges.add(rangeZeroIndexed); + } + + return Stream.of(new SingleFileDiff(path, lineRanges)); + }); } private static void format(FormatterService formatter, SingleFileDiff diff) { diff --git a/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/PalantirJavaFormatProviderPlugin.java b/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/PalantirJavaFormatProviderPlugin.java index 6fe503090..5218c258b 100644 --- a/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/PalantirJavaFormatProviderPlugin.java +++ b/gradle-palantir-java-format/src/main/java/com/palantir/javaformat/gradle/PalantirJavaFormatProviderPlugin.java @@ -38,10 +38,12 @@ public void apply(Project rootProject) { conf.setCanBeConsumed(false); conf.defaultDependencies(deps -> { - deps.add(rootProject.getDependencies().create(ImmutableMap.of( - "group", "com.palantir.javaformat", - "name", "palantir-java-format", - "version", JavaFormatExtension.class.getPackage().getImplementationVersion()))); + deps.add(rootProject + .getDependencies() + .create(ImmutableMap.of( + "group", "com.palantir.javaformat", + "name", "palantir-java-format", + "version", JavaFormatExtension.class.getPackage().getImplementationVersion()))); }); }); diff --git a/gradle-palantir-java-format/src/test/groovy/com/palantir/javaformat/gradle/FormatDiffTest.java b/gradle-palantir-java-format/src/test/groovy/com/palantir/javaformat/gradle/FormatDiffTest.java index 1561a0a8f..789548128 100644 --- a/gradle-palantir-java-format/src/test/groovy/com/palantir/javaformat/gradle/FormatDiffTest.java +++ b/gradle-palantir-java-format/src/test/groovy/com/palantir/javaformat/gradle/FormatDiffTest.java @@ -37,7 +37,8 @@ import org.junit.jupiter.api.io.TempDir; class FormatDiffTest { - @TempDir Path repo; + @TempDir + Path repo; @Test void parsing_git_diff_output_works() throws IOException { diff --git a/idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirCodeStyleManager.java b/idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirCodeStyleManager.java index 75f9d62a3..df1d96139 100644 --- a/idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirCodeStyleManager.java +++ b/idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirCodeStyleManager.java @@ -206,7 +206,9 @@ private static URL toUrlUnchecked(URI uri) { private static URL[] listDirAsUrlsUnchecked(Path dir) { try (Stream list = Files.list(dir)) { - return list.map(Path::toUri).map(PalantirCodeStyleManager::toUrlUnchecked).toArray(URL[]::new); + return list.map(Path::toUri) + .map(PalantirCodeStyleManager::toUrlUnchecked) + .toArray(URL[]::new); } catch (IOException e) { throw new RuntimeException("Couldn't list dir: " + dir.toString(), e); } @@ -229,8 +231,9 @@ private static FormatterService createFormatter(Optional> implementati URL[] implementationUrls = implementationClassPath .map(implementationUris -> { log.debug("Using palantir-java-format implementation defined by URIs: {}", implementationUris); - return implementationUris.stream().map(PalantirCodeStyleManager::toUrlUnchecked).toArray(URL[] - ::new); + return implementationUris.stream() + .map(PalantirCodeStyleManager::toUrlUnchecked) + .toArray(URL[]::new); }) .orElseGet(() -> { // Load from the jars bundled with the plugin. diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/Indent.java b/palantir-java-format/src/main/java/com/palantir/javaformat/Indent.java index b914cbbe2..925e3b81e 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/Indent.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/Indent.java @@ -65,9 +65,14 @@ public String toString() { /** A conditional function, whose value depends on whether a break was taken. */ @JsonTypeName("if") public static final class If extends Indent { - @JsonProperty private final BreakTag condition; - @JsonProperty private final Indent thenIndent; - @JsonProperty private final Indent elseIndent; + @JsonProperty + private final BreakTag condition; + + @JsonProperty + private final Indent thenIndent; + + @JsonProperty + private final Indent elseIndent; private If(BreakTag condition, Indent thenIndent, Indent elseIndent) { this.condition = condition; 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 3450c5227..4e65b61fa 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 @@ -337,8 +337,8 @@ public void token( * (for example) we're guessing at an optional token. */ if (realOrImaginary == Token.RealOrImaginary.REAL) { - throw new FormattingError(diagnostic(String.format( - "expected token: '%s'; generated %s instead", peekToken().orElse(null), token))); + throw new FormattingError(diagnostic( + String.format("expected token: '%s'; generated %s instead", peekToken().orElse(null), token))); } } } @@ -523,10 +523,12 @@ public OpsOutput build() { if (tokBefore.isNewline()) { newlines++; } else if (tokBefore.isComment()) { - tokOps.put(j, Break.make( - tokBefore.isSlashSlashComment() ? FillMode.FORCED : FillMode.UNIFIED, - "", - tokenOp.getPlusIndentCommentsBefore())); + tokOps.put( + j, + Break.make( + tokBefore.isSlashSlashComment() ? FillMode.FORCED : FillMode.UNIFIED, + "", + tokenOp.getPlusIndentCommentsBefore())); tokOps.putAll(j, makeComment(tokBefore)); space = tokBefore.isSlashStarComment(); newlines = 0; @@ -566,10 +568,13 @@ public OpsOutput build() { && tokenOp.breakAndIndentTrailingComment() .isPresent()); if (breakAfter) { - tokOps.put(tokAfterPos, Break.make( - FillMode.FORCED, - "", - tokenOp.breakAndIndentTrailingComment().orElse(Const.ZERO))); + tokOps.put( + tokAfterPos, + Break.make( + FillMode.FORCED, + "", + tokenOp.breakAndIndentTrailingComment() + .orElse(Const.ZERO))); } else { tokOps.put(tokAfterPos, SPACE); } diff --git a/palantir-java-format/src/main/java/com/palantir/javaformat/doc/JsonDocVisitor.java b/palantir-java-format/src/main/java/com/palantir/javaformat/doc/JsonDocVisitor.java index 8833ecf8b..2d1b85fe2 100644 --- a/palantir-java-format/src/main/java/com/palantir/javaformat/doc/JsonDocVisitor.java +++ b/palantir-java-format/src/main/java/com/palantir/javaformat/doc/JsonDocVisitor.java @@ -47,7 +47,10 @@ public JsonNode visitComment(Comment doc) { @Override public JsonNode visitToken(Token doc) { - return MAPPER.createObjectNode().put("type", "token").put("flat", doc.getFlat()).put("id", doc.id()); + return MAPPER.createObjectNode() + .put("type", "token") + .put("flat", doc.getFlat()) + .put("id", doc.id()); } @Override 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 6f00f0003..1e4c22a9e 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 @@ -267,9 +267,8 @@ private Optional handleBreakOnlyIfInnerLevelsThenFitOnOneLine( if (keepIndent) { newState = newState.withIndentIncrementedBy(getPlusIndent()); } - return Optional.of( - tryToLayOutLevelOnOneLine( - commentsHelper, maxWidth, newState, memoizedSplitsBreaks.get(), explorationNode)); + return Optional.of(tryToLayOutLevelOnOneLine( + commentsHelper, maxWidth, newState, memoizedSplitsBreaks.get(), explorationNode)); } return Optional.empty(); } @@ -347,12 +346,11 @@ private static Optional tryBreakLastLevel_acceptInlineChain( // Note: computeBreaks, not computeBroken, so it can try to do this logic recursively for the // lastLevel - return Optional.of( - explorationNode - .newChildNode(lastLevel, state) - .explore("end tryBreakLastLevel chain", state, exp -> - lastLevel.computeBreaks(commentsHelper, maxWidth, state, exp)) - .markAccepted()); + return Optional.of(explorationNode + .newChildNode(lastLevel, state) + .explore("end tryBreakLastLevel chain", state, exp -> + lastLevel.computeBreaks(commentsHelper, maxWidth, state, exp)) + .markAccepted()); } private static Optional tryBreakLastLevel_checkInner( 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 60801fcda..9dc276e98 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 @@ -96,11 +96,15 @@ private static String opsJson(OpsOutput opsOutput) { json.put("type", "token"); json.put( "beforeText", - inputToken.getToksBefore().stream().map(Input.Tok::getText).collect(Collectors.joining())); + inputToken.getToksBefore().stream() + .map(Input.Tok::getText) + .collect(Collectors.joining())); json.put("text", inputToken.getTok().getText()); json.put( "afterText", - inputToken.getToksAfter().stream().map(Input.Tok::getText).collect(Collectors.joining())); + inputToken.getToksAfter().stream() + .map(Input.Tok::getText) + .collect(Collectors.joining())); json.put("hue", computeHue(token)); } if (op instanceof Break) { 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 d43153054..a3b3056a4 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 @@ -644,8 +644,8 @@ public RangeSet characterRangesToTokenRanges(Collection> RangeSet tokenRangeSet = TreeRangeSet.create(); for (Range characterRange0 : characterRanges) { Range characterRange = characterRange0.canonical(DiscreteDomain.integers()); - tokenRangeSet.add(characterRangeToTokenRange(characterRange.lowerEndpoint(), characterRange.upperEndpoint() - - characterRange.lowerEndpoint())); + tokenRangeSet.add(characterRangeToTokenRange( + characterRange.lowerEndpoint(), characterRange.upperEndpoint() - characterRange.lowerEndpoint())); } return tokenRangeSet; } 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 43d977cd4..459a11c89 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 @@ -1572,7 +1572,8 @@ private static List handleStream(List parts) { } private static Stream indexes(Stream stream, Predicate predicate) { - return Streams.mapWithIndex(stream, (x, i) -> predicate.apply(x) ? i : -1).filter(x -> x != -1); + return Streams.mapWithIndex(stream, (x, i) -> predicate.apply(x) ? i : -1) + .filter(x -> x != -1); } @Override 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 2627cf36f..439bb450d 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 @@ -328,14 +328,13 @@ private static String reflow( } return lines.stream() - .collect( - joining( - "\"" - + separator - + Strings.repeat(" ", (first0 ? firstLineStartColumn + 4 : textStartColumn - 2)) - + "+ \"", - "\"", - "\"")); + .collect(joining( + "\"" + + separator + + Strings.repeat(" ", (first0 ? firstLineStartColumn + 4 : textStartColumn - 2)) + + "+ \"", + "\"", + "\"")); } /** 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 7d3e1ef7f..886cd5a5d 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 @@ -34,7 +34,8 @@ @Execution(ExecutionMode.CONCURRENT) public class CommandLineOptionsParserTest { - @TempDir public Path testFolder; + @TempDir + public Path testFolder; @Test public void defaults() { @@ -94,8 +95,10 @@ public void lines() { .lines() .asRanges()) .containsExactly( - Range.closedOpen(0, 2), Range.closedOpen(3, 5), Range.closedOpen(6, 8), Range.closedOpen( - 9, 11)); + Range.closedOpen(0, 2), + Range.closedOpen(3, 5), + Range.closedOpen(6, 8), + Range.closedOpen(9, 11)); } @Test 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 be5fcf439..3d492b094 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 @@ -36,7 +36,8 @@ @Execution(ExecutionMode.CONCURRENT) public class DiagnosticTest { - @TempDir public Path testFolder; + @TempDir + public Path testFolder; private Locale backupLocale; 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 cf61a517c..1a2284ada 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 @@ -38,7 +38,8 @@ @Execution(ExecutionMode.CONCURRENT) public final class FormatterTest { - @TempDir public Path testFolder; + @TempDir + public Path testFolder; @Test public void testFormatAosp() throws Exception { 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 925b6cff4..b04e8d37e 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 @@ -43,7 +43,8 @@ @Execution(ExecutionMode.CONCURRENT) public class MainTest { - @TempDir public Path testFolder; + @TempDir + public Path testFolder; // PrintWriter instances used below are hard-coded to use system-default line separator. private final Joiner joiner = Joiner.on(System.lineSeparator()); 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 e9167e4d1..b45aa36d3 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 @@ -47,7 +47,8 @@ public static List parameters() { return ImmutableList.copyOf(new Object[][] {{"\n"}, {"\r"}, {"\r\n"}}); } - @TempDir public Path testFolder; + @TempDir + public Path testFolder; private final String newline; @@ -595,10 +596,9 @@ public void testGetFormatReplacementRanges() throws Exception { assertThat(ranges).hasSize(1); Replacement replacement = ranges.get(0); assertThat(replacement.getReplacementString()) - .isEqualTo( - lines( - "", // - " void f() {}")); + .isEqualTo(lines( + "", // + " void f() {}")); int replaceFrom = input.indexOf("void f") - newline.length(); assertThat(replacement.getReplaceRange().lowerEndpoint()).isEqualTo(replaceFrom); }