From c0d0331a7e2fc74a44fe64e3837f1d819664119f Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Tue, 24 May 2016 02:09:26 +0200 Subject: [PATCH] simplify getting project from AnActionEvent --- .../impl/DefaultJavaProgramRunner.java | 9 +++++--- .../action/AttachExternalProjectAction.java | 7 ++----- .../action/ExternalSystemAction.java | 5 ++--- .../ExternalSystemRunConfigurationMenu.java | 9 +++++--- .../action/ExternalSystemToggleAction.java | 5 ++--- .../RefreshAllExternalProjectsAction.java | 21 +++++++++++++++---- .../AbstractGradleLinkedProjectAction.java | 18 ++++++++++++++-- .../action/GradleToolWindowHelpAction.java | 21 ++++++++++++++----- .../xml/ui/actions/AddDomElementAction.java | 4 ++-- 9 files changed, 69 insertions(+), 30 deletions(-) diff --git a/java/execution/impl/src/com/intellij/execution/impl/DefaultJavaProgramRunner.java b/java/execution/impl/src/com/intellij/execution/impl/DefaultJavaProgramRunner.java index 579ab6e098c0..2f4836551ee3 100644 --- a/java/execution/impl/src/com/intellij/execution/impl/DefaultJavaProgramRunner.java +++ b/java/execution/impl/src/com/intellij/execution/impl/DefaultJavaProgramRunner.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -29,7 +29,10 @@ import com.intellij.execution.runners.*; import com.intellij.execution.ui.ExecutionConsole; import com.intellij.execution.ui.RunContentDescriptor; import com.intellij.icons.AllIcons; -import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.CustomShortcutSet; +import com.intellij.openapi.actionSystem.Presentation; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.fileEditor.FileDocumentManager; @@ -165,7 +168,7 @@ public class DefaultJavaProgramRunner extends JavaPatchableProgramRunner { ProcessProxy proxy = ProcessProxyFactory.getInstance().getAttachedProxy(myProcessHandler); if (proxy != null) { final WiseDumpThreadsListener wiseListener = Boolean.TRUE.equals(Boolean.getBoolean(ourWiseThreadDumpProperty)) ? - new WiseDumpThreadsListener(CommonDataKeys.PROJECT.getData(e.getDataContext()), myProcessHandler) : null; + new WiseDumpThreadsListener(e.getProject(), myProcessHandler) : null; proxy.sendBreak(); diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/AttachExternalProjectAction.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/AttachExternalProjectAction.java index cafd4784df0e..5c2b659b4a91 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/AttachExternalProjectAction.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/AttachExternalProjectAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -20,15 +20,12 @@ import com.intellij.ide.actions.ImportModuleAction; import com.intellij.ide.util.newProjectWizard.AddModuleWizard; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.externalSystem.ExternalSystemManager; import com.intellij.openapi.externalSystem.model.ExternalSystemDataKeys; import com.intellij.openapi.externalSystem.model.ProjectSystemId; import com.intellij.openapi.externalSystem.service.project.wizard.AbstractExternalProjectImportProvider; import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil; import com.intellij.openapi.externalSystem.util.ExternalSystemBundle; -import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.SystemInfoRt; import com.intellij.projectImport.ProjectImportProvider; @@ -68,7 +65,7 @@ public class AttachExternalProjectAction extends AnAction { return; } - Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); + Project project = e.getProject(); if (project == null) { return; } diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/ExternalSystemAction.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/ExternalSystemAction.java index c8f77d218270..9598251f9915 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/ExternalSystemAction.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/ExternalSystemAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -17,7 +17,6 @@ package com.intellij.openapi.externalSystem.action; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.actionSystem.Presentation; import com.intellij.openapi.externalSystem.model.ExternalSystemDataKeys; import com.intellij.openapi.externalSystem.model.ProjectSystemId; @@ -49,7 +48,7 @@ public abstract class ExternalSystemAction extends AnAction implements DumbAware } protected Project getProject(AnActionEvent e) { - return CommonDataKeys.PROJECT.getData(e.getDataContext()); + return e.getProject(); } protected ProjectSystemId getSystemId(AnActionEvent e) { diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/ExternalSystemRunConfigurationMenu.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/ExternalSystemRunConfigurationMenu.java index 843eccece03f..c6995d726c39 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/ExternalSystemRunConfigurationMenu.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/ExternalSystemRunConfigurationMenu.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -17,7 +17,10 @@ package com.intellij.openapi.externalSystem.action; import com.intellij.execution.*; import com.intellij.execution.runners.ProgramRunner; -import com.intellij.openapi.actionSystem.*; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.Constraints; +import com.intellij.openapi.actionSystem.DefaultActionGroup; import com.intellij.openapi.externalSystem.model.ExternalSystemDataKeys; import com.intellij.openapi.externalSystem.view.ExternalSystemNode; import com.intellij.openapi.externalSystem.view.RunConfigurationNode; @@ -40,7 +43,7 @@ public class ExternalSystemRunConfigurationMenu extends DefaultActionGroup imple } } - final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); + final Project project = e.getProject(); final List selectedNodes = ExternalSystemDataKeys.SELECTED_NODES.getData(e.getDataContext()); if (selectedNodes == null || selectedNodes.size() != 1 || !(selectedNodes.get(0) instanceof RunConfigurationNode)) return; diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/ExternalSystemToggleAction.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/ExternalSystemToggleAction.java index feba1985a095..5baf676136d7 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/ExternalSystemToggleAction.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/ExternalSystemToggleAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -16,7 +16,6 @@ package com.intellij.openapi.externalSystem.action; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.actionSystem.Presentation; import com.intellij.openapi.actionSystem.ToggleAction; import com.intellij.openapi.externalSystem.model.ExternalSystemDataKeys; @@ -55,7 +54,7 @@ public abstract class ExternalSystemToggleAction extends ToggleAction implements protected abstract boolean doIsSelected(AnActionEvent e); protected Project getProject(AnActionEvent e) { - return CommonDataKeys.PROJECT.getData(e.getDataContext()); + return e.getProject(); } protected boolean hasProject(AnActionEvent e) { diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/RefreshAllExternalProjectsAction.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/RefreshAllExternalProjectsAction.java index 31979f1bfc49..dcf1441343db 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/RefreshAllExternalProjectsAction.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/action/RefreshAllExternalProjectsAction.java @@ -1,8 +1,22 @@ +/* + * Copyright 2000-2016 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. + */ package com.intellij.openapi.externalSystem.action; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.externalSystem.ExternalSystemManager; import com.intellij.openapi.externalSystem.model.ExternalSystemDataKeys; @@ -12,7 +26,6 @@ import com.intellij.openapi.externalSystem.service.internal.ExternalSystemProces import com.intellij.openapi.externalSystem.util.ExternalSystemBundle; import com.intellij.openapi.externalSystem.util.ExternalSystemUtil; import com.intellij.openapi.fileEditor.FileDocumentManager; -import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.Function; @@ -36,7 +49,7 @@ public class RefreshAllExternalProjectsAction extends AnAction implements AnActi @Override public void update(AnActionEvent e) { - final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); + final Project project = e.getProject(); if (project == null) { e.getPresentation().setEnabled(false); return; @@ -63,7 +76,7 @@ public class RefreshAllExternalProjectsAction extends AnAction implements AnActi @Override public void actionPerformed(AnActionEvent e) { - final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); + final Project project = e.getProject(); if (project == null) { e.getPresentation().setEnabled(false); return; diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/action/AbstractGradleLinkedProjectAction.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/action/AbstractGradleLinkedProjectAction.java index 8045316d5eee..ac5b111709a5 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/action/AbstractGradleLinkedProjectAction.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/action/AbstractGradleLinkedProjectAction.java @@ -1,10 +1,24 @@ +/* + * Copyright 2000-2016 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. + */ package org.jetbrains.plugins.gradle.action; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.actionSystem.DataContext; -import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; import org.jetbrains.annotations.NotNull; @@ -34,7 +48,7 @@ public abstract class AbstractGradleLinkedProjectAction extends AnAction { @Override public void actionPerformed(AnActionEvent e) { - final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext()); + final Project project = e.getProject(); if (project == null) { return; } diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/action/GradleToolWindowHelpAction.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/action/GradleToolWindowHelpAction.java index d8274df4b3a8..fb3df6d8c60f 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/action/GradleToolWindowHelpAction.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/action/GradleToolWindowHelpAction.java @@ -1,13 +1,24 @@ +/* + * Copyright 2000-2016 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. + */ package org.jetbrains.plugins.gradle.action; import com.intellij.ide.actions.ContextHelpAction; import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.CommonDataKeys; import com.intellij.openapi.actionSystem.DataContext; -import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.text.StringUtil; -import org.jetbrains.plugins.gradle.settings.GradleSettings; import org.jetbrains.plugins.gradle.util.GradleConstants; /** @@ -18,7 +29,7 @@ public class GradleToolWindowHelpAction extends ContextHelpAction { @Override public void update(AnActionEvent event) { - final Project project = CommonDataKeys.PROJECT.getData(event.getDataContext()); + final Project project = event.getProject(); if (project == null) { event.getPresentation().setVisible(false); return; diff --git a/xml/dom-openapi/src/com/intellij/util/xml/ui/actions/AddDomElementAction.java b/xml/dom-openapi/src/com/intellij/util/xml/ui/actions/AddDomElementAction.java index 4e6cf8a16378..d00aa0912c9a 100644 --- a/xml/dom-openapi/src/com/intellij/util/xml/ui/actions/AddDomElementAction.java +++ b/xml/dom-openapi/src/com/intellij/util/xml/ui/actions/AddDomElementAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -117,7 +117,7 @@ public abstract class AddDomElementAction extends AnAction { @NotNull public AnAction[] getChildren(@Nullable AnActionEvent e) { - Project project = e == null ? null : CommonDataKeys.PROJECT.getData(e.getDataContext()); + Project project = e == null ? null : e.getProject(); if (project == null) return AnAction.EMPTY_ARRAY; DomCollectionChildDescription[] descriptions = getDomCollectionChildDescriptions(e);