cleanup — use ConfigurationTypeBase in the UnknownConfigurationType

This commit is contained in:
Vladimir Krivosheev
2018-04-13 16:06:20 +02:00
parent dc6c54b9c7
commit d145aeafbf
3 changed files with 30 additions and 104 deletions
@@ -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<ConfigurationFactory>()
/**
* @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<ConfigurationFactory>? = 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<ConfigurationFactory>? {
return myFactories
}
companion object {
private val EMPTY_FACTORIES = arrayOfNulls<ConfigurationFactory>(0)
}
override fun getConfigurationFactories() = factories
}
@@ -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};
}
}
@@ -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<DefaultMutableTreeNode>()
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
}
}