package com.karateca.jstoolbox.torelated;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.roots.ContentIterator;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.karateca.jstoolbox.config.JsToolboxSettings;

/**
 * @author andresdom@google.com (Andres Dominguez)
 */
public class GoToRelatedAction extends AnAction {

  public void actionPerformed(AnActionEvent e) {
  }

  @Override
  public void update(AnActionEvent e) {
    PsiFile file = e.getData(LangDataKeys.PSI_FILE);
    Editor editor = e.getData(PlatformDataKeys.EDITOR);

    // Disable the option if there is no file or editor.
    if (file == null || editor == null || editor.getProject() == null) {
      e.getPresentation().setEnabled(false);
      return;
    }

    JsToolboxSettings settings = new JsToolboxSettings();

    final String fileName = file.getName();

    // Ignore non-js files.
    String fileSuffix = settings.getFileSuffix();
    String testSuffix = settings.getTestSuffix();

    if (!fileName.endsWith(fileSuffix)) {
      return;
    }

    String findFileName;
    if (fileName.endsWith(testSuffix)) {
      findFileName = fileName.replace(testSuffix, fileSuffix);
    } else {
      findFileName = fileName.replace(fileSuffix, testSuffix);
    }

    ContentIterator fileIterator = new FindRelatedFileIterator(findFileName, PsiManager.getInstance(
        editor.getProject()));

    ProjectRootManager.getInstance(editor.getProject()).getFileIndex().iterateContent(fileIterator);
  }
}

@@ -40,59 +40,8 @@
 d;%0A%0A
-import com.intellij.openapi.actionSystem.AnAction;%0A
 impo
@@ -415,32 +415,72 @@
 psi.PsiManager;%0A
+import com.karateca.jstoolbox.MyAction;%0A
 import com.karat
@@ -618,18 +618,18 @@
 extends 
-An
+My
 Action %7B
@@ -630,16 +630,28 @@
 tion %7B%0A%0A
+  @Override%0A
   public
@@ -697,79 +697,23 @@
 %7B%0A  
-%7D%0A%0A  @Override%0A  public void update(AnActionEvent e) %7B%0A    PsiFile file
+  Editor editor
  = e
@@ -721,20 +721,24 @@
 getData(
-Lang
+Platform
 DataKeys
@@ -742,36 +742,33 @@
 eys.
-PSI_FILE);%0A    Editor editor
+EDITOR);%0A    PsiFile file
  = e
@@ -772,32 +772,28 @@
 = e.getData(
-Platform
+Lang
 DataKeys.EDI
@@ -789,22 +789,24 @@
 ataKeys.
-EDITOR
+PSI_FILE
 );%0A%0A    
@@ -820,48 +820,35 @@
 ble 
-the option if there is no file or editor
+if dependencies are not met
 .%0A  
@@ -874,31 +874,8 @@
 %7C%7C e
-ditor == null %7C%7C editor
 .get

extend from MyAction