Set<PsiField> (PsiElement element) { PsiReferenceExpression ref = PsiTreeUtil.getNonStrictParentOfType(element, PsiReferenceExpression.class); if (ref == null) return Collections.emptySet(); final PsiStatement statement = PsiTreeUtil.getParentOfType(element, PsiStatement.class); //noinspection SSBasedInspection final PsiMethod method = PsiTreeUtil.getParentOfType(element, PsiMethod.class, true, PsiClass.class); if (statement == null || method == null || !method.isConstructor()) { return Collections.emptySet(); } PsiElement parent = element.getParent(); if (parent instanceof PsiReferenceExpression && !ExpressionUtil.isEffectivelyUnqualified((PsiReferenceExpression)parent)) { return Collections.emptySet(); } while (parent != statement) { PsiElement next = parent.getParent(); if (next instanceof PsiAssignmentExpression && parent == ((PsiAssignmentExpression)next).getLExpression()) { return Collections.emptySet(); } if (parent instanceof PsiJavaCodeReferenceElement) { PsiStatement psiStatement = PsiTreeUtil.getParentOfType(parent, PsiStatement.class); if (psiStatement != null && psiStatement.getTextRange().getStartOffset() == parent.getTextRange().getStartOffset()) { return Collections.emptySet(); } } parent = next; } boolean allowNonFinalFields = !isInsideConstructorCall(element); final Set<PsiField> fields = new HashSet<>(); final PsiClass containingClass = method.getContainingClass(); assert containingClass != null; InheritanceUtil.processSupers(containingClass, true, eachClass -> { for (PsiField field : eachClass.getFields()) { if (!seemsInitialized(allowNonFinalFields, containingClass, field)) { fields.add(field); } } return true; }); Set<PsiField> assigned = new HashSet<>(); method.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitAssignmentExpression(@NotNull PsiAssignmentExpression expression) { PsiExpression lExpression = expression.getLExpression(); if (lExpression instanceof PsiReferenceExpression && ExpressionUtil.isEffectivelyUnqualified((PsiReferenceExpression)lExpression)) { PsiElement target = ((PsiReferenceExpression)lExpression).resolve(); if (target instanceof PsiField) { if (expression.getTextRange().getStartOffset() < statement.getTextRange().getStartOffset()) { assigned.add((PsiField)target); fields.remove(target); } else if (ref == PsiUtil.deparenthesizeExpression(expression.getRExpression()) && !assigned.contains(target)) { fields.add((PsiField)target); } } } super.visitAssignmentExpression(expression); } @Override public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) { if (expression.getTextRange().getStartOffset() < statement.getTextRange().getStartOffset()) { final PsiReferenceExpression methodExpression = expression.getMethodExpression(); if (methodExpression.textMatches(PsiKeyword.THIS)) { fields.clear(); } } super.visitMethodCallExpression(expression); } }); return fields; }