boolean (PsiExpression expression, PsiVariable variable, boolean shouldBeOffsetArrayAccess) { expression = PsiUtil.skipParenthesizedExprDown(expression); if (expression == null) return false; if (!(expression instanceof PsiMethodCallExpression methodCallExpression)) return false; final PsiExpressionList argumentList = methodCallExpression.getArgumentList(); final PsiExpression[] arguments = argumentList.getExpressions(); if (arguments.length != 1) return false; final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression(); final PsiExpression qualifier = methodExpression.getQualifierExpression(); if (!(qualifier instanceof PsiReferenceExpression) && !(qualifier instanceof PsiThisExpression) && !(qualifier instanceof PsiSuperExpression)) { return false; } if (VariableAccessUtils.variableIsUsed(variable, qualifier)) return false; final PsiExpression argument = arguments[0]; final PsiType argumentType = argument.getType(); if (argumentType instanceof PsiPrimitiveType) return false; if (SideEffectChecker.mayHaveSideEffects(argument)) return false; if (shouldBeOffsetArrayAccess) { if (!ExpressionUtils.isOffsetArrayAccess(argument, variable)) return false; } else { if (!ExpressionUtils.isReferenceTo(argument, variable)) return false; } final PsiMethod method = methodCallExpression.resolveMethod(); if (method == null) return false; @NonNls final String name = method.getName(); if (!name.equals("add")) return false; final PsiClass containingClass = method.getContainingClass(); return InheritanceUtil.isInheritor(containingClass, CommonClassNames.JAVA_UTIL_COLLECTION); }