mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
GoTo Test: do not show 'Create Test' action if not applicable.
This commit is contained in:
@@ -15,14 +15,26 @@
|
||||
*/
|
||||
package com.intellij.testIntegration;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.testIntegration.createTest.CreateTestAction;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
|
||||
public class JavaTestCreator implements TestCreator {
|
||||
private static final Logger LOG = Logger.getInstance("com.intellij.testIntegration.JavaTestCreator");
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(Project project, Editor editor, PsiFile file) {
|
||||
CreateTestAction action = new CreateTestAction();
|
||||
PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
|
||||
|
||||
return action.isAvailableForElement(element);
|
||||
}
|
||||
|
||||
public void createTest(Project project, Editor editor, PsiFile file) {
|
||||
try {
|
||||
CreateTestAction action = new CreateTestAction();
|
||||
@@ -32,7 +44,7 @@ public class JavaTestCreator implements TestCreator {
|
||||
}
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
LOG.warn(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,5 +21,6 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
|
||||
public interface TestCreator {
|
||||
boolean isAvailable(Project project, Editor editor, PsiFile file);
|
||||
void createTest(Project project, Editor editor, PsiFile file);
|
||||
}
|
||||
|
||||
@@ -53,23 +53,25 @@ public class GotoTestOrCodeHandler extends GotoTargetHandler {
|
||||
}
|
||||
else {
|
||||
candidates = TestFinderHelper.findTestsForClass(selectedElement);
|
||||
actions.add(new AdditionalAction() {
|
||||
@Override
|
||||
public String getText() {
|
||||
return "Create New Test...";
|
||||
}
|
||||
final TestCreator creator = LanguageTestCreators.INSTANCE.forLanguage(file.getLanguage());
|
||||
if (creator != null && creator.isAvailable(file.getProject(), editor, file)) {
|
||||
actions.add(new AdditionalAction() {
|
||||
@Override
|
||||
public String getText() {
|
||||
return "Create New Test...";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return IconLoader.getIcon("/actions/intentionBulb.png");
|
||||
}
|
||||
@Override
|
||||
public Icon getIcon() {
|
||||
return IconLoader.getIcon("/actions/intentionBulb.png");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
final TestCreator creator = LanguageTestCreators.INSTANCE.forLanguage(file.getLanguage());
|
||||
if (creator != null) creator.createTest(file.getProject(), editor, file);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void execute() {
|
||||
creator.createTest(file.getProject(), editor, file);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return new GotoData(sourceElement, candidates.toArray(new PsiElement[candidates.size()]), actions);
|
||||
|
||||
Reference in New Issue
Block a user