From 3ffbaa92d376d1d66ed3eb7fea30969600b4d29c Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Thu, 14 May 2020 13:08:45 +0200 Subject: [PATCH] cleanup GitOrigin-RevId: 8edcbb87c482c4d73925aa9f3f9211368b29b2d2 --- .../run/BuildArtifactsBeforeRunTaskBase.java | 18 +---- ...ildArtifactsBeforeRunTaskProviderBase.java | 6 +- .../impl/BaseExecuteBeforeRunDialog.java | 35 +++++----- .../execution/impl/BeforeRunStepsPanel.java | 65 ++++++++++--------- .../execution/impl/BeforeRunTaskHelper.kt | 4 +- .../intellij/execution/impl/RunManagerImpl.kt | 15 ++--- .../execution/ui/BeforeRunFragment.java | 19 +++--- .../extensions/ProjectExtensionPointName.java | 6 ++ .../com/intellij/execution/BeforeRunTask.java | 29 ++------- .../execution/BeforeRunTaskProvider.java | 28 ++++---- .../configurations/RunConfiguration.java | 26 +++----- .../tools/AbstractToolBeforeRunTask.java | 4 +- .../AbstractToolBeforeRunTaskProvider.java | 2 +- .../explorer/AntExecuteBeforeRunDialog.java | 21 ++---- .../actions/MavenExecuteBeforeRunDialog.java | 21 ++---- 15 files changed, 122 insertions(+), 177 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRunTaskBase.java b/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRunTaskBase.java index 346ea12eafae..ca4b0c7acd97 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRunTaskBase.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRunTaskBase.java @@ -1,18 +1,4 @@ -/* - * 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-2020 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.packaging.impl.run; import com.intellij.execution.BeforeRunTask; @@ -29,7 +15,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -public abstract class BuildArtifactsBeforeRunTaskBase +public abstract class BuildArtifactsBeforeRunTaskBase> extends BeforeRunTask { @NonNls public static final String NAME_ATTRIBUTE = "name"; diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRunTaskProviderBase.java b/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRunTaskProviderBase.java index 9b2fec4c021e..bbb6611c0bdc 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRunTaskProviderBase.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/run/BuildArtifactsBeforeRunTaskProviderBase.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 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. +// Copyright 2000-2020 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.packaging.impl.run; import com.intellij.execution.BeforeRunTaskProvider; @@ -30,7 +30,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; -public abstract class BuildArtifactsBeforeRunTaskProviderBase +public abstract class BuildArtifactsBeforeRunTaskProviderBase> extends BeforeRunTaskProvider { private final Project myProject; @NotNull final private Class myTaskClass; @@ -99,7 +99,7 @@ public abstract class BuildArtifactsBeforeRunTaskProviderBase)task.getArtifactPointers()) { + for (ArtifactPointer pointer : task.getArtifactPointers()) { if (pointer.getArtifact() != null) { return true; } diff --git a/platform/execution-impl/src/com/intellij/execution/impl/BaseExecuteBeforeRunDialog.java b/platform/execution-impl/src/com/intellij/execution/impl/BaseExecuteBeforeRunDialog.java index c675068da4b6..a18138872322 100644 --- a/platform/execution-impl/src/com/intellij/execution/impl/BaseExecuteBeforeRunDialog.java +++ b/platform/execution-impl/src/com/intellij/execution/impl/BaseExecuteBeforeRunDialog.java @@ -1,4 +1,4 @@ -// 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. +// Copyright 2000-2020 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.impl; import com.intellij.execution.*; @@ -17,7 +17,7 @@ import com.intellij.util.ui.JBUI; import com.intellij.util.ui.ThreeStateCheckBox; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.tree.TreeUtil; -import gnu.trove.THashSet; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -33,9 +33,7 @@ import java.awt.event.MouseEvent; import java.util.List; import java.util.*; - -public abstract class BaseExecuteBeforeRunDialog extends DialogWrapper { - +public abstract class BaseExecuteBeforeRunDialog> extends DialogWrapper { private final static Object TEMPLATE_ROOT = new Object(); private final Project myProject; private DefaultMutableTreeNode myRoot; @@ -107,11 +105,11 @@ public abstract class BaseExecuteBeforeRunDialog extend private static void expandChecked(Tree tree) { TreeNode root = (TreeNode)tree.getModel().getRoot(); - Enumeration factories = root.children(); + Enumeration factories = root.children(); ArrayList toExpand = new ArrayList<>(); while (factories.hasMoreElements()) { DefaultMutableTreeNode factoryNode = (DefaultMutableTreeNode)factories.nextElement(); - Enumeration configurations = factoryNode.children(); + Enumeration configurations = factoryNode.children(); while (configurations.hasMoreElements()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode)configurations.nextElement(); Descriptor config = (Descriptor)node.getUserObject(); @@ -154,7 +152,7 @@ public abstract class BaseExecuteBeforeRunDialog extend GroupConfigurationDescriptor groupConfigurationDescriptor = new GroupConfigurationDescriptor(type, icon); DefaultMutableTreeNode typeNode = new DefaultMutableTreeNode(groupConfigurationDescriptor); root.add(typeNode); - final Set addedNames = new THashSet<>(); + Set addedNames = new ObjectOpenHashSet<>(); for (List list : entry.getValue().values()) { for (RunnerAndConfigurationSettings configuration : list) { final String configurationName = configuration.getName(); @@ -169,17 +167,16 @@ public abstract class BaseExecuteBeforeRunDialog extend groupConfigurationDescriptor.setChecked(selectedAll); } } - buildTemplatesNode(root, runManager); + buildTemplatesNode(root); return root; } - private void buildTemplatesNode(DefaultMutableTreeNode root, RunManagerImpl manager) { + private void buildTemplatesNode(DefaultMutableTreeNode root) { DefaultMutableTreeNode node = new DefaultMutableTreeNode(TEMPLATE_ROOT); root.add(node); for (ConfigurationType type : ConfigurationType.CONFIGURATION_TYPE_EP.getExtensionList()) { - final Icon icon = type.getIcon(); - DefaultMutableTreeNode typeNode = - new DefaultMutableTreeNode(new ConfigurationTypeDescriptor(type, icon, isConfigurationAssigned(type))); + Icon icon = type.getIcon(); + DefaultMutableTreeNode typeNode = new DefaultMutableTreeNode(new ConfigurationTypeDescriptor(type, icon, isConfigurationAssigned(type))); node.add(typeNode); } } @@ -194,7 +191,7 @@ public abstract class BaseExecuteBeforeRunDialog extend } private boolean isConfigurationAssigned(RunConfiguration configuration) { - for (T task : RunManagerEx.getInstanceEx(myProject).getBeforeRunTasks(configuration, getTaskID())) { + for (T task : RunManagerEx.getInstanceEx(myProject).getBeforeRunTasks(configuration, getTaskId())) { if (isRunning(task)) return true; } @@ -204,7 +201,7 @@ public abstract class BaseExecuteBeforeRunDialog extend @Override protected void doOKAction() { final RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(myProject); - for (Enumeration nodes = myRoot.depthFirstEnumeration(); nodes.hasMoreElements(); ) { + for (Enumeration nodes = myRoot.depthFirstEnumeration(); nodes.hasMoreElements(); ) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode)nodes.nextElement(); Object object = node.getUserObject(); if (!(object instanceof Descriptor)) { @@ -232,18 +229,18 @@ public abstract class BaseExecuteBeforeRunDialog extend protected abstract String getTargetDisplayString(); - protected abstract Key getTaskID(); + protected abstract Key getTaskId(); protected abstract boolean isRunning(T task); private void update(RunConfiguration config, boolean enabled, RunManagerImpl runManager) { List> tasks = RunManagerImplKt.doGetBeforeRunTasks(config); - BeforeRunTaskProvider provider = BeforeRunTaskProvider.getProvider(myProject, getTaskID()); + BeforeRunTaskProvider provider = BeforeRunTaskProvider.getProvider(myProject, getTaskId()); if (provider == null) { return; } - T task = provider.createTask(config); + T task = Objects.requireNonNull(provider.createTask(config)); update(task); task.setEnabled(true); if (enabled) { @@ -261,7 +258,7 @@ public abstract class BaseExecuteBeforeRunDialog extend runManager.setBeforeRunTasks(config, tasks); } - protected abstract void update(T task); + protected abstract void update(@NotNull T task); protected abstract void clear(T task); diff --git a/platform/execution-impl/src/com/intellij/execution/impl/BeforeRunStepsPanel.java b/platform/execution-impl/src/com/intellij/execution/impl/BeforeRunStepsPanel.java index 72f22531ec95..a29700118e96 100644 --- a/platform/execution-impl/src/com/intellij/execution/impl/BeforeRunStepsPanel.java +++ b/platform/execution-impl/src/com/intellij/execution/impl/BeforeRunStepsPanel.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 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. +// Copyright 2000-2020 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.impl; import com.intellij.execution.BeforeRunTask; @@ -13,6 +13,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonShortcuts; import com.intellij.openapi.actionSystem.DefaultActionGroup; import com.intellij.openapi.actionSystem.impl.SimpleDataContext; +import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.ui.popup.ListPopup; import com.intellij.openapi.util.Conditions; @@ -21,7 +22,7 @@ import com.intellij.ui.*; import com.intellij.ui.components.JBList; import com.intellij.ui.scale.JBUIScale; import com.intellij.util.SmartList; -import gnu.trove.THashSet; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -50,7 +51,7 @@ final class BeforeRunStepsPanel extends JPanel { private final StepsBeforeRunListener myListener; private final JPanel myPanel; - private final Set> clonedTasks = new THashSet<>(); + private final Set> clonedTasks = new ObjectOpenHashSet<>(); BeforeRunStepsPanel(@NotNull StepsBeforeRunListener listener) { myListener = listener; @@ -159,15 +160,13 @@ final class BeforeRunStepsPanel extends JPanel { updateText(); } - @Nullable - private BeforeRunTaskAndProvider getSelection() { - final int index = myList.getSelectedIndex(); + private @Nullable BeforeRunTaskAndProvider getSelection() { + int index = myList.getSelectedIndex(); if (index == -1) { return null; } BeforeRunTask task = myModel.getElementAt(index); - @SuppressWarnings("unchecked") - BeforeRunTaskProvider> provider = BeforeRunTaskProvider.getProvider(myRunConfiguration.getProject(), (Key)task.getProviderId()); + BeforeRunTaskProvider> provider = getProvider(myRunConfiguration.getProject(), task.getProviderId()); return provider == null ? null : new BeforeRunTaskAndProvider(task, provider, index); } @@ -196,8 +195,7 @@ final class BeforeRunStepsPanel extends JPanel { myListener.titleChanged(title + suffix); } - @NotNull - public List> getTasks() { + public @NotNull List> getTasks() { List> items = myModel.getItems(); return items.isEmpty() ? Collections.emptyList() : Collections.unmodifiableList(items); } @@ -215,8 +213,8 @@ final class BeforeRunStepsPanel extends JPanel { return false; } - Set activeProviderKeys = getActiveProviderKeys(); - for (final BeforeRunTaskProvider provider : getBeforeRunTaskProviders()) { + Set> activeProviderKeys = getActiveProviderKeys(); + for (BeforeRunTaskProvider> provider : getBeforeRunTaskProviders()) { if (provider.createTask(myRunConfiguration) != null) { if (!checkOnlyAddAction) { return true; @@ -238,9 +236,9 @@ final class BeforeRunStepsPanel extends JPanel { return; } - Set activeProviderKeys = getActiveProviderKeys(); + Set> activeProviderKeys = getActiveProviderKeys(); DefaultActionGroup actionGroup = new DefaultActionGroup(); - for (final BeforeRunTaskProvider provider : getBeforeRunTaskProviders()) { + for (BeforeRunTaskProvider> provider : getBeforeRunTaskProviders()) { if (provider.createTask(myRunConfiguration) == null || activeProviderKeys.contains(provider.getId()) && provider.isSingleton()) { continue; } @@ -248,7 +246,7 @@ final class BeforeRunStepsPanel extends JPanel { actionGroup.add(new AnAction(provider.getName(), null, provider.getIcon()) { @Override public void actionPerformed(@NotNull AnActionEvent e) { - BeforeRunTask task = provider.createTask(myRunConfiguration); + BeforeRunTask task = provider.createTask(myRunConfiguration); if (task == null) { return; } @@ -260,7 +258,7 @@ final class BeforeRunStepsPanel extends JPanel { } task.setEnabled(true); - Set configurationSet = new THashSet<>(); + Set configurationSet = new ObjectOpenHashSet<>(); getAllRunBeforeRuns(task, configurationSet); if (configurationSet.contains(myRunConfiguration)) { JOptionPane.showMessageDialog(BeforeRunStepsPanel.this, @@ -282,28 +280,27 @@ final class BeforeRunStepsPanel extends JPanel { popup.show(Objects.requireNonNull(button.getPreferredPopupPoint())); } - @NotNull - private List> getBeforeRunTaskProviders() { - return BeforeRunTaskProvider.EXTENSION_POINT_NAME.getExtensionList(myRunConfiguration.getProject()); + private @NotNull List>> getBeforeRunTaskProviders() { + return BeforeRunTaskProvider.EP_NAME.getExtensions(myRunConfiguration.getProject()); } - public void addTask(@NotNull BeforeRunTask task) { + public void addTask(@NotNull BeforeRunTask task) { myModel.add(task); } - @NotNull - private Set getActiveProviderKeys() { - Set result = new THashSet<>(); - for (BeforeRunTask task : myModel.getItems()) { + private @NotNull Set> getActiveProviderKeys() { + List> items = myModel.getItems(); + Set> result = new ObjectOpenHashSet<>(items.size()); + for (BeforeRunTask task : items) { result.add(task.getProviderId()); } return result; } - private void getAllRunBeforeRuns(@NotNull BeforeRunTask task, @NotNull Set configurationSet) { + private void getAllRunBeforeRuns(@NotNull BeforeRunTask task, @NotNull Set configurationSet) { if (task instanceof RunConfigurableBeforeRunTask) { RunConfiguration configuration = Objects.requireNonNull(((RunConfigurableBeforeRunTask)task).getSettings()).getConfiguration(); - for (BeforeRunTask beforeRunTask : RunManagerImplKt.doGetBeforeRunTasks(configuration)) { + for (BeforeRunTask beforeRunTask : RunManagerImplKt.doGetBeforeRunTasks(configuration)) { if (beforeRunTask instanceof RunConfigurableBeforeRunTask) { if (configurationSet.add(Objects.requireNonNull(((RunConfigurableBeforeRunTask)beforeRunTask).getSettings()).getConfiguration())) { getAllRunBeforeRuns(beforeRunTask, configurationSet); @@ -319,14 +316,13 @@ final class BeforeRunStepsPanel extends JPanel { void titleChanged(@NotNull String title); } - private class MyListCellRenderer extends JBList.StripedListCellRenderer { + private final class MyListCellRenderer extends JBList.StripedListCellRenderer { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value instanceof BeforeRunTask) { - BeforeRunTask task = (BeforeRunTask)value; - @SuppressWarnings("unchecked") - BeforeRunTaskProvider provider = BeforeRunTaskProvider.getProvider(myRunConfiguration.getProject(), task.getProviderId()); + BeforeRunTask task = (BeforeRunTask)value; + BeforeRunTaskProvider> provider = getProvider(myRunConfiguration.getProject(), task.getProviderId()); if (provider != null) { Icon icon = provider.getTaskIcon(task); setIcon(icon != null ? icon : provider.getIcon()); @@ -336,4 +332,13 @@ final class BeforeRunStepsPanel extends JPanel { return this; } } + + private static @Nullable BeforeRunTaskProvider> getProvider(@NotNull Project project, Key key) { + for (BeforeRunTaskProvider> provider : BeforeRunTaskProvider.EP_NAME.getIterable(project)) { + if (provider.getId() == key) { + return provider; + } + } + return null; + } } diff --git a/platform/execution-impl/src/com/intellij/execution/impl/BeforeRunTaskHelper.kt b/platform/execution-impl/src/com/intellij/execution/impl/BeforeRunTaskHelper.kt index 970fde845862..3256f0a33f6f 100644 --- a/platform/execution-impl/src/com/intellij/execution/impl/BeforeRunTaskHelper.kt +++ b/platform/execution-impl/src/com/intellij/execution/impl/BeforeRunTaskHelper.kt @@ -1,4 +1,4 @@ -// 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. +// Copyright 2000-2020 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.impl import com.intellij.execution.BeforeRunTask @@ -32,7 +32,7 @@ internal fun getEffectiveBeforeRunTaskList(ownTasks: List>, tem internal fun getHardcodedBeforeRunTasks(configuration: RunConfiguration, factory: ConfigurationFactory): List> { var result: MutableList>? = null - for (provider in BeforeRunTaskProvider.EXTENSION_POINT_NAME.getExtensionList(configuration.project)) { + for (provider in BeforeRunTaskProvider.EP_NAME.getExtensions(configuration.project)) { val task = provider.createTask(configuration) ?: continue if (task.isEnabled) { factory.configureBeforeRunTaskDefaults(provider.id, task) diff --git a/platform/execution-impl/src/com/intellij/execution/impl/RunManagerImpl.kt b/platform/execution-impl/src/com/intellij/execution/impl/RunManagerImpl.kt index d7eec2fc8ae9..d019740e0659 100644 --- a/platform/execution-impl/src/com/intellij/execution/impl/RunManagerImpl.kt +++ b/platform/execution-impl/src/com/intellij/execution/impl/RunManagerImpl.kt @@ -4,7 +4,6 @@ package com.intellij.execution.impl import com.intellij.ProjectTopics import com.intellij.configurationStore.* import com.intellij.execution.* -import com.intellij.execution.configuration.ConfigurationFactoryEx import com.intellij.execution.configurations.* import com.intellij.execution.runners.ExecutionEnvironment import com.intellij.execution.runners.ExecutionUtil @@ -195,7 +194,7 @@ open class RunManagerImpl @JvmOverloads constructor(val project: Project, shared private val stringIdToBeforeRunProvider = object : ClearableLazyValue>>() { override fun compute(): ConcurrentMap> { val result = ConcurrentHashMap>() - for (provider in BeforeRunTaskProvider.EXTENSION_POINT_NAME.getExtensionList(project)) { + for (provider in BeforeRunTaskProvider.EP_NAME.getExtensions(project)) { result.put(provider.id.toString(), provider) } return result @@ -222,7 +221,7 @@ open class RunManagerImpl @JvmOverloads constructor(val project: Project, shared } }) - BeforeRunTaskProvider.EXTENSION_POINT_NAME.getPoint(project).addChangeListener(Runnable(stringIdToBeforeRunProvider::drop), project) + BeforeRunTaskProvider.EP_NAME.getPoint(project).addChangeListener(Runnable(stringIdToBeforeRunProvider::drop), project) } private fun clearSelectedConfigurationIcon() { @@ -239,7 +238,7 @@ open class RunManagerImpl @JvmOverloads constructor(val project: Project, shared private fun buildConfigurationTypeMap(factories: List): Map { val types = factories.toMutableList() types.add(UnknownConfigurationType.getInstance()) - val map = THashMap() + val map = HashMap() for (type in types) { map.put(type.id, type) } @@ -691,7 +690,7 @@ open class RunManagerImpl @JvmOverloads constructor(val project: Project, shared settings.setConfiguration(configuration) } } - + lock.write { templateIdToConfiguration.retainEntries { _, settings -> settings.type != extension } } } }, this) @@ -1308,13 +1307,13 @@ internal fun RunConfiguration.cloneBeforeRunTasks() { fun callNewConfigurationCreated(factory: ConfigurationFactory, configuration: RunConfiguration) { @Suppress("UNCHECKED_CAST", "DEPRECATION") - (factory as? ConfigurationFactoryEx)?.onNewConfigurationCreated(configuration) + (factory as? com.intellij.execution.configuration.ConfigurationFactoryEx)?.onNewConfigurationCreated(configuration) (configuration as? ConfigurationCreationListener)?.onNewConfigurationCreated() } private fun getFactoryKey(factory: ConfigurationFactory): String { - return when { - factory.type is SimpleConfigurationType -> factory.type.id + return when (factory.type) { + is SimpleConfigurationType -> factory.type.id else -> "${factory.type.id}.${factory.id}" } } diff --git a/platform/execution-impl/src/com/intellij/execution/ui/BeforeRunFragment.java b/platform/execution-impl/src/com/intellij/execution/ui/BeforeRunFragment.java index 7016c2b59d1b..ca08ce4724da 100644 --- a/platform/execution-impl/src/com/intellij/execution/ui/BeforeRunFragment.java +++ b/platform/execution-impl/src/com/intellij/execution/ui/BeforeRunFragment.java @@ -26,8 +26,7 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; -public class BeforeRunFragment> extends RunConfigurationEditorFragment { - +public final class BeforeRunFragment> extends RunConfigurationEditorFragment { public static > List> createGroup() { ArrayList> list = new ArrayList<>(); list.add(new BeforeRunFragment<>()); @@ -107,9 +106,10 @@ public class BeforeRunFragment> extends RunCon if (myTags == null) { myTags = new ArrayList<>(); RunConfiguration configuration = s.getConfiguration(); - for (BeforeRunTaskProvider provider : BeforeRunTaskProvider.EXTENSION_POINT_NAME - .getExtensionList(configuration.getProject())) { - if (provider.createTask(configuration) == null) continue; + for (BeforeRunTaskProvider> provider : BeforeRunTaskProvider.EP_NAME.getExtensions(configuration.getProject())) { + if (provider.createTask(configuration) == null) { + continue; + } TaskButton button = new TaskButton(provider); add(button); myTags.add(button); @@ -123,13 +123,14 @@ public class BeforeRunFragment> extends RunCon public void apply(RunnerAndConfigurationSettingsImpl s) { RunConfiguration configuration = s.getConfiguration(); - List tasks = - myTags.stream().filter(button -> button.isVisible()).map(button -> button.myProvider.createTask(configuration)) - .collect(Collectors.toList()); + List> tasks = myTags.stream() + .filter(button -> button.isVisible()) + .map(button -> button.myProvider.createTask(configuration)) + .collect(Collectors.toList()); s.getManager().setBeforeRunTasks(configuration, tasks); } - private class TaskButton extends TagButton { + private final class TaskButton extends TagButton { @NotNull private final BeforeRunTaskProvider myProvider; private TaskButton(BeforeRunTaskProvider provider) { diff --git a/platform/extensions/src/com/intellij/openapi/extensions/ProjectExtensionPointName.java b/platform/extensions/src/com/intellij/openapi/extensions/ProjectExtensionPointName.java index dfe63205cb7c..08fad8d7700a 100644 --- a/platform/extensions/src/com/intellij/openapi/extensions/ProjectExtensionPointName.java +++ b/platform/extensions/src/com/intellij/openapi/extensions/ProjectExtensionPointName.java @@ -4,6 +4,7 @@ package com.intellij.openapi.extensions; import com.intellij.openapi.Disposable; import com.intellij.openapi.extensions.impl.ExtensionProcessingHelper; import com.intellij.util.ThreeState; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -75,4 +76,9 @@ public final class ProjectExtensionPointName extends BaseExtensionPointName consumer) { getPointImpl(areaInstance).processWithPluginDescriptor(true, consumer); } + + @ApiStatus.Experimental + public final @NotNull Iterable getIterable(@NotNull AreaInstance areaInstance) { + return getPointImpl(areaInstance); + } } diff --git a/platform/lang-api/src/com/intellij/execution/BeforeRunTask.java b/platform/lang-api/src/com/intellij/execution/BeforeRunTask.java index f5c6417406e0..558a20afb616 100644 --- a/platform/lang-api/src/com/intellij/execution/BeforeRunTask.java +++ b/platform/lang-api/src/com/intellij/execution/BeforeRunTask.java @@ -1,18 +1,4 @@ -/* - * 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-2020 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; @@ -21,12 +7,8 @@ import com.intellij.openapi.util.Key; import org.jdom.Element; import org.jetbrains.annotations.NotNull; -/** - * @author Eugene Zhuravlev - */ -public abstract class BeforeRunTask implements Cloneable { - @NotNull - protected final Key myProviderId; +public abstract class BeforeRunTask> implements Cloneable { + protected final @NotNull Key myProviderId; // cannot be set to true by default, because RunManager.getHardcodedBeforeRunTasks creates before run task for each provider // and some providers set enabled to true in the constructor to indicate, that before run task should be added to RC by default (on create) @@ -36,8 +18,7 @@ public abstract class BeforeRunTask implements Cloneabl myProviderId = providerId; } - @NotNull - public final Key getProviderId() { + public final @NotNull Key getProviderId() { return myProviderId; } @@ -93,7 +74,7 @@ public abstract class BeforeRunTask implements Cloneabl if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - BeforeRunTask that = (BeforeRunTask)o; + BeforeRunTask that = (BeforeRunTask)o; if (myProviderId != that.myProviderId) return false; if (myIsEnabled != that.myIsEnabled) return false; diff --git a/platform/lang-api/src/com/intellij/execution/BeforeRunTaskProvider.java b/platform/lang-api/src/com/intellij/execution/BeforeRunTaskProvider.java index 253b7ec1fc94..20981b50ebab 100644 --- a/platform/lang-api/src/com/intellij/execution/BeforeRunTaskProvider.java +++ b/platform/lang-api/src/com/intellij/execution/BeforeRunTaskProvider.java @@ -1,10 +1,11 @@ -// Copyright 2000-2019 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. +// Copyright 2000-2020 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; import com.intellij.execution.configurations.RunConfiguration; import com.intellij.execution.runners.ExecutionEnvironment; import com.intellij.openapi.actionSystem.DataContext; import com.intellij.openapi.extensions.ExtensionPointName; +import com.intellij.openapi.extensions.ProjectExtensionPointName; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; import org.jetbrains.annotations.NotNull; @@ -14,16 +15,22 @@ import org.jetbrains.concurrency.Promises; import javax.swing.*; -public abstract class BeforeRunTaskProvider { - public static final ExtensionPointName> EXTENSION_POINT_NAME = +public abstract class BeforeRunTaskProvider> { + public static final ProjectExtensionPointName>> EP_NAME = + new ProjectExtensionPointName<>("com.intellij.stepsBeforeRunProvider"); + + /** + * @deprecated Use {@link #EP_NAME} + */ + @Deprecated + public static final ExtensionPointName>> EXTENSION_POINT_NAME = new ExtensionPointName<>("com.intellij.stepsBeforeRunProvider"); public abstract Key getId(); public abstract String getName(); - @Nullable - public Icon getIcon() { + public @Nullable Icon getIcon() { return null; } @@ -31,8 +38,7 @@ public abstract class BeforeRunTaskProvider { return getName(); } - @Nullable - public Icon getTaskIcon(T task) { + public @Nullable Icon getTaskIcon(T task) { return null; } @@ -43,8 +49,7 @@ public abstract class BeforeRunTaskProvider { /** * @return 'before run' task for the configuration or null, if the task from this provider is not applicable to the specified configuration */ - @Nullable - public abstract T createTask(@NotNull RunConfiguration runConfiguration); + public abstract @Nullable T createTask(@NotNull RunConfiguration runConfiguration); /** * @return {@code true} if task configuration is changed @@ -77,9 +82,8 @@ public abstract class BeforeRunTaskProvider { return false; } - @Nullable - public static BeforeRunTaskProvider getProvider(@NotNull Project project, Key key) { - for (BeforeRunTaskProvider provider : EXTENSION_POINT_NAME.getExtensionList(project)) { + public static @Nullable > BeforeRunTaskProvider getProvider(@NotNull Project project, Key key) { + for (BeforeRunTaskProvider> provider : EP_NAME.getIterable(project)) { if (provider.getId() == key) { //noinspection unchecked return (BeforeRunTaskProvider)provider; diff --git a/platform/lang-api/src/com/intellij/execution/configurations/RunConfiguration.java b/platform/lang-api/src/com/intellij/execution/configurations/RunConfiguration.java index 39092b4bd619..3eed13c63afd 100644 --- a/platform/lang-api/src/com/intellij/execution/configurations/RunConfiguration.java +++ b/platform/lang-api/src/com/intellij/execution/configurations/RunConfiguration.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 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. +// Copyright 2000-2020 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.BeforeRunTask; @@ -35,8 +35,7 @@ public interface RunConfiguration extends RunProfile, Cloneable { /** * Returns the type of the run configuration. */ - @NotNull - default ConfigurationType getType() { + default @NotNull ConfigurationType getType() { ConfigurationFactory factory = getFactory(); return factory == null ? UnknownConfigurationType.getInstance() : factory.getType(); } @@ -44,8 +43,7 @@ public interface RunConfiguration extends RunProfile, Cloneable { /** * Returns the factory that has created the run configuration. */ - @Nullable - ConfigurationFactory getFactory(); + @Nullable ConfigurationFactory getFactory(); // do not annotate as Nullable because in this case Kotlin compiler will forbid field style access (because of different nullability for getter and setter). /** @@ -61,8 +59,7 @@ public interface RunConfiguration extends RunProfile, Cloneable { * * @return the settings editor component. */ - @NotNull - SettingsEditor getConfigurationEditor(); + @NotNull SettingsEditor getConfigurationEditor(); /** * Returns the project in which the run configuration exists. @@ -76,8 +73,7 @@ public interface RunConfiguration extends RunProfile, Cloneable { * @param provider source of assorted information about the configuration being edited. * @return the per-runner settings. */ - @Nullable - default ConfigurationPerRunnerSettings createRunnerSettings(ConfigurationInfoProvider provider) { + default @Nullable ConfigurationPerRunnerSettings createRunnerSettings(ConfigurationInfoProvider provider) { return null; } @@ -88,8 +84,7 @@ public interface RunConfiguration extends RunProfile, Cloneable { * @param runner the runner the settings for which need to be edited. * @return the editor for the per-runner settings. */ - @Nullable - default SettingsEditor getRunnerSettingsEditor(ProgramRunner runner) { + default @Nullable SettingsEditor getRunnerSettingsEditor(ProgramRunner runner) { return null; } @@ -113,14 +108,12 @@ public interface RunConfiguration extends RunProfile, Cloneable { * Returns the unique identifier of the run configuration. Return null if not applicable. * Used only for non-managed RC type. */ - @Nullable - default String getId() { + default @Nullable String getId() { return null; } - @NotNull @Transient - default String getPresentableType() { + default @NotNull String getPresentableType() { if (PlatformUtils.isPhpStorm()) { return " (" + StringUtil.first(getType().getDisplayName(), 10, true) + ")"; } @@ -154,8 +147,7 @@ public interface RunConfiguration extends RunProfile, Cloneable { default void writeExternal(@NotNull Element element) { } - @NotNull - default List> getBeforeRunTasks() { + default @NotNull List> getBeforeRunTasks() { return Collections.emptyList(); } diff --git a/platform/lang-impl/src/com/intellij/tools/AbstractToolBeforeRunTask.java b/platform/lang-impl/src/com/intellij/tools/AbstractToolBeforeRunTask.java index 423bf35e8b53..967ff90ee037 100644 --- a/platform/lang-impl/src/com/intellij/tools/AbstractToolBeforeRunTask.java +++ b/platform/lang-impl/src/com/intellij/tools/AbstractToolBeforeRunTask.java @@ -18,11 +18,11 @@ import org.jetbrains.annotations.Nullable; import java.util.List; -public abstract class AbstractToolBeforeRunTask +public abstract class AbstractToolBeforeRunTask, T extends Tool> extends BeforeRunTask { @NonNls private final static String ACTION_ID_ATTRIBUTE = "actionId"; private static final Logger LOG = Logger.getInstance(AbstractToolBeforeRunTask.class); - protected String myToolActionId; + private String myToolActionId; public AbstractToolBeforeRunTask(Key providerId) { super(providerId); diff --git a/platform/lang-impl/src/com/intellij/tools/AbstractToolBeforeRunTaskProvider.java b/platform/lang-impl/src/com/intellij/tools/AbstractToolBeforeRunTaskProvider.java index 46a305a5a424..256abd1c8327 100644 --- a/platform/lang-impl/src/com/intellij/tools/AbstractToolBeforeRunTaskProvider.java +++ b/platform/lang-impl/src/com/intellij/tools/AbstractToolBeforeRunTaskProvider.java @@ -12,7 +12,7 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; -public abstract class AbstractToolBeforeRunTaskProvider extends BeforeRunTaskProvider { +public abstract class AbstractToolBeforeRunTaskProvider> extends BeforeRunTaskProvider { protected static final Logger LOG = Logger.getInstance(ToolBeforeRunTaskProvider.class); @Override diff --git a/plugins/ant/src/com/intellij/lang/ant/config/explorer/AntExecuteBeforeRunDialog.java b/plugins/ant/src/com/intellij/lang/ant/config/explorer/AntExecuteBeforeRunDialog.java index 0dcf15125701..2eec73a1d8da 100644 --- a/plugins/ant/src/com/intellij/lang/ant/config/explorer/AntExecuteBeforeRunDialog.java +++ b/plugins/ant/src/com/intellij/lang/ant/config/explorer/AntExecuteBeforeRunDialog.java @@ -1,18 +1,4 @@ -/* - * 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-2020 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.lang.ant.config.explorer; import com.intellij.execution.impl.BaseExecuteBeforeRunDialog; @@ -23,6 +9,7 @@ import com.intellij.lang.ant.config.impl.AntBeforeRunTaskProvider; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; public final class AntExecuteBeforeRunDialog extends BaseExecuteBeforeRunDialog { private final AntBuildTarget myTarget; @@ -39,7 +26,7 @@ public final class AntExecuteBeforeRunDialog extends BaseExecuteBeforeRunDialog< } @Override - protected Key getTaskID() { + protected Key getTaskId() { return AntBeforeRunTaskProvider.ID; } @@ -49,7 +36,7 @@ public final class AntExecuteBeforeRunDialog extends BaseExecuteBeforeRunDialog< } @Override - protected void update(AntBeforeRunTask task) { + protected void update(@NotNull AntBeforeRunTask task) { VirtualFile f = myTarget.getModel().getBuildFile().getVirtualFile(); task.setAntFileUrl(f != null ? f.getUrl() : null); task.setTargetName(f != null ? myTarget.getName() : null); diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/actions/MavenExecuteBeforeRunDialog.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/actions/MavenExecuteBeforeRunDialog.java index 586c332aa63c..3cf07ea5fe64 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/actions/MavenExecuteBeforeRunDialog.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/tasks/actions/MavenExecuteBeforeRunDialog.java @@ -1,23 +1,10 @@ -/* - * 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-2020 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 org.jetbrains.idea.maven.tasks.actions; import com.intellij.execution.impl.BaseExecuteBeforeRunDialog; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; +import org.jetbrains.annotations.NotNull; import org.jetbrains.idea.maven.project.MavenProject; import org.jetbrains.idea.maven.tasks.MavenBeforeRunTask; import org.jetbrains.idea.maven.tasks.MavenBeforeRunTasksProvider; @@ -40,7 +27,7 @@ public class MavenExecuteBeforeRunDialog extends BaseExecuteBeforeRunDialog getTaskID() { + protected Key getTaskId() { return MavenBeforeRunTasksProvider.ID; } @@ -50,7 +37,7 @@ public class MavenExecuteBeforeRunDialog extends BaseExecuteBeforeRunDialog