langtools/test/tools/javac/NameClash/NameClashTest.java
author hseigel
Wed, 02 Mar 2016 23:48:41 +0000
changeset 36397 c487ced7231c
parent 34752 9c262a013456
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33367
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
     1
/*
34752
9c262a013456 8145342: Some copyright notices are inconsistently and ill formatted
vasya
parents: 33367
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
33367
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
     4
 *
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
     7
 * published by the Free Software Foundation.
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
     8
 *
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    13
 * accompanied this code).
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    14
 *
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    18
 *
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    21
 * questions.
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    22
 */
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    23
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    24
/*
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    25
 * @test
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    26
 * @bug 8074803
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    27
 * @summary Incorrect name clash error
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    28
 *
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    29
 * @compile NameClashTest.java
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    30
 */
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    31
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    32
public class NameClashTest {
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    33
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    34
    String log = "";
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    35
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    36
    interface A1 {
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    37
        A1 m(String s);
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    38
    }
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    39
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    40
    abstract class A2 implements A1 {
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    41
        public abstract A2 m(String s);
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    42
    }
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    43
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    44
    interface B1 {
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    45
        A1 m(String s);
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    46
    }
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    47
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    48
    interface B2 extends B1 {
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    49
        A2 m(String s);
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    50
    }
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    51
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    52
    abstract class C extends A2 implements B2 {}
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    53
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    54
    class D extends C {
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    55
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    56
        public A2 m(String s) {
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    57
            log += s;
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    58
            return null;
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    59
        }
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    60
    }
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    61
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    62
    public static void main(String[] args) {
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    63
        NameClashTest nct = new NameClashTest();
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    64
        A1 a1 = nct.new D();
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    65
        a1.m("A1.m ");
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    66
        A2 a2 = nct.new D();
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    67
        a2.m("A2.m ");
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    68
        B1 b1 = nct.new D();
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    69
        b1.m("B1.m ");
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    70
        B2 b2 = nct.new D();
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    71
        b2.m("B2.m ");
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    72
        C c = nct.new D();
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    73
        c.m("C.m ");
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    74
        D d = nct.new D();
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    75
        d.m("D.m ");
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    76
        if (!nct.log.equals("A1.m A2.m B1.m B2.m C.m D.m "))
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    77
            throw new AssertionError("unexpected output: " + nct.log);
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    78
    }
546ffcb790a5 8074803: Name clash
sadayapalam
parents:
diff changeset
    79
}