@Nullable
  public static PsiElement getContextElement(final StackFrameContext context, final SourcePosition position) {
    if (LOG.isDebugEnabled()) {
      final SourcePosition sourcePosition = getSourcePosition(context);
      LOG.assertTrue(Comparing.equal(sourcePosition, position));
    }

    return ReadAction.compute(() -> {
      final PsiElement element = getContextElement(position);

      if (element == null) {
        return null;
      }

      // further code is java specific, actually
      if (element.getLanguage().getAssociatedFileType() != DefaultCodeFragmentFactory.getInstance().getFileType()) {
        return element;
      }

      final StackFrameProxyImpl frameProxy = (StackFrameProxyImpl)context.getFrameProxy();

      if (frameProxy == null) {
        return element;
      }

      try {
        List<LocalVariableProxyImpl> list = frameProxy.visibleVariables();

        PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(element.getProject()).getResolveHelper();
        StringBuilder buf = null;
        for (LocalVariableProxyImpl localVariable : list) {
          final String varName = localVariable.name();
          if (resolveHelper.resolveReferencedVariable(varName, element) == null) {
            if (buf == null) {
              buf = new StringBuilder("{");
            }
            buf.append(localVariable.getVariable().typeName()).append(" ").append(varName).append(";");
          }
        }
        if (buf == null) {
          return element;
        }

        buf.append('}');

        final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(element.getProject());
        final PsiCodeBlock codeBlockFromText = elementFactory.createCodeBlockFromText(buf.toString(), element);

        final PsiStatement[] statements = codeBlockFromText.getStatements();
        for (PsiStatement statement : statements) {
          if (statement instanceof PsiDeclarationStatement declStatement) {
            PsiElement[] declaredElements = declStatement.getDeclaredElements();
            for (PsiElement declaredElement : declaredElements) {
              declaredElement.putUserData(IS_JSP_IMPLICIT, Boolean.TRUE);
            }
          }
        }
        return codeBlockFromText;
      }
      catch (IncorrectOperationException | EvaluateException ignored) {
        return element;
      }
    });
  }
@Nullable
  public static PsiElement getContextElement(final StackFrameContext context, final SourcePosition position)