From d145aeafbf1b71e725dd3d71b075d2d03d0dc0f0 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 13 Apr 2018 15:43:11 +0200 Subject: [PATCH] =?UTF-8?q?cleanup=20=E2=80=94=20use=20ConfigurationTypeBa?= =?UTF-8?q?se=20in=20the=20UnknownConfigurationType?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../configurations/ConfigurationTypeBase.kt | 64 ++++--------------- .../UnknownConfigurationType.java | 64 ++++--------------- .../execution/impl/RunConfigurable.kt | 6 +- 3 files changed, 30 insertions(+), 104 deletions(-) diff --git a/platform/lang-api/src/com/intellij/execution/configurations/ConfigurationTypeBase.kt b/platform/lang-api/src/com/intellij/execution/configurations/ConfigurationTypeBase.kt index 343387a3cac0..2650138f2685 100644 --- a/platform/lang-api/src/com/intellij/execution/configurations/ConfigurationTypeBase.kt +++ b/platform/lang-api/src/com/intellij/execution/configurations/ConfigurationTypeBase.kt @@ -1,66 +1,30 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.configurations import com.intellij.util.ArrayUtil -import org.jetbrains.annotations.Nls -import org.jetbrains.annotations.NonNls +import com.intellij.util.text.nullize +import javax.swing.Icon -import javax.swing.* +private val EMPTY_FACTORIES = arrayOf() -/** - * @author yole - */ -abstract class ConfigurationTypeBase protected constructor(@param:NonNls private val myId: String, @param:Nls private val myDisplayName: String, @param:Nls private val myDescription: String, - private val myIcon: Icon) : ConfigurationType { - private var myFactories: Array? = null +abstract class ConfigurationTypeBase protected constructor(private val id: String, private val displayName: String, description: String?, private val icon: Icon?) : ConfigurationType { + private var factories = EMPTY_FACTORIES - init { - myFactories = EMPTY_FACTORIES - } + private var description = description.nullize() ?: displayName protected fun addFactory(factory: ConfigurationFactory) { - myFactories = ArrayUtil.append(myFactories!!, factory) + factories = ArrayUtil.append(factories, factory) } - @Nls - override fun getDisplayName(): String { - return myDisplayName - } + override fun getDisplayName() = displayName - @Nls - override fun getConfigurationTypeDescription(): String { - return myDescription - } + override fun getConfigurationTypeDescription() = description - override fun getIcon(): Icon { - return myIcon - } + // open due to backward compatibility + override fun getIcon() = icon - @NonNls - override fun getId(): String { - return myId - } + override final fun getId() = id - override fun getConfigurationFactories(): Array? { - return myFactories - } - - companion object { - private val EMPTY_FACTORIES = arrayOfNulls(0) - } + override fun getConfigurationFactories() = factories } diff --git a/platform/lang-api/src/com/intellij/execution/configurations/UnknownConfigurationType.java b/platform/lang-api/src/com/intellij/execution/configurations/UnknownConfigurationType.java index 146fedb51fce..db1f18abfaea 100644 --- a/platform/lang-api/src/com/intellij/execution/configurations/UnknownConfigurationType.java +++ b/platform/lang-api/src/com/intellij/execution/configurations/UnknownConfigurationType.java @@ -1,37 +1,28 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.configurations; import com.intellij.execution.ExecutionBundle; import com.intellij.icons.AllIcons; import com.intellij.openapi.project.Project; import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.Nls; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import javax.swing.*; -/** - * @author spleaner - */ -public class UnknownConfigurationType implements ConfigurationType { +public class UnknownConfigurationType extends ConfigurationTypeBase { public static final UnknownConfigurationType INSTANCE = new UnknownConfigurationType(); - @NonNls public static final String NAME = "Unknown"; + protected UnknownConfigurationType() { + this(AllIcons.RunConfigurations.Unknown); + } + + protected UnknownConfigurationType(@NotNull Icon icon) { + super(NAME, NAME, ExecutionBundle.message("run.configuration.unknown.description"), icon); + + addFactory(FACTORY); + } + + public static final String NAME = "Unknown"; public static final ConfigurationFactory FACTORY = new ConfigurationFactory(new UnknownConfigurationType()) { @NotNull @@ -46,33 +37,4 @@ public class UnknownConfigurationType implements ConfigurationType { return false; } }; - - @Override - @Nls - public String getDisplayName() { - return getId(); - } - - @Override - @Nls - public String getConfigurationTypeDescription() { - return ExecutionBundle.message("run.configuration.unknown.description"); - } - - @Override - public Icon getIcon() { - return AllIcons.RunConfigurations.Unknown; - } - - @Override - @NotNull - @NonNls - public String getId() { - return NAME; - } - - @Override - public ConfigurationFactory[] getConfigurationFactories() { - return new ConfigurationFactory[] {FACTORY}; - } } diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.kt b/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.kt index 336095853403..700ba2faf55f 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.kt +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunConfigurable.kt @@ -759,11 +759,11 @@ open class RunConfigurable @JvmOverloads constructor(private val myProject: Proj var currentSettingCount = 0 for (i in 0 until root.childCount) { val typeNode = root.getChildAt(i) as DefaultMutableTreeNode - val `object` = typeNode.userObject as? ConfigurationType ?: continue + val configurationType = typeNode.userObject as? ConfigurationType ?: continue val configurationNodes = ArrayList() collectNodesRecursively(typeNode, configurationNodes, CONFIGURATION, TEMPORARY_CONFIGURATION) - val allTypeSettings = allSettings.filter { it.type == `object` } + val allTypeSettings = allSettings.filter { it.type == configurationType } if (allTypeSettings.size != configurationNodes.size) { return true } @@ -790,7 +790,7 @@ open class RunConfigurable @JvmOverloads constructor(private val myProject: Proj // we compare by instance, equals is not implemented and in any case object modification is checked by other logic // we compare by index among current types settings because indexes among all configurations may differ // since temporary configurations are stored in the end - if (allTypeSettings.size <= index || allTypeSettings[index] !== settings) { + if (allTypeSettings.size <= index || allTypeSettings.get(index) !== settings) { return true } }