From daf6226d5600034c8f3cbf2d1868a190b0109fcf Mon Sep 17 00:00:00 2001 From: thelooter Date: Fri, 8 Nov 2024 17:51:28 +0100 Subject: [PATCH 1/4] feat(detekt): add detekt for static analysis and fix issues Signed-off-by: thelooter --- .editorconfig | 3 + .github/workflows/build.yml | 4 + CHANGELOG.md | 1 + build.gradle.kts | 30 ++++++ detekt.yaml | 6 ++ .../jetbrains_icons/IconProvider.kt | 87 +++++++++++----- .../providers/JavaIconProvider.kt | 98 ++++++++++++++----- .../views/SettingsAdditionalSupportView.kt | 2 +- .../settings/views/SettingsHeaderView.kt | 17 +++- .../jetbrains_icons/util/PsiClassUtils.kt | 6 +- 10 files changed, 198 insertions(+), 56 deletions(-) create mode 100644 detekt.yaml diff --git a/.editorconfig b/.editorconfig index e29c6fe..e7ad3f8 100644 --- a/.editorconfig +++ b/.editorconfig @@ -19,3 +19,6 @@ trim_trailing_whitespace = false # windows shell scripts [*.{cmd,bat,ps1}] end_of_line = crlf + +[*.{kt,kts}] +ij_kotlin_name_count_to_use_star_import = 2147483647 \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5e0deec..05290f3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -60,6 +60,10 @@ jobs: - name: Check Formatting run: ./gradlew checkFormatting + - name: Run Static Analysis + run: ./gradlew runStaticAnalysis + continue-on-error: true + - name: Test & Build Plugin run: ./gradlew buildPlugin diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bffecb..fdad5f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### Changed - Add code formatting with ktfmt +- Add static analysis with detekt - Add tests ### Deprecated diff --git a/build.gradle.kts b/build.gradle.kts index f3ba8f3..9a07866 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,5 @@ import com.ncorti.ktfmt.gradle.tasks.KtfmtCheckTask +import io.gitlab.arturbosch.detekt.Detekt import org.jetbrains.changelog.Changelog import org.jetbrains.changelog.date import org.jetbrains.intellij.platform.gradle.TestFrameworkType @@ -21,6 +22,8 @@ plugins { // Code Quality // ktfmt id("com.ncorti.ktfmt.gradle") version "0.21.0" + //detekt + id("io.gitlab.arturbosch.detekt").version("1.23.7") } group = properties("pluginGroup") @@ -123,6 +126,8 @@ tasks { tasks.buildSearchableOptions { enabled = false } // Code quality settings + +// Formatting settings ktfmt { googleStyle() } // This is used over the "ktfmtCheck" task to exclude the autogenerated file Icons.kt. @@ -131,3 +136,28 @@ tasks.register("checkFormatting") { include("**/*.kt") exclude("src/main/kotlin/com/github/catppuccin/jetbrains_icons/Icons.kt") } + +// Static Analysis config +detekt { + parallel = true + config.setFrom("detekt.yaml") + buildUponDefaultConfig = true +} + +// This is used over the "detekt" task to exclude the autogenerated file Icons.kt. +tasks.withType().configureEach { + source = project.fileTree(rootDir) + include("**/*.kt") + exclude("src/main/kotlin/com/github/catppuccin/jetbrains_icons/Icons.kt") +} + +tasks.register("runStaticAnalysis") { + + parallel = true + config.setFrom("detekt.yaml") + buildUponDefaultConfig = true + + source = project.fileTree(rootDir) + include("**/*.kt") + exclude("src/main/kotlin/com/github/catppuccin/jetbrains_icons/Icons.kt") +} diff --git a/detekt.yaml b/detekt.yaml new file mode 100644 index 0000000..2a9d092 --- /dev/null +++ b/detekt.yaml @@ -0,0 +1,6 @@ +config: + validation: true + +naming: + PackageNaming: + active: false diff --git a/src/main/kotlin/com/github/catppuccin/jetbrains_icons/IconProvider.kt b/src/main/kotlin/com/github/catppuccin/jetbrains_icons/IconProvider.kt index 0a282b6..c6e1337 100644 --- a/src/main/kotlin/com/github/catppuccin/jetbrains_icons/IconProvider.kt +++ b/src/main/kotlin/com/github/catppuccin/jetbrains_icons/IconProvider.kt @@ -23,6 +23,14 @@ class IconProvider : IconProvider() { /** File extensions that are handled by more specific providers (not this class). */ private val fileTypesByProviders = listOf(".java") + /** + * Returns an icon for the given PsiElement. + * + * @param element The PsiElement to get an icon for. + * @param flags Additional flags for icon retrieval (not used in this implementation). + * @return The icon for the element, or null if no suitable icon is found or if the file type is + * handled by another provider. + */ override fun getIcon(element: PsiElement, flags: Int): Icon? { val virtualFile = PsiUtilCore.getVirtualFile(element) val file = virtualFile?.let { PsiManager.getInstance(element.project).findFile(it) } @@ -33,39 +41,70 @@ class IconProvider : IconProvider() { return null } - // Check if the name of the file is overridden by anything, if so return that icon. - if (iconOverrides.containsKey(file?.fileType?.name?.lowercase())) { - return iconOverrides[file?.fileType?.name?.lowercase()] - } + return findIcon(virtualFile, file) + } - // Folders - if (virtualFile?.isDirectory == true) { - return icons.FOLDER_TO_ICONS[virtualFile.name.lowercase()] ?: icons._folder + /** + * Finds an appropriate icon for the given virtual file and PsiFile. + * + * @param virtualFile The VirtualFile associated with the element. + * @param file The PsiFile associated with the element. + * @return The icon for the file, or a default icon if no specific icon is found. + */ + private fun findIcon( + virtualFile: com.intellij.openapi.vfs.VirtualFile?, + file: com.intellij.psi.PsiFile?, + ): Icon? { + val fileTypeName = file?.fileType?.name?.lowercase() + + return when { + // Check if the name of the file is overridden by anything, if so return that icon. + iconOverrides.containsKey(fileTypeName) -> iconOverrides[fileTypeName] + virtualFile?.isDirectory == true -> + icons.FOLDER_TO_ICONS[virtualFile.name.lowercase()] ?: icons._folder + else -> findFileIcon(virtualFile) ?: icons._file } + } + + /** + * Finds an icon specifically for a file (not a directory). + * + * @param virtualFile The VirtualFile to find an icon for. + * @return The icon for the file, or null if no specific icon is found. + */ + private fun findFileIcon(virtualFile: com.intellij.openapi.vfs.VirtualFile?): Icon? { + val fileName = virtualFile?.name?.lowercase() // Files - val icon = icons.FILE_TO_ICONS[virtualFile?.name?.lowercase()] - if (icon != null) { - return icon - } + return icons.FILE_TO_ICONS[fileName] + ?: findExtensionIcon(fileName) + ?: if (virtualFile?.fileType?.isBinary == true) icons.binary else null + } + /** + * Finds an icon based on the file extension. + * + * @param fileName The name of the file to find an icon for. + * @return The icon for the file extension, or null if no matching icon is found. + */ + private fun findExtensionIcon(fileName: String?): Icon? { // Extensions // if the file is abc.test.tsx, try abc.test.tsx, then test.tsx, then tsx - val parts = virtualFile?.name?.split(".") - if (parts != null) { - for (i in parts.indices) { - val path = parts.subList(i, parts.size).joinToString(".") - val icon = icons.EXT_TO_ICONS[path] - if (icon != null) { - return icon + return when { + // Return null if filename is null since we can't process it + fileName == null -> null + else -> { + val parts = fileName.split(".") + for (i in parts.indices) { + val path = parts.subList(i, parts.size).joinToString(".") + // Return the first matching icon we find, starting from the longest possible extension + icons.EXT_TO_ICONS[path]?.let { + return it + } } + // No matching extension was found, so return null to fall back to default icon + null } } - - if (virtualFile?.fileType?.isBinary == true) { - return icons.binary - } - - return icons._file } } diff --git a/src/main/kotlin/com/github/catppuccin/jetbrains_icons/providers/JavaIconProvider.kt b/src/main/kotlin/com/github/catppuccin/jetbrains_icons/providers/JavaIconProvider.kt index b96c52c..182d013 100644 --- a/src/main/kotlin/com/github/catppuccin/jetbrains_icons/providers/JavaIconProvider.kt +++ b/src/main/kotlin/com/github/catppuccin/jetbrains_icons/providers/JavaIconProvider.kt @@ -16,46 +16,90 @@ import com.intellij.ui.RowIcon import javax.swing.Icon import org.jetbrains.annotations.NotNull +/** Provides icons for Java classes in the IDE. */ class JavaIconProvider : IconProvider() { + /** + * Returns an icon for the given PsiElement if it's a Java class. + * + * @param element The PsiElement to get an icon for. + * @param flags Additional flags for icon retrieval. + * @return The icon for the element, or null if no suitable icon is found. + */ override fun getIcon(@NotNull element: PsiElement, @IconFlags flags: Int): Icon? { - if (!PluginSettingsState.instance.javaSupport) return icons.java - - if (element !is PsiClass) return null - - val virtualFile = PsiUtilCore.getVirtualFile(element) ?: return null - if (!virtualFile.name.endsWith(".java")) return null + return when { + !PluginSettingsState.instance.javaSupport -> icons.java + element !is PsiClass -> null + PsiUtilCore.getVirtualFile(element)?.name?.endsWith(".java") != true -> null + else -> getJavaClassIcon(element) + } + } + /** + * Gets the appropriate icon for a Java class, including static and visibility markers. + * + * @param element The PsiClass to get an icon for. + * @return The icon for the Java class. + */ + private fun getJavaClassIcon(element: PsiClass): Icon { val baseIcon = getJavaIcon(element) - val staticMark = getStaticMark(element) + val iconWithStaticMark = addStaticMarkIfNeeded(element, baseIcon) + return addVisibilityIconIfNeeded(element, iconWithStaticMark) + } - val icon = - when { - staticMark != null -> { - LayeredIcon(2).apply { - setIcon(baseIcon, 0) - setIcon(staticMark, 1) - } - } - else -> baseIcon + /** + * Adds a static mark to the icon if the class is static. + * + * @param element The PsiClass to check for static modifier. + * @param baseIcon The base icon to add the static mark to. + * @return The icon with static mark added if needed. + */ + private fun addStaticMarkIfNeeded(element: PsiClass, baseIcon: Icon): Icon { + val staticMark = getStaticMark(element) + return if (staticMark != null) { + LayeredIcon(2).apply { + setIcon(baseIcon, 0) + setIcon(staticMark, 1) } + } else { + baseIcon + } + } + /** + * Adds a visibility icon to the class icon if visibility icons are enabled in the project view. + * + * @param element The PsiClass to get the visibility for. + * @param icon The icon to add the visibility icon to. + * @return The icon with visibility icon added if needed. + */ + private fun addVisibilityIconIfNeeded(element: PsiClass, icon: Icon): Icon { val visibilityIconsEnabled = ProjectView.getInstance(element.project)?.isShowVisibilityIcons("ProjectPane") == true - - return when { - visibilityIconsEnabled -> { - RowIcon(2).apply { - setIcon(icon, 0) - getVisibilityIcon(element)?.let { setIcon(it, 1) } - } + return if (visibilityIconsEnabled) { + RowIcon(2).apply { + setIcon(icon, 0) + getVisibilityIcon(element)?.let { setIcon(it, 1) } } - else -> icon + } else { + icon } } + /** + * Gets the static mark icon if the class is static. + * + * @param element The PsiClass to check for static modifier. + * @return The static mark icon if the class is static, null otherwise. + */ private fun getStaticMark(element: PsiClass): Icon? = if (PsiClassUtils.isStatic(element)) AllIcons.Nodes.StaticMark else null + /** + * Gets the visibility icon for the given PsiClass. + * + * @param psiElement The PsiClass to get the visibility icon for. + * @return The visibility icon based on the class's modifier, or null if not applicable. + */ private fun getVisibilityIcon(psiElement: PsiClass): Icon? = when { psiElement.hasModifierProperty(PsiModifier.PUBLIC) -> AllIcons.Nodes.Public @@ -65,6 +109,12 @@ class JavaIconProvider : IconProvider() { else -> null } + /** + * Gets the appropriate Java icon based on the class type. + * + * @param aClass The PsiClass to get the icon for. + * @return The icon representing the Java class type. + */ private fun getJavaIcon(aClass: PsiClass): Icon = when { aClass.isAnnotationType -> icons.java_annotation diff --git a/src/main/kotlin/com/github/catppuccin/jetbrains_icons/settings/views/SettingsAdditionalSupportView.kt b/src/main/kotlin/com/github/catppuccin/jetbrains_icons/settings/views/SettingsAdditionalSupportView.kt index f7e35e4..ca38152 100644 --- a/src/main/kotlin/com/github/catppuccin/jetbrains_icons/settings/views/SettingsAdditionalSupportView.kt +++ b/src/main/kotlin/com/github/catppuccin/jetbrains_icons/settings/views/SettingsAdditionalSupportView.kt @@ -2,7 +2,7 @@ package com.github.catppuccin.jetbrains_icons.settings.views import com.github.catppuccin.jetbrains_icons.settings.PluginSettingsState import com.intellij.ide.plugins.PluginManager.isPluginInstalled -import com.intellij.openapi.extensions.PluginId.* +import com.intellij.openapi.extensions.PluginId.findId import com.intellij.ui.components.JBCheckBox import com.intellij.util.ui.FormBuilder import java.awt.FlowLayout diff --git a/src/main/kotlin/com/github/catppuccin/jetbrains_icons/settings/views/SettingsHeaderView.kt b/src/main/kotlin/com/github/catppuccin/jetbrains_icons/settings/views/SettingsHeaderView.kt index 9de8514..119da0a 100644 --- a/src/main/kotlin/com/github/catppuccin/jetbrains_icons/settings/views/SettingsHeaderView.kt +++ b/src/main/kotlin/com/github/catppuccin/jetbrains_icons/settings/views/SettingsHeaderView.kt @@ -8,16 +8,27 @@ import javax.swing.JLabel import javax.swing.JPanel class SettingsHeaderView : JPanel() { + + companion object { + private const val SPACER_WIDTH = 4 + private const val SPACER_HEIGHT = 8 + private const val LOGO_SIZE = 60 + private const val FONT_SIZE = 24.0f + } + init { drawLogo() - add(Box.createRigidArea(Dimension(4, 0))) + + // Draw spacer between Logo and Title + add(Box.createRigidArea(Dimension(SPACER_WIDTH, SPACER_HEIGHT))) + drawTitle() } private fun drawLogo() { val url = javaClass.getResource("/pluginIcon.png") var image = ImageIcon(url) - image = ImageIcon(image.image.getScaledInstance(60, 60, Image.SCALE_SMOOTH)) + image = ImageIcon(image.image.getScaledInstance(LOGO_SIZE, LOGO_SIZE, Image.SCALE_SMOOTH)) val field = JLabel(image) add(field) @@ -25,7 +36,7 @@ class SettingsHeaderView : JPanel() { private fun drawTitle() { val label = JLabel("Catppuccin Icons") - label.font = label.font.deriveFont(24.0f) + label.font = label.font.deriveFont(FONT_SIZE) add(label) } } diff --git a/src/main/kotlin/com/github/catppuccin/jetbrains_icons/util/PsiClassUtils.kt b/src/main/kotlin/com/github/catppuccin/jetbrains_icons/util/PsiClassUtils.kt index d5006de..d5e68b3 100644 --- a/src/main/kotlin/com/github/catppuccin/jetbrains_icons/util/PsiClassUtils.kt +++ b/src/main/kotlin/com/github/catppuccin/jetbrains_icons/util/PsiClassUtils.kt @@ -22,10 +22,8 @@ object PsiClassUtils { /** Returns true if the [psiClass] is an exception (inherits from an exception). */ fun isException(psiClass: PsiClass): Boolean { - val className = psiClass.name - if (className.isNullOrEmpty()) return false - if (!psiClass.isValid) return false - return extendsException(psiClass) + if (psiClass.name.isNullOrEmpty()) return false + return psiClass.isValid && extendsException(psiClass) } /** Returns true if the [psiClass] has package-private visibility. */ From e067f52803495041a8ff5fe727264c6f246db5ee Mon Sep 17 00:00:00 2001 From: thelooter Date: Wed, 13 Nov 2024 13:00:03 +0100 Subject: [PATCH 2/4] refactor: improve KDoc formatting and enhance parameter descriptions in IconProvider and JavaIconProvider --- .../jetbrains_icons/IconProvider.kt | 35 +++++++++--------- .../providers/JavaIconProvider.kt | 36 +++++++++---------- 2 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/main/kotlin/com/github/catppuccin/jetbrains_icons/IconProvider.kt b/src/main/kotlin/com/github/catppuccin/jetbrains_icons/IconProvider.kt index c6e1337..53d1e01 100644 --- a/src/main/kotlin/com/github/catppuccin/jetbrains_icons/IconProvider.kt +++ b/src/main/kotlin/com/github/catppuccin/jetbrains_icons/IconProvider.kt @@ -2,7 +2,9 @@ package com.github.catppuccin.jetbrains_icons import com.github.catppuccin.jetbrains_icons.IconPack.icons import com.intellij.ide.IconProvider +import com.intellij.openapi.vfs.VirtualFile import com.intellij.psi.PsiElement +import com.intellij.psi.PsiFile import com.intellij.psi.PsiManager import com.intellij.psi.util.PsiUtilCore import javax.swing.Icon @@ -24,12 +26,11 @@ class IconProvider : IconProvider() { private val fileTypesByProviders = listOf(".java") /** - * Returns an icon for the given PsiElement. + * Returns an icon for the given [PsiElement]. * - * @param element The PsiElement to get an icon for. - * @param flags Additional flags for icon retrieval (not used in this implementation). - * @return The icon for the element, or null if no suitable icon is found or if the file type is - * handled by another provider. + * @param element the [PsiElement] to get an icon for. + * @param flags additional flags for icon retrieval (not used in this implementation). + * @return the [Icon] corresponding to the file type */ override fun getIcon(element: PsiElement, flags: Int): Icon? { val virtualFile = PsiUtilCore.getVirtualFile(element) @@ -45,15 +46,15 @@ class IconProvider : IconProvider() { } /** - * Finds an appropriate icon for the given virtual file and PsiFile. + * Finds an appropriate icon for the given virtual file and [PsiFile]. * - * @param virtualFile The VirtualFile associated with the element. - * @param file The PsiFile associated with the element. - * @return The icon for the file, or a default icon if no specific icon is found. + * @param virtualFile the [VirtualFile] associated with the element. + * @param file the [PsiFile] associated with the element. + * @return the icon for the file, or a default icon if no specific icon is found. */ private fun findIcon( - virtualFile: com.intellij.openapi.vfs.VirtualFile?, - file: com.intellij.psi.PsiFile?, + virtualFile: VirtualFile?, + file: PsiFile?, ): Icon? { val fileTypeName = file?.fileType?.name?.lowercase() @@ -69,10 +70,10 @@ class IconProvider : IconProvider() { /** * Finds an icon specifically for a file (not a directory). * - * @param virtualFile The VirtualFile to find an icon for. - * @return The icon for the file, or null if no specific icon is found. + * @param virtualFile the [VirtualFile] to find an icon for. + * @return the icon for the file, or null if no specific icon is found. */ - private fun findFileIcon(virtualFile: com.intellij.openapi.vfs.VirtualFile?): Icon? { + private fun findFileIcon(virtualFile: VirtualFile?): Icon? { val fileName = virtualFile?.name?.lowercase() // Files @@ -84,8 +85,8 @@ class IconProvider : IconProvider() { /** * Finds an icon based on the file extension. * - * @param fileName The name of the file to find an icon for. - * @return The icon for the file extension, or null if no matching icon is found. + * @param fileName the name of the file to find an icon for. + * @return the icon for the file extension, or null if no matching icon is found. */ private fun findExtensionIcon(fileName: String?): Icon? { // Extensions @@ -102,7 +103,7 @@ class IconProvider : IconProvider() { return it } } - // No matching extension was found, so return null to fall back to default icon + // No matching extension was found, so return null, falling back to default icon null } } diff --git a/src/main/kotlin/com/github/catppuccin/jetbrains_icons/providers/JavaIconProvider.kt b/src/main/kotlin/com/github/catppuccin/jetbrains_icons/providers/JavaIconProvider.kt index 182d013..6647b53 100644 --- a/src/main/kotlin/com/github/catppuccin/jetbrains_icons/providers/JavaIconProvider.kt +++ b/src/main/kotlin/com/github/catppuccin/jetbrains_icons/providers/JavaIconProvider.kt @@ -16,28 +16,26 @@ import com.intellij.ui.RowIcon import javax.swing.Icon import org.jetbrains.annotations.NotNull -/** Provides icons for Java classes in the IDE. */ +/** Provides icons for Java classes*/ class JavaIconProvider : IconProvider() { /** - * Returns an icon for the given PsiElement if it's a Java class. + * Returns an icon for the given [PsiElement] if it's a Java class. * - * @param element The PsiElement to get an icon for. + * @param element The [PsiElement] to get an icon for. * @param flags Additional flags for icon retrieval. * @return The icon for the element, or null if no suitable icon is found. */ - override fun getIcon(@NotNull element: PsiElement, @IconFlags flags: Int): Icon? { - return when { - !PluginSettingsState.instance.javaSupport -> icons.java - element !is PsiClass -> null - PsiUtilCore.getVirtualFile(element)?.name?.endsWith(".java") != true -> null - else -> getJavaClassIcon(element) - } + override fun getIcon(@NotNull element: PsiElement, @IconFlags flags: Int): Icon? = when { + !PluginSettingsState.instance.javaSupport -> icons.java + element !is PsiClass -> null + PsiUtilCore.getVirtualFile(element)?.name?.endsWith(".java") != true -> null + else -> getJavaClassIcon(element) } /** * Gets the appropriate icon for a Java class, including static and visibility markers. * - * @param element The PsiClass to get an icon for. + * @param element The [PsiClass] to get an icon for. * @return The icon for the Java class. */ private fun getJavaClassIcon(element: PsiClass): Icon { @@ -49,7 +47,7 @@ class JavaIconProvider : IconProvider() { /** * Adds a static mark to the icon if the class is static. * - * @param element The PsiClass to check for static modifier. + * @param element The [PsiClass] to check for static modifier. * @param baseIcon The base icon to add the static mark to. * @return The icon with static mark added if needed. */ @@ -66,9 +64,9 @@ class JavaIconProvider : IconProvider() { } /** - * Adds a visibility icon to the class icon if visibility icons are enabled in the project view. + * Adds a visibility icon to the class icon if visibility icons are enabled. * - * @param element The PsiClass to get the visibility for. + * @param element The [PsiClass] to get the visibility for. * @param icon The icon to add the visibility icon to. * @return The icon with visibility icon added if needed. */ @@ -87,17 +85,19 @@ class JavaIconProvider : IconProvider() { /** * Gets the static mark icon if the class is static. + * This is a small icon that is added to the class icon to indicate that the class is static. * - * @param element The PsiClass to check for static modifier. + * @param element The [PsiClass] to check for static modifier. * @return The static mark icon if the class is static, null otherwise. + * @see AllIcons.Nodes.StaticMark */ private fun getStaticMark(element: PsiClass): Icon? = if (PsiClassUtils.isStatic(element)) AllIcons.Nodes.StaticMark else null /** - * Gets the visibility icon for the given PsiClass. + * Gets the visibility icon for the given [PsiClass]. * - * @param psiElement The PsiClass to get the visibility icon for. + * @param psiElement The [PsiClass] to get the visibility icon for. * @return The visibility icon based on the class's modifier, or null if not applicable. */ private fun getVisibilityIcon(psiElement: PsiClass): Icon? = @@ -112,7 +112,7 @@ class JavaIconProvider : IconProvider() { /** * Gets the appropriate Java icon based on the class type. * - * @param aClass The PsiClass to get the icon for. + * @param aClass The [PsiClass] to get the icon for. * @return The icon representing the Java class type. */ private fun getJavaIcon(aClass: PsiClass): Icon = From 36f58253b83edf87b9af92b00c4f9b01ab15af88 Mon Sep 17 00:00:00 2001 From: thelooter Date: Wed, 13 Nov 2024 13:03:05 +0100 Subject: [PATCH 3/4] refactor(settings): move companion object in SettingsHeaderView to bottom --- .../settings/views/SettingsHeaderView.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/com/github/catppuccin/jetbrains_icons/settings/views/SettingsHeaderView.kt b/src/main/kotlin/com/github/catppuccin/jetbrains_icons/settings/views/SettingsHeaderView.kt index 119da0a..919f7ed 100644 --- a/src/main/kotlin/com/github/catppuccin/jetbrains_icons/settings/views/SettingsHeaderView.kt +++ b/src/main/kotlin/com/github/catppuccin/jetbrains_icons/settings/views/SettingsHeaderView.kt @@ -9,13 +9,6 @@ import javax.swing.JPanel class SettingsHeaderView : JPanel() { - companion object { - private const val SPACER_WIDTH = 4 - private const val SPACER_HEIGHT = 8 - private const val LOGO_SIZE = 60 - private const val FONT_SIZE = 24.0f - } - init { drawLogo() @@ -39,4 +32,11 @@ class SettingsHeaderView : JPanel() { label.font = label.font.deriveFont(FONT_SIZE) add(label) } + + companion object { + private const val SPACER_WIDTH = 4 + private const val SPACER_HEIGHT = 8 + private const val LOGO_SIZE = 60 + private const val FONT_SIZE = 24.0f + } } From 4b532fac62d8aa44305918ac069debd523a04947 Mon Sep 17 00:00:00 2001 From: thelooter Date: Wed, 13 Nov 2024 13:21:23 +0100 Subject: [PATCH 4/4] fix(iconprovider): clarify KDoc for flags parameter in getIcon method --- .../jetbrains_icons/IconProvider.kt | 9 ++++----- .../providers/JavaIconProvider.kt | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/com/github/catppuccin/jetbrains_icons/IconProvider.kt b/src/main/kotlin/com/github/catppuccin/jetbrains_icons/IconProvider.kt index 53d1e01..4ebcc07 100644 --- a/src/main/kotlin/com/github/catppuccin/jetbrains_icons/IconProvider.kt +++ b/src/main/kotlin/com/github/catppuccin/jetbrains_icons/IconProvider.kt @@ -29,7 +29,8 @@ class IconProvider : IconProvider() { * Returns an icon for the given [PsiElement]. * * @param element the [PsiElement] to get an icon for. - * @param flags additional flags for icon retrieval (not used in this implementation). + * @param flags additional flags for icon retrieval (not used in this implementation). It is only + * used because the method signature requires it. * @return the [Icon] corresponding to the file type */ override fun getIcon(element: PsiElement, flags: Int): Icon? { @@ -52,10 +53,7 @@ class IconProvider : IconProvider() { * @param file the [PsiFile] associated with the element. * @return the icon for the file, or a default icon if no specific icon is found. */ - private fun findIcon( - virtualFile: VirtualFile?, - file: PsiFile?, - ): Icon? { + private fun findIcon(virtualFile: VirtualFile?, file: PsiFile?): Icon? { val fileTypeName = file?.fileType?.name?.lowercase() return when { @@ -63,6 +61,7 @@ class IconProvider : IconProvider() { iconOverrides.containsKey(fileTypeName) -> iconOverrides[fileTypeName] virtualFile?.isDirectory == true -> icons.FOLDER_TO_ICONS[virtualFile.name.lowercase()] ?: icons._folder + else -> findFileIcon(virtualFile) ?: icons._file } } diff --git a/src/main/kotlin/com/github/catppuccin/jetbrains_icons/providers/JavaIconProvider.kt b/src/main/kotlin/com/github/catppuccin/jetbrains_icons/providers/JavaIconProvider.kt index 6647b53..8c9c7bb 100644 --- a/src/main/kotlin/com/github/catppuccin/jetbrains_icons/providers/JavaIconProvider.kt +++ b/src/main/kotlin/com/github/catppuccin/jetbrains_icons/providers/JavaIconProvider.kt @@ -16,7 +16,7 @@ import com.intellij.ui.RowIcon import javax.swing.Icon import org.jetbrains.annotations.NotNull -/** Provides icons for Java classes*/ +/** Provides icons for Java classes */ class JavaIconProvider : IconProvider() { /** * Returns an icon for the given [PsiElement] if it's a Java class. @@ -25,12 +25,13 @@ class JavaIconProvider : IconProvider() { * @param flags Additional flags for icon retrieval. * @return The icon for the element, or null if no suitable icon is found. */ - override fun getIcon(@NotNull element: PsiElement, @IconFlags flags: Int): Icon? = when { - !PluginSettingsState.instance.javaSupport -> icons.java - element !is PsiClass -> null - PsiUtilCore.getVirtualFile(element)?.name?.endsWith(".java") != true -> null - else -> getJavaClassIcon(element) - } + override fun getIcon(@NotNull element: PsiElement, @IconFlags flags: Int): Icon? = + when { + !PluginSettingsState.instance.javaSupport -> icons.java + element !is PsiClass -> null + PsiUtilCore.getVirtualFile(element)?.name?.endsWith(".java") != true -> null + else -> getJavaClassIcon(element) + } /** * Gets the appropriate icon for a Java class, including static and visibility markers. @@ -84,8 +85,8 @@ class JavaIconProvider : IconProvider() { } /** - * Gets the static mark icon if the class is static. - * This is a small icon that is added to the class icon to indicate that the class is static. + * Gets the static mark icon if the class is static. This is a small icon that is added to the + * class icon to indicate that the class is static. * * @param element The [PsiClass] to check for static modifier. * @return The static mark icon if the class is static, null otherwise.