You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

InterType.java 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import junit.framework.Assert;
  2. public class InterType {
  3. public static void main(String[] args) {
  4. Target t = new Target();
  5. Assert.assertEquals(0, t.i);
  6. t.i = 37;
  7. Assert.assertEquals(37, t.i);
  8. Assert.assertEquals(37, t.i++);
  9. Assert.assertEquals(38, t.i);
  10. Assert.assertEquals(39, ++t.i);
  11. Assert.assertEquals(39, t.i);
  12. System.out.println("t.i = " + t.i);
  13. Assert.assertEquals(0, ((I)t).i);
  14. Assert.assertEquals("foo", t.s);
  15. t.s += "-bar";
  16. Assert.assertEquals("foo-bar", t.s);
  17. System.out.println("t.s = " + t.s);
  18. // this captures an interesting property of initializers:
  19. // that introduced inits run before non-introduced inits
  20. Assert.assertEquals("inst00onA", A.getInstS(t));
  21. System.out.println("t.instS = " + A.getInstS(t));
  22. I i = t;
  23. Assert.assertEquals("dummy", i.myString);
  24. i.myString = "foo";
  25. Assert.assertEquals(i.myString, "foo");
  26. System.out.println("t.myString = " + t.myString);
  27. Assert.assertNotNull(A.aspectOf());
  28. Assert.assertEquals(A.aspectOf(), A.aspectOf());
  29. Assert.assertTrue(A.hasAspect());
  30. //XXX don't handle constants
  31. // int x = 10;
  32. // switch(x) {
  33. // case Target.CONST: break;
  34. // default: Assert.fail("bad switch");
  35. // }
  36. }
  37. }
  38. class Target implements I {
  39. public int j = 2;
  40. private boolean instS = true; // potential conflict need to handle gracefully
  41. public boolean getInstS() { return instS; }
  42. String conflict = "boo";
  43. }
  44. class SubTarget extends Target {
  45. public static String foo() {
  46. return A.aspectOf().toString();
  47. }
  48. }
  49. interface I { }
  50. aspect A {
  51. private static String aStatic = "onA";
  52. public int Target.foobarvas = 0;
  53. public int I.i = 0;
  54. public int Target.i;
  55. public static String Target.s = "foo";
  56. public static int Target.CONST = 10;
  57. private String Target.instS = "inst" + j + this.j + aStatic;
  58. //private String Target.conflict = "goo"; error
  59. public static String getInstS(Target t) {
  60. return t.instS;
  61. }
  62. public String I.myString = "dummy";
  63. }