mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
AssignmentOrReturnOfFieldWithMutableType: Guava test & field type check (IDEA-191042)
This commit is contained in:
+3
-1
@@ -145,7 +145,9 @@ public class AssignmentOrReturnOfFieldWithMutableTypeInspection extends BaseInsp
|
||||
if (field == null) return;
|
||||
final String type = TypeUtils.expressionHasTypeOrSubtype(returnValue, MUTABLE_TYPES);
|
||||
if (type == null && !(returnValue.getType() instanceof PsiArrayType)) return;
|
||||
if (CollectionUtils.isConstantEmptyArray(field) || Mutability.getMutability(field).isUnmodifiable()) return;
|
||||
if (CollectionUtils.isConstantEmptyArray(field) ||
|
||||
ClassUtils.isImmutable(field.getType()) ||
|
||||
Mutability.getMutability(field).isUnmodifiable()) return;
|
||||
registerError(returnValue, field, returnValue, type, Boolean.FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -1,6 +1,7 @@
|
||||
package com.siyeh.igtest.encapsulation;
|
||||
|
||||
import java.util.*;
|
||||
import com.google.common.collect.*;
|
||||
|
||||
public class AssignmentOrReturnOfFieldWithMutableType
|
||||
{
|
||||
@@ -151,4 +152,12 @@ class ImmutableTest {
|
||||
public List<String> getList() {
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
class GuavaTest {
|
||||
private final ImmutableList<?> list = ImmutableList.of();
|
||||
|
||||
public ImmutableList<?> getList() {
|
||||
return list;
|
||||
}
|
||||
}
|
||||
+13
@@ -22,6 +22,19 @@ public class AssignmentOrReturnOfFieldWithMutableTypeInspectionTest extends Ligh
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected String[] getEnvironmentClasses() {
|
||||
return new String[] {
|
||||
"package com.google.common.collect;\n" +
|
||||
"\n" +
|
||||
"import java.util.List;\n" +
|
||||
"\n" +
|
||||
"public class ImmutableList<E> implements List<E> {\n" +
|
||||
" public static ImmutableList<?> of() {return new ImmutableList<>();}\n" +
|
||||
"}"
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
|
||||
Reference in New Issue
Block a user