summaryrefslogtreecommitdiffstats
path: root/tests/new/AroundDoubleAssignmentC.java
blob: f1b13d63086123ed50c7860da44e159d192597e5 (plain)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import org.aspectj.testing.*;

/**
 * with -usejavac: cannot resolve symbol
 * without -usejavac: VerifyError
 */
public aspect AroundDoubleAssignmentC {
    public static void main( String[] args ){
        //---------- passing tests
        // field init
        Tester.expectEvent("proceed-fieldinit");
        new FieldInit();
        
        // field set
        Tester.expectEvent("fieldset");
        Tester.expectEvent("proceed-fieldset");
        new FieldSet().test();


        //---------- failing tests
        // static method, field set
        Tester.expectEvent("staticfieldset-test");
        Tester.expectEvent("proceed-staticset");
        StaticSet.staticTest();

        // static initializer
        Tester.expectEvent("staticinit");
        Tester.expectEvent("proceed-staticinit");
        Class c2 = StaticInit.class.getClass();
        Tester.check("test".equals(StaticInit.string),
                           "\"test\".equals(StaticInit.string)");

        // instance initializer
        Tester.expectEvent("init");
        Tester.expectEvent("proceed-init");
        String s = new Init().string;
        Tester.check("test".equals(s),
                           "\"test\".equals(new Init().string)");
        Tester.checkAllEvents();
    } // main

    Object around() : within(FieldInit) && execution( * *() ) {
        Tester.event("proceed-fieldinit");
        return proceed();
    }

    Object around() : execution( * FieldSet.*() ) {
        Tester.event("proceed-fieldset");
        return proceed();
    }

    // static method
    Object around() : execution( * StaticSet.*() ) {
        Tester.event("proceed-staticset");
        return proceed();
    }

    // static initializer
    Object around() : staticinitialization(StaticInit) {
        Tester.event("proceed-staticinit");
        return proceed();
    }

    // instance initializer
    Object around() : initialization(Init.new(..)) {
        Tester.event("proceed-init");
        return proceed();
    }
}

class FieldInit {
    /** @testcase PR#687 around all execution with double assignment in initializer (fieldinit) */
    String s = s = getString();
    String getString() { return "test".toString(); }
}

class FieldSet {

    /** @testcase PR#687 around all execution with double assignment in initializer (fieldset) */
    String s;
    public void test(){
        s = s = "test"; // not initializer, so...
        Tester.event("fieldset");
    }
}

class StaticSet {
    /** @testcase PR#687 around all execution with double assignment in initializer (staticfieldset) */
    static String string;
    public static void staticTest(){
        String s = s = "test";
        string = s;
        Tester.event("staticfieldset-" + string);
    }
}

/** @testcase PR#687 around all execution with double assignment in initializer (staticinitialization) */
class StaticInit {
    static String string;
    static {
        String s = s = getString();
        Tester.event("staticinit");
        string = s;
    }
    static String getString() { return "test"; }
}

/** @testcase PR#687 around all execution with double assignment in initializer (instance initialization) */
class Init {
    String string;
    Init() {
        String s = s = "test";
        Tester.event("init");
        string = s;
    }
}