PsiField (@Nullable PsiMethod method, boolean useIndex) { if (method == null) { return null; } final PsiParameterList parameterList = method.getParameterList(); if (parameterList.getParametersCount() != 1) { return null; } PsiField field; if (useIndex && method instanceof PsiMethodImpl && method.isPhysical()) { field = JavaSimplePropertyGistKt.getFieldOfSetter(method); } else { @NonNls final String name = method.getName(); if (!name.startsWith(SET_PREFIX)) { return null; } final PsiCodeBlock body = method.getBody(); if (body == null) { return null; } final PsiStatement[] statements = body.getStatements(); if (statements.length != 1) { return null; } final PsiStatement statement = statements[0]; if (!(statement instanceof PsiExpressionStatement possibleAssignmentStatement)) { return null; } final PsiExpression possibleAssignment = possibleAssignmentStatement.getExpression(); if (!(possibleAssignment instanceof PsiAssignmentExpression assignment)) { return null; } if (!JavaTokenType.EQ.equals(assignment.getOperationTokenType())) { return null; } final PsiExpression lhs = PsiUtil.skipParenthesizedExprDown(assignment.getLExpression()); if (!(lhs instanceof PsiReferenceExpression reference)) { return null; } final PsiExpression qualifier = PsiUtil.skipParenthesizedExprDown(reference.getQualifierExpression()); if (qualifier instanceof PsiReferenceExpression referenceExpression) { final PsiElement target = referenceExpression.resolve(); if (!(target instanceof PsiClass)) { return null; } } else if (qualifier != null && !(qualifier instanceof PsiThisExpression) && !(qualifier instanceof PsiSuperExpression)) { return null; } final PsiElement referent = reference.resolve(); if (!(referent instanceof PsiField)) { return null; } field = (PsiField)referent; final PsiExpression rhs = PsiUtil.skipParenthesizedExprDown(assignment.getRExpression()); if (!(rhs instanceof PsiReferenceExpression rReference)) { return null; } final PsiExpression rQualifier = rReference.getQualifierExpression(); if (rQualifier != null) { return null; } final PsiElement rReferent = rReference.resolve(); if (rReferent == null) { return null; } if (!(rReferent instanceof PsiParameter)) { return null; } } return field != null && field.getType().equals(parameterList.getParameters()[0].getType()) && checkFieldLocation(method, field) ? field : null; }