From 6ae95331aa4854a7664c8db21f115aa42f9333eb Mon Sep 17 00:00:00 2001 From: Egor Ushakov Date: Tue, 11 Mar 2025 11:41:56 +0100 Subject: [PATCH] IDEA-368449 Modify NPE message in console for Java 30th anniversary - review IJ-CR-157382 (cherry picked from commit 6b62e3a667907da7a1dfec9e5432aef22d3b9ee8) GitOrigin-RevId: a1570d664c669ec6231935f28b7677cc78ec60b0 --- .../execution/filters/JavaExceptionFilter.kt | 57 +++++++++++++++++++ java/java-impl/src/META-INF/JavaPlugin.xml | 1 + platform/icons/src/promo/javaDuke.svg | 6 ++ platform/icons/src/promo/javaDuke_dark.svg | 6 ++ .../util/resources/misc/registry.properties | 3 + platform/util/ui/api-dump.txt | 3 + .../ui/src/com/intellij/icons/AllIcons.java | 4 ++ 7 files changed, 80 insertions(+) create mode 100644 java/execution/impl/src/com/intellij/execution/filters/JavaExceptionFilter.kt create mode 100644 platform/icons/src/promo/javaDuke.svg create mode 100644 platform/icons/src/promo/javaDuke_dark.svg diff --git a/java/execution/impl/src/com/intellij/execution/filters/JavaExceptionFilter.kt b/java/execution/impl/src/com/intellij/execution/filters/JavaExceptionFilter.kt new file mode 100644 index 000000000000..104e47ea836f --- /dev/null +++ b/java/execution/impl/src/com/intellij/execution/filters/JavaExceptionFilter.kt @@ -0,0 +1,57 @@ +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.execution.filters + +import com.intellij.codeInsight.hints.presentation.PresentationFactory +import com.intellij.codeInsight.hints.presentation.PresentationRenderer +import com.intellij.execution.filters.Filter.ResultItem +import com.intellij.execution.impl.InlayProvider +import com.intellij.icons.AllIcons +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.editor.EditorCustomElementRenderer +import com.intellij.openapi.editor.Inlay +import com.intellij.openapi.util.registry.Registry +import com.intellij.psi.PsiClass +import java.time.LocalDate + +class JavaExceptionFilter : JvmExceptionOccurrenceFilter { + override fun applyFilter( + exceptionClassName: String, + classes: MutableList, + exceptionStartOffset: Int, + ): ResultItem? { + with(Registry.get("java.exceptions.anniversary.banner")) { + if (isOptionEnabled("off")) { + return null + } + if (isOptionEnabled("on")) { + val startDate = LocalDate.of(2025, 5, 23) + val endDate = LocalDate.of(2025, 5, 30) + if (LocalDate.now() !in startDate..endDate) { + return null + } + } + } + return CreateExceptionBreakpointResult(exceptionStartOffset, exceptionStartOffset + exceptionClassName.length) + } + + private class CreateExceptionBreakpointResult(highlightStartOffset: Int, highlightEndOffset: Int) : ResultItem(highlightStartOffset, highlightEndOffset, null), InlayProvider { + override fun createInlay(editor: Editor, offset: Int): Inlay<*>? { + return editor.getInlayModel().addBlockElement(offset, true, false, 0, createInlayRenderer(editor)) + } + + override fun createInlayRenderer(editor: Editor): EditorCustomElementRenderer { + val presentation = with(PresentationFactory(editor)) { + roundWithBackground( + seq( + smallScaledIcon(AllIcons.Promo.JavaDuke), + inset( + smallText("from Java with love - happy 30th anniversary! (captured by IntelliJ IDEA)"), + left = 6, top = 1, down = 1 + ) + ) + ) + } + return PresentationRenderer(presentation) + } + } +} diff --git a/java/java-impl/src/META-INF/JavaPlugin.xml b/java/java-impl/src/META-INF/JavaPlugin.xml index 305ebfcb332c..b225c1c7b136 100644 --- a/java/java-impl/src/META-INF/JavaPlugin.xml +++ b/java/java-impl/src/META-INF/JavaPlugin.xml @@ -934,6 +934,7 @@ + diff --git a/platform/icons/src/promo/javaDuke.svg b/platform/icons/src/promo/javaDuke.svg new file mode 100644 index 000000000000..80321b67a65d --- /dev/null +++ b/platform/icons/src/promo/javaDuke.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/platform/icons/src/promo/javaDuke_dark.svg b/platform/icons/src/promo/javaDuke_dark.svg new file mode 100644 index 000000000000..2aae99426747 --- /dev/null +++ b/platform/icons/src/promo/javaDuke_dark.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/platform/util/resources/misc/registry.properties b/platform/util/resources/misc/registry.properties index 3974745f1e90..63db04adf8d9 100644 --- a/platform/util/resources/misc/registry.properties +++ b/platform/util/resources/misc/registry.properties @@ -701,6 +701,9 @@ debugger.hotswap.floating.toolbar.description=Show a floating toolbar with a hot debugger.hotswap.show.ide.popup=false debugger.hotswap.show.ide.popup.description=Show hot swap successful notification as a popup, or regular notification otherwise +java.exceptions.anniversary.banner=[on*|off|force] +java.exceptions.anniversary.banner.description=Show the java anniversary banner in the console + index.run.configuration.jre=false index.run.configuration.jre.restartRequired=true index.run.configuration.jre.description=Index jre specified in run configuration for goto navigation etc. diff --git a/platform/util/ui/api-dump.txt b/platform/util/ui/api-dump.txt index 0cdd466a655b..6ee0e5bbccbd 100644 --- a/platform/util/ui/api-dump.txt +++ b/platform/util/ui/api-dump.txt @@ -1067,6 +1067,9 @@ f:com.intellij.icons.AllIcons$Profiler - sf:ExpandNode:javax.swing.Icon - sf:Rec:javax.swing.Icon - ():V +f:com.intellij.icons.AllIcons$Promo +- sf:JavaDuke:javax.swing.Icon +- ():V f:com.intellij.icons.AllIcons$Providers - sf:ActiveMQ:javax.swing.Icon - sf:Apache:javax.swing.Icon diff --git a/platform/util/ui/src/com/intellij/icons/AllIcons.java b/platform/util/ui/src/com/intellij/icons/AllIcons.java index 549b6d8ca4f0..a15f7b96ee1b 100644 --- a/platform/util/ui/src/com/intellij/icons/AllIcons.java +++ b/platform/util/ui/src/com/intellij/icons/AllIcons.java @@ -1137,6 +1137,10 @@ public class AllIcons { /** 12x12 */ public static final @NotNull Icon Rec = load("expui/profiler/rec.svg", "profiler/rec.svg", 204716318, 2); } + public static final class Promo { + /** 14x14 */ public static final @NotNull Icon JavaDuke = load("promo/javaDuke.svg", 820578884, 2); + } + public static final class Providers { /** 16x16 */ public static final @NotNull Icon ActiveMQ = load("providers/activeMQ.svg", -1202590345, 0); /** 16x16 */ public static final @NotNull Icon Apache = load("providers/apache.svg", 1920166272, 2);