mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ReadOnly -> Unmodifiable; introduced UnmodifiableView distinguish between unmodifiable and unmodifiable view
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.ReadOnly;
|
||||
import org.jetbrains.annotations.Unmodifiable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -7,7 +7,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class MutabilityBasics {
|
||||
@ReadOnly
|
||||
@Unmodifiable
|
||||
static <T> List<T> emptyList() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -43,7 +43,7 @@ public class MutabilityBasics {
|
||||
}
|
||||
}
|
||||
|
||||
@ReadOnly
|
||||
@Unmodifiable
|
||||
static Point getZero() {
|
||||
return new Point() {
|
||||
@Override
|
||||
@@ -59,12 +59,12 @@ public class MutabilityBasics {
|
||||
}
|
||||
|
||||
// Differs from getZero as getZero() is considered as getter with predefined value
|
||||
@ReadOnly
|
||||
@Unmodifiable
|
||||
static Point zero() {
|
||||
return getZero();
|
||||
}
|
||||
|
||||
@ReadOnly List<String> list = Arrays.asList("foo", "bar", "baz");
|
||||
@Unmodifiable List<String> list = Arrays.asList("foo", "bar", "baz");
|
||||
|
||||
void test() {
|
||||
List<String> collection = emptyList();
|
||||
|
||||
@@ -59,4 +59,18 @@ public class MutabilityJdk {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void testNoFlush() {
|
||||
List<String> list1 = Collections.emptyList();
|
||||
List<String> list2 = new ArrayList<>();
|
||||
List<String> list3 = Collections.unmodifiableList(list2);
|
||||
if(<warning descr="Condition 'list1.isEmpty()' is always 'true'">list1.isEmpty()</warning>) System.out.println("ok");
|
||||
if(!list3.isEmpty()) return;
|
||||
if(<warning descr="Condition '!list3.isEmpty()' is always 'false'">!<warning descr="Condition 'list3.isEmpty()' is always 'true'">list3.isEmpty()</warning></warning>) return;
|
||||
list2.add("foo");
|
||||
// list1 size is not flushed (UNMODIFIABLE)
|
||||
if(<warning descr="Condition 'list1.isEmpty()' is always 'true'">list1.isEmpty()</warning>) System.out.println("ok");
|
||||
// list3 size is flushed (UNMODIFIABLE_VIEW)
|
||||
if(!list3.isEmpty()) return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user