Skip to content

Some nullability and documentation cleanup in package io.flutter.dart #8150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2025
Merged
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
15 changes: 13 additions & 2 deletions flutter-idea/src/io/flutter/dart/DartPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@
import org.jetbrains.annotations.Nullable;

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

Expand Down Expand Up @@ -64,9 +71,13 @@ public static boolean isDartTestConfiguration(@NotNull ConfigurationType type) {
return type.getId().equals("DartTestRunConfigurationType");
}

/**
* Returns the version of the Dart plugin installed in the IDE.
*/
@NotNull
public static DartPluginVersion getDartPluginVersion() {
final IdeaPluginDescriptor dartPlugin = PluginManagerCore.getPlugin(PluginId.getId("Dart"));
final String versionString = dartPlugin.getVersion();
final String versionString = dartPlugin != null ? dartPlugin.getVersion() : null;
return new DartPluginVersion(versionString);
}

Expand Down
28 changes: 18 additions & 10 deletions flutter-idea/src/io/flutter/dart/DartPluginVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

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

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

public DartPluginVersion(@Nullable String versionString) {
rawVersionString = versionString;
version = Version.parseVersion(versionString);
version = versionString == null ? null : Version.parseVersion(versionString);
}

@Override
public int compareTo(@NotNull DartPluginVersion otherVersion) {
if (rawVersionString == null) return -1;
if (otherVersion.rawVersionString == null) return 1;
if (rawVersionString == null || version == null) return -1;
if (otherVersion.rawVersionString == null || otherVersion.version == null) return 1;
return version.compareTo(otherVersion.version);
}

public boolean supportsPropertyEditor() {
if (version == null) return false;
if (version == null) {
return false;
}
final int major = version.major;

if (major == 243) {
return this.compareTo(new DartPluginVersion("243.26753.1")) >= 0;
}

if (major == 251) {
} else if (major == 251) {
return this.compareTo(new DartPluginVersion("251.23774.318")) >= 0;
} else {
return major >= 244;
}

return major >= 244;
}
}
18 changes: 18 additions & 0 deletions flutter-idea/src/io/flutter/dart/DartPsiUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,26 @@

import java.util.List;

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

private DartPsiUtil() {
throw new AssertionError("No instances.");
}

public static int parseLiteralNumber(@NotNull String val) throws NumberFormatException {
return val.startsWith("0x") || val.startsWith("0X")
? Integer.parseUnsignedInt(val.substring(2), 16)
Expand Down
18 changes: 17 additions & 1 deletion flutter-idea/src/io/flutter/dart/DartSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,26 @@
import java.util.regex.Pattern;

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

private DartSyntax() {
throw new AssertionError("No instances.");
}

/**
* Finds the enclosing function call where the function being called has the given name.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public FlutterDartAnalysisServer(@NotNull Project project) {

@Override
public void serverConnected(String s) {
// If the server reconnected we need to let it know that we still care
// If the server reconnected, we need to let it know that we still care
// about our subscriptions.
if (!subscriptions.isEmpty()) {
sendSubscriptions();
Expand Down Expand Up @@ -233,7 +233,7 @@ private void processResponse(@Nullable JsonObject response) {
*/
@SuppressWarnings("DataFlowIssue") // Ignore for de-marshalling JSON objects.
private void processNotification(JsonObject response, @NotNull JsonElement eventName) {
// If we add code to handle more event types below, update the filter in processString().
// If we add code to handle the more event types below, update the filter in processString().
final String event = eventName.getAsString();
if (Objects.equals(event, FLUTTER_NOTIFICATION_OUTLINE)) {
final JsonObject paramsObject = response.get("params").getAsJsonObject();
Expand Down
8 changes: 5 additions & 3 deletions flutter-idea/src/io/flutter/dart/FlutterRequestUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.util.Map;

/**
* A utilities class for generating analysis server json requests.
* Utility class for generating analysis server json requests.
*/
public class FlutterRequestUtilities {
private static final String FILE = "file";
Expand All @@ -34,6 +34,7 @@ public class FlutterRequestUtilities {
private static final String METHOD_FLUTTER_SET_WIDGET_PROPERTY_VALUE = "flutter.setWidgetPropertyValue";

private FlutterRequestUtilities() {
throw new AssertionError("No instances.");
}

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

/**
* Return the name of the given object, may be {@code "null"} string.
* Return the name of the given object, may be {@code "null"} String.
*/
@NotNull
private static String getClassName(Object object) {
return object != null ? object.getClass().getName() : "null";
return object != null && object.getClass().getName() != null ? object.getClass().getName() : "null";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindo
FlutterSdk sdk = FlutterSdk.getFlutterSdk(project);
FlutterSdkVersion sdkVersion = sdk == null ? null : sdk.getVersion();

DartPluginVersion dartPluginVersion = DartPlugin.getDartPluginVersion();
if (!dartPluginVersion.supportsPropertyEditor()) {
final DartPluginVersion dartPluginVersion = DartPlugin.getDartPluginVersion();
if (dartPluginVersion == null || !dartPluginVersion.supportsPropertyEditor()) {
viewUtils.presentLabel(toolWindow, "Flutter Property Editor requires a newer version of the Dart plugin.");
return;
}
Expand Down