import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.ide.DataManager;
+import com.intellij.injected.editor.EditorWindow;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.impl.SimpleDataContext;
import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.extensions.Extensions;
+import com.intellij.openapi.fileEditor.impl.text.TextEditorPsiDataProvider;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiFile;
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
import com.intellij.refactoring.actions.RenameElementAction;
import com.intellij.refactoring.rename.NameSuggestionProvider;
if (provider != null) {
provider.setActive(true);
}
+
HashMap<String, Object> map = new HashMap<String, Object>();
PsiElement psiElement = descriptor.getPsiElement();
- map.put(LangDataKeys.PSI_ELEMENT.getName(), psiElement);
- map.put(
- LangDataKeys.EDITOR.getName(),
- InjectedLanguageUtil.openEditorFor(psiElement.getContainingFile(), project)
- );
+ PsiFile containingFile = psiElement.getContainingFile();
+ Editor editor = InjectedLanguageUtil.openEditorFor(containingFile, project);
+
+ if (editor instanceof EditorWindow) {
+ map.put(LangDataKeys.EDITOR.getName(), editor);
+ map.put(LangDataKeys.PSI_ELEMENT.getName(), psiElement);
+ } else if (ApplicationManager.getApplication().isUnitTestMode()) { // TextEditorComponent / FiledEditorManagerImpl give away the data in real life
+ map.put(
+ LangDataKeys.PSI_ELEMENT.getName(),
+ new TextEditorPsiDataProvider().getData(
+ LangDataKeys.PSI_ELEMENT.getName(),
+ editor,
+ containingFile.getVirtualFile()
+ )
+ );
+ }
DataContext dataContext = SimpleDataContext.getSimpleContext(map, DataManager.getInstance().getDataContext());
AnAction action = new RenameElementAction();
};
if (ApplicationManager.getApplication().isUnitTestMode()) fix.run();
- else SwingUtilities.invokeLater(fix); // TODO [shkate] this is ugly, has problem with undo and hard to test!
+ else SwingUtilities.invokeLater(fix); // TODO [shkate] this is hard to test!
}
}
\ No newline at end of file