@Override
  public @Nullable PsiElement getAnchor(@NotNull PsiElement element) {
    while (element instanceof PsiWhiteSpace || element instanceof PsiComment) {
      element = element.getNextSibling();
    }
    while (!(element instanceof PsiStatement)) {
      PsiElement parent = element.getParent();
      if (!(parent instanceof PsiStatement) && (parent == null || element.getTextRangeInParent().getStartOffset() > 0)) {
        if (parent instanceof PsiCodeBlock && ((PsiCodeBlock)parent).getRBrace() == element) {
          PsiElement grandParent = parent.getParent();
          if (grandParent instanceof PsiBlockStatement) {
            return PsiTreeUtil.getNextSiblingOfType(grandParent, PsiStatement.class);
          }
        }
        if (parent instanceof PsiPolyadicExpression) {
          // If we are inside the expression we can position only at locations where the stack is empty
          // currently only && and || chains inside if/return/yield are allowed
          IElementType tokenType = ((PsiPolyadicExpression)parent).getOperationTokenType();
          if (tokenType.equals(JavaTokenType.ANDAND) || tokenType.equals(JavaTokenType.OROR)) {
            PsiElement grandParent = parent.getParent();
            if (grandParent instanceof PsiIfStatement || grandParent instanceof PsiYieldStatement ||
                grandParent instanceof PsiReturnStatement) {
              if (element instanceof PsiExpression) {
                return element;
              }
              return PsiTreeUtil.getNextSiblingOfType(element, PsiExpression.class);
            }
          }
        }
        return null;
      }
      element = parent;
    }
    return element;
  }
@Override
  public @Nullable PsiElement getAnchor(@NotNull PsiElement element)