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.

AdviceKind.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver;
  13. import java.io.IOException;
  14. import org.aspectj.util.TypeSafeEnum;
  15. /**
  16. * The five kinds of advice in AspectJ.
  17. *
  18. * @author Erik Hilsdale
  19. * @author Jim Hugunin
  20. */
  21. public class AdviceKind extends TypeSafeEnum {
  22. private int precedence;
  23. private boolean isAfter;
  24. private boolean isCflow;
  25. public AdviceKind(String name, int key, int precedence, boolean isAfter, boolean isCflow) {
  26. super(name, key);
  27. this.precedence = precedence;
  28. this.isAfter = isAfter;
  29. this.isCflow = isCflow;
  30. }
  31. public static AdviceKind read(VersionedDataInputStream s) throws IOException {
  32. int key = s.readByte();
  33. switch (key) {
  34. case 1:
  35. return Before;
  36. case 2:
  37. return After;
  38. case 3:
  39. return AfterThrowing;
  40. case 4:
  41. return AfterReturning;
  42. case 5:
  43. return Around;
  44. case 6:
  45. return CflowEntry;
  46. case 7:
  47. return CflowBelowEntry;
  48. case 8:
  49. return InterInitializer;
  50. case 9:
  51. return PerCflowEntry;
  52. case 10:
  53. return PerCflowBelowEntry;
  54. case 11:
  55. return PerThisEntry;
  56. case 12:
  57. return PerTargetEntry;
  58. case 13:
  59. return Softener;
  60. case 14:
  61. return PerTypeWithinEntry;
  62. }
  63. throw new RuntimeException("unimplemented kind: " + key);
  64. }
  65. public static final AdviceKind Before = new AdviceKind("before", 1, 0, false, false);
  66. public static final AdviceKind After = new AdviceKind("after", 2, 0, true, false);
  67. public static final AdviceKind AfterThrowing = new AdviceKind("afterThrowing", 3, 0, true, false);
  68. public static final AdviceKind AfterReturning = new AdviceKind("afterReturning", 4, 0, true, false);
  69. public static final AdviceKind Around = new AdviceKind("around", 5, 0, false, false);
  70. // these kinds can't be declared, but are used by the weaver
  71. public static final AdviceKind CflowEntry = new AdviceKind("cflowEntry", 6, 1, false, true);
  72. public static final AdviceKind CflowBelowEntry = new AdviceKind("cflowBelowEntry", 7, -1, false, true); // XXX resolve
  73. // precednece with the
  74. // below
  75. public static final AdviceKind InterInitializer = new AdviceKind("interInitializer", 8, -2, false, false);
  76. public static final AdviceKind PerCflowEntry = new AdviceKind("perCflowEntry", 9, 1, false, true);
  77. public static final AdviceKind PerCflowBelowEntry = new AdviceKind("perCflowBelowEntry", 10, -1, false, true);
  78. public static final AdviceKind PerThisEntry = new AdviceKind("perThisEntry", 11, 1, false, false);
  79. public static final AdviceKind PerTargetEntry = new AdviceKind("perTargetEntry", 12, 1, false, false);
  80. public static final AdviceKind Softener = new AdviceKind("softener", 13, 1, false, false);
  81. // PTWIMPL Advice representing when aspect should be initialized
  82. public static final AdviceKind PerTypeWithinEntry = new AdviceKind("perTypeWithinEntry", 14, 1, false, false);
  83. public static AdviceKind stringToKind(String s) {
  84. if (s.equals(Before.getName()))
  85. return Before;
  86. if (s.equals(After.getName()))
  87. return After;
  88. if (s.equals(AfterThrowing.getName()))
  89. return AfterThrowing;
  90. if (s.equals(AfterReturning.getName()))
  91. return AfterReturning;
  92. if (s.equals(Around.getName()))
  93. return Around;
  94. throw new IllegalArgumentException("unknown kind: " + "\"" + s + "\"");
  95. }
  96. public boolean isAfter() {
  97. return this.isAfter;
  98. }
  99. public boolean isCflow() {
  100. return this.isCflow;
  101. }
  102. public int getPrecedence() {
  103. return precedence;
  104. }
  105. public boolean isPerEntry() {
  106. return this == PerCflowEntry || this == PerCflowBelowEntry || this == PerThisEntry || this == PerTargetEntry
  107. || this == PerTypeWithinEntry; // PTWIMPL Allow for PTW case
  108. }
  109. public boolean isPerObjectEntry() {
  110. return this == PerThisEntry || this == PerTargetEntry;
  111. }
  112. @Override
  113. public int hashCode() {
  114. return ((super.hashCode()*37 + precedence)*37+(isAfter?0:1))*37 + (isCflow?0:1);
  115. }
  116. @Override
  117. public boolean equals(Object o) {
  118. if (!(o instanceof AdviceKind)) {
  119. return false;
  120. }
  121. AdviceKind ak = (AdviceKind)o;
  122. return super.equals(ak) &&
  123. ak.precedence == precedence &&
  124. ak.isAfter == isAfter &&
  125. ak.isCflow == isCflow;
  126. }
  127. }