Skip to content

Commit 27099a2

Browse files
Excavator: Upgrades Baseline to the latest version (#1375)
1 parent fee143a commit 27099a2

File tree

5 files changed

+24
-43
lines changed

5 files changed

+24
-43
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
dependencies {
88
classpath 'com.palantir.jakartapackagealignment:jakarta-package-alignment:0.6.0'
99
classpath 'com.gradle.publish:plugin-publish-plugin:1.3.1'
10-
classpath 'com.palantir.baseline:gradle-baseline-java:6.44.0'
10+
classpath 'com.palantir.baseline:gradle-baseline-java:6.46.0'
1111
classpath 'com.palantir.gradle.consistentversions:gradle-consistent-versions:2.36.0'
1212
classpath 'com.palantir.gradle.externalpublish:gradle-external-publish-plugin:1.19.0'
1313
classpath 'com.palantir.gradle.failure-reports:gradle-failure-reports:1.14.0'

eclipse_plugin/src/main/java/com/palantir/javaformat/java/PalantirJavaFormatter.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,20 @@ public String createIndentationString(int indentationLevel) {
6060
}
6161

6262
/** Runs the Google Java formatter on the given source, with only the given ranges specified. */
63-
@SuppressWarnings("for-rollout:StatementSwitchToExpressionSwitch")
6463
@Nullable
6564
private TextEdit formatInternal(int kind, String source, IRegion[] regions, int initialIndent) {
6665
try {
6766
boolean includeComments = (kind & CodeFormatter.F_INCLUDE_COMMENTS) == CodeFormatter.F_INCLUDE_COMMENTS;
6867
kind &= ~CodeFormatter.F_INCLUDE_COMMENTS;
69-
SnippetKind snippetKind;
70-
switch (kind) {
71-
case ASTParser.K_EXPRESSION:
72-
snippetKind = SnippetKind.EXPRESSION;
73-
break;
74-
case ASTParser.K_STATEMENTS:
75-
snippetKind = SnippetKind.STATEMENTS;
76-
break;
77-
case ASTParser.K_CLASS_BODY_DECLARATIONS:
78-
snippetKind = SnippetKind.CLASS_BODY_DECLARATIONS;
79-
break;
80-
case ASTParser.K_COMPILATION_UNIT:
81-
snippetKind = SnippetKind.COMPILATION_UNIT;
82-
break;
83-
default:
84-
throw new IllegalArgumentException(String.format("Unknown snippet kind: %d", kind));
85-
}
68+
69+
SnippetKind snippetKind =
70+
switch (kind) {
71+
case ASTParser.K_EXPRESSION -> SnippetKind.EXPRESSION;
72+
case ASTParser.K_STATEMENTS -> SnippetKind.STATEMENTS;
73+
case ASTParser.K_CLASS_BODY_DECLARATIONS -> SnippetKind.CLASS_BODY_DECLARATIONS;
74+
case ASTParser.K_COMPILATION_UNIT -> SnippetKind.COMPILATION_UNIT;
75+
default -> throw new IllegalArgumentException(String.format("Unknown snippet kind: %d", kind));
76+
};
8677
List<Replacement> replacements = new SnippetFormatter()
8778
.format(snippetKind, source, rangesFromRegions(regions), initialIndent, includeComments);
8879
if (idempotent(source, regions, replacements)) {

eclipse_plugin/src/main/java/com/palantir/javaformat/java/SnippetFormatter.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,14 @@ private static List<Replacement> toReplacements(String source, String replacemen
153153
return replacements;
154154
}
155155

156-
@SuppressWarnings("for-rollout:StatementSwitchToExpressionSwitch")
157156
private SnippetWrapper snippetWrapper(SnippetKind kind, String source, int initialIndent) {
158157
/*
159158
* Synthesize a dummy class around the code snippet provided by Eclipse. The
160159
* dummy class is correctly formatted -- the blocks use correct indentation,
161160
* etc.
162161
*/
163162
switch (kind) {
164-
case COMPILATION_UNIT: {
163+
case COMPILATION_UNIT -> {
165164
SnippetWrapper wrapper = new SnippetWrapper();
166165
for (int i = 1; i <= initialIndent; i++) {
167166
wrapper.append("class Dummy {\n").append(createIndentationString(i));
@@ -170,7 +169,7 @@ private SnippetWrapper snippetWrapper(SnippetKind kind, String source, int initi
170169
wrapper.closeBraces(initialIndent);
171170
return wrapper;
172171
}
173-
case CLASS_BODY_DECLARATIONS: {
172+
case CLASS_BODY_DECLARATIONS -> {
174173
SnippetWrapper wrapper = new SnippetWrapper();
175174
for (int i = 1; i <= initialIndent; i++) {
176175
wrapper.append("class Dummy {\n").append(createIndentationString(i));
@@ -179,7 +178,7 @@ private SnippetWrapper snippetWrapper(SnippetKind kind, String source, int initi
179178
wrapper.closeBraces(initialIndent);
180179
return wrapper;
181180
}
182-
case STATEMENTS: {
181+
case STATEMENTS -> {
183182
SnippetWrapper wrapper = new SnippetWrapper();
184183
wrapper.append("class Dummy {\n").append(createIndentationString(1));
185184
for (int i = 2; i <= initialIndent; i++) {
@@ -189,7 +188,7 @@ private SnippetWrapper snippetWrapper(SnippetKind kind, String source, int initi
189188
wrapper.closeBraces(initialIndent);
190189
return wrapper;
191190
}
192-
case EXPRESSION: {
191+
case EXPRESSION -> {
193192
SnippetWrapper wrapper = new SnippetWrapper();
194193
wrapper.append("class Dummy {\n").append(createIndentationString(1));
195194
for (int i = 2; i <= initialIndent; i++) {
@@ -201,8 +200,7 @@ private SnippetWrapper snippetWrapper(SnippetKind kind, String source, int initi
201200
wrapper.closeBraces(initialIndent);
202201
return wrapper;
203202
}
204-
default:
205-
throw new IllegalArgumentException("Unknown snippet kind: " + kind);
203+
default -> throw new IllegalArgumentException("Unknown snippet kind: " + kind);
206204
}
207205
}
208206
}

idea-plugin/src/main/java/com/palantir/javaformat/intellij/PalantirJavaFormatSettings.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,16 +180,13 @@ public void setEnabled(@Nullable String enabledStr) {
180180
}
181181
}
182182

183-
@SuppressWarnings({"for-rollout:NullAway", "for-rollout:StatementSwitchToExpressionSwitch"})
183+
@SuppressWarnings("for-rollout:NullAway")
184184
public String getEnabled() {
185-
switch (enabled) {
186-
case ENABLED:
187-
return "true";
188-
case DISABLED:
189-
return "false";
190-
default:
191-
return null;
192-
}
185+
return switch (enabled) {
186+
case ENABLED -> "true";
187+
case DISABLED -> "false";
188+
default -> null;
189+
};
193190
}
194191

195192
@Override

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ public static void assumeJavaVersionForTest(String testName) {
8585
Formatter.getRuntimeVersion() >= version, String.format("Not running on jdk %d or later", version)));
8686
}
8787

88-
@SuppressWarnings("for-rollout:StatementSwitchToExpressionSwitch")
8988
public List<Object[]> paramsAsNameInputOutput() throws IOException {
9089
ClassLoader classLoader = testClass.getClassLoader();
9190
Map<String, String> inputs = new TreeMap<>();
@@ -105,13 +104,9 @@ public List<Object[]> paramsAsNameInputOutput() throws IOException {
105104
contents = CharStreams.toString(new InputStreamReader(stream, UTF_8));
106105
}
107106
switch (extension) {
108-
case "input":
109-
inputs.put(baseName, contents);
110-
break;
111-
case "output":
112-
outputs.put(baseName, contents);
113-
break;
114-
default:
107+
case "input" -> inputs.put(baseName, contents);
108+
case "output" -> outputs.put(baseName, contents);
109+
default -> {}
115110
}
116111
}
117112
}

0 commit comments

Comments
 (0)