Holder (PsiExpression expression, String methodName, PsiElement secondDeclaredElement) { expression = PsiUtil.skipParenthesizedExprDown(expression); if (expression instanceof PsiReferenceExpression) { final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)expression; final PsiElement target = referenceExpression.resolve(); if (secondDeclaredElement != null && !secondDeclaredElement.equals(target)) { return null; } if (!(target instanceof PsiVariable variable)) { return null; } final PsiCodeBlock context = PsiTreeUtil.getParentOfType(variable, PsiCodeBlock.class); if (context == null) { return null; } if (VariableAccessUtils.variableIsAssigned(variable, context)) { return null; } expression = PsiUtil.skipParenthesizedExprDown(variable.getInitializer()); } else if (secondDeclaredElement != null) { return null; } if (!(expression instanceof PsiMethodCallExpression methodCallExpression)) { return null; } final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression(); final String referenceName = methodExpression.getReferenceName(); if (!methodName.equals(referenceName)) { return null; } final PsiMethod method = methodCallExpression.resolveMethod(); if (method == null) { return null; } final PsiClass containingClass = method.getContainingClass(); if (!InheritanceUtil.isInheritor(containingClass, CommonClassNames.JAVA_UTIL_LIST)) { return null; } final PsiExpression qualifierExpression = PsiUtil.skipParenthesizedExprDown(methodExpression.getQualifierExpression()); if (qualifierExpression == null || qualifierExpression instanceof PsiThisExpression || qualifierExpression instanceof PsiSuperExpression) { return new Holder(methodExpression); } if (!(qualifierExpression instanceof PsiReferenceExpression)) { return null; } final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)qualifierExpression; final PsiElement target = referenceExpression.resolve(); if (!(target instanceof PsiVariable)) { return null; } final PsiVariable variable = (PsiVariable)target; return new Holder(variable, methodExpression); }