void (PsiElement element) { element.accept(new JavaRecursiveElementVisitor() { @Override public void visitReturnStatement(@NotNull PsiReturnStatement statement) { // do something } @Override public void visitClass(@NotNull PsiClass aClass) { // do something } @Override public void visitLambdaExpression(PsiLambdaExpression expression) { // do something } }); }