mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-07 22:09:38 +07:00
[java-dfa] Simplify Mutability computation using external annotations
GitOrigin-RevId: 6570f36a8fa94ca14f4341875b5b980c7124641a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
9d683df66a
commit
73943d0839
@@ -10,7 +10,6 @@ import com.intellij.java.analysis.JavaAnalysisBundle;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.ModificationTracker;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.light.LightElement;
|
||||
import com.intellij.psi.impl.source.PsiMethodImpl;
|
||||
@@ -20,7 +19,6 @@ import com.intellij.psi.util.CachedValuesManager;
|
||||
import com.intellij.psi.util.PsiModificationTracker;
|
||||
import com.intellij.testFramework.LightVirtualFile;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.siyeh.ig.callMatcher.CallMatcher;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import one.util.streamex.StreamEx;
|
||||
@@ -72,12 +70,6 @@ public enum Mutability {
|
||||
|
||||
public static final @NotNull String UNMODIFIABLE_ANNOTATION = UNMODIFIABLE.myAnnotation;
|
||||
public static final @NotNull String UNMODIFIABLE_VIEW_ANNOTATION = UNMODIFIABLE_VIEW.myAnnotation;
|
||||
private static final @NotNull CallMatcher STREAM_COLLECT = CallMatcher.instanceCall(
|
||||
CommonClassNames.JAVA_UTIL_STREAM_STREAM, "collect").parameterTypes("java.util.stream.Collector");
|
||||
private static final @NotNull CallMatcher STREAM_TO_LIST = CallMatcher.instanceCall(
|
||||
CommonClassNames.JAVA_UTIL_STREAM_STREAM, "toList").withLanguageLevelAtLeast(LanguageLevel.JDK_16);
|
||||
private static final @NotNull CallMatcher UNMODIFIABLE_COLLECTORS = CallMatcher.staticCall(
|
||||
CommonClassNames.JAVA_UTIL_STREAM_COLLECTORS, "toUnmodifiableList", "toUnmodifiableSet", "toUnmodifiableMap");
|
||||
private final @PropertyKey(resourceBundle = JavaAnalysisBundle.BUNDLE) String myResourceKey;
|
||||
private final String myAnnotation;
|
||||
private final Key<CachedValue<PsiAnnotation>> myKey;
|
||||
@@ -199,18 +191,12 @@ public enum Mutability {
|
||||
Mutability mutability = UNMODIFIABLE;
|
||||
for (PsiExpression initializer : expressions) {
|
||||
Mutability newMutability = UNKNOWN;
|
||||
if (ClassUtils.isImmutable(initializer.getType())) {
|
||||
PsiType type = initializer.getType();
|
||||
if (ClassUtils.isImmutable(type) || (type != null && type.hasAnnotation(UNMODIFIABLE_ANNOTATION))) {
|
||||
newMutability = UNMODIFIABLE;
|
||||
} else if (initializer instanceof PsiMethodCallExpression call) {
|
||||
if (STREAM_COLLECT.test(call)) {
|
||||
PsiExpression collector = call.getArgumentList().getExpressions()[0];
|
||||
newMutability = UNMODIFIABLE_COLLECTORS.matches(collector) ? UNMODIFIABLE : UNKNOWN;
|
||||
} else if (STREAM_TO_LIST.test(call)) {
|
||||
newMutability = UNMODIFIABLE;
|
||||
} else {
|
||||
PsiMethod method = call.resolveMethod();
|
||||
newMutability = method == null ? UNKNOWN : getMutability(method);
|
||||
}
|
||||
PsiMethod method = call.resolveMethod();
|
||||
newMutability = method == null ? UNKNOWN : getMutability(method);
|
||||
}
|
||||
mutability = mutability.join(newMutability);
|
||||
if (!mutability.isUnmodifiable()) break;
|
||||
|
||||
Reference in New Issue
Block a user