Add TestCreators to Generate popup (GO-5889)

This commit is contained in:
Alexander Zolotov
2018-08-21 21:17:27 +03:00
parent 809486503c
commit 83d6d09304
2 changed files with 55 additions and 0 deletions
@@ -0,0 +1,54 @@
// 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.testIntegration;
import com.intellij.navigation.ItemPresentation;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
import com.intellij.util.ObjectUtils;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class GenerateFromTestCreatorsGroup extends ActionGroup {
@NotNull
@Override
public AnAction[] getChildren(@Nullable AnActionEvent e) {
if (e == null) {
return AnAction.EMPTY_ARRAY;
}
Project project = e.getData(CommonDataKeys.PROJECT);
PsiFile file = e.getData(CommonDataKeys.PSI_FILE);
Editor editor = e.getData(CommonDataKeys.EDITOR);
if (project == null || file == null) {
return AnAction.EMPTY_ARRAY;
}
List<AnAction> result = ContainerUtil.newSmartList();
for (TestCreator creator : LanguageTestCreators.INSTANCE.allForLanguage(file.getLanguage())) {
result.add(new AnAction() {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
creator.createTest(project, editor, file);
}
@Override
public void update(@NotNull AnActionEvent e) {
String text = creator instanceof ItemPresentation ? ((ItemPresentation)creator).getPresentableText() : null;
Presentation presentation = e.getPresentation();
presentation.setText(ObjectUtils.notNull(text, "New Test..."));
presentation.setEnabledAndVisible(creator.isAvailable(project, editor, file));
}
@Override
public boolean isDumbAware() {
return DumbService.isDumbAware(creator);
}
});
}
return result.toArray(AnAction.EMPTY_ARRAY);
}
}
@@ -35,6 +35,7 @@
<action id="ImplementMethods" class="com.intellij.codeInsight.generation.actions.ImplementMethodsAction"/>
<action id="DelegateMethods" class="com.intellij.codeInsight.generation.actions.DelegateMethodsAction"/>
<action id="GeneratePattern" class="com.intellij.codeInsight.generation.GenerateByPatternAction" text="Generate by Pattern..."/>
<group id="GenerateFromTestCreatorsGroup" class="com.intellij.testIntegration.GenerateFromTestCreatorsGroup"/>
</group>
<action id="ShowIntentionActions" class="com.intellij.codeInsight.intention.actions.ShowIntentionActionsAction"/>