EA-910800 ISE: JBColor.$$$reportNull$$$0

GitOrigin-RevId: a8b304c359bfd12abe85207656a23ea1a9cddf5a
This commit is contained in:
Alexey Kudravtsev
2023-09-22 18:34:34 +00:00
committed by intellij-monorepo-bot
parent 18e06d5e0e
commit 4d1d97efae
14 changed files with 36 additions and 31 deletions
@@ -44,6 +44,7 @@ import com.intellij.util.LazyInitializer;
import com.intellij.util.ObjectUtils;
import com.intellij.util.SVGLoader;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtil;
import org.intellij.images.ImagesBundle;
import org.intellij.images.editor.ImageDocument;
import org.intellij.images.editor.ImageDocument.ScaledImageProvider;
@@ -72,6 +73,7 @@ import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Objects;
/**
* Image editor UI
@@ -156,7 +158,7 @@ final class ImageEditorUI extends JPanel implements DataProvider, CopyProvider,
actionToolbar.setTargetComponent(this);
toolbarPanel = actionToolbar.getComponent();
toolbarPanel.setBackground(JBColor.lazy(() -> getBackground()));
toolbarPanel.setBackground(JBColor.lazy(() -> Objects.requireNonNullElse(getBackground(), UIUtil.getPanelBackground())));
toolbarPanel.addMouseListener(new FocusRequester());
}
@@ -15,6 +15,7 @@ import com.intellij.ui.components.ZoomableViewport
import com.intellij.ui.components.panels.NonOpaquePanel
import com.intellij.util.ObjectUtils
import com.intellij.util.ui.JBUI
import com.intellij.util.ui.UIUtil
import org.intellij.images.ImagesBundle
import org.intellij.images.editor.actionSystem.ImageEditorActions
import org.intellij.images.editor.impl.jcef.JCefImageViewer.Companion.isDebugMode
@@ -110,7 +111,7 @@ class JCefImageViewerUI(private val myContentComponent: Component,
}
val toolbarPanel = actionToolbar.component
toolbarPanel.background = JBColor.lazy { background }
toolbarPanel.background = JBColor.lazy { background ?: UIUtil.getPanelBackground()}
val topPanel: JPanel = NonOpaquePanel(BorderLayout())
topPanel.add(toolbarPanel, BorderLayout.WEST)
@@ -123,7 +124,7 @@ class JCefImageViewerUI(private val myContentComponent: Component,
myViewPort.setLayout(CardLayout())
myViewer.preferredFocusedComponent.addMouseWheelListener(MOUSE_WHEEL_LISTENER)
myViewPort.add(myContentComponent, IMAGE_PANEL)
myContentComponent.background = JBColor.lazy { background }
myContentComponent.background = JBColor.lazy { background ?: UIUtil.getPanelBackground()}
val errorLabel = JLabel(
ImagesBundle.message("error.broken.image.file.format"),
@@ -11,7 +11,7 @@ import java.awt.Insets
internal object CombinedDiffUI {
val MAIN_HEADER_BACKGROUND: Color = JBColor.lazy {
return@lazy if (ExperimentalUI.isNewUI()) JBUI.CurrentTheme.EditorTabs.background() else UIUtil.getPanelBackground()
if (ExperimentalUI.isNewUI()) JBUI.CurrentTheme.EditorTabs.background() else UIUtil.getPanelBackground()
}
val MAIN_HEADER_INSETS: Insets
@@ -475,12 +475,11 @@ public final class DiffUtil {
Color commentFg = JBColor.lazy(() -> {
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
TextAttributes commentAttributes = scheme.getAttributes(DefaultLanguageHighlighterColors.LINE_COMMENT);
if (commentAttributes.getForegroundColor() != null && commentAttributes.getBackgroundColor() == null) {
return commentAttributes.getForegroundColor();
}
else {
return scheme.getDefaultForeground();
Color commentAttributesForegroundColor = commentAttributes.getForegroundColor();
if (commentAttributesForegroundColor != null && commentAttributes.getBackgroundColor() == null) {
return commentAttributesForegroundColor;
}
return scheme.getDefaultForeground();
});
label.setForeground(commentFg);
@@ -99,7 +99,7 @@ private class ReaderModeActionProvider : InspectionWidgetActionProvider {
}
}
}.also {
it.foreground = JBColor.lazy { editor.colorsScheme.getColor(FOREGROUND) ?: FOREGROUND.defaultColor }
it.foreground = JBColor.lazy { editor.colorsScheme.getColor(FOREGROUND) ?: FOREGROUND.defaultColor ?: UIUtil.getInactiveTextColor()}
if (!SystemInfo.isWindows) {
it.font = FontUIResource(it.font.deriveFont(it.font.style, it.font.size - JBUIScale.scale(2).toFloat()))
}
@@ -11,15 +11,16 @@ import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.JBColor;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.awt.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;
@@ -131,7 +132,7 @@ public final class ColoredOutputTypeRegistryImpl extends ColoredOutputTypeRegist
}
private static Color getColorByKey(TextAttributesKey colorKey) {
return JBColor.lazy(() -> EditorColorsManager.getInstance().getGlobalScheme().getAttributes(colorKey).getForegroundColor());
return JBColor.lazy(() -> Objects.requireNonNullElse(EditorColorsManager.getInstance().getGlobalScheme().getAttributes(colorKey).getForegroundColor(), UIUtil.getListForeground()));
}
private static @NotNull Color getDefaultForegroundColor() {
@@ -307,7 +308,7 @@ public final class ColoredOutputTypeRegistryImpl extends ColoredOutputTypeRegist
return new ConsoleViewContentType(attribute, attrs);
}
private static Color getColor(int colorIndex, Color enforcedColor, Supplier<? extends Color> getDefaultColor) {
private static Color getColor(int colorIndex, Color enforcedColor, @NotNull Supplier<? extends @NotNull Color> getDefaultColor) {
if (enforcedColor != null) {
return enforcedColor;
}
@@ -391,7 +391,7 @@ private fun addPattern(key: String?, value: Any?, defaults: UIDefaults) {
}
}
internal class IJColorUIResource(color: Color?, private val name: String) : JBColor(Supplier { color }), UIResource {
internal class IJColorUIResource(color: Color, private val name: String) : JBColor(Supplier { color }), UIResource {
override fun getName(): String = name
override fun toString(): String = "IJColorUIResource(color=${super.toString()}, name=$name)"
@@ -47,6 +47,7 @@ import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Supplier;
import static com.intellij.openapi.actionSystem.ActionPlaces.TEXT_EDITOR_WITH_PREVIEW;
@@ -144,7 +145,7 @@ public class TextEditorWithPreview extends UserDataHolderBase implements TextEdi
mySplitter.setFirstComponent(myEditor.getComponent());
mySplitter.setSecondComponent(myPreview.getComponent());
mySplitter.setDividerWidth(ExperimentalUI.isNewUI() ? 1 : 2); // We're using OnePixelSplitter, but it actually supports wider dividers.
mySplitter.getDivider().setBackground(JBColor.lazy(() -> EditorColorsManager.getInstance().getGlobalScheme().getColor(EditorColors.PREVIEW_BORDER_COLOR)));
mySplitter.getDivider().setBackground(JBColor.lazy(() -> Objects.requireNonNullElse(EditorColorsManager.getInstance().getGlobalScheme().getColor(EditorColors.PREVIEW_BORDER_COLOR), UIUtil.getPanelBackground())));
myToolbarWrapper = createSplitEditorToolbar(mySplitter);
@@ -190,7 +190,7 @@ private fun getTextColor(button: AbstractButton) = when {
else -> button.foreground ?: getLinkColor(button)
}
private fun getLinkColor(button: AbstractButton) = when {
private fun getLinkColor(button: AbstractButton): Color = when {
isPressed(button) -> Link.Foreground.PRESSED
isHovered(button) -> Link.Foreground.HOVERED
isVisited(button) -> Link.Foreground.VISITED
@@ -15,6 +15,7 @@ import com.intellij.ui.scale.JBUIScale;
import com.intellij.util.Alarm;
import com.intellij.util.MethodHandleUtil;
import com.intellij.util.concurrency.SynchronizedClearableLazy;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@@ -42,7 +43,7 @@ public class ButtonlessScrollBarUI extends BasicScrollBarUI {
return jbColor(Gray._230, UIUtil.getListBackground());
}
private JBColor jbColor(final Color regular, final Color dark) {
private JBColor jbColor(@NotNull Color regular, @NotNull Color dark) {
return JBColor.lazy(() -> isDark() ? dark : regular);
}
@@ -111,7 +111,7 @@ public final class ColorUtil {
});
}
private static Color wrap(@NotNull Color color, Supplier<? extends Color> func) {
private static Color wrap(@NotNull Color color, @NotNull Supplier<? extends @NotNull Color> func) {
return color instanceof JBColor ? JBColor.lazy(func) : func.get();
}
@@ -121,7 +121,7 @@ public final class ColorUtil {
}
public static @NotNull Color shift(final @NotNull Color c, final double d) {
Supplier<Color> func = () -> new Color(shift(c.getRed(), d), shift(c.getGreen(), d), shift(c.getBlue(), d), c.getAlpha());
Supplier<@NotNull Color> func = () -> new Color(shift(c.getRed(), d), shift(c.getGreen(), d), shift(c.getBlue(), d), c.getAlpha());
return wrap(c, func);
}
@@ -138,7 +138,7 @@ public final class ColorUtil {
public static @NotNull Color toAlpha(@Nullable Color color, final int a) {
final Color c = color == null ? Color.black : color;
Supplier<Color> func = () -> new Color(c.getRed(), c.getGreen(), c.getBlue(), a);
Supplier<@NotNull Color> func = () -> new Color(c.getRed(), c.getGreen(), c.getBlue(), a);
return wrap(c, func);
}
@@ -51,7 +51,7 @@ public class JBColor extends Color {
}
@SuppressWarnings("LambdaUnfriendlyMethodOverload")
protected JBColor(@NotNull Supplier<? extends Color> function) {
protected JBColor(@NotNull Supplier<? extends @NotNull Color> function) {
super(0);
name = null;
defaultColor = null;
@@ -80,7 +80,8 @@ public class JBColor extends Color {
func = null;
}
public static JBColor lazy(@NotNull Supplier<? extends Color> supplier) {
@NotNull
public static JBColor lazy(@NotNull Supplier<? extends @NotNull Color> supplier) {
return new JBColor(supplier);
}
@@ -10,8 +10,8 @@ import java.util.function.Supplier;
/**
* This is a color producer that allows dynamically mix two colors.
*/
public final class MixedColorProducer implements Supplier<Color> {
private final Couple<Color> couple;
public final class MixedColorProducer implements Supplier<@NotNull Color> {
private final Couple<@NotNull Color> couple;
private double mixer;
private Color cached;
private int argb0;
@@ -68,10 +68,11 @@ public final class MixedColorProducer implements Supplier<Color> {
if (mixer >= 1) return couple.second;
updateFirstARGB();
updateSecondARGB();
if (cached == null) {
Color result = cached;
if (result == null) {
//noinspection UseJBColor
cached = new Color(mix(16), mix(8), mix(0), mix(24));
cached = result = new Color(mix(16), mix(8), mix(0), mix(24));
}
return cached;
return result;
}
}
@@ -61,9 +61,7 @@ import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.*;
import java.util.List;
public abstract class XDebuggerEditorBase implements Expandable {
@@ -153,7 +151,7 @@ public abstract class XDebuggerEditorBase implements Expandable {
protected JComponent addChooser(JComponent component) {
BorderLayoutPanel panel = JBUI.Panels.simplePanel(component);
panel.setBackground(JBColor.lazy(() -> component.getBackground()));
panel.setBackground(JBColor.lazy(() -> Objects.requireNonNullElse(component.getBackground(), UIUtil.getPanelBackground())));
panel.addToRight(myLanguageChooser);
return panel;
}