Skip to content

Commit 1b2fa45

Browse files
authored
[CQ] remove experimental BadgeIcon dependency (#8365)
The class `com.intellij.ui.BadgeIcon` is marked `@experimental` and is flagged by the verifier: ``` Experimental API usages (4): #Experimental API class com.intellij.ui.BadgeIcon reference Experimental API class com.intellij.ui.BadgeIcon is referenced in io.flutter.toolwindow.ToolWindowBadgeUpdater.lambda$updateBadgedIcon$1(ToolWindow) : void. This class can be changed in a future release leading to incompatibilities Experimental API class com.intellij.ui.BadgeIcon is referenced in io.flutter.toolwindow.ToolWindowBadgeUpdater.lambda$updateBadgedIcon$0(ToolWindow) : void. This class can be changed in a future release leading to incompatibilities #Experimental API constructor com.intellij.ui.BadgeIcon.<init>(Icon, Paint) invocation Experimental API constructor com.intellij.ui.BadgeIcon.<init>(javax.swing.Icon icon, java.awt.Paint paint) is invoked in io.flutter.toolwindow.ToolWindowBadgeUpdater.lambda$updateBadgedIcon$1(ToolWindow) : void. This constructor can be changed in a future release leading to incompatibilities Experimental API constructor com.intellij.ui.BadgeIcon.<init>(javax.swing.Icon icon, java.awt.Paint paint) is invoked in io.flutter.toolwindow.ToolWindowBadgeUpdater.lambda$updateBadgedIcon$0(ToolWindow) : void. This constructor can be changed in a future release leading to incompatibilities ``` This change introduces a lightweight replacement, allowing us to remove the dependency and enable `VerifyPluginTask.FailureLevel.EXPERIMENTAL_API_USAGES` failure checking in the verifier (see: #8361). --- Behavior is preserved w/ the replacement: Default: <img width="1056" height="76" alt="image" src="https://github.com/user-attachments/assets/ecbe93f7-6f71-4862-abda-49434cbea405" /> with badge: <img width="1124" height="84" alt="image" src="https://github.com/user-attachments/assets/ddda5bc5-6e79-4866-b2a5-07d1a4d466b1" /> --- - [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 4351801 commit 1b2fa45

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ intellijPlatform {
171171
VerifyPluginTask.FailureLevel.COMPATIBILITY_PROBLEMS,
172172
// VerifyPluginTask.FailureLevel.DEPRECATED_API_USAGES, // https://github.com/flutter/flutter-intellij/issues/7718
173173
// VerifyPluginTask.FailureLevel.SCHEDULED_FOR_REMOVAL_API_USAGES,
174-
// VerifyPluginTask.FailureLevel.EXPERIMENTAL_API_USAGES,
174+
VerifyPluginTask.FailureLevel.EXPERIMENTAL_API_USAGES,
175175
// VerifyPluginTask.FailureLevel.INTERNAL_API_USAGES,
176176
// VerifyPluginTask.FailureLevel.OVERRIDE_ONLY_API_USAGES,
177177
VerifyPluginTask.FailureLevel.NON_EXTENDABLE_API_USAGES,

src/io/flutter/toolwindow/ToolWindowBadgeUpdater.java

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,81 @@
1010
import com.intellij.openapi.wm.ToolWindow;
1111
import com.intellij.openapi.wm.ToolWindowId;
1212
import com.intellij.openapi.wm.ToolWindowManager;
13-
import com.intellij.ui.BadgeIcon;
1413
import io.flutter.run.common.RunMode;
1514
import io.flutter.run.daemon.FlutterApp;
1615

17-
import java.awt.Color;
18-
import java.awt.Paint;
16+
import javax.swing.*;
17+
import java.awt.*;
1918
import java.util.Objects;
20-
import javax.swing.Icon;
2119

2220
public class ToolWindowBadgeUpdater {
23-
public static final Paint BADGE_PAINT = Color.decode("#5ca963");
21+
public static final Color BADGE_PAINT = Color.decode("#5ca963");
2422

2523
/**
2624
* Updates the tool window icons for RUN or DEBUG mode with a green badge.
2725
*
28-
* @param app The FlutterApp instance running in a given mode.
26+
* @param app The FlutterApp instance running in a given mode.
2927
* @param project The current IntelliJ project context.
3028
*/
3129
public static void updateBadgedIcon(FlutterApp app, Project project) {
3230
final ToolWindowManager manager = ToolWindowManager.getInstance(Objects.requireNonNull(project));
3331
final ToolWindow runToolWindow = manager.getToolWindow(ToolWindowId.RUN);
3432
final ToolWindow debugToolWindow = manager.getToolWindow(ToolWindowId.DEBUG);
3533

36-
if(Objects.requireNonNull(app).getMode() == RunMode.RUN) {
34+
if (Objects.requireNonNull(app).getMode() == RunMode.RUN) {
3735
if (runToolWindow != null) {
3836
manager.invokeLater(() -> {
3937
Icon baseIcon = AllIcons.Toolwindows.ToolWindowRun;
4038
BadgeIcon iconWithBadge = new BadgeIcon(baseIcon, BADGE_PAINT);
41-
4239
runToolWindow.setIcon(iconWithBadge);
4340
});
4441
}
4542
}
46-
else if(app.getMode() == RunMode.DEBUG) {
43+
else if (app.getMode() == RunMode.DEBUG) {
4744
manager.invokeLater(() -> {
4845
Icon baseIcon = AllIcons.Toolwindows.ToolWindowDebugger;
4946
BadgeIcon iconWithBadge = new BadgeIcon(baseIcon, BADGE_PAINT);
50-
5147
Objects.requireNonNull(debugToolWindow).setIcon(iconWithBadge);
5248
});
5349
}
50+
}
51+
52+
private static class BadgeIcon implements Icon {
53+
private final Icon baseIcon;
54+
private final Color overlayColor;
55+
private static final float alpha = 1.0F;
56+
57+
public BadgeIcon(Icon baseIcon, Color overlayColor) {
58+
this.baseIcon = baseIcon;
59+
this.overlayColor = overlayColor;
60+
}
61+
62+
@Override
63+
public void paintIcon(Component c, Graphics g, int x, int y) {
64+
baseIcon.paintIcon(c, g, x, y);
65+
66+
Graphics2D g2d = (Graphics2D)g.create();
67+
try {
68+
g2d.translate(x, y);
69+
70+
g2d.setComposite(AlphaComposite.SrcOver.derive(alpha));
71+
72+
g2d.setColor(overlayColor);
73+
g2d.fillRect(0, 0, getIconWidth(), getIconHeight());
74+
}
75+
finally {
76+
g2d.dispose();
77+
}
78+
}
79+
80+
@Override
81+
public int getIconWidth() {
82+
return baseIcon.getIconWidth();
83+
}
5484

85+
@Override
86+
public int getIconHeight() {
87+
return baseIcon.getIconHeight();
88+
}
5589
}
5690
}

0 commit comments

Comments
 (0)