private static FilterPattern rightAfterElement(final PsiElementPattern.Capture<? extends PsiElement> pattern) {
    return new FilterPattern(new ElementFilter() {
      @Override
      public boolean isAcceptable(Object element, @Nullable PsiElement context) {
        if (!(element instanceof PsiElement)) return false;
        PsiElement prevLeaf = PsiTreeUtil.prevVisibleLeaf((PsiElement)element);
        if (prevLeaf == null) return false;
        PsiElement parent = PsiTreeUtil.findFirstParent(prevLeaf, element1 -> pattern.accepts(element1));
        if (parent == null) return false;
        if (PsiTreeUtil.hasErrorElements(parent)) return false;
        return prevLeaf.getTextRange().getEndOffset() == parent.getTextRange().getEndOffset();
      }

      @Override
      public boolean isClassAcceptable(Class hintClass) {
        return true;
      }
    });
  }
private static FilterPattern rightAfterElement(final PsiElementPattern.Capture<? extends PsiElement> pattern)