0N/A/*
553N/A * Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
0N/A */
0N/A
0N/A
0N/A/*
0N/A * @test
0N/A * @bug 5037165
0N/A * @summary Test the Declarations.overrides method
0N/A * @library ../../lib
131N/A * @run main/othervm Overrides
0N/A */
0N/A
0N/A
0N/Aimport java.util.*;
0N/Aimport com.sun.mirror.declaration.*;
0N/Aimport com.sun.mirror.type.*;
0N/Aimport com.sun.mirror.util.*;
0N/A
0N/A
0N/Apublic class Overrides extends Tester {
0N/A
0N/A public static void main(String[] args) {
0N/A (new Overrides()).run();
0N/A }
0N/A
0N/A
0N/A // Declarations used by tests
0N/A
0N/A static class A {
0N/A void m1(int i) {}; // does not override itself
0N/A void m2(int i) {};
0N/A static void m3(int i) {};
0N/A }
0N/A
0N/A static class B extends A {
0N/A void m1(int j) {}; // overrides A.m1
0N/A void m1(String i) {}; // does not override A.m1
0N/A void m4(int i) {}; // does not override A.m1
0N/A }
0N/A
0N/A static class C extends B {
0N/A void m1(int i) {}; // overrides A.m1 and B.m1
0N/A void m2(int i) {}; // overrides A.m2
0N/A }
0N/A
0N/A static class D extends A {
0N/A static void m3(int i) {}; // does not override A.m3
0N/A }
0N/A
0N/A static class E {
0N/A void m1(int i) {}; // does not override A.m1
0N/A }
0N/A
0N/A
0N/A
0N/A private Declarations decls;
0N/A
0N/A private TypeDeclaration A;
0N/A private TypeDeclaration B;
0N/A private TypeDeclaration C;
0N/A private TypeDeclaration D;
0N/A private TypeDeclaration E;
0N/A private MethodDeclaration Am1;
0N/A private MethodDeclaration Am2;
0N/A private MethodDeclaration Am3;
0N/A private MethodDeclaration Bm1;
0N/A private MethodDeclaration Bm1b;
0N/A private MethodDeclaration Bm4;
0N/A private MethodDeclaration Cm1;
0N/A private MethodDeclaration Cm2;
0N/A private MethodDeclaration Dm3;
0N/A private MethodDeclaration Em1;
0N/A
0N/A protected void init() {
0N/A decls = env.getDeclarationUtils();
0N/A
0N/A A = env.getTypeDeclaration("Overrides.A");
0N/A B = env.getTypeDeclaration("Overrides.B");
0N/A C = env.getTypeDeclaration("Overrides.C");
0N/A D = env.getTypeDeclaration("Overrides.D");
0N/A E = env.getTypeDeclaration("Overrides.E");
0N/A
0N/A Am1 = getMethod(A, "m1", "i");
0N/A Am2 = getMethod(A, "m2", "i");
0N/A Am3 = getMethod(A, "m3", "i");
0N/A Bm1 = getMethod(B, "m1", "j");
0N/A Bm1b = getMethod(B, "m1", "i");
0N/A Bm4 = getMethod(B, "m4", "i");
0N/A Cm1 = getMethod(C, "m1", "i");
0N/A Cm2 = getMethod(C, "m2", "i");
0N/A Dm3 = getMethod(D, "m3", "i");
0N/A Em1 = getMethod(E, "m1", "i");
0N/A }
0N/A
0N/A private MethodDeclaration getMethod(TypeDeclaration t,
0N/A String methodName, String paramName) {
0N/A for (MethodDeclaration m : t.getMethods()) {
0N/A if (methodName.equals(m.getSimpleName()) &&
0N/A paramName.equals(m.getParameters().iterator().next()
0N/A .getSimpleName())) {
0N/A return m;
0N/A }
0N/A }
0N/A throw new AssertionError();
0N/A }
0N/A
0N/A
0N/A // Declarations methods
0N/A
0N/A @Test(result={"false",
0N/A "true",
0N/A "false",
0N/A "false",
0N/A "true",
0N/A "true",
0N/A "true",
0N/A "false",
0N/A "false"},
0N/A ordered=true)
0N/A List<Boolean> overrides() {
0N/A return Arrays.asList(
0N/A decls.overrides(Am1, Am1),
0N/A decls.overrides(Bm1, Am1),
0N/A decls.overrides(Bm1b,Am1),
0N/A decls.overrides(Bm4, Am1),
0N/A decls.overrides(Cm1, Am1),
0N/A decls.overrides(Cm1, Bm1),
0N/A decls.overrides(Cm2, Am2),
0N/A decls.overrides(Dm3, Am3),
0N/A decls.overrides(Em1, Am1));
0N/A }
0N/A}