[java-slice] See through unmodifiable list and friends (IDEA-194774)

GitOrigin-RevId: bd16ad8947c86e8d2b17cc230544ca66203c1d2d
This commit is contained in:
Tagir Valeev
2021-04-12 10:56:58 +00:00
committed by intellij-monorepo-bot
parent aa5d05cb34
commit a866093918
4 changed files with 85 additions and 1 deletions
@@ -174,12 +174,13 @@ final class SliceUtil {
}
}
}
if (method != null && builder.hasNesting()) {
if (method != null) {
PsiParameter[] parameters = method.getParameterList().getParameters();
boolean hasFlownParameter = false;
for (int i = 0; i < parameters.length; i++) {
Flow paramAnno = isParamFlowAnnotated(method, i);
if (paramAnno != null && !parameters[i].isVarArgs()) {
if (!builder.hasNesting() && !paramAnno.sourceIsContainer()) continue;
PsiExpression[] args = call.getArgumentList().getExpressions();
if (args.length > i) {
JavaSliceBuilder argBuilder = builder.updateNesting(paramAnno);
@@ -0,0 +1,11 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class MainTest {
public static void main(String[] args) {
List<String> list = <flown111>new ArrayList<>();
List<String> unmodifiable = <flown1>Collections.unmodifiableList(<flown11>list);
System.out.println(<caret>unmodifiable);
}
}
@@ -147,4 +147,5 @@ public class SliceBackwardTest extends SliceTestCase {
public void testRecordComponent2() throws Exception { doTest();}
public void testRecordComponent3() throws Exception { doTest();}
public void testOptionalAsContainer() throws Exception { doTest();}
public void testUnmodifiableList() throws Exception { doTest();}
}
@@ -2099,6 +2099,10 @@
</item>
<item name="java.util.Collections java.util.Collection&lt;E&gt; checkedCollection(java.util.Collection&lt;E&gt;, java.lang.Class&lt;E&gt;) 0">
<annotation name="org.jetbrains.annotations.NotNull" />
<annotation name='org.intellij.lang.annotations.Flow'>
<val name="sourceIsContainer" val="true"/>
<val name="targetIsContainer" val="true"/>
</annotation>
</item>
<item name="java.util.Collections java.util.Collection&lt;E&gt; checkedCollection(java.util.Collection&lt;E&gt;, java.lang.Class&lt;E&gt;) 1">
<annotation name="org.jetbrains.annotations.NotNull" />
@@ -2111,6 +2115,10 @@
</item>
<item name="java.util.Collections java.util.Collection&lt;T&gt; synchronizedCollection(java.util.Collection&lt;T&gt;) 0">
<annotation name="org.jetbrains.annotations.NotNull" />
<annotation name='org.intellij.lang.annotations.Flow'>
<val name="sourceIsContainer" val="true"/>
<val name="targetIsContainer" val="true"/>
</annotation>
</item>
<item name="java.util.Collections java.util.Collection&lt;T&gt; unmodifiableCollection(java.util.Collection&lt;? extends T&gt;)">
<annotation name="org.jetbrains.annotations.NotNull" />
@@ -2118,6 +2126,10 @@
</item>
<item name="java.util.Collections java.util.Collection&lt;T&gt; unmodifiableCollection(java.util.Collection&lt;? extends T&gt;) 0">
<annotation name="org.jetbrains.annotations.NotNull" />
<annotation name='org.intellij.lang.annotations.Flow'>
<val name="sourceIsContainer" val="true"/>
<val name="targetIsContainer" val="true"/>
</annotation>
</item>
<item name="java.util.Collections java.util.Comparator&lt;T&gt; reverseOrder()">
<annotation name="org.jetbrains.annotations.NotNull" />
@@ -2164,6 +2176,10 @@
</item>
<item name="java.util.Collections java.util.List&lt;E&gt; checkedList(java.util.List&lt;E&gt;, java.lang.Class&lt;E&gt;) 0">
<annotation name="org.jetbrains.annotations.NotNull" />
<annotation name='org.intellij.lang.annotations.Flow'>
<val name="sourceIsContainer" val="true"/>
<val name="targetIsContainer" val="true"/>
</annotation>
</item>
<item name="java.util.Collections java.util.List&lt;E&gt; checkedList(java.util.List&lt;E&gt;, java.lang.Class&lt;E&gt;) 1">
<annotation name="org.jetbrains.annotations.NotNull" />
@@ -2183,6 +2199,11 @@
<val name="pure" val="true"/>
</annotation>
</item>
<item name="java.util.Collections java.util.List&lt;T&gt; nCopies(int, T) 1">
<annotation name='org.intellij.lang.annotations.Flow'>
<val name="targetIsContainer" val="true"/>
</annotation>
</item>
<item name="java.util.Collections java.util.List&lt;T&gt; singletonList(T)">
<annotation name="org.jetbrains.annotations.NotNull" />
<annotation name="org.jetbrains.annotations.Unmodifiable" />
@@ -2191,6 +2212,11 @@
<val name="pure" val="true"/>
</annotation>
</item>
<item name="java.util.Collections java.util.List&lt;T&gt; singletonList(T) 0">
<annotation name='org.intellij.lang.annotations.Flow'>
<val name="targetIsContainer" val="true"/>
</annotation>
</item>
<item name='java.util.Collections java.util.List&lt;T&gt; synchronizedList(java.util.List&lt;T&gt;)'>
<annotation name='org.jetbrains.annotations.Contract'>
<val name="pure" val="true"/>
@@ -2199,6 +2225,10 @@
</item>
<item name="java.util.Collections java.util.List&lt;T&gt; synchronizedList(java.util.List&lt;T&gt;) 0">
<annotation name="org.jetbrains.annotations.NotNull" />
<annotation name='org.intellij.lang.annotations.Flow'>
<val name="sourceIsContainer" val="true"/>
<val name="targetIsContainer" val="true"/>
</annotation>
</item>
<item name="java.util.Collections java.util.List&lt;T&gt; unmodifiableList(java.util.List&lt;? extends T&gt;)">
<annotation name="org.jetbrains.annotations.NotNull" />
@@ -2206,6 +2236,10 @@
</item>
<item name="java.util.Collections java.util.List&lt;T&gt; unmodifiableList(java.util.List&lt;? extends T&gt;) 0">
<annotation name="org.jetbrains.annotations.NotNull" />
<annotation name='org.intellij.lang.annotations.Flow'>
<val name="sourceIsContainer" val="true"/>
<val name="targetIsContainer" val="true"/>
</annotation>
</item>
<item name="java.util.Collections java.util.ListIterator&lt;T&gt; emptyListIterator()">
<annotation name="org.jetbrains.annotations.NotNull" />
@@ -2303,6 +2337,10 @@
</item>
<item name="java.util.Collections java.util.Queue&lt;E&gt; checkedQueue(java.util.Queue&lt;E&gt;, java.lang.Class&lt;E&gt;) 0">
<annotation name="org.jetbrains.annotations.NotNull" />
<annotation name='org.intellij.lang.annotations.Flow'>
<val name="sourceIsContainer" val="true"/>
<val name="targetIsContainer" val="true"/>
</annotation>
</item>
<item name="java.util.Collections java.util.Queue&lt;E&gt; checkedQueue(java.util.Queue&lt;E&gt;, java.lang.Class&lt;E&gt;) 1">
<annotation name="org.jetbrains.annotations.NotNull" />
@@ -2315,6 +2353,10 @@
</item>
<item name="java.util.Collections java.util.Queue&lt;T&gt; asLifoQueue(java.util.Deque&lt;T&gt;) 0">
<annotation name="org.jetbrains.annotations.NotNull" />
<annotation name='org.intellij.lang.annotations.Flow'>
<val name="sourceIsContainer" val="true"/>
<val name="targetIsContainer" val="true"/>
</annotation>
</item>
<item name='java.util.Collections java.util.Set&lt;E&gt; checkedSet(java.util.Set&lt;E&gt;, java.lang.Class&lt;E&gt;)'>
<annotation name='org.jetbrains.annotations.Contract'>
@@ -2324,6 +2366,10 @@
</item>
<item name="java.util.Collections java.util.Set&lt;E&gt; checkedSet(java.util.Set&lt;E&gt;, java.lang.Class&lt;E&gt;) 0">
<annotation name="org.jetbrains.annotations.NotNull" />
<annotation name='org.intellij.lang.annotations.Flow'>
<val name="sourceIsContainer" val="true"/>
<val name="targetIsContainer" val="true"/>
</annotation>
</item>
<item name="java.util.Collections java.util.Set&lt;E&gt; checkedSet(java.util.Set&lt;E&gt;, java.lang.Class&lt;E&gt;) 1">
<annotation name="org.jetbrains.annotations.NotNull" />
@@ -2352,6 +2398,11 @@
<val name="pure" val="true"/>
</annotation>
</item>
<item name="java.util.Collections java.util.Set&lt;T&gt; singleton(T) 0">
<annotation name='org.intellij.lang.annotations.Flow'>
<val name="targetIsContainer" val="true"/>
</annotation>
</item>
<item name='java.util.Collections java.util.Set&lt;T&gt; synchronizedSet(java.util.Set&lt;T&gt;)'>
<annotation name='org.jetbrains.annotations.Contract'>
<val name="pure" val="true"/>
@@ -2360,6 +2411,10 @@
</item>
<item name="java.util.Collections java.util.Set&lt;T&gt; synchronizedSet(java.util.Set&lt;T&gt;) 0">
<annotation name="org.jetbrains.annotations.NotNull" />
<annotation name='org.intellij.lang.annotations.Flow'>
<val name="sourceIsContainer" val="true"/>
<val name="targetIsContainer" val="true"/>
</annotation>
</item>
<item name="java.util.Collections java.util.Set&lt;T&gt; unmodifiableSet(java.util.Set&lt;? extends T&gt;)">
<annotation name="org.jetbrains.annotations.NotNull" />
@@ -2367,6 +2422,10 @@
</item>
<item name="java.util.Collections java.util.Set&lt;T&gt; unmodifiableSet(java.util.Set&lt;? extends T&gt;) 0">
<annotation name="org.jetbrains.annotations.NotNull" />
<annotation name='org.intellij.lang.annotations.Flow'>
<val name="sourceIsContainer" val="true"/>
<val name="targetIsContainer" val="true"/>
</annotation>
</item>
<item name='java.util.Collections java.util.SortedMap&lt;K,V&gt; checkedSortedMap(java.util.SortedMap&lt;K,V&gt;, java.lang.Class&lt;K&gt;, java.lang.Class&lt;V&gt;)'>
<annotation name='org.jetbrains.annotations.Contract'>
@@ -2413,6 +2472,10 @@
</item>
<item name="java.util.Collections java.util.SortedSet&lt;E&gt; checkedSortedSet(java.util.SortedSet&lt;E&gt;, java.lang.Class&lt;E&gt;) 0">
<annotation name="org.jetbrains.annotations.NotNull" />
<annotation name='org.intellij.lang.annotations.Flow'>
<val name="sourceIsContainer" val="true"/>
<val name="targetIsContainer" val="true"/>
</annotation>
</item>
<item name="java.util.Collections java.util.SortedSet&lt;E&gt; checkedSortedSet(java.util.SortedSet&lt;E&gt;, java.lang.Class&lt;E&gt;) 1">
<annotation name="org.jetbrains.annotations.NotNull" />
@@ -2432,6 +2495,10 @@
</item>
<item name="java.util.Collections java.util.SortedSet&lt;T&gt; synchronizedSortedSet(java.util.SortedSet&lt;T&gt;) 0">
<annotation name="org.jetbrains.annotations.NotNull" />
<annotation name='org.intellij.lang.annotations.Flow'>
<val name="sourceIsContainer" val="true"/>
<val name="targetIsContainer" val="true"/>
</annotation>
</item>
<item name="java.util.Collections java.util.SortedSet&lt;T&gt; unmodifiableSortedSet(java.util.SortedSet&lt;T&gt;)">
<annotation name="org.jetbrains.annotations.NotNull" />
@@ -2439,6 +2506,10 @@
</item>
<item name="java.util.Collections java.util.SortedSet&lt;T&gt; unmodifiableSortedSet(java.util.SortedSet&lt;T&gt;) 0">
<annotation name="org.jetbrains.annotations.NotNull" />
<annotation name='org.intellij.lang.annotations.Flow'>
<val name="sourceIsContainer" val="true"/>
<val name="targetIsContainer" val="true"/>
</annotation>
</item>
<item name='java.util.Collections void copy(java.util.List&lt;? super T&gt;, java.util.List&lt;? extends T&gt;)'>
<annotation name='org.jetbrains.annotations.Contract'>