Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private static void configureResolvedVersionsWithVersionMapping(Project project)
| IntelliJ plugin ID | `palantir-java-format` | `open-java-format` |
| Eclipse plugin bundle | `palantir-java-format-eclipse-plugin` | `open-java-format-eclipse-plugin` |
| CLI style flag | `--palantir`, `-palantir` | none: there is one style |
| Formatter style | `PALANTIR` | `OJF` |
| Formatter style | `PALANTIR` | `OJF` (`PALANTIR` kept as a `@Deprecated` alias) |
| Native formatter Gradle property | `palantir.native.formatter` | `openjavaformat.native.formatter` |
| Java packages | `com.palantir.javaformat.*` | **unchanged** |
| Version numbers | `2.98.0` | `21.<minor>.<build>`, see [Versions](#versions) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ public enum Style {
/** The default Open Java Format Style configuration. */
OJF(2, 120),

/**
* Alias for {@link #OJF} kept for backward compatibility with {@code palantir-java-format} callers (such as
* Spotless's {@code palantirJavaFormat()} step).
*
* @deprecated use {@link #OJF} instead.
*/
@Deprecated
PALANTIR(2, 120),

/** The default Google Java Style configuration. */
GOOGLE(1, 100),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,12 @@ private static boolean shouldInsertBlankLineAosp(Import prev, Import curr) {
private final Comparator<Import> importComparator;
private final BiFunction<Import, Import, Boolean> shouldInsertBlankLineFn;

@SuppressWarnings("deprecation")
private ImportOrderer(String text, ImmutableList<Tok> toks, Style style) {
this.text = text;
this.toks = toks;
this.lineSeparator = Newlines.guessLineSeparator(text);
if (style.equals(Style.GOOGLE) || style.equals(Style.OJF)) {
if (style.equals(Style.GOOGLE) || style.equals(Style.OJF) || style.equals(Style.PALANTIR)) {
this.importComparator = GOOGLE_IMPORT_COMPARATOR;
this.shouldInsertBlankLineFn = ImportOrderer::shouldInsertBlankLineGoogle;
} else if (style.equals(Style.AOSP)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,35 @@ public value record PointValueRecord(int x, int y) {}

assertThat(formatter.formatSource(input)).isEqualTo(expected);
}

@Test
@SuppressWarnings("deprecation")
void palantirStyleAliasMatchesOjfStyle() throws FormatterException {
Style palantirStyle = Style.valueOf("PALANTIR");
assertThat(palantirStyle).isEqualTo(Style.PALANTIR);
assertThat(palantirStyle.indentationMultiplier()).isEqualTo(Style.OJF.indentationMultiplier());
assertThat(palantirStyle.maxLineLength()).isEqualTo(Style.OJF.maxLineLength());

String input = """
package com.example;

import java.util.Set;
import java.util.List;
import static java.util.Collections.emptyList;

public class Sample {
public List<String> items() {
return emptyList();
}
}
""";
Formatter palantirFormatter = Formatter.createFormatter(
JavaFormatterOptions.builder().style(palantirStyle).build());

assertThat(palantirFormatter.formatSource(input)).isEqualTo(FORMATTER.formatSource(input));
assertThat(palantirFormatter.formatSourceAndFixImports(input))
.isEqualTo(FORMATTER.formatSourceAndFixImports(input));
assertThat(ImportOrderer.reorderImports(input, palantirStyle))
.isEqualTo(ImportOrderer.reorderImports(input, Style.OJF));
}
}