From db26ca6bfae1917b31a930d540dfc05f3b893f61 Mon Sep 17 00:00:00 2001 From: weisj <31143295+weisJ@users.noreply.github.com> Date: Tue, 17 Aug 2021 11:07:12 +0200 Subject: [PATCH] Theme: Fix errorprone warnings --- theme/build.gradle.kts | 1 + .../weisj/darklaf/theme/DarculaTheme.java | 6 +++++- .../weisj/darklaf/theme/IntelliJTheme.java | 6 +++++- .../com/github/weisj/darklaf/theme/Theme.java | 18 ++++++++---------- .../theme/event/ThemeChangeListener.java | 1 + .../theme/event/ThemePreferenceListener.java | 1 + .../darklaf/theme/info/AccentColorRule.java | 2 +- .../weisj/darklaf/theme/info/FontSizeRule.java | 4 ++-- .../theme/info/PreferredThemeStyle.java | 2 +- .../theme/laf/SynthesisedThemedLaf.java | 4 ++-- 10 files changed, 27 insertions(+), 18 deletions(-) diff --git a/theme/build.gradle.kts b/theme/build.gradle.kts index 95e8597a..f85054e4 100644 --- a/theme/build.gradle.kts +++ b/theme/build.gradle.kts @@ -8,6 +8,7 @@ dependencies { implementation(projects.darklafUtils) compileOnly(projects.darklafAnnotations) + compileOnly(libs.tools.errorprone.annotations) annotationProcessor(projects.darklafAnnotationsProcessor) compileOnly(libs.autoservice.annotations) diff --git a/theme/src/main/java/com/github/weisj/darklaf/theme/DarculaTheme.java b/theme/src/main/java/com/github/weisj/darklaf/theme/DarculaTheme.java index d78b1426..11a76f8d 100644 --- a/theme/src/main/java/com/github/weisj/darklaf/theme/DarculaTheme.java +++ b/theme/src/main/java/com/github/weisj/darklaf/theme/DarculaTheme.java @@ -31,7 +31,11 @@ import com.github.weisj.darklaf.theme.info.ColorToneRule; import com.github.weisj.darklaf.theme.info.PresetIconRule; import com.google.auto.service.AutoService; -/** @author Jannis Weis */ +/** + * A theme following the color scheme from the IntelliJ Darcula theme. + * + * @author Jannis Weis + */ @AutoService(Theme.class) @SynthesiseLaf public class DarculaTheme extends Theme { diff --git a/theme/src/main/java/com/github/weisj/darklaf/theme/IntelliJTheme.java b/theme/src/main/java/com/github/weisj/darklaf/theme/IntelliJTheme.java index b7022e4e..be47c2e7 100644 --- a/theme/src/main/java/com/github/weisj/darklaf/theme/IntelliJTheme.java +++ b/theme/src/main/java/com/github/weisj/darklaf/theme/IntelliJTheme.java @@ -31,7 +31,11 @@ import com.github.weisj.darklaf.theme.info.ColorToneRule; import com.github.weisj.darklaf.theme.info.PresetIconRule; import com.google.auto.service.AutoService; -/** @author Jannis Weis */ +/** + * A theme following the default IntelliJ color scheme. + * + * @author Jannis Weis + */ @AutoService(Theme.class) @SynthesiseLaf public class IntelliJTheme extends Theme { diff --git a/theme/src/main/java/com/github/weisj/darklaf/theme/Theme.java b/theme/src/main/java/com/github/weisj/darklaf/theme/Theme.java index 16229754..eb141057 100644 --- a/theme/src/main/java/com/github/weisj/darklaf/theme/Theme.java +++ b/theme/src/main/java/com/github/weisj/darklaf/theme/Theme.java @@ -23,7 +23,6 @@ package com.github.weisj.darklaf.theme; import java.io.InputStream; import java.io.Serializable; -import java.util.Comparator; import java.util.Objects; import java.util.Properties; import java.util.logging.Level; @@ -38,8 +37,13 @@ import com.github.weisj.darklaf.theme.info.*; import com.github.weisj.darklaf.theme.laf.RenamedTheme; import com.github.weisj.darklaf.util.LogUtil; -/** @author Jannis Weis */ -public abstract class Theme implements Comparable, Comparator, Serializable { +/** + * A {@link Theme} is responsible for providing colors and customizing properties used by the + * darklaf look and feel. + * + * @author Jannis Weis + */ +public abstract class Theme implements Comparable, Serializable { private static final Logger LOGGER = LogUtil.getLogger(Theme.class); private final FontSizeRule fontSizeRule; @@ -451,12 +455,6 @@ public abstract class Theme implements Comparable, Comparator, Ser return stringComp; } - @Override - public int compare(final Theme o1, final Theme o2) { - if (o1 == null) return -1; - return o1.compareTo(o2); - } - public Class getThemeClass() { return getClass(); } @@ -471,7 +469,7 @@ public abstract class Theme implements Comparable, Comparator, Ser public int hashCode() { int result = fontSizeRule != null ? fontSizeRule.hashCode() : 0; result = 31 * result + (accentColorRule != null ? accentColorRule.hashCode() : 0); - result = 31 * result + (getThemeClass().hashCode()); + result = 31 * result + getThemeClass().hashCode(); return result; } diff --git a/theme/src/main/java/com/github/weisj/darklaf/theme/event/ThemeChangeListener.java b/theme/src/main/java/com/github/weisj/darklaf/theme/event/ThemeChangeListener.java index 8eb8fb0f..54cde905 100644 --- a/theme/src/main/java/com/github/weisj/darklaf/theme/event/ThemeChangeListener.java +++ b/theme/src/main/java/com/github/weisj/darklaf/theme/event/ThemeChangeListener.java @@ -23,6 +23,7 @@ package com.github.weisj.darklaf.theme.event; public interface ThemeChangeListener extends ThemeEventListener { + @Override default void onEvent(final ThemeChangeEvent event) { themeChanged(event); } diff --git a/theme/src/main/java/com/github/weisj/darklaf/theme/event/ThemePreferenceListener.java b/theme/src/main/java/com/github/weisj/darklaf/theme/event/ThemePreferenceListener.java index a6122846..72b2a7cf 100644 --- a/theme/src/main/java/com/github/weisj/darklaf/theme/event/ThemePreferenceListener.java +++ b/theme/src/main/java/com/github/weisj/darklaf/theme/event/ThemePreferenceListener.java @@ -23,6 +23,7 @@ package com.github.weisj.darklaf.theme.event; public interface ThemePreferenceListener extends ThemeEventListener { + @Override default void onEvent(final ThemePreferenceChangeEvent event) { themePreferenceChanged(event); } diff --git a/theme/src/main/java/com/github/weisj/darklaf/theme/info/AccentColorRule.java b/theme/src/main/java/com/github/weisj/darklaf/theme/info/AccentColorRule.java index 27ec4ad5..fff3ea2b 100644 --- a/theme/src/main/java/com/github/weisj/darklaf/theme/info/AccentColorRule.java +++ b/theme/src/main/java/com/github/weisj/darklaf/theme/info/AccentColorRule.java @@ -63,7 +63,7 @@ public class AccentColorRule implements Serializable { @Override public boolean equals(final Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (!(o instanceof AccentColorRule)) return false; AccentColorRule that = (AccentColorRule) o; if (!Objects.equals(accentColor, that.accentColor)) return false; return Objects.equals(selectionColor, that.selectionColor); diff --git a/theme/src/main/java/com/github/weisj/darklaf/theme/info/FontSizeRule.java b/theme/src/main/java/com/github/weisj/darklaf/theme/info/FontSizeRule.java index fb651d3c..a942762c 100644 --- a/theme/src/main/java/com/github/weisj/darklaf/theme/info/FontSizeRule.java +++ b/theme/src/main/java/com/github/weisj/darklaf/theme/info/FontSizeRule.java @@ -104,9 +104,9 @@ public class FontSizeRule implements Serializable { @Override public boolean equals(final Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (!(o instanceof FontSizeRule)) return false; FontSizeRule that = (FontSizeRule) o; - return Float.compare(that.getPercentage(), getPercentage()) == 0; + return that.getPercentage() == getPercentage(); } @Override diff --git a/theme/src/main/java/com/github/weisj/darklaf/theme/info/PreferredThemeStyle.java b/theme/src/main/java/com/github/weisj/darklaf/theme/info/PreferredThemeStyle.java index ad2c03df..f7f305f8 100644 --- a/theme/src/main/java/com/github/weisj/darklaf/theme/info/PreferredThemeStyle.java +++ b/theme/src/main/java/com/github/weisj/darklaf/theme/info/PreferredThemeStyle.java @@ -102,7 +102,7 @@ public class PreferredThemeStyle { @Override public boolean equals(final Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (!(o instanceof PreferredThemeStyle)) return false; PreferredThemeStyle that = (PreferredThemeStyle) o; return contrastRule == that.contrastRule && colorToneRule == that.colorToneRule && Objects.equals(fontSizeRule, that.fontSizeRule) diff --git a/theme/src/main/java/com/github/weisj/darklaf/theme/laf/SynthesisedThemedLaf.java b/theme/src/main/java/com/github/weisj/darklaf/theme/laf/SynthesisedThemedLaf.java index 008bbba1..ea56be01 100644 --- a/theme/src/main/java/com/github/weisj/darklaf/theme/laf/SynthesisedThemedLaf.java +++ b/theme/src/main/java/com/github/weisj/darklaf/theme/laf/SynthesisedThemedLaf.java @@ -23,9 +23,8 @@ package com.github.weisj.darklaf.theme.laf; import java.util.ServiceLoader; -import javax.swing.*; - import com.github.weisj.darklaf.theme.Theme; +import com.google.errorprone.annotations.Immutable; public class SynthesisedThemedLaf extends DelegatingThemedLaf { @@ -33,6 +32,7 @@ public class SynthesisedThemedLaf extends DelegatingThemedLaf { super(theme, BaseLafProvider.INSTANCE.createBaseLaf()); } + @Immutable public interface ThemedLafProvider { ThemedLookAndFeel create(); }