codegen: handle exceptions of a method
[mate.git] / tests / InstanceOf3.java
1 package tests;
2
3 public class InstanceOf3 {
4         static interface i1 { };
5         static interface i2 { };
6         static interface i3 extends i2 { };
7         static interface i4 extends i3 { };
8         static interface i5 { };
9         static interface i6 extends i3 { };
10         static interface i7 extends i4, i6 { };
11         static interface i8 extends i2, i7 { };
12         static class c1 { };
13         static class c2 extends c1 implements i1 { };
14         static class c3 extends c2 implements i4 { };
15         static class c4 { };
16
17         public static void main(String []args) {
18                 Object x = new c3();
19                 i2 y = new i3() { };
20                 i6 z = new i6() { };
21                 i7 u = new i7() { };
22                 i8 v = new i8() { };
23
24                 checkInstance(x instanceof c1, "x", "c1");
25                 checkInstance(x instanceof c2, "x", "c2");
26                 checkInstance(x instanceof c3, "x", "c3");
27                 checkInstance(x instanceof c4, "x", "c4");
28                 checkInstance(x instanceof String, "x", "String");
29                 checkInstance(x instanceof Integer, "x", "Integer");
30
31                 checkInterfaces(x, "x");
32                 checkInterfaces(y, "y");
33                 checkInterfaces(z, "z");
34                 checkInterfaces(u, "u");
35                 checkInterfaces(v, "v");
36         }
37
38         public static void checkInterfaces(Object y, String name) {
39                 checkInstance(y instanceof Object, name, "Object");
40                 checkInstance(y instanceof i1, name, "i1");
41                 checkInstance(y instanceof i2, name, "i2");
42                 checkInstance(y instanceof i3, name, "i3");
43                 checkInstance(y instanceof i4, name, "i4");
44                 checkInstance(y instanceof i5, name, "i5");
45                 checkInstance(y instanceof i6, name, "i6");
46                 checkInstance(y instanceof i7, name, "i7");
47                 checkInstance(y instanceof i8, name, "i8");
48         }
49
50         public static void checkInstance(boolean cond, String obj, String classname) {
51                 System.out.printf(obj);
52                 if (cond) {
53                         System.out.printf(" is instance of ");
54                         System.out.printf(classname);
55                         System.out.printf(" :-)\n");
56                 } else {
57                         System.out.printf(" is *not* instance of ");
58                         System.out.printf(classname);
59                         System.out.printf(" :-(\n");
60                 }
61         }
62 }