package com.intellij.testIntegration;

import com.intellij.codeInsight.CodeInsightActionHandler;
import com.intellij.codeInsight.actions.BaseCodeInsightAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiUtilBase;
import com.intellij.idea.ActionsBundle;

public class GotoTestOrCodeAction extends BaseCodeInsightAction {
  protected CodeInsightActionHandler getHandler(){
    return new GotoTestOrCodeHandler();
  }

  protected boolean isValidForFile(Project project, Editor editor, final PsiFile file) {
    return true;
  }

  @Override
  public void update(AnActionEvent event) {
    Project project = event.getData(PlatformDataKeys.PROJECT);
    Editor editor = event.getData(PlatformDataKeys.EDITOR);
    if (editor == null || project == null) return;

    PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(editor, project);
    if (psiFile == null) return;

    PsiElement element = GotoTestOrCodeHandler.getSelectedElement(editor, psiFile);
    Presentation p = event.getPresentation();

    if (element == null) {
      p.setEnabled(false);
    }
    else {
      p.setEnabled(true);
      if (TestFinderHelper.isTest(element)) {
        p.setText(ActionsBundle.message("action.GotoTestSubject.text"));
        p.setDescription(ActionsBundle.message("action.GotoTestSubject.description"));
      } else {
        p.setText(ActionsBundle.message("action.GotoTest.text"));
        p.setDescription(ActionsBundle.message("action.GotoTest.description"));
      }
    }
  }
}

@@ -888,24 +888,95 @@
 nt event) %7B%0A
+    Presentation p = event.getPresentation();%0A    p.setEnabled(false);%0A
     Project 
@@ -1331,128 +1331,43 @@
 e);%0A
-    Presentation p = event.getPresentation();%0A%0A    if (element == null) %7B%0A      p.setEnabled(false);%0A    %7D%0A    else %7B%0A  
+%0A    if (element == null) return;%0A%0A
     
@@ -1390,18 +1390,16 @@
 e);%0A    
-  
 if (Test
@@ -1430,18 +1430,16 @@
 ent)) %7B%0A
-  
       p.
@@ -1499,34 +1499,32 @@
 .text%22));%0A      
-  
 p.setDescription
@@ -1590,18 +1590,16 @@
 ));%0A    
- 
- 
 %7D else %7B
@@ -1599,18 +1599,16 @@
  else %7B%0A
-  
       p.
@@ -1665,26 +1665,24 @@
 t%22));%0A      
- 
- 
 p.setDescrip
@@ -1745,16 +1745,8 @@
 ));%0A
-      %7D%0A
     

disable "goto test or code" when appropriate