private boolean isLastStatement(PsiStatement statement) {
    if (statement == null) {
      return false;
    }
    if (!(statement.getParent() instanceof PsiCodeBlock codeBlock)) {
      return true;
    }
    PsiStatement[] siblings = codeBlock.getStatements();
    PsiStatement lastOne = siblings[siblings.length - 1];
    if (statement == lastOne) {
      return true;
    }

    int posEnd = myPosition.getTextRange().getEndOffset();
    int blockContentEnd = lastOne.getTextRange().getEndOffset();
    CharSequence fileText = myPosition.getContainingFile().getViewProvider().getContents();
    String afterPos = fileText.subSequence(posEnd, blockContentEnd).toString();
    int nonSpace = CharArrayUtil.shiftForward(afterPos, 0, " \t");
    if (nonSpace < afterPos.length() && afterPos.charAt(nonSpace) == '\n') return false;

    try {
      PsiStatement asStatement = JavaPsiFacade.getElementFactory(myPosition.getProject()).createStatementFromText(afterPos.trim(), null);
      return asStatement instanceof PsiExpressionStatement;
    }
    catch (IncorrectOperationException e) {
      return false;
    }
  }
private boolean isLastStatement(PsiStatement statement)