File: TwrVarKinds.java

package info (click to toggle)
libnb-javaparser-java 9%2B2018-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 65,320 kB
  • sloc: java: 440,096; xml: 6,359; sh: 865; makefile: 314
file content (81 lines) | stat: -rw-r--r-- 1,948 bytes parent folder | download | duplicates (9)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
 * @test /nodynamiccopyright/
 * @bug 7196163
 * @summary Twr with different kinds of variables: local, instance, class, array component, parameter
 * @compile/fail/ref=TwrVarKinds.out -XDrawDiagnostics TwrVarKinds.java
 */

public class TwrVarKinds implements AutoCloseable {

    final static TwrVarKinds r1 = new TwrVarKinds();
    final TwrVarKinds r2 = new TwrVarKinds();
    static TwrVarKinds r3 = new TwrVarKinds();
    TwrVarKinds r4 = new TwrVarKinds();

    public static void main(String... args) {

        TwrVarKinds r5 = new TwrVarKinds();

        /* static final field - ok */
        try (r1) {
        }

        /* non-static final field - ok */
        try (r1.r2) {
        }

        /* static non-final field - wrong */
        try (r3) {
            fail("Static non-final field is not allowed");
        }

        /* non-static non-final field - wrong */
        try (r1.r4) {
            fail("Non-static non-final field is not allowed");
        }

        /* local variable - covered by TwrForVariable1 test */

        /* array components - covered by TwrForVariable2 test */

        /* method parameter - ok */
        method(r5);

        /* constructor parameter - ok */
        TwrVarKinds r6 = new TwrVarKinds(r5);

        /* lambda parameter - covered by TwrAndLambda */

        /* exception parameter - ok */
        try {
            throw new ResourceException();
        } catch (ResourceException e) {
            try (e) {
            }
        }
    }

    public TwrVarKinds() {
    }

    public TwrVarKinds(TwrVarKinds r) {
        try (r) {
        }
    }

    static void method(TwrVarKinds r) {
        /* parameter */
        try (r) {
        }
    }

    static void fail(String reason) {
        throw new RuntimeException(reason);
    }

    public void close() {}

    static class ResourceException extends Exception implements AutoCloseable {
        public void close() {}
    }
}