Java: Don't offer the quick-fix Collection.toArray() for type parameter arrays (like T[]) (IDEA-163341)

This commit is contained in:
Pavel Dolgov
2017-01-13 12:22:32 +03:00
parent 5e888e75a7
commit 83b5637a43
3 changed files with 21 additions and 0 deletions
@@ -651,6 +651,7 @@ public class HighlightUtil extends HighlightUtilBase {
if (toType instanceof PsiArrayType) {
PsiType arrayComponentType = ((PsiArrayType)toType).getComponentType();
if (!(arrayComponentType instanceof PsiPrimitiveType) &&
!(PsiUtil.resolveClassInType(arrayComponentType) instanceof PsiTypeParameter) &&
InheritanceUtil.isInheritor(fromType, CommonClassNames.JAVA_UTIL_COLLECTION)) {
PsiType collectionItemType = JavaGenericsUtil.getCollectionItemType(fromType, expression.getResolveScope());
if (collectionItemType != null && arrayComponentType.isAssignableFrom(collectionItemType)) {
@@ -0,0 +1,10 @@
// "Apply conversion '.toArray(new T[0])'" "false"
import java.util.*;
class TypeVar<T> {
T[] foo() {
Set<T> set = new HashSet<>();
T[] arr = <caret>set;
return arr;
}
}
@@ -0,0 +1,10 @@
// "Apply conversion '.toArray(new T[0][])'" "false"
import java.util.*;
class TypeVarArray<T> {
T[][] foo() {
Set<T[]> set = new HashSet<>();
T[][] arr = <caret>set;
return arr;
}
}