RedundantCollectionOperationHandler (PsiMethodCallExpression call) { PsiExpression arg = ArrayUtil.getFirstElement(call.getArgumentList().getExpressions()); PsiExpression arrayLength = null; String targetComponentType; if (arg != null) { if (!(arg instanceof PsiNewExpression)) return null; PsiJavaCodeReferenceElement classRef = ((PsiNewExpression)arg).getClassReference(); if (classRef == null) return null; targetComponentType = classRef.getQualifiedName(); PsiExpression[] dimensions = ((PsiNewExpression)arg).getArrayDimensions(); if (dimensions.length != 1) return null; if (!ExpressionUtils.isZero(dimensions[0])) { arrayLength = dimensions[0]; } } else { targetComponentType = CommonClassNames.JAVA_LANG_OBJECT; } PsiExpression from = null; PsiExpression to = null; PsiMethodCallExpression qualifier = MethodCallUtils.getQualifierMethodCall(call); if (SUBLIST.test(qualifier)) { PsiExpression[] subListArgs = qualifier.getArgumentList().getExpressions(); from = subListArgs[0]; to = subListArgs[1]; qualifier = MethodCallUtils.getQualifierMethodCall(qualifier); } if (!AS_LIST.test(qualifier) || MethodCallUtils.isVarArgCall(qualifier)) return null; PsiExpression array = qualifier.getArgumentList().getExpressions()[0]; PsiArrayType sourceArrayType = tryCast(array.getType(), PsiArrayType.class); if (sourceArrayType == null) return null; PsiClass componentClass = PsiUtil.resolveClassInClassTypeOnly(sourceArrayType.getComponentType()); if (componentClass == null) return null; String sourceComponentType = componentClass.getQualifiedName(); if (sourceComponentType == null) return null; if (from != null && to != null) { if (arrayLength != null && !ExpressionUtils.isDifference(from, to, arrayLength)) return null; } else { if (!sourceComponentType.equals(targetComponentType)) return null; if (arrayLength != null) { PsiExpression arrayFromLength = ExpressionUtils.getArrayFromLengthExpression(arrayLength); if (arrayFromLength == null || !PsiEquivalenceUtil.areElementsEquivalent(array, arrayFromLength)) return null; } } return new AsListToArrayHandler(from, to, array, sourceComponentType, targetComponentType); }