Skip to content

Commit 7c38ef0

Browse files
committed
Merge remote-tracking branch 'origin/21.X.X' into abashev/Fix-imports-out-of-process
2 parents 05ed5dc + 4a29a26 commit 7c38ef0

932 files changed

Lines changed: 262 additions & 156 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎open-java-format/src/main/java/com/palantir/javaformat/doc/Level.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ case BreakOnlyIfInnerLevelsThenFitOnOneLine(boolean keepIndentWhenInlined) -> {
590590
// levels that are meant to look good even if partially inlined, e.g. method
591591
// chains, which will catch things like builders, but not other kinds of levels like
592592
// constant expressions.
593-
// See the palantir-expression-lambdas cases in test-cases/testdata for an example of
593+
// See the palantir-expression-lambdas cases in test-cases-java21/testdata for an example of
594594
// what this is trying to avoid.
595595

596596
// For this, need to actually check the last inner level of `lastLevel` (2 levels down).

‎open-java-format/src/test/java/com/palantir/javaformat/java/FileBasedTests.java‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@
4343

4444
@Execution(ExecutionMode.CONCURRENT)
4545
public final class FileBasedTests {
46-
// Test files that are only used when run with a minimum Java version
47-
private static final ImmutableMultimap<Integer, String> VERSIONED_TESTS =
48-
ImmutableMultimap.<Integer, String>builder()
49-
.putAll(23, "ModuleImport")
50-
.build();
51-
5246
private final Class<?> testClass;
5347
/** The path prefix for all tests if loaded as resources. */
5448
private final Path resourcePrefix;
@@ -66,13 +60,6 @@ public FileBasedTests(Class<?> testClass, String testDirName) {
6660
this.fullTestPath = Paths.get("src/test/resources").resolve(resourcePrefix);
6761
}
6862

69-
public static void assumeJavaVersionForTest(String testName) {
70-
Optional<Integer> maybeJavaVersion =
71-
VERSIONED_TESTS.inverse().get(testName).stream().collect(toOptional());
72-
maybeJavaVersion.ifPresent(version -> Assumptions.assumeTrue(
73-
Formatter.getRuntimeVersion() >= version, String.format("Not running on jdk %d or later", version)));
74-
}
75-
7663
/** The names of the resources under {@link #resourcePrefix}, in every directory of the class path that has it. */
7764
private List<String> resourceNames(ClassLoader classLoader) throws IOException {
7865
var names = new ArrayList<String>();
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package com.palantir.javaformat.java;
16+
17+
import java.util.List;
18+
import org.junit.jupiter.api.DynamicTest;
19+
import org.junit.jupiter.api.TestFactory;
20+
import org.junit.jupiter.api.condition.EnabledForJreRange;
21+
import org.junit.jupiter.api.condition.JRE;
22+
import org.junit.jupiter.api.parallel.Execution;
23+
import org.junit.jupiter.api.parallel.ExecutionMode;
24+
25+
/** The cases on JDK 21 and later: those for the syntax of JDK 21. */
26+
@EnabledForJreRange(min = JRE.JAVA_21)
27+
@Execution(ExecutionMode.CONCURRENT)
28+
final class FormatterCasesJava21Test {
29+
@TestFactory
30+
List<DynamicTest> cases() throws Exception {
31+
return FormatterCasesTest.casesIn("test-cases-java21");
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package com.palantir.javaformat.java;
16+
17+
import java.util.List;
18+
import org.junit.jupiter.api.DynamicTest;
19+
import org.junit.jupiter.api.TestFactory;
20+
import org.junit.jupiter.api.condition.EnabledForJreRange;
21+
import org.junit.jupiter.api.condition.JRE;
22+
import org.junit.jupiter.api.parallel.Execution;
23+
import org.junit.jupiter.api.parallel.ExecutionMode;
24+
25+
/** The cases on JDK 25 and later: those of JDK 21, and those for the syntax of JDK 25. */
26+
@EnabledForJreRange(min = JRE.JAVA_25)
27+
@Execution(ExecutionMode.CONCURRENT)
28+
final class FormatterCasesJava25Test {
29+
@TestFactory
30+
List<DynamicTest> cases() throws Exception {
31+
return FormatterCasesTest.casesIn("test-cases-java25", "test-cases-java21");
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package com.palantir.javaformat.java;
16+
17+
import java.util.List;
18+
import org.junit.jupiter.api.DynamicTest;
19+
import org.junit.jupiter.api.TestFactory;
20+
import org.junit.jupiter.api.condition.EnabledForJreRange;
21+
import org.junit.jupiter.api.condition.JRE;
22+
import org.junit.jupiter.api.parallel.Execution;
23+
import org.junit.jupiter.api.parallel.ExecutionMode;
24+
25+
/** The cases on JDK 28 and later: those of JDK 21 and 25, and those for the syntax of JDK 28. */
26+
@EnabledForJreRange(min = JRE.JAVA_28)
27+
@Execution(ExecutionMode.CONCURRENT)
28+
final class FormatterCasesJava28Test {
29+
@TestFactory
30+
List<DynamicTest> cases() throws Exception {
31+
return FormatterCasesTest.casesIn("test-cases-java28", "test-cases-java25", "test-cases-java21");
32+
}
33+
}

‎open-java-format/src/test/java/com/palantir/javaformat/java/FormatterCasesTest.java‎

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -23,51 +23,49 @@
2323
import java.util.ArrayList;
2424
import java.util.List;
2525
import org.junit.jupiter.api.DynamicTest;
26-
import org.junit.jupiter.api.TestFactory;
27-
import org.junit.jupiter.api.parallel.Execution;
28-
import org.junit.jupiter.api.parallel.ExecutionMode;
2926

3027
/**
31-
* One test for each {@link CaseFile} under {@code test-cases} on the test classpath: formatting the before block gives
32-
* the after block, and formatting that again changes nothing. Adding a case is adding a file.
28+
* One test for each {@link CaseFile} in the given folders on the test classpath: formatting the before block gives the
29+
* after block, and formatting that again changes nothing. Adding a case is adding a file. The cases are in a folder of
30+
* the JDK they need, and each JDK has a class that runs the folders it can parse, such as
31+
* {@link FormatterCasesJava21Test}.
3332
*/
34-
@Execution(ExecutionMode.CONCURRENT)
3533
final class FormatterCasesTest {
36-
private static final String CASES = "test-cases";
37-
3834
private static final Formatter FORMATTER = Formatter.createFormatter(
3935
JavaFormatterOptions.builder().style(Style.OJF).build());
4036

41-
@TestFactory
42-
List<DynamicTest> cases() throws Exception {
43-
var folder = requireNonNull(
44-
FormatterCasesTest.class.getClassLoader().getResource(CASES),
45-
"no " + CASES + " folder on the test classpath");
46-
var root = Path.of(folder.toURI());
47-
var paths = CaseFile.pathsIn(root);
37+
/** The tests of the case files under {@code folders} on the test classpath. */
38+
static List<DynamicTest> casesIn(String... folders) throws Exception {
39+
var tests = new ArrayList<DynamicTest>();
4840

49-
// A wrong folder or a resource filter would otherwise pass with no tests at all.
50-
assertThat(paths).as("the case files under %s", root).isNotEmpty();
41+
for (var folder : folders) {
42+
var url = requireNonNull(
43+
FormatterCasesTest.class.getClassLoader().getResource(folder),
44+
"no " + folder + " folder on the test classpath");
45+
var root = Path.of(url.toURI());
46+
var paths = CaseFile.pathsIn(root);
5147

52-
var tests = new ArrayList<DynamicTest>();
48+
// A wrong folder or a resource filter would otherwise pass with no tests at all.
49+
assertThat(paths).as("the case files under %s", root).isNotEmpty();
5350

54-
for (var path : paths) {
55-
var name = path.substring(0, path.length() - CaseFile.EXTENSION.length());
51+
for (var path : paths) {
52+
var name = path.substring(0, path.length() - CaseFile.EXTENSION.length());
5653

57-
tests.add(DynamicTest.dynamicTest(name, () -> {
58-
var testCase = CaseFile.parse(path, Files.readString(root.resolve(path)));
59-
var once = FORMATTER.formatSourceAndFixImports(testCase.before());
54+
tests.add(DynamicTest.dynamicTest(name, () -> {
55+
var testCase = CaseFile.parse(path, Files.readString(root.resolve(path)));
56+
var once = FORMATTER.formatSourceAndFixImports(testCase.before());
6057

61-
assertThat(once)
62-
.as(() -> CASES + "/" + path + ", first run, " + testCase.firstDifference(once))
63-
.isEqualTo(testCase.after());
58+
assertThat(once)
59+
.as(() -> folder + "/" + path + ", first run, " + testCase.firstDifference(once))
60+
.isEqualTo(testCase.after());
6461

65-
var twice = FORMATTER.formatSourceAndFixImports(once);
62+
var twice = FORMATTER.formatSourceAndFixImports(once);
6663

67-
assertThat(twice)
68-
.as(() -> CASES + "/" + path + ", second run, " + testCase.firstDifference(twice))
69-
.isEqualTo(once);
70-
}));
64+
assertThat(twice)
65+
.as(() -> folder + "/" + path + ", second run, " + testCase.firstDifference(twice))
66+
.isEqualTo(once);
67+
}));
68+
}
7169
}
7270

7371
return tests;

‎open-java-format/src/test/java/com/palantir/javaformat/java/FormatterIntegrationTest.java‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
package com.palantir.javaformat.java;
1616

1717
import static com.google.common.base.Preconditions.checkNotNull;
18-
import static com.palantir.javaformat.java.FileBasedTests.assumeJavaVersionForTest;
1918
import static com.palantir.javaformat.java.FileBasedTests.isRecreate;
2019
import static org.assertj.core.api.Assertions.assertThat;
2120

@@ -74,7 +73,6 @@ private static boolean isDebugMode() {
7473

7574
@TestTemplate
7675
public void format() {
77-
assumeJavaVersionForTest(name);
7876
try {
7977
Formatter formatter = createFormatter();
8078
String output = formatter.formatSource(input);
@@ -99,7 +97,6 @@ private static Formatter createFormatter() {
9997

10098
@TestTemplate
10199
public void idempotentLF() {
102-
assumeJavaVersionForTest(name);
103100
Assumptions.assumeFalse(isRecreate(), "Not running when recreating test outputs");
104101
try {
105102
String mangled = expected.replace(separator(), "\n");
@@ -112,7 +109,6 @@ public void idempotentLF() {
112109

113110
@TestTemplate
114111
public void idempotentCR() {
115-
assumeJavaVersionForTest(name);
116112
Assumptions.assumeFalse(isRecreate(), "Not running when recreating test outputs");
117113
try {
118114
String mangled = expected.replace(separator(), "\r");
@@ -125,7 +121,6 @@ public void idempotentCR() {
125121

126122
@TestTemplate
127123
public void idempotentCRLF() {
128-
assumeJavaVersionForTest(name);
129124
Assumptions.assumeFalse(isRecreate(), "Not running when recreating test outputs");
130125
try {
131126
String mangled = expected.replace(separator(), "\r\n");

‎open-java-format/src/test/java/com/palantir/javaformat/java/FormatterTest.java‎

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,8 @@
3333
import java.nio.file.Files;
3434
import java.nio.file.Path;
3535
import java.time.Duration;
36-
import java.util.Arrays;
3736
import java.util.List;
38-
import javax.lang.model.element.Modifier;
3937
import org.jspecify.annotations.Nullable;
40-
import org.junit.jupiter.api.Assumptions;
4138
import org.junit.jupiter.api.Test;
4239
import org.junit.jupiter.api.io.TempDir;
4340
import org.junit.jupiter.api.parallel.Execution;
@@ -352,44 +349,6 @@ void indentsCommentsThatShareALineLinearly() throws FormatterException {
352349
assertThat(formatter.formatSource(input.toString()).length()).isLessThan(10_000);
353350
}
354351

355-
@Test
356-
void valueClassAndRecord() throws FormatterException {
357-
Assumptions.assumeTrue(
358-
Arrays.stream(Modifier.values())
359-
.anyMatch(modifier -> modifier.name().equals("VALUE")),
360-
"`value` is a modifier only on a JDK with Project Valhalla's value classes");
361-
String input = """
362-
value final public class PointValueClass {
363-
final int x;
364-
final int y;
365-
366-
PointValueClass(int x, int y) {
367-
this.x = x;
368-
this.y = y;
369-
}
370-
}
371-
372-
value public record PointValueRecord(int x, int y) {}
373-
""";
374-
String expected = """
375-
public final value class PointValueClass {
376-
final int x;
377-
final int y;
378-
379-
PointValueClass(int x, int y) {
380-
this.x = x;
381-
this.y = y;
382-
}
383-
}
384-
385-
public value record PointValueRecord(int x, int y) {}
386-
""";
387-
Formatter formatter = Formatter.createFormatter(
388-
JavaFormatterOptions.builder().style(Style.OJF).build());
389-
390-
assertThat(formatter.formatSource(input)).isEqualTo(expected);
391-
}
392-
393352
@Test
394353
@SuppressWarnings("deprecation")
395354
void palantirStyleAliasMatchesOjfStyle() throws FormatterException {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package com.palantir.javaformat.java;
16+
17+
import static com.google.common.truth.Truth.assertThat;
18+
19+
import org.junit.jupiter.api.Test;
20+
import org.junit.jupiter.api.condition.EnabledForJreRange;
21+
import org.junit.jupiter.api.condition.JRE;
22+
import org.junit.jupiter.api.parallel.Execution;
23+
import org.junit.jupiter.api.parallel.ExecutionMode;
24+
25+
/** {@link ModifierOrderer} on the {@code value} modifier of value classes, a preview of JDK 28. */
26+
@EnabledForJreRange(min = JRE.JAVA_28)
27+
@Execution(ExecutionMode.CONCURRENT)
28+
final class ModifierOrdererJava28Test {
29+
@Test
30+
void valueClass() throws FormatterException {
31+
assertThat(ModifierOrderer.reorderModifiers("value final public").getText())
32+
.isEqualTo("public final value");
33+
}
34+
}

‎open-java-format/src/test/java/com/palantir/javaformat/java/ModifierOrdererTest.java‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import com.google.common.base.Joiner;
2222
import com.google.common.collect.Range;
2323
import java.util.Arrays;
24-
import javax.lang.model.element.Modifier;
25-
import org.junit.jupiter.api.Assumptions;
2624
import org.junit.jupiter.api.Test;
2725
import org.junit.jupiter.api.parallel.Execution;
2826
import org.junit.jupiter.api.parallel.ExecutionMode;
@@ -115,16 +113,6 @@ void nonSealedBeforeAccessModifier() throws FormatterException {
115113
.isEqualTo("private non-sealed interface B extends I {}");
116114
}
117115

118-
@Test
119-
void valueClass() throws FormatterException {
120-
Assumptions.assumeTrue(
121-
Arrays.stream(Modifier.values())
122-
.anyMatch(modifier -> modifier.name().equals("VALUE")),
123-
"`value` is a modifier only on a JDK with Project Valhalla's value classes");
124-
assertThat(ModifierOrderer.reorderModifiers("value final public").getText())
125-
.isEqualTo("public final value");
126-
}
127-
128116
@Test
129117
void nonMinusValueIsAnExpression() throws FormatterException {
130118
// `non - value` lexes like `non-sealed`, and there is no NON_VALUE modifier to look up for it

0 commit comments

Comments
 (0)