File: KeyForPolyKeyFor.java

package info (click to toggle)
checker-framework-java 3.2.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 22,840 kB
  • sloc: java: 145,910; xml: 839; sh: 518; makefile: 401; perl: 26
file content (27 lines) | stat: -rw-r--r-- 1,021 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package nullness.generics;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.checkerframework.checker.nullness.qual.*;

// test related to issue 429: https://github.com/typetools/checker-framework/issues/429
class KeyForPolyKeyFor {
    // TODO: Figure out why diamond operator does not work:
    // Map<@KeyFor("dict") String, String> dict = new HashMap<>();
    Map<@KeyFor("dict") String, String> dict = new HashMap<@KeyFor("dict") String, String>();

    void m() {
        Set<@KeyFor("dict") String> s = nounSubset(dict.keySet());

        for (@KeyFor("dict") String noun : nounSubset(dict.keySet())) {}
    }

    // This method's declaration uses no @KeyFor annotations
    // because in addition to being used by the dictionary feature,
    // it is also used by a spell checker that only stores sets of words
    // and does not use the notions of dictionaries, maps or keys.
    Set<@PolyKeyFor String> nounSubset(Set<@PolyKeyFor String> words) {
        return words;
    }
}