1 /*
   2  * @test
   3  * @summary Basic tests for bindings from instanceof
   4  * @compile BindingsTest1.java
   5  * @run main BindingsTest1
   6  */
   7 
   8 public class BindingsTest1 {
   9     public static boolean Ktrue() { return true; }
  10     public static void main(String[] args) {
  11         Object o1 = "hello";
  12         Integer i = 42;
  13         Object o2 = i;
  14         Object o3 = "there";
  15 
  16 
  17         // Test for (e matches P).T = { binding variables in P }
  18         if (o1 instanceof String s) {
  19             s.length();
  20         }
  21 
  22         // Test for e1 && e2.T = union(e1.T, e2.T)
  23         if (o1 instanceof String s && o2 instanceof Integer in) {
  24             s.length();
  25             in.intValue();
  26         }
  27         // Test for e1 && e2.F = intersect(e1.F, e2.F)
  28         if (!(o1 instanceof String s) && !(o1 instanceof String s)) {
  29 
  30         } else {
  31             s.length();
  32         }
  33 
  34         // test for e1&&e2 - include e1.T in e2
  35         if (o1 instanceof String s && s.length()>0) {
  36             System.out.print("done");
  37         }
  38 
  39         // Test for (e1 || e2).T = intersect(e1.T, e2.T)
  40         if (o1 instanceof String s || o3 instanceof String s){
  41             System.out.println(s); // ?
  42         }
  43 
  44         // Test for (e1 || e2).F = union(e1.F, e2.F)
  45         if (!(o1 instanceof String s) || !(o3 instanceof Integer in)){
  46         } else {
  47             s.length();
  48             i.intValue();
  49         }
  50 
  51         // Test for e1||e2 - include e1.F in e2
  52 
  53         if (!(o1 instanceof String s) || s.length()>0) {
  54             System.out.println("done");
  55         }
  56 
  57         // Test for (e1 ? e2 : e3).T contains intersect(e2.T, e3.T)
  58         if (Ktrue() ? o2 instanceof Integer x : o2 instanceof Integer x) {
  59             x.intValue();
  60         }
  61 
  62         // Test for (e1 ? e2 : e3).T contains intersect(e1.T, e3.T)
  63         if (o1 instanceof String s ? true : o1 instanceof String s) {
  64             s.length();
  65         }
  66 
  67         // Test for (e1 ? e2 : e3).T contains intersect(e1.F, e2.T)
  68         if (!(o1 instanceof String s) ? (o1 instanceof String s) : true) {
  69             s.length();
  70         }
  71 
  72         // Test for (e1 ? e2 : e3).F contains intersect(e2.F, e3.F)
  73         if (Ktrue() ? !(o2 instanceof Integer x) : !(o2 instanceof Integer x)){
  74         } else {
  75             x.intValue();
  76         }
  77 
  78         // Test for (e1 ? e2 : e3).F contains intersect(e1.T, e3.F)
  79         if (o1 instanceof String s ? true : !(o1 instanceof String s)){
  80         } else {
  81             s.length();
  82         }
  83 
  84         // Test for (e1 ? e2 : e3).F contains intersect(e1.F, e2.F)
  85         if (!(o1 instanceof String s) ? !(o1 instanceof String s) : true){
  86         } else {
  87             s.length();
  88         }
  89 
  90         // Test for e1 ? e2: e3 - include e1.T in e2
  91         if (o1 instanceof String s ? s.length()>0 : false) {
  92             System.out.println("done");
  93         }
  94 
  95         // Test for e1 ? e2 : e3 - include e1.F in e3
  96         if (!(o1 instanceof String s) ? false : s.length()>0){
  97             System.out.println("done");
  98         }
  99 
 100         // Test for (!e).T = e.F
 101 
 102         if (!(!(o1 instanceof String s) || !(o3 instanceof Integer in))){
 103             s.length();
 104             i.intValue();
 105         }
 106 
 107         // Test for (!e).F = e.T
 108         if (!(o1 instanceof String s)) {
 109 
 110         } else {
 111             s.length();
 112         }
 113 
 114         L1: {
 115             if (o1 instanceof String s) {
 116                 s.length();
 117             } else {
 118                 break L1;
 119             }
 120             s.length();
 121         }
 122 
 123         L2: {
 124             if (!(o1 instanceof String s)) {
 125                 break L2;
 126             } else {
 127                 s.length();
 128             }
 129             s.length();
 130         }
 131 
 132         L3: {
 133             if ((o1 instanceof String s) || (o3 instanceof String s)) {
 134                 s.length();
 135             } else {
 136                 break L3;
 137             }
 138             s.length();
 139         }
 140 
 141         L4: {
 142             if (!(o1 instanceof String s)) {
 143                 break L4;
 144             }
 145             s.length();
 146         }
 147 
 148         {
 149             while (!(o1 instanceof String s)) {
 150             }
 151 
 152             s.length();
 153         }
 154 
 155         L5: {
 156             while (!(o1 instanceof String s)) {
 157             }
 158 
 159             s.length();
 160         }
 161 
 162         {
 163             L6: for ( ;!(o1 instanceof String s); ) {
 164 
 165             }
 166 
 167             s.length();
 168         }
 169 
 170         {
 171             L7: do {
 172 
 173             } while (!(o1 instanceof String s));
 174 
 175             s.length();
 176         }
 177 
 178         if (o1 instanceof String s) {
 179             Runnable r1 = new Runnable() {
 180                 @Override
 181                 public void run() {
 182                     s.length();
 183                 }
 184             };
 185             r1.run();
 186             Runnable r2 = () -> {
 187                 s.length();
 188             };
 189             r2.run();
 190             String s2 = s;
 191         }
 192 
 193         System.out.println("BindingsTest1 complete");
 194     }
 195 }