Debian Codegraph @

checker/tests/nullness/generics/KeyForPolyKeyFor.java

raw
1 package nullness.generics;
2
3 import java.util.HashMap;
4 import java.util.Map;
5 import java.util.Set;
6 import org.checkerframework.checker.nullness.qual.*;
7
8 // test related to issue 429: https://github.com/typetools/checker-framework/issues/429
9 class KeyForPolyKeyFor {
10 // TODO: Figure out why diamond operator does not work:
11 // Map<@KeyFor("dict") String, String> dict = new HashMap<>();
12 Map<@KeyFor("dict") String, String> dict = new HashMap<@KeyFor("dict") String, String>();
13
14 void m() {
15 Set<@KeyFor("dict") String> s = nounSubset(dict.keySet());
16
17 for (@KeyFor("dict") String noun : nounSubset(dict.keySet())) {}
18 }
19
20 // This method's declaration uses no @KeyFor annotations
21 // because in addition to being used by the dictionary feature,
22 // it is also used by a spell checker that only stores sets of words
23 // and does not use the notions of dictionaries, maps or keys.
24 Set<@PolyKeyFor String> nounSubset(Set<@PolyKeyFor String> words) {
25 return words;
26 }
27 }