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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 Common Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/cpl-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 5 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: return Before;
  35. case 2: return After;
  36. case 3: return AfterThrowing;
  37. case 4: return AfterReturning;
  38. case 5: return Around;
  39. case 6: return CflowEntry;
  40. case 7: return CflowBelowEntry;
  41. case 8: return InterInitializer;
  42. case 9: return PerCflowEntry;
  43. case 10: return PerCflowBelowEntry;
  44. case 11: return PerThisEntry;
  45. case 12: return PerTargetEntry;
  46. case 13: return Softener;
  47. }
  48. throw new RuntimeException("unimplemented kind: " + key);
  49. }
  50. public static final AdviceKind Before = new AdviceKind("before", 1, 0, false, false);
  51. public static final AdviceKind After = new AdviceKind("after", 2, 0, true, false);
  52. public static final AdviceKind AfterThrowing = new AdviceKind("afterThrowing", 3, 0, true, false);
  53. public static final AdviceKind AfterReturning = new AdviceKind("afterReturning", 4, 0, true, false);
  54. public static final AdviceKind Around = new AdviceKind("around", 5, 0, false, false);
  55. // these kinds can't be declared, but are used by the weaver
  56. public static final AdviceKind CflowEntry = new AdviceKind("cflowEntry", 6, 1, false, true);
  57. public static final AdviceKind CflowBelowEntry = new AdviceKind("cflowBelowEntry", 7, -1, false, true); //XXX resolve precednece with the below
  58. public static final AdviceKind InterInitializer = new AdviceKind("interInitializer", 8, -2, false, false);
  59. public static final AdviceKind PerCflowEntry = new AdviceKind("perCflowEntry", 9, 1, false, true);
  60. public static final AdviceKind PerCflowBelowEntry = new AdviceKind("perCflowBelowEntry", 10, -1, false, true);
  61. public static final AdviceKind PerThisEntry = new AdviceKind("perThisEntry", 11, 1, false, false);
  62. public static final AdviceKind PerTargetEntry = new AdviceKind("perTargetEntry", 12, 1, false, false);
  63. public static final AdviceKind Softener = new AdviceKind("softener", 13, 1, false, false);
  64. public static AdviceKind stringToKind(String s) {
  65. if (s.equals(Before.getName())) return Before;
  66. if (s.equals(After.getName())) return After;
  67. if (s.equals(AfterThrowing.getName())) return AfterThrowing;
  68. if (s.equals(AfterReturning.getName())) return AfterReturning;
  69. if (s.equals(Around.getName())) return Around;
  70. throw new IllegalArgumentException("unknown kind: " + "\"" + s + "\"");
  71. }
  72. public boolean isAfter() {
  73. return this.isAfter;
  74. }
  75. public boolean isCflow() {
  76. return this.isCflow;
  77. }
  78. public int getPrecedence() {
  79. return precedence;
  80. }
  81. public boolean isPerEntry() {
  82. return this == PerCflowEntry || this == PerCflowBelowEntry ||
  83. this == PerThisEntry || this == PerTargetEntry;
  84. }
  85. public boolean isPerObjectEntry() {
  86. return this == PerThisEntry || this == PerTargetEntry;
  87. }
  88. }