GoTo Test: do not show 'Create Test' action if not applicable.
[idea/community.git] / java / java-impl / src / com / intellij / testIntegration / JavaTestCreator.java
index 3edb3d5bdc5c330701cf5fd2e977c87b57069fec..d85ac9212f16fe4c423413ceffdc062cd0977813 100644 (file)
  */
 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);
     }
   }
 }