test/tools/javac/AccessMethods/ChainedAssignment.java

Wed, 27 May 2009 22:34:43 -0700

author
darcy
date
Wed, 27 May 2009 22:34:43 -0700
changeset 289
84061bd68019
parent 1
9a66ca7c79fa
child 554
9d9f26857129
permissions
-rw-r--r--

6843761: Update langtools tests to remove unncessary -source and -target options
Reviewed-by: jjg

     1 /*
     2  * Copyright 1998-2001 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
    21  * have any questions.
    22  */
    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  */
    34 public class ChainedAssignment {
    36     private int a = 0;
    37     private int b = 0;
    38     private int c = 0;
    40     static private int sa = 0;
    41     static private int sb = 0;
    42     static private int sc = 0;
    44     private class Inner {
    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         }
    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         }
    82     }
    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     }
    91 }

mercurial