Get rid of reflection in new project wizard core: manually specify properties in plugins
This commit is contained in:
committed by
Kirill Shmakov
parent
cc35529b9a
commit
63e2d771b3
+6
-7
@@ -4,7 +4,6 @@ import com.intellij.facet.impl.ui.libraries.LibraryOptionsPanel
|
||||
import com.intellij.framework.library.FrameworkLibraryVersionFilter
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.projectRoots.Sdk
|
||||
import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer
|
||||
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainerFactory
|
||||
import org.jetbrains.kotlin.idea.framework.JavaRuntimeLibraryDescription
|
||||
@@ -43,14 +42,14 @@ class IdeWizard(
|
||||
)
|
||||
var jdk: Sdk? = null
|
||||
|
||||
var projectPath by setting(StructurePlugin::projectPath.reference)
|
||||
var projectName by setting(StructurePlugin::name.reference)
|
||||
var projectPath by setting(StructurePlugin.projectPath.reference)
|
||||
var projectName by setting(StructurePlugin.name.reference)
|
||||
|
||||
var groupId by setting(StructurePlugin::groupId.reference)
|
||||
var artifactId by setting(StructurePlugin::artifactId.reference)
|
||||
var buildSystemType by setting(BuildSystemPlugin::type.reference)
|
||||
var groupId by setting(StructurePlugin.groupId.reference)
|
||||
var artifactId by setting(StructurePlugin.artifactId.reference)
|
||||
var buildSystemType by setting(BuildSystemPlugin.type.reference)
|
||||
|
||||
var projectTemplate by setting(ProjectTemplatesPlugin::template.reference)
|
||||
var projectTemplate by setting(ProjectTemplatesPlugin.template.reference)
|
||||
|
||||
private fun <V : Any, T : SettingType<V>> setting(reference: SettingReference<V, T>) =
|
||||
object : ReadWriteProperty<Any?, V?> {
|
||||
|
||||
+5
-8
@@ -3,7 +3,6 @@ package org.jetbrains.kotlin.tools.projectWizard.wizard
|
||||
import com.intellij.ide.RecentProjectsManager
|
||||
import com.intellij.ide.actions.NewProjectAction
|
||||
import com.intellij.ide.impl.NewProjectUtil
|
||||
import com.intellij.ide.projectWizard.NewProjectWizard
|
||||
import com.intellij.ide.util.projectWizard.*
|
||||
import com.intellij.ide.wizard.AbstractWizard
|
||||
import com.intellij.openapi.Disposable
|
||||
@@ -14,11 +13,9 @@ import com.intellij.openapi.module.ModuleType
|
||||
import com.intellij.openapi.options.ConfigurationException
|
||||
import com.intellij.openapi.progress.ProgressManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.project.ProjectManager
|
||||
import com.intellij.openapi.roots.ui.configuration.ModulesProvider
|
||||
import com.intellij.openapi.ui.Messages
|
||||
import com.intellij.util.SystemProperties
|
||||
import org.jetbrains.kotlin.idea.configuration.ExperimentalFeatures
|
||||
import org.jetbrains.kotlin.idea.framework.KotlinTemplatesFactory
|
||||
import org.jetbrains.kotlin.idea.projectWizard.ProjectCreationStats
|
||||
import org.jetbrains.kotlin.idea.projectWizard.UiEditorUsageStats
|
||||
@@ -201,12 +198,12 @@ class ModuleNewWizardFirstStep(wizard: IdeWizard) : WizardStep(wizard, Generatio
|
||||
val suggestedProjectParentLocation = suggestProjectLocation()
|
||||
val suggestedProjectName = ProjectWizardUtil.findNonExistingFileName(suggestedProjectParentLocation, "untitled", "")
|
||||
wizard.context.writeSettings {
|
||||
StructurePlugin::name.reference.setValue(suggestedProjectName)
|
||||
StructurePlugin::projectPath.reference.setValue(suggestedProjectParentLocation / suggestedProjectName)
|
||||
StructurePlugin::artifactId.reference.setValue(suggestedProjectName)
|
||||
StructurePlugin.name.reference.setValue(suggestedProjectName)
|
||||
StructurePlugin.projectPath.reference.setValue(suggestedProjectParentLocation / suggestedProjectName)
|
||||
StructurePlugin.artifactId.reference.setValue(suggestedProjectName)
|
||||
|
||||
if (StructurePlugin::groupId.reference.notRequiredSettingValue == null) {
|
||||
StructurePlugin::groupId.reference.setValue(suggestGroupId())
|
||||
if (StructurePlugin.groupId.notRequiredSettingValue == null) {
|
||||
StructurePlugin.groupId.reference.setValue(suggestGroupId())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-6
@@ -6,10 +6,8 @@ import org.jetbrains.kotlin.tools.projectWizard.core.Reader
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.SettingsWriter
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.Writer
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.ValidationResult
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.settings.PluginSettingPropertyReference
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.settings.SettingReference
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.settings.SettingType
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.settings.reference
|
||||
|
||||
abstract class Component : Displayable, ErrorNavigatable {
|
||||
private val subComponents = mutableListOf<Component>()
|
||||
@@ -45,10 +43,6 @@ abstract class DynamicComponent(private val context: Context) : Component() {
|
||||
value?.let { setValue(it) }
|
||||
}
|
||||
|
||||
|
||||
inline val <V : Any, reified T : SettingType<V>> PluginSettingPropertyReference<V, T>.value: V?
|
||||
get() = reference.value
|
||||
|
||||
init {
|
||||
write {
|
||||
eventManager.addSettingUpdaterEventListener { reference ->
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ import javax.swing.JComponent
|
||||
class BuildSystemTypeSettingComponent(
|
||||
context: Context
|
||||
) : SettingComponent<BuildSystemType, DropDownSettingType<BuildSystemType>>(
|
||||
BuildSystemPlugin::type.reference,
|
||||
BuildSystemPlugin.type.reference,
|
||||
context
|
||||
) {
|
||||
|
||||
|
||||
+15
-16
@@ -12,7 +12,6 @@ import com.intellij.ui.layout.panel
|
||||
import com.intellij.util.ui.JBUI
|
||||
import com.intellij.util.ui.components.BorderLayoutPanel
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.Context
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.path
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.settings.SettingReference
|
||||
import org.jetbrains.kotlin.tools.projectWizard.core.entity.settings.reference
|
||||
import org.jetbrains.kotlin.tools.projectWizard.plugins.StructurePlugin
|
||||
@@ -53,8 +52,8 @@ class ProjectSettingsComponent(ideWizard: IdeWizard) : DynamicComponent(ideWizar
|
||||
|
||||
private val nameAndLocationComponent = TitledComponentsList(
|
||||
listOf(
|
||||
StructurePlugin::name.reference.createSettingComponent(context),
|
||||
StructurePlugin::projectPath.reference.createSettingComponent(context),
|
||||
StructurePlugin.name.reference.createSettingComponent(context),
|
||||
StructurePlugin.projectPath.reference.createSettingComponent(context),
|
||||
projectTemplateComponent,
|
||||
buildSystemSetting,
|
||||
jdkComponent
|
||||
@@ -84,17 +83,17 @@ class ProjectSettingsComponent(ideWizard: IdeWizard) : DynamicComponent(ideWizar
|
||||
override fun onValueUpdated(reference: SettingReference<*, *>?) {
|
||||
super.onValueUpdated(reference)
|
||||
when (reference?.path) {
|
||||
StructurePlugin::name.path -> {
|
||||
val isNameValid = read { StructurePlugin::name.reference.validate().isOk }
|
||||
StructurePlugin.name.path -> {
|
||||
val isNameValid = read { StructurePlugin.name.reference.validate().isOk }
|
||||
if (isNameValid) {
|
||||
tryUpdateLocationByProjectName()
|
||||
tryArtifactIdByProjectName()
|
||||
}
|
||||
}
|
||||
StructurePlugin::artifactId.path -> {
|
||||
StructurePlugin.artifactId.path -> {
|
||||
artifactIdWasUpdatedByHand = true
|
||||
}
|
||||
StructurePlugin::projectPath.path -> {
|
||||
StructurePlugin.projectPath.path -> {
|
||||
locationWasUpdatedByHand = true
|
||||
}
|
||||
}
|
||||
@@ -102,9 +101,9 @@ class ProjectSettingsComponent(ideWizard: IdeWizard) : DynamicComponent(ideWizar
|
||||
|
||||
private fun tryUpdateLocationByProjectName() {
|
||||
if (!locationWasUpdatedByHand) {
|
||||
val location = read { StructurePlugin::projectPath.settingValue }
|
||||
val location = read { StructurePlugin.projectPath.settingValue }
|
||||
if (location.parent != null) modify {
|
||||
StructurePlugin::projectPath.reference.setValue(location.parent.resolve(StructurePlugin::name.settingValue))
|
||||
StructurePlugin.projectPath.reference.setValue(location.parent.resolve(StructurePlugin.name.settingValue))
|
||||
locationWasUpdatedByHand = false
|
||||
}
|
||||
}
|
||||
@@ -112,7 +111,7 @@ class ProjectSettingsComponent(ideWizard: IdeWizard) : DynamicComponent(ideWizar
|
||||
|
||||
private fun tryArtifactIdByProjectName() {
|
||||
if (!artifactIdWasUpdatedByHand) modify {
|
||||
StructurePlugin::artifactId.reference.setValue(StructurePlugin::name.settingValue)
|
||||
StructurePlugin.artifactId.reference.setValue(StructurePlugin.name.settingValue)
|
||||
artifactIdWasUpdatedByHand = false
|
||||
}
|
||||
}
|
||||
@@ -124,7 +123,7 @@ class BuildSystemAdditionalSettingsComponent(ideWizard: IdeWizard) : DynamicComp
|
||||
|
||||
override fun onValueUpdated(reference: SettingReference<*, *>?) {
|
||||
super.onValueUpdated(reference)
|
||||
if (reference == BuildSystemPlugin::type.reference) {
|
||||
if (reference == BuildSystemPlugin.type.reference) {
|
||||
updateBuildSystemComponent()
|
||||
}
|
||||
}
|
||||
@@ -135,7 +134,7 @@ class BuildSystemAdditionalSettingsComponent(ideWizard: IdeWizard) : DynamicComp
|
||||
}
|
||||
|
||||
private fun updateBuildSystemComponent() {
|
||||
val buildSystemType = read { BuildSystemPlugin::type.settingValue() }
|
||||
val buildSystemType = read { BuildSystemPlugin.type.settingValue }
|
||||
val state = buildSystemType.state()
|
||||
section.updateTitleAndComponent(state.sectionTitle, state.component)
|
||||
}
|
||||
@@ -162,9 +161,9 @@ class BuildSystemAdditionalSettingsComponent(ideWizard: IdeWizard) : DynamicComp
|
||||
|
||||
private class PomSettingsComponent(context: Context) : TitledComponentsList(
|
||||
listOf(
|
||||
StructurePlugin::groupId.reference.createSettingComponent(context),
|
||||
StructurePlugin::artifactId.reference.createSettingComponent(context),
|
||||
StructurePlugin::version.reference.createSettingComponent(context)
|
||||
StructurePlugin.groupId.reference.createSettingComponent(context),
|
||||
StructurePlugin.artifactId.reference.createSettingComponent(context),
|
||||
StructurePlugin.version.reference.createSettingComponent(context)
|
||||
),
|
||||
context,
|
||||
stretchY = true
|
||||
@@ -257,7 +256,7 @@ class ProjectPreviewComponent(context: Context) : DynamicComponent(context) {
|
||||
|
||||
override fun onValueUpdated(reference: SettingReference<*, *>?) {
|
||||
super.onValueUpdated(reference)
|
||||
if (reference == ProjectTemplatesPlugin::template.reference) {
|
||||
if (reference == ProjectTemplatesPlugin.template.reference) {
|
||||
modulesEditorComponent.updateModel()
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ import javax.swing.JComponent
|
||||
class ProjectTemplateSettingComponent(
|
||||
context: Context
|
||||
) : SettingComponent<ProjectTemplate, DropDownSettingType<ProjectTemplate>>(
|
||||
ProjectTemplatesPlugin::template.reference,
|
||||
ProjectTemplatesPlugin.template.reference,
|
||||
context
|
||||
) {
|
||||
override val validationIndicator: ValidationIndicator? get() = null
|
||||
@@ -58,7 +58,7 @@ class ProjectTemplateSettingComponent(
|
||||
|
||||
override fun onValueUpdated(reference: SettingReference<*, *>?) {
|
||||
super.onValueUpdated(reference)
|
||||
if (reference == ProjectTemplatesPlugin::template.reference) {
|
||||
if (reference == ProjectTemplatesPlugin.template.reference) {
|
||||
applySelectedTemplate()
|
||||
value?.let { template ->
|
||||
list.setSelectedValue(template, true)
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@ class ModuleDependenciesComponent(
|
||||
}
|
||||
|
||||
private fun possibleDependencies(): List<Module> =
|
||||
read { KotlinPlugin::modules.settingValue }.withAllSubModules().toMutableList().apply {
|
||||
read { KotlinPlugin.modules.settingValue }.withAllSubModules().toMutableList().apply {
|
||||
module?.let(::remove)
|
||||
removeAll(
|
||||
module
|
||||
|
||||
+2
-2
@@ -90,7 +90,7 @@ private class ModuleNameComponent(context: Context, private val module: Module)
|
||||
|
||||
override fun onInit() {
|
||||
super.onInit()
|
||||
val isSingleRootMode = read { KotlinPlugin::modules.settingValue }.size == 1
|
||||
val isSingleRootMode = read { KotlinPlugin.modules.settingValue }.size == 1
|
||||
when {
|
||||
isSingleRootMode && module.isRootModule -> {
|
||||
textField.disable(KotlinNewProjectWizardUIBundle.message("module.settings.name.same.as.project"))
|
||||
@@ -168,7 +168,7 @@ private object NoneTemplate : Template() {
|
||||
}
|
||||
|
||||
fun Reader.availableTemplatesFor(module: Module) =
|
||||
TemplatesPlugin::templates.propertyValue.values.filter { template ->
|
||||
TemplatesPlugin.templates.propertyValue.values.filter { template ->
|
||||
module.configurator.moduleType in template.moduleTypes
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -26,14 +26,14 @@ class ModulesEditorComponent(
|
||||
needBorder: Boolean,
|
||||
private val editable: Boolean,
|
||||
oneEntrySelected: (data: DisplayableSettingItem?) -> Unit
|
||||
) : SettingComponent<List<Module>, ListSettingType<Module>>(KotlinPlugin::modules.reference, context) {
|
||||
) : SettingComponent<List<Module>, ListSettingType<Module>>(KotlinPlugin.modules.reference, context) {
|
||||
private val tree: ModulesEditorTree =
|
||||
ModulesEditorTree(
|
||||
onSelected = { oneEntrySelected(it) },
|
||||
context = context,
|
||||
isTreeEditable = editable,
|
||||
addModule = { component ->
|
||||
val isMppProject = KotlinPlugin::projectKind.value == ProjectKind.Singleplatform
|
||||
val isMppProject = KotlinPlugin.projectKind.reference.value == ProjectKind.Singleplatform
|
||||
moduleCreator.create(
|
||||
target = null, // The empty tree case
|
||||
allowMultiplatform = isMppProject,
|
||||
@@ -77,7 +77,7 @@ class ModulesEditorComponent(
|
||||
moduleCreator = moduleCreator,
|
||||
model = model,
|
||||
getModules = { value ?: emptyList() },
|
||||
isMultiplatformProject = { KotlinPlugin::projectKind.value != ProjectKind.Singleplatform }
|
||||
isMultiplatformProject = { KotlinPlugin.projectKind.reference.value != ProjectKind.Singleplatform }
|
||||
) else null
|
||||
|
||||
override val component: JComponent by lazy(LazyThreadSafetyMode.NONE) {
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ class GradleProjectImportingTestWizardService(private val project: Project) : Pr
|
||||
return importingErrorMessage?.let { message ->
|
||||
Failure(
|
||||
ProjectImportingError(
|
||||
reader { KotlinPlugin::version.propertyValue.version.toString() },
|
||||
reader { KotlinPlugin.version.propertyValue.version.toString() },
|
||||
message,
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user