File: GenericsBoundsRange.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 (37 lines) | stat: -rw-r--r-- 1,280 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
28
29
30
31
32
33
34
35
36
37
package regex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.checkerframework.checker.regex.qual.Regex;

/** Designed to test whether or not a bounds range of generics actually works. */
public class GenericsBoundsRange<@Regex(3) T extends @Regex(1) String> {
    public T t;

    public GenericsBoundsRange(T t) {
        Matcher matcher = Pattern.compile(t).matcher("some str");
        if (matcher.matches()) {
            matcher.group(0);
            matcher.group(1);

            // T has at least 1 group so the above 2 group calls are good
            // however, T MAY or MAY NOT have 2 or 3 groups, so issue an error

            // :: error: (group.count.invalid)
            matcher.group(2);

            // :: error: (group.count.invalid)
            matcher.group(3);

            // T definitely does not have 4 groups, issue an error

            // :: error: (group.count.invalid)
            matcher.group(4);
        }
    }

    // Bounds used to not actually be bounds but instead exactly the lower bound
    // so line below would fail because the argument could only be Regex(0).  So this
    // tests BaseTypeValidator.checkTypeArguments range checking
    public void method(GenericsBoundsRange<@Regex(2) String> gbr) {}
}