Self (final ElementPattern<? extends PsiElement> ancestor) { return with(new PatternCondition<PsiElement>("insideStarting") { @Override public boolean accepts(@NotNull PsiElement start, ProcessingContext context) { PsiElement element = getParent(start); TextRange range = start.getTextRange(); if (range == null) return false; int startOffset = range.getStartOffset(); while (element != null && element.getTextRange() != null && element.getTextRange().getStartOffset() == startOffset) { if (ancestor.accepts(element, context)) { return true; } element = getParent(element); } return false; } }); }