mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
Java: When generating return statement where the returned type is a type parameter array (like T[]) don't suggest Collection.toArray() (IDEA-163341)
This commit is contained in:
@@ -23,6 +23,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiTypesUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -100,6 +101,7 @@ public class AddReturnFix implements IntentionAction {
|
||||
if (type instanceof PsiArrayType) {
|
||||
PsiType arrayComponentType = ((PsiArrayType)type).getComponentType();
|
||||
if (!(arrayComponentType instanceof PsiPrimitiveType) &&
|
||||
!(PsiUtil.resolveClassInType(arrayComponentType) instanceof PsiTypeParameter) &&
|
||||
InheritanceUtil.isInheritor(varType, CommonClassNames.JAVA_UTIL_COLLECTION)) {
|
||||
PsiType collectionItemType = JavaGenericsUtil.getCollectionItemType(varType, myMethod.getResolveScope());
|
||||
if (collectionItemType != null && arrayComponentType.isAssignableFrom(collectionItemType)) {
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Add 'return' statement" "true"
|
||||
import java.util.*;
|
||||
class A<T> {
|
||||
T[] f() {
|
||||
Set<T> set = new HashSet<>();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Add 'return' statement" "true"
|
||||
import java.util.*;
|
||||
class A<T> {
|
||||
T[] f() {
|
||||
Set<T> set = new HashSet<>();
|
||||
<caret>}
|
||||
}
|
||||
Reference in New Issue
Block a user