String (@NotNull PsiParameterListOwner method, @NotNull PsiVariable variable, @Nullable PsiType type, boolean preciseTypeRequired) { PsiType varType = variable.getType(); if (!(type instanceof PsiArrayType arrayType)) return null; PsiType arrayComponentType = arrayType.getComponentType(); if (!(arrayComponentType instanceof PsiPrimitiveType) && !(PsiUtil.resolveClassInType(arrayComponentType) instanceof PsiTypeParameter) && InheritanceUtil.isInheritor(varType, CommonClassNames.JAVA_UTIL_COLLECTION)) { PsiType erasedComponentType = TypeConversionUtil.erasure(arrayComponentType); if (!preciseTypeRequired || arrayComponentType.equals(erasedComponentType)) { PsiType collectionItemType = JavaGenericsUtil.getCollectionItemType(varType, method.getResolveScope()); if (collectionItemType != null && erasedComponentType.isAssignableFrom(collectionItemType)) { if (erasedComponentType.equalsToText(CommonClassNames.JAVA_LANG_OBJECT)) { return variable.getName() + ".toArray()"; } return variable.getName() + ".toArray(new " + erasedComponentType.getCanonicalText() + "[0])"; } } } return null; }