simplify getting project from AnActionEvent

This commit is contained in:
Konstantin Bulenkov
2016-05-24 01:52:46 +02:00
parent d6f6c795e5
commit 4a328a3dc4
7 changed files with 32 additions and 32 deletions
@@ -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 org.jetbrains.idea.devkit.actions;
import com.intellij.ide.IdeView;
import com.intellij.ide.actions.CreateElementActionBase;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.module.ModuleType;
@@ -80,10 +83,10 @@ public abstract class GeneratePluginClassAction extends CreateElementActionBase
final Presentation presentation = e.getPresentation();
if (presentation.isEnabled()) {
final DataContext context = e.getDataContext();
final Module module = LangDataKeys.MODULE.getData(context);
final Module module = e.getData(LangDataKeys.MODULE);
if (PluginModuleType.isPluginModuleOrDependency(module)) {
final IdeView view = LangDataKeys.IDE_VIEW.getData(e.getDataContext());
final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
final Project project = e.getProject();
if (view != null && project != null) {
// from com.intellij.ide.actions.CreateClassAction.update()
ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
@@ -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.
@@ -20,7 +20,6 @@ import com.intellij.notification.NotificationGroup;
import com.intellij.notification.NotificationType;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.compiler.CompileContext;
@@ -79,7 +78,7 @@ public class PrepareToDeployAction extends AnAction {
public void actionPerformed(final AnActionEvent e) {
final Module module = LangDataKeys.MODULE.getData(e.getDataContext());
if (module != null && PluginModuleType.isOfType(module)) {
doPrepare(Arrays.asList(module), CommonDataKeys.PROJECT.getData(e.getDataContext()));
doPrepare(Arrays.asList(module), e.getProject());
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2010 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,8 +17,6 @@ package org.jetbrains.idea.devkit.dom.generator;
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.project.Project;
/**
@@ -27,7 +25,7 @@ import com.intellij.openapi.project.Project;
public class GenerateDomModelAction extends AnAction {
@Override
public void actionPerformed(AnActionEvent e) {
final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
final Project project = e.getProject();
if (project != null) {
new DomGenDialog(project).show();
}
@@ -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.
@@ -15,7 +15,9 @@
*/
package org.jetbrains.idea.devkit.internal;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.fileChooser.FileChooser;
@@ -42,10 +44,9 @@ public class DumpCleanHighlightingTestdataAction extends AnAction implements Dum
}
@Override
public void actionPerformed(final AnActionEvent event) {
final DataContext dataContext = event.getDataContext();
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
final PsiFile psiFile = CommonDataKeys.PSI_FILE.getData(dataContext);
public void actionPerformed(final AnActionEvent e) {
final Project project = e.getProject();
final PsiFile psiFile = e.getData(CommonDataKeys.PSI_FILE);
if (psiFile != null) {
final VirtualFile virtualFile = psiFile.getVirtualFile();
if (virtualFile != null) {
@@ -83,8 +84,8 @@ public class DumpCleanHighlightingTestdataAction extends AnAction implements Dum
try {
FileUtil.writeToFile(file, document.getText());
}
catch (IOException e) {
LOG.error(e);
catch (IOException ex) {
LOG.error(ex);
}
}
}
@@ -94,6 +95,6 @@ public class DumpCleanHighlightingTestdataAction extends AnAction implements Dum
@Override
public void update(AnActionEvent e) {
e.getPresentation().setEnabled(CommonDataKeys.PROJECT.getData(e.getDataContext()) != null);
e.getPresentation().setEnabled(e.getProject() != null);
}
}
@@ -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.
@@ -48,7 +48,7 @@ public class NavigateToTestDataAction extends AnAction implements TestTreeViewAc
@Override
public void actionPerformed(AnActionEvent e) {
final DataContext dataContext = e.getDataContext();
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
final Project project = e.getProject();
List<String> fileNames = findTestDataFiles(dataContext);
if (fileNames == null || fileNames.isEmpty()) {
String testData = guessTestData(dataContext);
@@ -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.
@@ -23,7 +23,6 @@ import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
@@ -34,9 +33,9 @@ public class TestCaseAsRelatedFileProvider extends GotoRelatedProvider {
@NotNull
@Override
public List<? extends GotoRelatedItem> getItems(@NotNull DataContext context) {
final Editor editor = CommonDataKeys.EDITOR.getData(context);
final Project project = CommonDataKeys.PROJECT.getData(context);
final VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(context);
final Editor editor = context.getData(CommonDataKeys.EDITOR);
final Project project = context.getData(CommonDataKeys.PROJECT);
final VirtualFile file = context.getData(CommonDataKeys.VIRTUAL_FILE);
if (editor == null || file == null || project == null) {
return Collections.emptyList();
}
@@ -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.
@@ -37,9 +37,9 @@ public class TestDataAsRelatedFileProvider extends GotoRelatedProvider {
@NotNull
@Override
public List<? extends GotoRelatedItem> getItems(@NotNull DataContext context) {
final Editor editor = CommonDataKeys.EDITOR.getData(context);
final Project project = CommonDataKeys.PROJECT.getData(context);
final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(context);
final Editor editor = context.getData(CommonDataKeys.EDITOR);
final Project project = context.getData(CommonDataKeys.PROJECT);
final PsiElement element = context.getData(CommonDataKeys.PSI_ELEMENT);
if (editor == null || element == null || project == null) {
return Collections.emptyList();
}