TypeConversionDescriptorBase (final PsiType from, final PsiType to, PsiMember member, final PsiExpression context, final TypeMigrationLabeler labeler) { PsiExpression expression = context; PsiClassType classType = from instanceof PsiClassType ? (PsiClassType)from : to instanceof PsiClassType ? (PsiClassType)to : null; PsiArrayType arrayType = from instanceof PsiArrayType ? (PsiArrayType)from : to instanceof PsiArrayType ? (PsiArrayType)to : null; if (classType == null || arrayType == null) return null; final PsiType collectionType = evaluateCollectionsType(classType, expression); if (collectionType == null) return null; if (member == null) { final PsiMethodCallExpression callExpression = PsiTreeUtil.getParentOfType(context, PsiMethodCallExpression.class); if (callExpression != null) { member = callExpression.resolveMethod(); expression = callExpression; } } if (member instanceof PsiMethod method) { TypeConversionDescriptor descriptor = changeCollectionCallsToArray(method, context, collectionType, arrayType); if (descriptor != null) return descriptor; @NonNls final String memberName = member.getName(); assert memberName != null; descriptor = switch (memberName) { case "sort" -> { if (method.getParameterList().getParametersCount() == 1) { yield new TypeConversionDescriptor("Arrays.sort($qualifier$)", "Collections.sort($qualifier$)", expression); } else { yield new TypeConversionDescriptor("Arrays.sort($qualifier$, $expr$)", "Collections.sort($qualifier$, $expr$)", expression); } } case "binarySearch" -> { if (method.getParameterList().getParametersCount() == 2) { yield new TypeConversionDescriptor("Arrays.binarySearch($qualifier$, $key$)", "Collections.binarySearch($qualifier$, $key$)", expression); } else { yield new TypeConversionDescriptor("Arrays.binarySearch($qualifier$, $key$, $comparator$)", "Collections.binarySearch($qualifier$, $key$, $comparator$)", expression); } } case "asList" -> { if (method.getParameterList().getParametersCount() == 1) { yield new TypeConversionDescriptor("Arrays.asList($qualifier$)", "$qualifier$", expression); } else { yield null; } } case "fill" -> new TypeConversionDescriptor("Arrays.fill($qualifier$, $filler$)", "Collections.fill($qualifier$, $filler$)", expression); default -> null; }; if (descriptor != null) { return from instanceof PsiClassType ? new TypeConversionDescriptor(descriptor.getReplaceByString(), descriptor.getStringToReplace(), descriptor.getExpression()) : descriptor; } } if (member instanceof PsiField && "length".equals(member.getName())) { return new TypeConversionDescriptor("$qualifier$.length", "$qualifier$.size()"); } final PsiElement parent = context.getParent(); if (parent instanceof PsiAssignmentExpression && ((PsiAssignmentExpression)parent).getLExpression() == context) { if (TypeConversionUtil.isAssignable(collectionType, arrayType.getComponentType())) { return new TypeConversionDescriptor("$qualifier$[$idx$] = $expr$", "$qualifier$.set($idx$, $expr$)", (PsiExpression)parent); } } else if (context instanceof PsiArrayAccessExpression && TypeConversionUtil.isAssignable(arrayType.getComponentType(), collectionType)) { return new TypeConversionDescriptor("$qualifier$[$idx$]", "$qualifier$.get($idx$)"); } return null; }