String (CommentTracker ct, PsiExpression initializer, PsiType type, boolean strictMode) { String collector; PsiType initializerType = initializer.getType(); PsiClassType rawType = initializerType instanceof PsiClassType ? ((PsiClassType)initializerType).rawType() : null; PsiClassType rawVarType = type instanceof PsiClassType ? ((PsiClassType)type).rawType() : null; if (!strictMode && rawType != null && rawVarType != null && rawType.equalsToText(JAVA_UTIL_ARRAY_LIST) && (rawVarType.equalsToText(JAVA_UTIL_LIST) || rawVarType.equalsToText(JAVA_UTIL_COLLECTION)) && !ConstructionUtils.isCustomizedEmptyCollectionInitializer(initializer)) { collector = "toList()"; } else if (!strictMode && rawType != null && rawVarType != null && rawType.equalsToText(JAVA_UTIL_HASH_SET) && (rawVarType.equalsToText(JAVA_UTIL_SET) || rawVarType.equalsToText(JAVA_UTIL_COLLECTION)) && !ConstructionUtils.isCustomizedEmptyCollectionInitializer(initializer)) { collector = "toSet()"; } else { PsiExpression copy = JavaPsiFacade.getElementFactory(initializer.getProject()) .createExpressionFromText(ct.text(initializer), initializer); if (copy instanceof PsiCallExpression && ConstructionUtils.isPrepopulatedCollectionInitializer(copy)) { PsiExpressionList argumentList = ((PsiCallExpression)copy).getArgumentList(); if (argumentList != null) { PsiExpression arg = ArrayUtil.getFirstElement(argumentList.getExpressions()); if (arg != null && !(arg.getType() instanceof PsiPrimitiveType)) { arg.delete(); } } } collector = "toCollection(() -> " + copy.getText() + ")"; } return JAVA_UTIL_STREAM_COLLECTORS + "." + collector; }