mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
dfa: consider methods in @Immutable classes referentially transparent (IDEA-167658)
This commit is contained in:
+4
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.codeInspection.dataFlow.value;
|
||||
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
import com.intellij.codeInspection.dataFlow.DfaPsiUtil;
|
||||
import com.intellij.codeInspection.dataFlow.Nullness;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -173,6 +174,9 @@ public class DfaExpressionFactory {
|
||||
return method;
|
||||
}
|
||||
}
|
||||
if (AnnotationUtil.findAnnotation(method.getContainingClass(), "javax.annotation.concurrent.Immutable") != null) {
|
||||
return method;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
@javax.annotation.concurrent.Immutable
|
||||
interface Intf {
|
||||
@org.jetbrains.annotations.Nullable String foo();
|
||||
}
|
||||
|
||||
class Usage {
|
||||
void bar(Intf i) {
|
||||
if (i.foo() != null) {
|
||||
System.out.println(i.foo().length());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -260,6 +260,11 @@ public class DataFlowInspectionTest extends DataFlowInspectionTestCase {
|
||||
public void testFinalGetter() { doTest(); }
|
||||
public void testGetterResultsNotSame() { doTest(); }
|
||||
|
||||
public void testImmutableClassNonGetterMethod() {
|
||||
myFixture.addClass("package javax.annotation.concurrent; public @interface Immutable {}");
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testByteBufferGetter() {
|
||||
myFixture.addClass("package java.nio; public class MappedByteBuffer { public int getInt() {} }");
|
||||
doTest();
|
||||
|
||||
Reference in New Issue
Block a user