private static <T extends PsiElement> boolean hasParentOfTypeBeforeAncestor(@NotNull PsiElement descendant, @NotNull PsiElement ancestor,
                                                                                @NotNull Class<? extends T> @NotNull ... classes) {
      PsiElement elementToTest = descendant.getParent();
      while (elementToTest != null) {
        if (elementToTest.equals(ancestor)) return false;
        if (PsiTreeUtil.instanceOf(elementToTest, classes)) return true;
        elementToTest = elementToTest.getParent();
      }
      return false;
    }
private static <T extends PsiElement> boolean hasParentOfTypeBeforeAncestor(@NotNull PsiElement descendant, @NotNull PsiElement ancestor,
                                                                                @NotNull Class<? extends T> @NotNull ... classes)