void (PsiClass aClass, final Set<? super PsiField> candidates, final Set<? super PsiField> usedFields, final boolean ignoreFieldsUsedInMultipleMethods) { final Set<PsiField> ignored = new HashSet<>(); aClass.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitElement(@NotNull PsiElement element) { if (!candidates.isEmpty()) super.visitElement(element); } @Override public void visitMethod(@NotNull PsiMethod method) { super.visitMethod(method); final PsiCodeBlock body = method.getBody(); if (body != null) { checkCodeBlock(body, candidates, usedFields, ignoreFieldsUsedInMultipleMethods, ignored); } } @Override public void visitLambdaExpression(@NotNull PsiLambdaExpression expression) { super.visitLambdaExpression(expression); final PsiElement body = expression.getBody(); if (body != null) { checkCodeBlock(body, candidates, usedFields, ignoreFieldsUsedInMultipleMethods, ignored); } } @Override public void visitClassInitializer(@NotNull PsiClassInitializer initializer) { super.visitClassInitializer(initializer); checkCodeBlock(initializer.getBody(), candidates, usedFields, ignoreFieldsUsedInMultipleMethods, ignored); } }); }