mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
RedundantCollectionOperationInspection: fix redundant asList type
This commit is contained in:
+17
@@ -0,0 +1,17 @@
|
||||
// "Unwrap" "true"
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
class Foo {
|
||||
interface Parent1 {}
|
||||
interface Parent2 {}
|
||||
interface Child1 extends Parent1, Parent2 {}
|
||||
interface Child2 extends Parent1, Parent2 {}
|
||||
|
||||
void bar(boolean flag, Child1[] arr1, Child2[] arr2) {
|
||||
Parent2[] list = flag ? arr1 : arr2;
|
||||
for (Parent2 parent2 : list) {
|
||||
System.out.println(parent2);
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Unwrap" "true"
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
class Foo {
|
||||
interface Parent1 {}
|
||||
interface Parent2 {}
|
||||
interface Child1 extends Parent1, Parent2 {}
|
||||
interface Child2 extends Parent1, Parent2 {}
|
||||
|
||||
void bar(boolean flag, Child1[] arr1, Child2[] arr2) {
|
||||
List<? extends Parent2> list = Arrays.a<caret>sList(flag ? arr1 : arr2);
|
||||
for (Parent2 parent2 : list) {
|
||||
System.out.println(parent2);
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-6
@@ -413,14 +413,17 @@ public class RedundantCollectionOperationInspection extends AbstractBaseJavaLoca
|
||||
if (parent instanceof PsiLocalVariable) {
|
||||
PsiTypeElement typeElement = ((PsiLocalVariable)parent).getTypeElement();
|
||||
if (!typeElement.isInferredType()) {
|
||||
PsiType type = args[0].getType();
|
||||
if (type == null) return;
|
||||
if(type instanceof PsiEllipsisType) {
|
||||
type = ((PsiEllipsisType)type).toArrayType();
|
||||
PsiType varType = ((PsiLocalVariable)parent).getType();
|
||||
PsiType elementType = PsiUtil.substituteTypeParameter(varType, CommonClassNames.JAVA_LANG_ITERABLE, 0, false);
|
||||
if (elementType == null) {
|
||||
PsiType type = args[0].getType();
|
||||
if (!(type instanceof PsiArrayType)) return;
|
||||
elementType = ((PsiArrayType)type).getComponentType();
|
||||
}
|
||||
if (!typeElement.isInferredType()) {
|
||||
typeElement.replace(JavaPsiFacade.getElementFactory(project).createTypeElement(type));
|
||||
if (elementType instanceof PsiWildcardType) {
|
||||
elementType = ((PsiWildcardType)elementType).getExtendsBound();
|
||||
}
|
||||
typeElement.replace(JavaPsiFacade.getElementFactory(project).createTypeElement(elementType.createArrayType()));
|
||||
}
|
||||
}
|
||||
ct.replaceAndRestoreComments(call, ct.markUnchanged(args[0]));
|
||||
|
||||
Reference in New Issue
Block a user