選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ClassMethods.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import org.aspectj.testing.Tester;
  2. import java.lang.reflect.*;
  3. import java.util.*;
  4. public class ClassMethods {
  5. public static void main(String[] args) {
  6. new ClassMethods().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 SomeType();
  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. class SomeType {
  53. // public Object cloneNew() { try { return clone(); } catch (Throwable t) {} return null; }
  54. // public boolean equalsNew(Object o) { return equals(o); }
  55. // public void finalizeNew() { try { finalize(); } catch (Throwable t) {} }
  56. // public Class getClassNew() { return getClass(); }
  57. // public int hashCodeNew() { return hashCode(); }
  58. // public void notifyNew() { try { notify(); } catch (Throwable t) {} }
  59. // public void notifyAllNew() { try { notifyAll(); } catch (Throwable t) {} }
  60. // public String toStringNew() { return toString(); }
  61. // public void waitNew() { try { wait(); } catch (Throwable t) {} }
  62. // public void waitLNew(long l) { try { wait(l); } catch (Throwable t) {} }
  63. // public void waitLINew(long l, int i) { try { wait(l,i); } catch (Throwable t) {} }
  64. }
  65. aspect AspectToIntroduce_clone {
  66. introduction SomeType {
  67. public Object cloneNew() { try { return clone(); } catch (Throwable t) {} return null; }
  68. }
  69. }
  70. aspect AspectToIntroduce_equals {
  71. introduction SomeType {
  72. public boolean equalsNew(Object o) { return equals(o); }
  73. }
  74. }
  75. aspect AspectToIntroduce_finalize {
  76. introduction SomeType {
  77. public void finalizeNew() { try { finalize(); } catch (Throwable t) {} }
  78. }
  79. }
  80. aspect AspectToIntroduce_getClass {
  81. introduction SomeType {
  82. public Class getClassNew() { return getClass(); }
  83. }
  84. }
  85. aspect AspectToIntroduce_hashCode {
  86. introduction SomeType {
  87. public int hashCodeNew() { return hashCode(); }
  88. }
  89. }
  90. aspect AspectToIntroduce_notify {
  91. introduction SomeType {
  92. public void notifyNew() { try { notify(); } catch (Throwable t) {} }
  93. }
  94. }
  95. aspect AspectToIntroduce_notifyAll {
  96. introduction SomeType {
  97. public void notifyAllNew() { try { notifyAll(); } catch (Throwable t) {} }
  98. }
  99. }
  100. aspect AspectToIntroduce_toString {
  101. introduction SomeType {
  102. public String toStringNew() { return toString(); }
  103. }
  104. }
  105. aspect AspectToIntroduce_wait {
  106. introduction SomeType {
  107. public void waitNew() { try { wait(); } catch (Throwable t) {} }
  108. }
  109. }
  110. aspect AspectToIntroduce_waitL {
  111. introduction SomeType {
  112. public void waitLNew(long l) { try { wait(l); } catch (Throwable t) {} }
  113. }
  114. }
  115. aspect AspectToIntroduce_waitLI {
  116. introduction SomeType {
  117. public void waitLINew(long l, int i) { try { wait(l,i); } catch (Throwable t) {} }
  118. }
  119. }