Skip to content

Commit 42ec771

Browse files
authored
[CQ] Java 16: migrate to Records (#8240)
JLS 16 brings [records](https://docs.oracle.com/javase/specs/jls/se21/html/jls-8.html#jls-8.10) to Java which (like Dart) gives us a more terse way to describe simple value aggregating classes. This PR migrates 4 simple classes to Records. (I brought attention to a few things in PR comments to amplify some Dart comparisons.) --- - [x] I’ve reviewed the contributor guide and applied the relevant portions to this PR. <details> <summary>Contribution guidelines:</summary><br> - See our [contributor guide]([https://github.com/dart-lang/sdk/blob/main/CONTRIBUTING.md](https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview) for general expectations for PRs. - Larger or significant changes should be discussed in an issue before creating a PR. - Dart contributions to our repos should follow the [Dart style guide](https://dart.dev/guides/language/effective-dart) and use `dart format`. - Java and Kotlin contributions should strive to follow Java and Kotlin best practices ([discussion](#8098)). </details>
1 parent 4350bae commit 42ec771

File tree

5 files changed

+11
-51
lines changed

5 files changed

+11
-51
lines changed

flutter-idea/src/io/flutter/editor/FlutterIconLineMarkerProvider.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -382,18 +382,7 @@ public double findPattern(@NotNull String t, @NotNull String p) {
382382
return jw.similarity(t, p);
383383
}
384384

385-
static class IconInfo {
386-
final @NotNull String iconName;
387-
final @NotNull String className;
388-
final @Nullable String familyName;
389-
final @NotNull String codepoint;
390-
391-
IconInfo(@NotNull String className, @NotNull String iconName, @Nullable String familyName, @NotNull String codepoint) {
392-
this.className = className;
393-
this.iconName = iconName;
394-
this.familyName = familyName;
395-
this.codepoint = codepoint;
396-
}
385+
record IconInfo(@NotNull String className, @NotNull String iconName, @Nullable String familyName, @NotNull String codepoint) {
397386
}
398387

399388
static class IconInfoVisitor extends DartRecursiveVisitor {

flutter-idea/src/io/flutter/run/ObservatoryFile.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,10 @@ ObservatoryFile downloadOrGet(@NotNull String scriptId, boolean wantSnapshot) {
175175
}
176176
}
177177

178-
private static class Position {
179-
final int line; // zero-based
180-
final int column; // zero-based
181-
182-
Position(int line, int column) {
183-
this.line = line;
184-
this.column = column;
185-
}
178+
/**
179+
* @param line zero-based
180+
* @param column zero-based
181+
*/
182+
private record Position(int line, int column) {
186183
}
187184
}

flutter-idea/src/io/flutter/run/common/CommonTestConfigUtils.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,18 +242,8 @@ private void populateTestTypeMap(@NotNull FlutterOutline outline, @NotNull PsiFi
242242
* <p>
243243
* Used to ensure that we don't get stuck with out-of-date line markers.
244244
*/
245-
private static class LineMarkerUpdatingListener implements ActiveEditorsOutlineService.Listener {
246-
@NotNull final CommonTestConfigUtils commonTestConfigUtils;
247-
@NotNull final Project project;
248-
@NotNull final ActiveEditorsOutlineService service;
249-
250-
private LineMarkerUpdatingListener(@NotNull CommonTestConfigUtils commonTestConfigUtils,
251-
@NotNull Project project,
252-
@NotNull ActiveEditorsOutlineService service) {
253-
this.commonTestConfigUtils = commonTestConfigUtils;
254-
this.project = project;
255-
this.service = service;
256-
}
245+
private record LineMarkerUpdatingListener(@NotNull CommonTestConfigUtils commonTestConfigUtils, @NotNull Project project,
246+
@NotNull ActiveEditorsOutlineService service) implements ActiveEditorsOutlineService.Listener {
257247

258248
@Override
259249
public void onOutlineChanged(@NotNull String filePath, @Nullable FlutterOutline outline) {

flutter-idea/src/io/flutter/vmService/ServiceExtensionState.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,5 @@
77

88
import org.jetbrains.annotations.Nullable;
99

10-
public final class ServiceExtensionState {
11-
private final boolean enabled;
12-
@Nullable private final Object value;
13-
14-
public ServiceExtensionState(boolean enabled, @Nullable Object value) {
15-
this.enabled = enabled;
16-
this.value = value;
17-
}
18-
19-
public boolean isEnabled() {
20-
return enabled;
21-
}
22-
23-
@Nullable
24-
public Object getValue() {
25-
return value;
26-
}
10+
public record ServiceExtensionState(boolean enabled, @Nullable Object value) {
2711
}

flutter-idea/src/io/flutter/vmService/VMServiceManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ else if (!stream.getValue()) {
294294
restoreExtensionFromDevice(name);
295295

296296
// Restore any previously true states by calling their service extensions.
297-
if (getServiceExtensionState(name).getValue().isEnabled()) {
297+
if (getServiceExtensionState(name).getValue().enabled()) {
298298
restoreServiceExtensionState(name);
299299
}
300300
}
@@ -347,7 +347,7 @@ private void restoreServiceExtensionState(String name) {
347347
return;
348348
}
349349

350-
@Nullable final Object value = getServiceExtensionState(name).getValue().getValue();
350+
@Nullable final Object value = getServiceExtensionState(name).getValue().value();
351351

352352
if (value instanceof Boolean) {
353353
app.callBooleanExtension(name, (Boolean)value);

0 commit comments

Comments
 (0)