PsiField (@NotNull PsiParameter parameter, boolean findIndirectAssignments) { for (PsiReference reference : ReferencesSearch.search(parameter, new LocalSearchScope(parameter.getDeclarationScope()), false)) { if (!(reference instanceof PsiReferenceExpression expression)) continue; PsiAssignmentExpression assignmentExpression; if (findIndirectAssignments) { assignmentExpression = PsiTreeUtil.getParentOfType(expression, PsiAssignmentExpression.class, true, PsiClass.class); } else { PsiElement parent = PsiUtil.skipParenthesizedExprUp(expression.getParent()); if (parent instanceof PsiExpressionList) { // skip validating calls like Objects.requireNonNull PsiMethodCallExpression call = ObjectUtils.tryCast(parent.getParent(), PsiMethodCallExpression.class); PsiExpression returnedValue = PsiUtil.skipParenthesizedExprDown(JavaMethodContractUtil.findReturnedValue(call)); if (returnedValue == expression) { parent = PsiUtil.skipParenthesizedExprUp(call.getParent()); } } assignmentExpression = parent instanceof PsiAssignmentExpression ? (PsiAssignmentExpression)parent : null; } if (assignmentExpression == null) continue; if (!PsiTreeUtil.isAncestor(assignmentExpression.getRExpression(), expression, false)) continue; PsiExpression lExpression = assignmentExpression.getLExpression(); if (!(lExpression instanceof PsiReferenceExpression)) continue; PsiElement element = ((PsiReferenceExpression)lExpression).resolve(); if (element instanceof PsiField) return (PsiField)element; } return null; }