Skip to content

Commit

Permalink
[maintenance] WithBuildToolId moved to a better location
Browse files Browse the repository at this point in the history
detekt

lil update

[maintenance] `WithBuildToolId` moved to a better location


Merge-request: BAZEL-MR-671
Merged-by: Marcin Abramowicz <[email protected]>
  • Loading branch information
abrams27 authored and qodana-bot committed Nov 29, 2023
1 parent 3422c1b commit 9428e08
Show file tree
Hide file tree
Showing 21 changed files with 51 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package org.jetbrains.plugins.bsp.assets
import com.intellij.icons.AllIcons
import com.intellij.openapi.util.IconLoader
import org.jetbrains.plugins.bsp.config.BspPluginIcons
import org.jetbrains.plugins.bsp.flow.open.BuildToolId
import org.jetbrains.plugins.bsp.extension.points.BuildToolId
import org.jetbrains.plugins.bsp.extension.points.bspBuildToolId
import javax.swing.Icon

public class BspAssetsExtension : BuildToolAssetsExtension {
override val buildToolId: BuildToolId = BuildToolId("bsp")
override val buildToolId: BuildToolId = bspBuildToolId

override val presentableName: String = "BSP"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.jetbrains.plugins.bsp.assets

import com.intellij.openapi.extensions.ExtensionPointName
import org.jetbrains.plugins.bsp.flow.open.WithBuildToolId
import org.jetbrains.plugins.bsp.extension.points.WithBuildToolId
import javax.swing.Icon

public interface BuildToolAssetsExtension : WithBuildToolId {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.intellij.ide.util.PropertiesComponent
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.VirtualFileManager
import org.jetbrains.plugins.bsp.flow.open.BuildToolId
import org.jetbrains.plugins.bsp.extension.points.BuildToolId

private const val IS_BSP_PROJECT_KEY = "org.jetbrains.bsp.is.bsp.project"

Expand All @@ -15,18 +15,18 @@ public var Project.isBspProject: Boolean
private const val PROJECT_ROOT_DIR_KEY = "org.jetbrains.bsp.project.root.dir"

public var Project.rootDir: VirtualFile
get() = properties.getValue(PROJECT_ROOT_DIR_KEY)
?.let { VirtualFileManager.getInstance().findFileByUrl(it) }
?: error("$PROJECT_ROOT_DIR_KEY value not set!")
get() = properties.getValueOrThrow(PROJECT_ROOT_DIR_KEY)
.let { VirtualFileManager.getInstance().findFileByUrl(it) ?: error("Cannot find file by url (url: $it)") }
set(value) = properties.setValue(PROJECT_ROOT_DIR_KEY, value.url)

private const val BUILD_TOOL_ID_KEY = "org.jetbrains.bsp.build.tool.id"

public var Project.buildToolId: BuildToolId
get() = properties.getValue(BUILD_TOOL_ID_KEY)
?.let { BuildToolId(it) }
?: error("$BUILD_TOOL_ID_KEY value not set!")
get() = BuildToolId(properties.getValueOrThrow(BUILD_TOOL_ID_KEY))
set(value) = properties.setValue(BUILD_TOOL_ID_KEY, value.id)

private val Project.properties: PropertiesComponent
get() = PropertiesComponent.getInstance(this)

private fun PropertiesComponent.getValueOrThrow(key: String): String =
getValue(key) ?: error("$key value not set")
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.jetbrains.plugins.bsp.extension.points

import com.intellij.openapi.extensions.ExtensionPointName

public data class BuildToolId(public val id: String)

public interface WithBuildToolId {
public val buildToolId: BuildToolId
}

internal val bspBuildToolId = BuildToolId("bsp")

internal fun <T : WithBuildToolId> ExtensionPointName<T>.withBuildToolId(buildToolId: BuildToolId): T? =
this.extensions.find { it.buildToolId == buildToolId }

internal fun <T : WithBuildToolId> ExtensionPointName<T>.withBuildToolIdOrDefault(buildToolId: BuildToolId): T =
this.withBuildToolId(buildToolId)
?: withBuildToolId(bspBuildToolId)
?: error("Missing default implementation (BSP) for extension: ${this.javaClass.name}. Something is wrong.")
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.jetbrains.magicmetamodel.ProjectDetails
import org.jetbrains.plugins.bsp.config.buildToolId
import org.jetbrains.plugins.bsp.config.isBspProject
import org.jetbrains.plugins.bsp.config.rootDir
import org.jetbrains.plugins.bsp.extension.points.BuildToolId
import org.jetbrains.plugins.bsp.services.BspCoroutineService
import org.jetbrains.plugins.bsp.services.MagicMetaModelService
import java.nio.file.Path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,13 @@ import com.intellij.openapi.extensions.ExtensionPointName
import com.intellij.openapi.vfs.VirtualFile
import org.jetbrains.plugins.bsp.config.BspPluginBundle
import org.jetbrains.plugins.bsp.config.BspPluginIcons
import org.jetbrains.plugins.bsp.extension.points.BuildToolId
import org.jetbrains.plugins.bsp.extension.points.WithBuildToolId
import org.jetbrains.plugins.bsp.extension.points.bspBuildToolId
import org.jetbrains.plugins.bsp.extension.points.withBuildToolId
import org.jetbrains.plugins.bsp.protocol.connection.BspConnectionFilesProvider
import javax.swing.Icon

// TODO: move to a better package
public data class BuildToolId(public val id: String)

// TODO: move to a better package
public interface WithBuildToolId {
public val buildToolId: BuildToolId
}

// TODO: move to a better package
internal fun <T : WithBuildToolId> ExtensionPointName<T>.withBuildToolId(buildToolId: BuildToolId): T? =
this.extensions.find { it.buildToolId == buildToolId }

internal fun <T : WithBuildToolId> ExtensionPointName<T>.withBuildToolIdOrDefault(buildToolId: BuildToolId): T =
this.extensions.find { it.buildToolId == buildToolId }
?: withBuildToolId(BuildToolId("bsp"))
?: error("Missing default implementation for extension: ${this.javaClass.name}")

public interface BspProjectOpenProcessorExtension : WithBuildToolId {
/**
* When a project is opened for the first time [com.intellij.projectImport.ProjectOpenProcessor.canOpenProject]
Expand All @@ -47,7 +34,7 @@ public interface BspProjectOpenProcessorExtension : WithBuildToolId {
}
}

internal class BspProjectOpenProcessor : BaseBspProjectOpenProcessor(BuildToolId("bsp")) {
internal class BspProjectOpenProcessor : BaseBspProjectOpenProcessor(bspBuildToolId) {
override val name: String = BspPluginBundle.message("plugin.name")

override val icon: Icon = BspPluginIcons.bsp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.jetbrains.magicmetamodel.impl.workspacemodel.BuildTargetId
import org.jetbrains.plugins.bsp.assets.BuildToolAssetsExtension
import org.jetbrains.plugins.bsp.config.BspPluginBundle
import org.jetbrains.plugins.bsp.config.buildToolId
import org.jetbrains.plugins.bsp.flow.open.withBuildToolIdOrDefault
import org.jetbrains.plugins.bsp.extension.points.withBuildToolIdOrDefault
import org.jetbrains.plugins.bsp.services.MagicMetaModelService
import org.jetbrains.plugins.bsp.ui.notifications.BspBalloonNotifier

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import com.intellij.openapi.project.Project
import org.jetbrains.plugins.bsp.assets.BuildToolAssetsExtension
import org.jetbrains.plugins.bsp.config.BspPluginBundle
import org.jetbrains.plugins.bsp.config.buildToolId
import org.jetbrains.plugins.bsp.flow.open.withBuildToolIdOrDefault
import org.jetbrains.plugins.bsp.extension.points.withBuildToolIdOrDefault
import org.jetbrains.plugins.bsp.server.tasks.RunTargetTask
import org.jetbrains.plugins.bsp.ui.configuration.BspProcessHandler
import org.jetbrains.plugins.bsp.ui.console.BspConsoleService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.intellij.openapi.project.Project
import org.jetbrains.plugins.bsp.assets.BuildToolAssetsExtension
import org.jetbrains.plugins.bsp.config.BspPluginBundle
import org.jetbrains.plugins.bsp.config.buildToolId
import org.jetbrains.plugins.bsp.flow.open.withBuildToolIdOrDefault
import org.jetbrains.plugins.bsp.extension.points.withBuildToolIdOrDefault
import org.jetbrains.plugins.bsp.server.tasks.TestTargetTask
import org.jetbrains.plugins.bsp.ui.configuration.BspProcessHandler
import org.jetbrains.plugins.bsp.ui.console.BspConsoleService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.intellij.openapi.project.Project
import org.jetbrains.plugins.bsp.assets.BuildToolAssetsExtension
import org.jetbrains.plugins.bsp.config.buildToolId
import org.jetbrains.plugins.bsp.config.rootDir
import org.jetbrains.plugins.bsp.flow.open.withBuildToolIdOrDefault
import org.jetbrains.plugins.bsp.extension.points.withBuildToolIdOrDefault

@Service(Service.Level.PROJECT)
public class BspConsoleService(project: Project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.jetbrains.magicmetamodel.impl.workspacemodel.BuildTargetId
import org.jetbrains.plugins.bsp.assets.BuildToolAssetsExtension
import org.jetbrains.plugins.bsp.config.buildToolId
import org.jetbrains.plugins.bsp.config.isBspProject
import org.jetbrains.plugins.bsp.flow.open.withBuildToolIdOrDefault
import org.jetbrains.plugins.bsp.extension.points.withBuildToolIdOrDefault
import org.jetbrains.plugins.bsp.services.MagicMetaModelService
import org.jetbrains.plugins.bsp.ui.widgets.tool.window.actions.RunTargetAction
import org.jetbrains.plugins.bsp.ui.widgets.tool.window.actions.TestTargetAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.intellij.workspaceModel.ide.getInstance
import org.jetbrains.plugins.bsp.assets.BuildToolAssetsExtension
import org.jetbrains.plugins.bsp.config.buildToolId
import org.jetbrains.plugins.bsp.config.isBspProject
import org.jetbrains.plugins.bsp.flow.open.withBuildToolIdOrDefault
import org.jetbrains.plugins.bsp.extension.points.withBuildToolIdOrDefault
import org.jetbrains.plugins.bsp.services.MagicMetaModelService
import javax.swing.Icon

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import org.jetbrains.plugins.bsp.assets.BuildToolAssetsExtension
import org.jetbrains.plugins.bsp.config.BspPluginBundle
import org.jetbrains.plugins.bsp.config.buildToolId
import org.jetbrains.plugins.bsp.config.isBspProject
import org.jetbrains.plugins.bsp.flow.open.withBuildToolIdOrDefault
import org.jetbrains.plugins.bsp.extension.points.withBuildToolIdOrDefault
import org.jetbrains.plugins.bsp.services.MagicMetaModelService
import org.jetbrains.plugins.bsp.ui.actions.LoadTargetAction
import java.net.URI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import kotlinx.coroutines.withContext
import org.jetbrains.plugins.bsp.assets.BuildToolAssetsExtension
import org.jetbrains.plugins.bsp.config.buildToolId
import org.jetbrains.plugins.bsp.config.isBspProject
import org.jetbrains.plugins.bsp.flow.open.withBuildToolIdOrDefault
import org.jetbrains.plugins.bsp.extension.points.withBuildToolIdOrDefault
import org.jetbrains.plugins.bsp.ui.widgets.tool.window.components.BspToolWindowPanel
import org.jetbrains.plugins.bsp.ui.widgets.tool.window.components.BspToolWindowService

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.intellij.ui.components.panels.VerticalLayout
import org.jetbrains.magicmetamodel.impl.workspacemodel.BuildTargetId
import org.jetbrains.magicmetamodel.impl.workspacemodel.BuildTargetInfo
import org.jetbrains.plugins.bsp.config.BspPluginBundle
import org.jetbrains.plugins.bsp.flow.open.BuildToolId
import org.jetbrains.plugins.bsp.extension.points.BuildToolId
import org.jetbrains.plugins.bsp.ui.widgets.tool.window.search.SearchBarPanel
import java.awt.Component
import java.awt.event.MouseListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.jetbrains.plugins.bsp.assets.BuildToolAssetsExtension
import org.jetbrains.plugins.bsp.config.BspPluginBundle
import org.jetbrains.plugins.bsp.config.BspPluginIcons
import org.jetbrains.plugins.bsp.config.buildToolId
import org.jetbrains.plugins.bsp.flow.open.withBuildToolIdOrDefault
import org.jetbrains.plugins.bsp.extension.points.withBuildToolIdOrDefault
import org.jetbrains.plugins.bsp.services.MagicMetaModelService
import org.jetbrains.plugins.bsp.ui.widgets.tool.window.all.targets.StickyTargetAction
import org.jetbrains.plugins.bsp.ui.widgets.tool.window.filter.FilterActionGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import com.intellij.ui.components.panels.VerticalLayout
import com.intellij.util.concurrency.NonUrgentExecutor
import org.jetbrains.magicmetamodel.impl.workspacemodel.BuildTargetInfo
import org.jetbrains.plugins.bsp.config.BspPluginBundle
import org.jetbrains.plugins.bsp.config.buildToolId
import org.jetbrains.plugins.bsp.flow.open.BuildToolId
import org.jetbrains.plugins.bsp.extension.points.BuildToolId
import org.jetbrains.plugins.bsp.ui.widgets.tool.window.actions.CopyTargetIdAction
import org.jetbrains.plugins.bsp.ui.widgets.tool.window.search.LazySearchListDisplay
import org.jetbrains.plugins.bsp.ui.widgets.tool.window.search.LazySearchTreeDisplay
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.jetbrains.magicmetamodel.impl.workspacemodel.BuildTargetId
import org.jetbrains.magicmetamodel.impl.workspacemodel.BuildTargetInfo
import org.jetbrains.plugins.bsp.config.BspPluginBundle
import org.jetbrains.plugins.bsp.extension.points.BspBuildTargetClassifierExtension
import org.jetbrains.plugins.bsp.flow.open.BuildToolId
import org.jetbrains.plugins.bsp.extension.points.BuildToolId
import org.jetbrains.plugins.bsp.ui.widgets.tool.window.actions.CopyTargetIdAction
import org.jetbrains.plugins.bsp.ui.widgets.tool.window.utils.BspBuildTargetClassifierProvider
import java.awt.Component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.jetbrains.plugins.bsp.ui.widgets.tool.window.search

import org.jetbrains.magicmetamodel.impl.workspacemodel.BuildTargetInfo
import org.jetbrains.plugins.bsp.flow.open.BuildToolId
import org.jetbrains.plugins.bsp.extension.points.BuildToolId
import org.jetbrains.plugins.bsp.ui.widgets.tool.window.components.BuildTargetTree
import java.awt.event.MouseListener
import javax.swing.Icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.intellij.testFramework.registerExtension
import com.intellij.testFramework.utils.vfs.createFile
import com.intellij.util.application
import io.kotest.matchers.shouldBe
import org.jetbrains.plugins.bsp.extension.points.BuildToolId
import org.jetbrains.workspace.model.test.framework.MockProjectBaseTest
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.DisplayName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.intellij.openapi.options.SettingsEditor
import com.intellij.openapi.project.Project
import io.kotest.matchers.shouldBe
import org.jetbrains.plugins.bsp.config.buildToolId
import org.jetbrains.plugins.bsp.flow.open.BuildToolId
import org.jetbrains.plugins.bsp.extension.points.BuildToolId
import org.jetbrains.plugins.bsp.ui.configuration.run.BspDebugType
import org.jetbrains.plugins.bsp.ui.configuration.run.BspRunConfiguration
import org.jetbrains.plugins.bsp.ui.configuration.run.BspRunConfigurationType
Expand Down

0 comments on commit 9428e08

Please sign in to comment.