mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Add TestCreators to Generate popup (GO-5889)
This commit is contained in:
+54
@@ -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"/>
|
||||
|
||||
Reference in New Issue
Block a user