PsiArrayType (PsiMethodCallExpression call) { PsiType type = call.getType(); if (!(type instanceof PsiArrayType candidate)) return null; PsiExpression[] args = call.getArgumentList().getExpressions(); if (args.length == 0) return candidate; if (args.length != 1) return null; PsiExpression supplier = skipParenthesizedExprDown(args[0]); if (supplier instanceof PsiMethodReferenceExpression methodRef) { // like toArray(String[]::new) PsiTypeElement qualifierType = methodRef.getQualifierType(); if (methodRef.isConstructor() && qualifierType != null && candidate.isAssignableFrom(qualifierType.getType())) { return candidate; } } else if (supplier instanceof PsiLambdaExpression lambda) { // like toArray(size -> new String[size]) PsiParameter[] parameters = lambda.getParameterList().getParameters(); if (parameters.length != 1) return null; PsiParameter sizeParameter = parameters[0]; PsiExpression body = LambdaUtil.extractSingleExpressionFromBody(lambda.getBody()); if (body instanceof PsiNewExpression newExpression) { PsiExpression[] dimensions = newExpression.getArrayDimensions(); PsiType newExpressionType = newExpression.getType(); if (dimensions.length != 0 && ExpressionUtils.isReferenceTo(dimensions[0], sizeParameter) && newExpressionType != null && candidate.isAssignableFrom(newExpressionType)) { return candidate; } } } return null; }