mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
Java: When generating return statement where the returned type is a primitive array don't suggest Collection.toArray() (IDEA-163341)
This commit is contained in:
@@ -97,11 +97,12 @@ public class AddReturnFix implements IntentionAction {
|
||||
|
||||
private String getConversionToType(@NotNull PsiVariable variable, @Nullable PsiType type) {
|
||||
PsiType varType = variable.getType();
|
||||
if (type instanceof PsiArrayType && InheritanceUtil.isInheritor(varType, CommonClassNames.JAVA_UTIL_COLLECTION)) {
|
||||
PsiType collectionItemType = JavaGenericsUtil.getCollectionItemType(varType, myMethod.getResolveScope());
|
||||
if (collectionItemType != null) {
|
||||
PsiType arrayComponentType = ((PsiArrayType)type).getComponentType();
|
||||
if (arrayComponentType.isAssignableFrom(collectionItemType)) {
|
||||
if (type instanceof PsiArrayType) {
|
||||
PsiType arrayComponentType = ((PsiArrayType)type).getComponentType();
|
||||
if (!(arrayComponentType instanceof PsiPrimitiveType) &&
|
||||
InheritanceUtil.isInheritor(varType, CommonClassNames.JAVA_UTIL_COLLECTION)) {
|
||||
PsiType collectionItemType = JavaGenericsUtil.getCollectionItemType(varType, myMethod.getResolveScope());
|
||||
if (collectionItemType != null && arrayComponentType.isAssignableFrom(collectionItemType)) {
|
||||
if (arrayComponentType.equalsToText(CommonClassNames.JAVA_LANG_OBJECT)) {
|
||||
return variable.getName() + ".toArray()";
|
||||
}
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Add 'return' statement" "true"
|
||||
import java.util.*;
|
||||
class T {
|
||||
String[] f() {
|
||||
List<String> list = Arrays.asList("a", "b");
|
||||
String[] arr = {"c", "d"};
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Add 'return' statement" "true"
|
||||
import java.util.*;
|
||||
class T {
|
||||
int[] f() {
|
||||
Set<Integer> set = new HashSet<>();
|
||||
set.add(42);
|
||||
return new int[0];
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Add 'return' statement" "true"
|
||||
import java.util.*;
|
||||
class T {
|
||||
String[] f() {
|
||||
List<String> list = Arrays.asList("a", "b");
|
||||
String[] arr = {"c", "d"};
|
||||
<caret>}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Add 'return' statement" "true"
|
||||
import java.util.*;
|
||||
class T {
|
||||
int[] f() {
|
||||
Set<Integer> set = new HashSet<>();
|
||||
set.add(42);
|
||||
<caret>}
|
||||
}
|
||||
Reference in New Issue
Block a user