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.

PerClause.java 3.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 v 2.0
  6. * which accompanies this distribution and is available at
  7. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.patterns;
  13. import java.io.IOException;
  14. import org.aspectj.util.TypeSafeEnum;
  15. import org.aspectj.weaver.*;
  16. // PTWIMPL New kind added to this class, can be (de)serialized
  17. public abstract class PerClause extends Pointcut {
  18. protected ResolvedType inAspect;
  19. public static PerClause readPerClause(VersionedDataInputStream s, ISourceContext context) throws IOException {
  20. Kind kind = Kind.read(s);
  21. if (kind == SINGLETON) return PerSingleton.readPerClause(s, context);
  22. else if (kind == PERCFLOW) return PerCflow.readPerClause(s, context);
  23. else if (kind == PEROBJECT) return PerObject.readPerClause(s, context);
  24. else if (kind == FROMSUPER) return PerFromSuper.readPerClause(s, context);
  25. else if (kind == PERTYPEWITHIN) return PerTypeWithin.readPerClause(s,context);
  26. throw new BCException("unknown kind: " + kind);
  27. }
  28. public final Pointcut concretize1(ResolvedType inAspect, ResolvedType declaringType, IntMap bindings) {
  29. throw new RuntimeException("unimplemented: wrong concretize");
  30. }
  31. public abstract PerClause concretize(ResolvedType inAspect);
  32. public abstract PerClause.Kind getKind();
  33. public abstract String toDeclarationString();
  34. public static class Kind extends TypeSafeEnum {
  35. public Kind(String name, int key) { super(name, key); }
  36. public static Kind read(VersionedDataInputStream s) throws IOException {
  37. int key = s.readByte();
  38. switch(key) {
  39. case 1: return SINGLETON;
  40. case 2: return PERCFLOW;
  41. case 3: return PEROBJECT;
  42. case 4: return FROMSUPER;
  43. case 5: return PERTYPEWITHIN;
  44. }
  45. throw new BCException("weird kind " + key);
  46. }
  47. }
  48. public static final Kind SINGLETON = new Kind("issingleton", 1);
  49. public static final Kind PERCFLOW = new Kind("percflow", 2);
  50. public static final Kind PEROBJECT = new Kind("perobject", 3);
  51. public static final Kind FROMSUPER = new Kind("fromsuper", 4);
  52. public static final Kind PERTYPEWITHIN = new Kind("pertypewithin",5);
  53. public static class KindAnnotationPrefix extends TypeSafeEnum {
  54. private KindAnnotationPrefix(String name, int key) {
  55. super(name, key);
  56. }
  57. public String extractPointcut(String perClause) {
  58. int from = getName().length();
  59. int to = perClause.length()-1;
  60. if (!perClause.startsWith(getName())
  61. || !perClause.endsWith(")")
  62. || from > perClause.length()) {
  63. throw new RuntimeException("cannot read perclause " + perClause);
  64. }
  65. return perClause.substring(from, to);
  66. }
  67. public static final KindAnnotationPrefix PERCFLOW = new KindAnnotationPrefix("percflow(", 1);
  68. public static final KindAnnotationPrefix PERCFLOWBELOW = new KindAnnotationPrefix("percflowbelow(", 2);
  69. public static final KindAnnotationPrefix PERTHIS = new KindAnnotationPrefix("perthis(", 3);
  70. public static final KindAnnotationPrefix PERTARGET = new KindAnnotationPrefix("pertarget(", 4);
  71. public static final KindAnnotationPrefix PERTYPEWITHIN = new KindAnnotationPrefix("pertypewithin(", 5);
  72. }
  73. }