1/*
2 * Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/*
25 * @test
26 * @bug 4098316 4522720
27 * @summary Test chained assignments using access methods.
28 * @author William Maddox (maddox)
29 *
30 * @compile ChainedAssignment.java
31 * @run main ChainedAssignment
32 */
33
34public class ChainedAssignment {
35
36    private int a = 0;
37    private int b = 0;
38    private int c = 0;
39
40    static private int sa = 0;
41    static private int sb = 0;
42    static private int sc = 0;
43
44    private class Inner {
45
46        void test1() throws Exception {
47            (a) = (b) = 1;
48            if (a != 1 || b != 1) {
49                throw new Exception("FAILED (11)");
50            }
51            System.out.println(a + " " + b + " " + c);
52            a = b = c;
53            if (a != 0 || b != 0) {
54                throw new Exception("FAILED (12)");
55            }
56            System.out.println(a + " " + b + " " + c);
57            a = (b) += 5;
58            if (a != 5 || b != 5) {
59                throw new Exception("FAILED (13)");
60            }
61            System.out.println(a + " " + b + " " + c);
62        }
63
64        void test2() throws Exception {
65            sa = sb = 1;
66            if (sa != 1 || sb != 1) {
67                throw new Exception("FAILED (21)");
68            }
69            System.out.println(sa + " " + sb + " " + sc);
70            sa = sb = sc;
71            if (sa != 0 || sb != 0) {
72                throw new Exception("FAILED (22)");
73            }
74            System.out.println(sa + " " + sb + " " + sc);
75            sa = sb += 5;
76            if (sa != 5 || sb != 5) {
77                throw new Exception("FAILED (23)");
78            }
79            System.out.println(sa + " " + sb + " " + sc);
80        }
81
82    }
83
84    public static void main(String[] args) throws Exception {
85        ChainedAssignment outer = new ChainedAssignment();
86        Inner inner = outer.new Inner();
87        inner.test1();
88        inner.test2();
89    }
90
91}
92