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.

InterfaceMethods.java 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import org.aspectj.testing.Tester;
  2. import java.lang.reflect.*;
  3. import java.util.*;
  4. public class InterfaceMethods {
  5. public static void main(String[] args) {
  6. new InterfaceMethods().realMain(args);
  7. }
  8. final static Object[] tuples = new Object[] {
  9. "clone", null, null,
  10. "equals", new Class[]{Object.class}, new Object[]{""},
  11. "finalize", null, null,
  12. "getClass", null, null,
  13. "hashCode", null, null,
  14. "notify", null, null,
  15. "notifyAll", null, null,
  16. "toString", null, null,
  17. "wait", null, null,
  18. "waitL", new Class[]{long.class}, new Object[]{new Long(3L)},
  19. "waitLI", new Class[]{long.class, int.class}, new Object[]{new Long(4L), new Integer(5)},
  20. };
  21. final List list = new Vector();
  22. {
  23. for (int i = 0; i < tuples.length; i += 3) {
  24. List tuple = new Vector();
  25. tuple.add(tuples[i]+ "New");
  26. tuple.add(tuples[i+1] == null ? new Class[]{} : tuples[i+1]);
  27. tuple.add(tuples[i+2] == null ? new Object[]{} : tuples[i+2]);
  28. list.add(tuple);
  29. }
  30. }
  31. public void realMain(String[] argv) {
  32. Iterator iter = list.iterator();
  33. while (iter.hasNext()) {
  34. List tuple = (List) iter.next();
  35. String name = (String) tuple.get(0);
  36. Class[] params = (Class[]) tuple.get(1);
  37. Object[] args = (Object[]) tuple.get(2);
  38. boolean ran = false;
  39. Throwable caught = null;
  40. try {
  41. Object o = new SomeClass();
  42. o.getClass().getMethod(name, params).invoke(o, args);
  43. ran = true;
  44. } catch (Throwable t) {
  45. caught = t;
  46. } finally {
  47. Tester.check(ran, name + " didn't run" + (caught != null ? ":"+caught : ""));
  48. }
  49. }
  50. }
  51. }
  52. interface SomeType {}
  53. class SomeClass implements SomeType {
  54. // public Object cloneNew() { try { return clone(); } catch (Throwable t) {} return null; }
  55. // public boolean equalsNew(Object o) { return equals(o); }
  56. // public void finalizeNew() { try { finalize(); } catch (Throwable t) {} }
  57. // public Class getClassNew() { return getClass(); }
  58. // public int hashCodeNew() { return hashCode(); }
  59. // public void notifyNew() { try { notify(); } catch (Throwable t) {} }
  60. // public void notifyAllNew() { try { notifyAll(); } catch (Throwable t) {} }
  61. // public String toStringNew() { return toString(); }
  62. // public void waitNew() { try { wait(); } catch (Throwable t) {} }
  63. // public void waitLNew(long l) { try { wait(l); } catch (Throwable t) {} }
  64. // public void waitLINew(long l, int i) { try { wait(l,i); } catch (Throwable t) {} }
  65. }
  66. aspect AspectToIntroduce_clone {
  67. introduction SomeType {
  68. public Object cloneNew() { try { return clone(); } catch (Throwable t) {} return null; }
  69. }
  70. }
  71. aspect AspectToIntroduce_equals {
  72. introduction SomeType {
  73. public boolean equalsNew(Object o) { return equals(o); }
  74. }
  75. }
  76. aspect AspectToIntroduce_finalize {
  77. introduction SomeType {
  78. public void finalizeNew() { try { finalize(); } catch (Throwable t) {} }
  79. }
  80. }
  81. aspect AspectToIntroduce_getClass {
  82. introduction SomeType {
  83. public Class getClassNew() { return getClass(); }
  84. }
  85. }
  86. aspect AspectToIntroduce_hashCode {
  87. introduction SomeType {
  88. public int hashCodeNew() { return hashCode(); }
  89. }
  90. }
  91. aspect AspectToIntroduce_notify {
  92. introduction SomeType {
  93. public void notifyNew() { try { notify(); } catch (Throwable t) {} }
  94. }
  95. }
  96. aspect AspectToIntroduce_notifyAll {
  97. introduction SomeType {
  98. public void notifyAllNew() { try { notifyAll(); } catch (Throwable t) {} }
  99. }
  100. }
  101. aspect AspectToIntroduce_toString {
  102. introduction SomeType {
  103. public String toStringNew() { return toString(); }
  104. }
  105. }
  106. aspect AspectToIntroduce_wait {
  107. introduction SomeType {
  108. public void waitNew() { try { wait(); } catch (Throwable t) {} }
  109. }
  110. }
  111. aspect AspectToIntroduce_waitL {
  112. introduction SomeType {
  113. public void waitLNew(long l) { try { wait(l); } catch (Throwable t) {} }
  114. }
  115. }
  116. aspect AspectToIntroduce_waitLI {
  117. introduction SomeType {
  118. public void waitLINew(long l, int i) { try { wait(l,i); } catch (Throwable t) {} }
  119. }
  120. }