void (PsiElement aClass, PsiElement root, Set<PsiField> candidates) { root.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitMethod(@NotNull PsiMethod method) { if (method.isConstructor()) { final PsiCodeBlock body = method.getBody(); if (body != null) { final PsiStatement[] statements = body.getStatements(); if (statements.length > 0 && statements[0] instanceof PsiExpressionStatement) { final PsiExpression expression = ((PsiExpressionStatement)statements[0]).getExpression(); if (expression instanceof PsiMethodCallExpression) { final PsiMethod resolveMethod = ((PsiMethodCallExpression)expression).resolveMethod(); if (resolveMethod != null && resolveMethod.isConstructor()) { removeFieldsReferencedFromInitializers(aClass, expression, candidates); } } } } } final PsiDocComment docComment = method.getDocComment(); if (docComment != null) { removeFieldsReferencedFromInitializers(aClass, docComment, candidates); } //do not go inside method } @Override public void visitClassInitializer(@NotNull PsiClassInitializer initializer) { //do not go inside class initializer } @Override public void visitLambdaExpression(@NotNull PsiLambdaExpression expression) { // do not go inside lambda } @Override public void visitReferenceExpression(@NotNull PsiReferenceExpression expression) { excludeFieldCandidate(expression); super.visitReferenceExpression(expression); } @Override public void visitDocTagValue(@NotNull PsiDocTagValue value) { excludeFieldCandidate(value.getReference()); super.visitDocTagValue(value); } private void excludeFieldCandidate(PsiReference ref) { if (ref == null) return; final PsiElement resolved = ref.resolve(); if (resolved instanceof PsiField field && aClass.equals(field.getContainingClass())) { candidates.remove(field); } } }); }