boolean (@Nullable PsiElement element, @NotNull PsiElementProcessor<? super PsiElement> processor) { if (element == null) return true; if (element instanceof PsiCompiledElement || !element.isPhysical()) { // DummyHolders cannot be visited by walking visitors because children/parent relationship is broken there if (!processor.execute(element)) return false; for (PsiElement child : element.getChildren()) { if (!processElements(child, processor)) return false; } return true; } boolean[] result = {true}; element.accept(new PsiRecursiveElementWalkingVisitor() { @Override public void visitElement(@NotNull PsiElement element) { if (processor.execute(element)) { super.visitElement(element); } else { stopWalking(); result[0] = false; } } }); return result[0]; }