Self (final int level, final @NotNull ElementPattern<? extends ParentType> pattern) { return with(new PatternConditionPlus<T, ParentType>(level == 1 ? "withParent" : "withSuperParent", pattern) { @Override public boolean processValues(T t, ProcessingContext context, PairProcessor<? super ParentType, ? super ProcessingContext> processor) { ParentType parent = t; for (int i = 0; i < level; i++) { if (parent == null) return true; parent = getParent(parent); } return processor.process(parent, context); } }); }