private static SelectInContext createEditorContext(@Nullable Project project,
                                                     @Nullable FileEditor editor,
                                                     @Nullable VirtualFile contextFile) {
    if (project == null || editor == null || project.isDefault()) {
      return null;
    }

    VirtualFile file = editor.getFile();
    if (file == null) {
      file = contextFile;
    }

    PsiFile psiFile = file == null || !file.isValid() ? null : PsiManager.getInstance(project).findFile(file);
    if (psiFile == null) {
      return null;
    }

    if (editor instanceof TextEditor) {
      return new FileEditorSelectInContext(editor, psiFile) {
        @Override
        public Object getSelectorInFile() {
          PsiFile file = getPsiFile();
          if (file == null) return null;

          if (file.getViewProvider() instanceof TemplateLanguageFileViewProvider) {
            return super.getSelectorInFile();
          }
          Editor editor = getEditor();
          if (editor == null) {
            return super.getSelectorInFile();
          }
          int offset = TargetElementUtil.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset());
          PsiElement element = file.findElementAt(offset);
          return element != null ? element : super.getSelectorInFile();
        }
      };
    }
    else {
      Object selectorInFile = getElementFromStructureView(project, editor);
      if (selectorInFile == null) return new SmartSelectInContext(psiFile, psiFile);
      if (selectorInFile instanceof PsiElement) return new SmartSelectInContext(psiFile, (PsiElement)selectorInFile);
      return new SelectInContextImpl(psiFile, selectorInFile);
    }
  }
private static SelectInContext createEditorContext(@Nullable Project project,
                                                     @Nullable FileEditor editor,
                                                     @Nullable VirtualFile contextFile)