Skip to content

Commit 2a9f01e

Browse files
committed
Some nullability and documentation cleanup in package io.flutter.dart
1 parent bd618ad commit 2a9f01e

File tree

7 files changed

+83
-21
lines changed

7 files changed

+83
-21
lines changed

flutter-idea/src/io/flutter/dart/DartPlugin.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,14 @@
1919
import org.jetbrains.annotations.Nullable;
2020

2121
/**
22-
* Provides access to the Dart Plugin for IntelliJ.
22+
* A service component that manages Dart plugin functionality within IntelliJ IDEA.
23+
* <p>
24+
* This class provides project-level services for Dart integration, including version
25+
* management and feature compatibility checks. It acts as a central point for
26+
* accessing Dart plugin capabilities and configurations within a project.
27+
* <p>
28+
* The service is automatically instantiated by the IntelliJ Platform on a per-project
29+
* basis and can be accessed via getInstance(Project).
2330
*/
2431
public class DartPlugin {
2532

@@ -64,10 +71,21 @@ public static boolean isDartTestConfiguration(@NotNull ConfigurationType type) {
6471
return type.getId().equals("DartTestRunConfigurationType");
6572
}
6673

74+
/**
75+
* Returns the version of the Dart plugin installed in the IDE.
76+
*
77+
* @return a {@link DartPluginVersion} object representing the current Dart plugin version,
78+
* or {@code null} if and only if no Dart plugin is found in the runtime
79+
*/
80+
@Nullable
6781
public static DartPluginVersion getDartPluginVersion() {
6882
final IdeaPluginDescriptor dartPlugin = PluginManagerCore.getPlugin(PluginId.getId("Dart"));
69-
final String versionString = dartPlugin.getVersion();
70-
return new DartPluginVersion(versionString);
83+
if (dartPlugin == null) {
84+
return null;
85+
}
86+
else {
87+
return new DartPluginVersion(dartPlugin.getVersion());
88+
}
7189
}
7290

7391
/**

flutter-idea/src/io/flutter/dart/DartPluginVersion.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
import org.jetbrains.annotations.NotNull;
1010
import org.jetbrains.annotations.Nullable;
1111

12+
/**
13+
* Represents and manages Dart plugin version information.
14+
* This class provides functionality to parse, compare, and check compatibility
15+
* of different Dart plugin versions. It supports version-specific feature
16+
* detection, such as determining if a particular version supports the property editor.
17+
* <p>
18+
* Versions can be compared using standard comparison operators through the
19+
* {@link Comparable} interface implementation.
20+
*/
1221
public class DartPluginVersion implements Comparable<DartPluginVersion> {
1322

1423
@Nullable
@@ -19,28 +28,27 @@ public class DartPluginVersion implements Comparable<DartPluginVersion> {
1928

2029
public DartPluginVersion(@Nullable String versionString) {
2130
rawVersionString = versionString;
22-
version = Version.parseVersion(versionString);
31+
version = versionString == null ? null : Version.parseVersion(versionString);
2332
}
2433

2534
@Override
2635
public int compareTo(@NotNull DartPluginVersion otherVersion) {
27-
if (rawVersionString == null) return -1;
28-
if (otherVersion.rawVersionString == null) return 1;
36+
if (rawVersionString == null || version == null) return -1;
37+
if (otherVersion.rawVersionString == null || otherVersion.version == null) return 1;
2938
return version.compareTo(otherVersion.version);
3039
}
3140

3241
public boolean supportsPropertyEditor() {
33-
if (version == null) return false;
42+
if (version == null) {
43+
return false;
44+
}
3445
final int major = version.major;
35-
3646
if (major == 243) {
3747
return this.compareTo(new DartPluginVersion("243.26753.1")) >= 0;
38-
}
39-
40-
if (major == 251) {
48+
} else if (major == 251) {
4149
return this.compareTo(new DartPluginVersion("251.23774.318")) >= 0;
50+
} else {
51+
return major >= 244;
4252
}
43-
44-
return major >= 244;
4553
}
4654
}

flutter-idea/src/io/flutter/dart/DartPsiUtil.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,26 @@
1717

1818
import java.util.List;
1919

20+
/**
21+
* Utility class for working with Dart PSI (Program Structure Interface) elements.
22+
* <p>
23+
* This class provides helper methods for analyzing and manipulating the PSI tree
24+
* of Dart files. It contains utility functions for common operations on Dart
25+
* language constructs, making it easier to work with the syntactic and semantic
26+
* structure of Dart code.
27+
* <p>
28+
* PSI elements represent the structure of the source code in the IntelliJ Platform,
29+
* and this utility class helps plugin developers interact with Dart-specific PSI
30+
* elements in a more convenient way.
31+
* <p>
32+
* All methods in this class are static as this is a utility class.
33+
*/
2034
public class DartPsiUtil {
2135

36+
private DartPsiUtil() {
37+
throw new AssertionError("No instances.");
38+
}
39+
2240
public static int parseLiteralNumber(@NotNull String val) throws NumberFormatException {
2341
return val.startsWith("0x") || val.startsWith("0X")
2442
? Integer.parseUnsignedInt(val.substring(2), 16)

flutter-idea/src/io/flutter/dart/DartSyntax.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,26 @@
1717
import java.util.regex.Pattern;
1818

1919
/**
20-
* Finds Dart PSI elements in IntelliJ's syntax tree.
20+
* Constants and utility methods for working with Dart language syntax.
21+
* <p>
22+
* This class provides a collection of common Dart syntax elements, patterns,
23+
* and keywords used throughout the plugin. It serves as a central repository
24+
* for syntax-related constants and helper methods to ensure consistency in
25+
* Dart code analysis and manipulation.
26+
* <p>
27+
* The class includes regular expressions, common syntax patterns, and utility
28+
* methods for identifying and working with various Dart language constructs.
29+
* This helps maintain consistency across the plugin when dealing with Dart
30+
* syntax elements.
31+
* <p>
32+
* All members in this class are static as this is a utility class.
2133
*/
2234
public class DartSyntax {
2335

36+
private DartSyntax() {
37+
throw new AssertionError("No instances.");
38+
}
39+
2440
/**
2541
* Finds the enclosing function call where the function being called has the given name.
2642
* <p>

flutter-idea/src/io/flutter/dart/FlutterDartAnalysisServer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public FlutterDartAnalysisServer(@NotNull Project project) {
8181

8282
@Override
8383
public void serverConnected(String s) {
84-
// If the server reconnected we need to let it know that we still care
84+
// If the server reconnected, we need to let it know that we still care
8585
// about our subscriptions.
8686
if (!subscriptions.isEmpty()) {
8787
sendSubscriptions();
@@ -233,7 +233,7 @@ private void processResponse(@Nullable JsonObject response) {
233233
*/
234234
@SuppressWarnings("DataFlowIssue") // Ignore for de-marshalling JSON objects.
235235
private void processNotification(JsonObject response, @NotNull JsonElement eventName) {
236-
// If we add code to handle more event types below, update the filter in processString().
236+
// If we add code to handle the more event types below, update the filter in processString().
237237
final String event = eventName.getAsString();
238238
if (Objects.equals(event, FLUTTER_NOTIFICATION_OUTLINE)) {
239239
final JsonObject paramsObject = response.get("params").getAsJsonObject();

flutter-idea/src/io/flutter/dart/FlutterRequestUtilities.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import java.util.Map;
1818

1919
/**
20-
* A utilities class for generating analysis server json requests.
20+
* Utility class for generating analysis server json requests.
2121
*/
2222
public class FlutterRequestUtilities {
2323
private static final String FILE = "file";
@@ -34,6 +34,7 @@ public class FlutterRequestUtilities {
3434
private static final String METHOD_FLUTTER_SET_WIDGET_PROPERTY_VALUE = "flutter.setWidgetPropertyValue";
3535

3636
private FlutterRequestUtilities() {
37+
throw new AssertionError("No instances.");
3738
}
3839

3940
public static JsonObject generateFlutterGetWidgetDescription(String id, String file, int offset) {
@@ -130,9 +131,10 @@ private static JsonObject buildJsonObjectRequest(String idValue, String methodVa
130131
}
131132

132133
/**
133-
* Return the name of the given object, may be {@code "null"} string.
134+
* Return the name of the given object, may be {@code "null"} String.
134135
*/
136+
@NotNull
135137
private static String getClassName(Object object) {
136-
return object != null ? object.getClass().getName() : "null";
138+
return object != null && object.getClass().getName() != null ? object.getClass().getName() : "null";
137139
}
138140
}

flutter-idea/src/io/flutter/propertyeditor/PropertyEditorViewFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindo
4545
FlutterSdk sdk = FlutterSdk.getFlutterSdk(project);
4646
FlutterSdkVersion sdkVersion = sdk == null ? null : sdk.getVersion();
4747

48-
DartPluginVersion dartPluginVersion = DartPlugin.getDartPluginVersion();
49-
if (!dartPluginVersion.supportsPropertyEditor()) {
48+
final DartPluginVersion dartPluginVersion = DartPlugin.getDartPluginVersion();
49+
if (dartPluginVersion == null || !dartPluginVersion.supportsPropertyEditor()) {
5050
viewUtils.presentLabel(toolWindow, "Flutter Property Editor requires a newer version of the Dart plugin.");
5151
return;
5252
}

0 commit comments

Comments
 (0)