Skip to content

Commit 7fe3f70

Browse files
authored
Merge pull request #200 from glaforge/restore-style-palantir-alias
Keep Style.PALANTIR as a @deprecated alias for Style.OJF
2 parents c7354ce + a89167b commit 7fe3f70

4 files changed

Lines changed: 43 additions & 2 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private static void configureResolvedVersionsWithVersionMapping(Project project)
105105
| IntelliJ plugin ID | `palantir-java-format` | `open-java-format` |
106106
| Eclipse plugin bundle | `palantir-java-format-eclipse-plugin` | `open-java-format-eclipse-plugin` |
107107
| CLI style flag | `--palantir`, `-palantir` | none: there is one style |
108-
| Formatter style | `PALANTIR` | `OJF` |
108+
| Formatter style | `PALANTIR` | `OJF` (`PALANTIR` kept as a `@Deprecated` alias) |
109109
| Native formatter Gradle property | `palantir.native.formatter` | `openjavaformat.native.formatter` |
110110
| Java packages | `com.palantir.javaformat.*` | **unchanged** |
111111
| Version numbers | `2.98.0` | `21.<minor>.<build>`, see [Versions](#versions) |

‎open-java-format-spi/src/main/java/com/palantir/javaformat/java/JavaFormatterOptions.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ public enum Style {
3232
/** The default Open Java Format Style configuration. */
3333
OJF(2, 120),
3434

35+
/**
36+
* Alias for {@link #OJF} kept for backward compatibility with {@code palantir-java-format} callers (such as
37+
* Spotless's {@code palantirJavaFormat()} step).
38+
*
39+
* @deprecated use {@link #OJF} instead.
40+
*/
41+
@Deprecated
42+
PALANTIR(2, 120),
43+
3544
/** The default Google Java Style configuration. */
3645
GOOGLE(1, 100),
3746

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,12 @@ private static boolean shouldInsertBlankLineAosp(Import prev, Import curr) {
181181
private final Comparator<Import> importComparator;
182182
private final BiFunction<Import, Import, Boolean> shouldInsertBlankLineFn;
183183

184+
@SuppressWarnings("deprecation")
184185
private ImportOrderer(String text, ImmutableList<Tok> toks, Style style) {
185186
this.text = text;
186187
this.toks = toks;
187188
this.lineSeparator = Newlines.guessLineSeparator(text);
188-
if (style.equals(Style.GOOGLE) || style.equals(Style.OJF)) {
189+
if (style.equals(Style.GOOGLE) || style.equals(Style.OJF) || style.equals(Style.PALANTIR)) {
189190
this.importComparator = GOOGLE_IMPORT_COMPARATOR;
190191
this.shouldInsertBlankLineFn = ImportOrderer::shouldInsertBlankLineGoogle;
191192
} else if (style.equals(Style.AOSP)) {

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,4 +389,35 @@ public value record PointValueRecord(int x, int y) {}
389389

390390
assertThat(formatter.formatSource(input)).isEqualTo(expected);
391391
}
392+
393+
@Test
394+
@SuppressWarnings("deprecation")
395+
void palantirStyleAliasMatchesOjfStyle() throws FormatterException {
396+
Style palantirStyle = Style.valueOf("PALANTIR");
397+
assertThat(palantirStyle).isEqualTo(Style.PALANTIR);
398+
assertThat(palantirStyle.indentationMultiplier()).isEqualTo(Style.OJF.indentationMultiplier());
399+
assertThat(palantirStyle.maxLineLength()).isEqualTo(Style.OJF.maxLineLength());
400+
401+
String input = """
402+
package com.example;
403+
404+
import java.util.Set;
405+
import java.util.List;
406+
import static java.util.Collections.emptyList;
407+
408+
public class Sample {
409+
public List<String> items() {
410+
return emptyList();
411+
}
412+
}
413+
""";
414+
Formatter palantirFormatter = Formatter.createFormatter(
415+
JavaFormatterOptions.builder().style(palantirStyle).build());
416+
417+
assertThat(palantirFormatter.formatSource(input)).isEqualTo(FORMATTER.formatSource(input));
418+
assertThat(palantirFormatter.formatSourceAndFixImports(input))
419+
.isEqualTo(FORMATTER.formatSourceAndFixImports(input));
420+
assertThat(ImportOrderer.reorderImports(input, palantirStyle))
421+
.isEqualTo(ImportOrderer.reorderImports(input, Style.OJF));
422+
}
392423
}

0 commit comments

Comments
 (0)