From 182fd9a08c815e85aa1b2a7a67f59cfd21fc901a Mon Sep 17 00:00:00 2001 From: Nicolas Peters Date: Sat, 27 Apr 2024 23:04:10 +0200 Subject: [PATCH] Java 21: rebase + fix Unnamed pattern --- build.gradle | 2 +- .../javaformat/java/JavaInputAstVisitor.java | 39 ++++++----- palantir-java-format21/build.gradle | 2 +- palantir-java-format21/versions.lock | 65 +++++-------------- versions.lock | 6 +- 5 files changed, 45 insertions(+), 69 deletions(-) diff --git a/build.gradle b/build.gradle index 5ede706a..eeb1822f 100644 --- a/build.gradle +++ b/build.gradle @@ -38,7 +38,7 @@ allprojects { apply plugin: 'com.palantir.java-format' apply plugin: 'com.palantir.jakarta-package-alignment' group = 'com.palantir.javaformat' - version = rootProject.version + version = "2.44.1" repositories { mavenLocal() { metadataSources { mavenPom(); ignoreGradleMetadataRedirection() } } 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 b4428c64..3dfc8d37 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 @@ -390,7 +390,8 @@ public Void visitCompilationUnit(CompilationUnitTree node, Void unused) { return null; } - protected void handleModule(boolean first, CompilationUnitTree node) {} + protected void handleModule(boolean first, CompilationUnitTree node) { + } /** Skips over extra semi-colons at the top-level, or in a class member declaration lists. */ protected void dropEmptyDeclarations() { @@ -1005,7 +1006,7 @@ public Void visitForLoop(ForLoopTree node, Void unused) { builder.open(plusFour); builder.open( node.getInitializer().size() > 1 - && node.getInitializer().get(0).getKind() == Tree.Kind.EXPRESSION_STATEMENT + && node.getInitializer().get(0).getKind() == Tree.Kind.EXPRESSION_STATEMENT ? plusFour : ZERO); if (!node.getInitializer().isEmpty()) { @@ -1611,12 +1612,12 @@ private boolean handleLogStatement(MethodInvocationTree node) { private static List handleStream(List parts) { return indexes(parts.stream(), p -> { - if (!(p instanceof MethodInvocationTree)) { - return false; - } - Name name = getMethodName((MethodInvocationTree) p); - return Stream.of("stream", "parallelStream", "toBuilder").anyMatch(name::contentEquals); - }) + if (!(p instanceof MethodInvocationTree)) { + return false; + } + Name name = getMethodName((MethodInvocationTree) p); + return Stream.of("stream", "parallelStream", "toBuilder").anyMatch(name::contentEquals); + }) .collect(toList()); } @@ -1783,7 +1784,12 @@ public Void visitPrimitiveType(PrimitiveTypeTree node, Void unused) { } public boolean visit(Name name) { - token(name.toString()); + String value = name.toString(); + if (value.isEmpty()) { + token("_"); + } else { + token(value); + } return false; } @@ -2471,8 +2477,8 @@ public Void visitModule(ModuleTree node, Void unused) { markForPartialFormat(); builder.blankLineWanted( previousDirective - .map(k -> !k.equals(directiveTree.getKind())) - .orElse(false) + .map(k -> !k.equals(directiveTree.getKind())) + .orElse(false) ? BlankLineWanted.YES : BlankLineWanted.NO); builder.forcedBreak(); @@ -2926,7 +2932,7 @@ private void visitDotWithPrefix( *
  • {@code foo().bar()[0]} *
  • {@code foo().bar()[0][0]} * - * + *

    * Whereas an expression like a name {@code com.palantir.foo.bar.Baz} would not. */ private boolean shouldHaveColumnLimit(ExpressionTree expr) { @@ -3413,8 +3419,8 @@ int declareOne( builder.open( kind == DeclarationKind.PARAMETER - && (modifiers.isPresent() - && !modifiers.get().getAnnotations().isEmpty()) + && (modifiers.isPresent() + && !modifiers.get().getAnnotations().isEmpty()) ? plusFour : ZERO); { @@ -3519,7 +3525,7 @@ private void maybeAddDims(Deque> annotations) { * * @param dimExpressions an ordered list of dimension expressions (e.g. the {@code 0} in {@code new int[0]} * @param annotations an ordered list of type annotations grouped by dimension (e.g. {@code [[@A, @B], [@C]]} for - * {@code int @A [] @B @C []} + * {@code int @A [] @B @C []} */ private void maybeAddDims(Deque dimExpressions, Deque> annotations) { boolean lastWasAnnotation = false; @@ -3675,6 +3681,7 @@ protected void addBodyDeclarations( } } } + /** Gets the permits clause for the given node. This is only available in Java 15 and later. */ protected List getPermitsClause(ClassTree node) { return ImmutableList.of(); @@ -3762,7 +3769,7 @@ private Direction canLocalHaveHorizontalAnnotations(ModifiersTree modifiers) { } } return markerAnnotations <= 1 - && markerAnnotations == modifiers.getAnnotations().size() + && markerAnnotations == modifiers.getAnnotations().size() ? Direction.HORIZONTAL : Direction.VERTICAL; } diff --git a/palantir-java-format21/build.gradle b/palantir-java-format21/build.gradle index f04999d9..5b6eedd5 100644 --- a/palantir-java-format21/build.gradle +++ b/palantir-java-format21/build.gradle @@ -50,7 +50,7 @@ mainClassName = 'com.palantir.javaformat.java.Main' description = 'Palantir Java Format Java 21' dependencies { - implementation "com.palantir.javaformat:palantir-java-format:2.39" + implementation "com.palantir.javaformat:palantir-java-format:2.44.0-3-gc5a0bc7.dirty" testImplementation 'com.google.guava:guava-testlib' testImplementation 'com.google.truth:truth' testImplementation 'com.google.testing.compile:compile-testing' diff --git a/palantir-java-format21/versions.lock b/palantir-java-format21/versions.lock index e708dce4..fc5f426e 100644 --- a/palantir-java-format21/versions.lock +++ b/palantir-java-format21/versions.lock @@ -1,60 +1,33 @@ # Run ./gradlew --write-locks to regenerate this file -com.diffplug.durian:durian-collect:1.2.0 (3 constraints: 4d313bd2) -com.diffplug.durian:durian-core:1.2.0 (4 constraints: 2640ae56) -com.diffplug.durian:durian-io:1.2.0 (1 constraints: 1313c62d) -com.diffplug.durian:durian-swt.os:4.2.0 (1 constraints: c50945a9) -com.diffplug.spotless:spotless-lib:2.41.0 (2 constraints: ea24c1e5) -com.diffplug.spotless:spotless-lib-extra:2.41.0 (1 constraints: 47131c41) -com.diffplug.spotless:spotless-plugin-gradle:6.21.0 (1 constraints: 3b054e3b) -com.fasterxml.jackson.core:jackson-annotations:2.15.2 (2 constraints: c517c371) -com.fasterxml.jackson.core:jackson-core:2.15.2 (5 constraints: 4a5dbc98) -com.fasterxml.jackson.core:jackson-databind:2.15.2 (4 constraints: c14a9555) -com.fasterxml.jackson.datatype:jackson-datatype-guava:2.15.2 (1 constraints: 3c05403b) -com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.15.2 (1 constraints: 3c05403b) -com.fasterxml.jackson.module:jackson-module-parameter-names:2.15.2 (1 constraints: 3c05403b) -com.google.auto:auto-common:1.2.1 (2 constraints: 5a219b5a) -com.google.auto.service:auto-service:1.1.1 (1 constraints: 0505f435) -com.google.auto.service:auto-service-annotations:1.1.1 (1 constraints: 9c0f6a86) +com.fasterxml.jackson.core:jackson-annotations:2.16.1 (2 constraints: 0f27a8e4) +com.fasterxml.jackson.core:jackson-core:2.16.1 (5 constraints: 1b6b801e) +com.fasterxml.jackson.core:jackson-databind:2.16.1 (5 constraints: cd5d2e54) +com.fasterxml.jackson.datatype:jackson-datatype-guava:2.16.1 (1 constraints: 86142390) +com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.16.1 (1 constraints: 0d132339) +com.fasterxml.jackson.module:jackson-module-parameter-names:2.16.1 (1 constraints: 0d132339) com.google.code.findbugs:jsr305:3.0.2 (3 constraints: 571ca3f6) -com.google.errorprone:error_prone_annotations:2.22.0 (4 constraints: 51279d7c) -com.google.guava:failureaccess:1.0.1 (1 constraints: 140ae1b4) -com.google.guava:guava:32.1.2-jre (7 constraints: 7e6ddaa1) +com.google.errorprone:error_prone_annotations:2.23.0 (4 constraints: 4d27767b) +com.google.guava:failureaccess:1.0.2 (1 constraints: 150ae2b4) +com.google.guava:guava:33.0.0-jre (8 constraints: ec85ae15) com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava (1 constraints: bd17c918) com.google.j2objc:j2objc-annotations:2.8 (2 constraints: 9716ab11) -com.googlecode.concurrent-trees:concurrent-trees:2.6.1 (1 constraints: 761166da) -com.googlecode.javaewah:JavaEWAH:1.2.3 (1 constraints: 460e7e50) -com.squareup.okhttp3:okhttp:4.10.0 (1 constraints: f40938b3) -com.squareup.okio:okio-jvm:3.0.0 (1 constraints: 4d0c26fd) -dev.equo.ide:solstice:1.3.1 (1 constraints: 721158da) -org.checkerframework:checker-qual:3.35.0 (3 constraints: 1b224228) -org.derive4j:derive4j-annotation:1.1.1 (1 constraints: 0505f435) -org.eclipse.jgit:org.eclipse.jgit:6.6.0.202305301015-r (2 constraints: da2a65d5) -org.eclipse.platform:org.eclipse.osgi:3.18.300 (1 constraints: 5e0ad9c7) -org.functionaljava:functionaljava:4.8 (1 constraints: b0042b2c) -org.immutables:value:2.9.3 (1 constraints: 10051336) -org.jetbrains:annotations:13.0 (1 constraints: df0e795c) -org.jetbrains.kotlin:kotlin-stdlib:1.6.20 (3 constraints: 422e99b4) -org.jetbrains.kotlin:kotlin-stdlib-common:1.6.20 (2 constraints: 3c1b0a83) -org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.5.31 (1 constraints: e110f4d2) -org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.31 (1 constraints: fb0b19f9) -org.slf4j:slf4j-api:1.7.36 (2 constraints: 801849c0) -org.tukaani:xz:1.9 (1 constraints: 6b09e995) +com.palantir.javaformat:palantir-java-format:2.44.0-3-gc5a0bc7.dirty (1 constraints: af0ab1bf) +com.palantir.javaformat:palantir-java-format-spi:2.44.0-3-gc5a0bc7.dirty (1 constraints: 801882a8) +org.checkerframework:checker-qual:3.41.0 (3 constraints: 1a22f927) +org.functionaljava:functionaljava:4.8 (2 constraints: 3017b01b) [Test dependencies] -cglib:cglib-nodep:3.2.2 (1 constraints: 490ded24) +com.google.auto:auto-common:0.9 (1 constraints: be1116d7) com.google.auto.value:auto-value:1.5.3 (1 constraints: 1c121afb) com.google.auto.value:auto-value-annotations:1.10.1 (1 constraints: 8b0aa0c3) com.google.guava:guava-testlib:27.0.1-jre (1 constraints: aa067c53) com.google.testing.compile:compile-testing:0.15 (1 constraints: da04f230) com.google.truth:truth:1.1.5 (3 constraints: b92b54b9) com.google.truth.extensions:truth-java8-extension:0.37 (1 constraints: ef11ffe8) -com.netflix.nebula:nebula-test:10.0.0 (1 constraints: 3305273b) -junit:junit:4.13.2 (7 constraints: 796291b5) +junit:junit:4.13.2 (5 constraints: 10444717) net.bytebuddy:byte-buddy:1.12.21 (1 constraints: 7d0bbfea) -org.apiguardian:apiguardian-api:1.1.2 (7 constraints: 9d791b5f) +org.apiguardian:apiguardian-api:1.1.2 (6 constraints: 24695e60) org.assertj:assertj-core:3.24.2 (1 constraints: 3d05473b) -org.codehaus.groovy:groovy:3.0.6 (2 constraints: 1e1b476d) -org.hamcrest:hamcrest:2.2 (1 constraints: d20cdc04) org.hamcrest:hamcrest-core:1.3 (1 constraints: cc05fe3f) org.junit.jupiter:junit-jupiter:5.10.0 (1 constraints: 3805413b) org.junit.jupiter:junit-jupiter-api:5.10.0 (4 constraints: 3145aef5) @@ -62,10 +35,6 @@ org.junit.jupiter:junit-jupiter-engine:5.10.0 (1 constraints: 330efd49) org.junit.jupiter:junit-jupiter-migrationsupport:5.10.0 (1 constraints: 3805413b) org.junit.jupiter:junit-jupiter-params:5.10.0 (1 constraints: 330efd49) org.junit.platform:junit-platform-commons:1.10.0 (2 constraints: 2b211983) -org.junit.platform:junit-platform-engine:1.10.0 (3 constraints: ac2e4dc4) -org.junit.vintage:junit-vintage-engine:5.10.0 (1 constraints: 3805413b) -org.objenesis:objenesis:2.4 (1 constraints: ea0c8c0a) +org.junit.platform:junit-platform-engine:1.10.0 (1 constraints: d210e4c4) org.opentest4j:opentest4j:1.3.0 (2 constraints: cf209249) org.ow2.asm:asm:9.5 (1 constraints: 080aaba4) -org.spockframework:spock-core:2.0-M4-groovy-3.0 (2 constraints: e822d65a) -org.spockframework:spock-junit4:2.0-M4-groovy-3.0 (1 constraints: 25115ddf) diff --git a/versions.lock b/versions.lock index b9f8e834..9012b0f4 100644 --- a/versions.lock +++ b/versions.lock @@ -16,9 +16,9 @@ com.google.auto:auto-common:1.2.1 (2 constraints: b321cc9d) com.google.auto.service:auto-service:1.1.1 (1 constraints: 0505f435) com.google.auto.service:auto-service-annotations:1.1.1 (1 constraints: 9c0f6a86) com.google.code.findbugs:jsr305:3.0.2 (3 constraints: 571ca3f6) -com.google.errorprone:error_prone_annotations:2.22.0 (4 constraints: 51279d7c) -com.google.guava:failureaccess:1.0.1 (1 constraints: 140ae1b4) -com.google.guava:guava:32.1.2-jre (7 constraints: 7e6ddaa1) +com.google.errorprone:error_prone_annotations:2.24.1 (4 constraints: 49276b7b) +com.google.guava:failureaccess:1.0.2 (1 constraints: 150ae2b4) +com.google.guava:guava:33.0.0-jre (7 constraints: 156d100b) com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava (1 constraints: bd17c918) com.google.j2objc:j2objc-annotations:2.8 (2 constraints: 9716ab11) com.googlecode.concurrent-trees:concurrent-trees:2.6.1 (1 constraints: 761166da)