diff --git a/spring-javaformat/spring-javaformat-formatter-tests/src/test/java/io/spring/javaformat/formatter/AbstractFormatterTests.java b/spring-javaformat/spring-javaformat-formatter-tests/src/test/java/io/spring/javaformat/formatter/AbstractFormatterTests.java index a87814c3..bf873dd2 100644 --- a/spring-javaformat/spring-javaformat-formatter-tests/src/test/java/io/spring/javaformat/formatter/AbstractFormatterTests.java +++ b/spring-javaformat/spring-javaformat-formatter-tests/src/test/java/io/spring/javaformat/formatter/AbstractFormatterTests.java @@ -54,18 +54,27 @@ protected static Item[] items(String expectedOverride) { File configDir = new File("src/test/resources/config"); File expectedOverrideDir = new File("src/test/resources/" + expectedOverride); for (File source : sourceDir.listFiles((dir, name) -> !name.startsWith("."))) { - File expected = new File(expectedOverrideDir, source.getName()); - if (!expected.exists()) { - expected = new File(expectedDir, source.getName()); - } File config = new File(configDir, source.getName()); for (JavaBaseline javaBaseline : JavaBaseline.values()) { + File expected = getExpected(source, javaBaseline, expectedOverrideDir, expectedDir); addItem(items, javaBaseline, source, expected, config); } } return items.toArray(new Item[0]); } + private static File getExpected(File source, JavaBaseline javaBaseline, File... expectedDirs) { + for (File expectedDir : expectedDirs) { + File versionSpecificExpectedDir = new File(expectedDir, javaBaseline.toString().toLowerCase()); + File expected = new File(versionSpecificExpectedDir, source.getName()); + expected = (!expected.exists()) ? new File(expectedDir, source.getName()) : expected; + if (expected.exists()) { + return expected; + } + } + throw new IllegalStateException("Unable to find expected file"); + } + private static void addItem(List items, JavaBaseline javaBaseline, File source, File expected, File config) { if (source.getName().contains("lineendings")) { items.add(new Item(javaBaseline, copy(source, LineEnding.CR), copy(expected, LineEnding.CR), config)); diff --git a/spring-javaformat/spring-javaformat-formatter-tests/src/test/resources/expected/generics.txt b/spring-javaformat/spring-javaformat-formatter-tests/src/test/resources/expected/generics.txt new file mode 100644 index 00000000..4c3055e0 --- /dev/null +++ b/spring-javaformat/spring-javaformat-formatter-tests/src/test/resources/expected/generics.txt @@ -0,0 +1,8 @@ +package simple; + +/** + * gh-363. + */ +class SpectatorToDoubleGauge extends AbstractMeter implements Gauge { + +} diff --git a/spring-javaformat/spring-javaformat-formatter-tests/src/test/resources/expected/record-with-generic.txt b/spring-javaformat/spring-javaformat-formatter-tests/src/test/resources/expected/v11/record-with-generic.txt similarity index 100% rename from spring-javaformat/spring-javaformat-formatter-tests/src/test/resources/expected/record-with-generic.txt rename to spring-javaformat/spring-javaformat-formatter-tests/src/test/resources/expected/v11/record-with-generic.txt diff --git a/spring-javaformat/spring-javaformat-formatter-tests/src/test/resources/expected/v8/record-with-generic.txt b/spring-javaformat/spring-javaformat-formatter-tests/src/test/resources/expected/v8/record-with-generic.txt new file mode 100644 index 00000000..d31ccb47 --- /dev/null +++ b/spring-javaformat/spring-javaformat-formatter-tests/src/test/resources/expected/v8/record-with-generic.txt @@ -0,0 +1,11 @@ +package simple; + +/** + * Record with generic. + * + * @author Andy Wilkinson + * @since 1.0.0 + */ +public record SomeRecord (T item) { + +} diff --git a/spring-javaformat/spring-javaformat-formatter-tests/src/test/resources/source/generics.txt b/spring-javaformat/spring-javaformat-formatter-tests/src/test/resources/source/generics.txt new file mode 100644 index 00000000..4c3055e0 --- /dev/null +++ b/spring-javaformat/spring-javaformat-formatter-tests/src/test/resources/source/generics.txt @@ -0,0 +1,8 @@ +package simple; + +/** + * gh-363. + */ +class SpectatorToDoubleGauge extends AbstractMeter implements Gauge { + +} diff --git a/spring-javaformat/spring-javaformat-formatter/src/main/java/io/spring/javaformat/formatter/eclipse/Options.java b/spring-javaformat/spring-javaformat-formatter/src/main/java/io/spring/javaformat/formatter/eclipse/Options.java index 3f50237e..7006feb9 100644 --- a/spring-javaformat/spring-javaformat-formatter/src/main/java/io/spring/javaformat/formatter/eclipse/Options.java +++ b/spring-javaformat/spring-javaformat-formatter/src/main/java/io/spring/javaformat/formatter/eclipse/Options.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2021 the original author or authors. + * Copyright 2017-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ import java.util.Properties; import io.spring.javaformat.config.IndentationStyle; +import io.spring.javaformat.config.JavaBaseline; import io.spring.javaformat.config.JavaFormatConfig; /** @@ -63,8 +64,12 @@ private Map loadProperties() throws IOException { } private void applyConfig(Map properties, JavaFormatConfig javaFormatConfig) { + String coreFormatter = this.prefix + ".core.formatter."; if (javaFormatConfig.getIndentationStyle() == IndentationStyle.SPACES) { - properties.put(this.prefix + ".core.formatter.tabulation.char", "space"); + properties.put(coreFormatter + "tabulation.char", "space"); + } + if (javaFormatConfig.getJavaBaseline() == JavaBaseline.V8) { + properties.put(coreFormatter + "insert_space_after_closing_angle_bracket_in_type_parameters", "insert"); } }