@Override
    protected void typeCalculationFinished(@Nullable final PsiType type) {
      if (type == null) {
        return;
      }

      hold();
      final Project project = myElement.getProject();
      DebuggerInvocationUtil.invokeLater(project, () -> WriteCommandAction.writeCommandAction(project).withName(
        JavaDebuggerBundle.message("command.name.surround.with.runtime.cast")).run(() -> {
        try {
          PsiElementFactory factory = JavaPsiFacade.getElementFactory(myElement.getProject());
          PsiParenthesizedExpression parenth =
            (PsiParenthesizedExpression)factory.createExpressionFromText("((" + type.getCanonicalText() + ")expr)", null);
          //noinspection ConstantConditions
          ((PsiTypeCastExpression)parenth.getExpression()).getOperand().replace(myElement);
          parenth = (PsiParenthesizedExpression)JavaCodeStyleManager.getInstance(project).shortenClassReferences(parenth);
          PsiExpression expr = (PsiExpression)myElement.replace(parenth);
          TextRange range = expr.getTextRange();
          myEditor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset());
          myEditor.getCaretModel().moveToOffset(range.getEndOffset());
          myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
        }
        catch (IncorrectOperationException e) {
          // OK here. Can be caused by invalid type like one for proxy starts with . '.Proxy34'
        }
        finally {
          release();
        }
      }), myProgressIndicator.getModalityState());
    }
@Override
    protected void typeCalculationFinished(@Nullable final PsiType type)