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.

PerCflow.java 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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.patterns;
  13. import java.io.IOException;
  14. import java.lang.reflect.Modifier;
  15. import java.util.ArrayList;
  16. import java.util.Collection;
  17. import java.util.List;
  18. import java.util.Map;
  19. import org.aspectj.util.FuzzyBoolean;
  20. import org.aspectj.weaver.Advice;
  21. import org.aspectj.weaver.AjcMemberMaker;
  22. import org.aspectj.weaver.CompressingDataOutputStream;
  23. import org.aspectj.weaver.CrosscuttingMembers;
  24. import org.aspectj.weaver.ISourceContext;
  25. import org.aspectj.weaver.Member;
  26. import org.aspectj.weaver.NameMangler;
  27. import org.aspectj.weaver.ResolvedMemberImpl;
  28. import org.aspectj.weaver.ResolvedType;
  29. import org.aspectj.weaver.Shadow;
  30. import org.aspectj.weaver.ShadowMunger;
  31. import org.aspectj.weaver.UnresolvedType;
  32. import org.aspectj.weaver.VersionedDataInputStream;
  33. import org.aspectj.weaver.World;
  34. import org.aspectj.weaver.ast.Expr;
  35. import org.aspectj.weaver.ast.Test;
  36. public class PerCflow extends PerClause {
  37. private final boolean isBelow;
  38. private final Pointcut entry;
  39. public PerCflow(Pointcut entry, boolean isBelow) {
  40. this.entry = entry;
  41. this.isBelow = isBelow;
  42. }
  43. // -----
  44. public Object accept(PatternNodeVisitor visitor, Object data) {
  45. return visitor.visit(this, data);
  46. }
  47. public int couldMatchKinds() {
  48. return Shadow.ALL_SHADOW_KINDS_BITS;
  49. }
  50. public FuzzyBoolean fastMatch(FastMatchInfo type) {
  51. return FuzzyBoolean.MAYBE;
  52. }
  53. protected FuzzyBoolean matchInternal(Shadow shadow) {
  54. return FuzzyBoolean.YES;
  55. }
  56. public void resolveBindings(IScope scope, Bindings bindings) {
  57. // assert bindings == null;
  58. entry.resolve(scope);
  59. }
  60. public Pointcut parameterizeWith(Map<String,UnresolvedType> typeVariableMap, World w) {
  61. PerCflow ret = new PerCflow(entry.parameterizeWith(typeVariableMap, w), isBelow);
  62. ret.copyLocationFrom(this);
  63. return ret;
  64. }
  65. protected Test findResidueInternal(Shadow shadow, ExposedState state) {
  66. Expr myInstance = Expr.makeCallExpr(AjcMemberMaker.perCflowAspectOfMethod(inAspect), Expr.NONE, inAspect);
  67. state.setAspectInstance(myInstance);
  68. return Test.makeCall(AjcMemberMaker.perCflowHasAspectMethod(inAspect), Expr.NONE);
  69. }
  70. public PerClause concretize(ResolvedType inAspect) {
  71. PerCflow ret = new PerCflow(entry, isBelow);
  72. ret.inAspect = inAspect;
  73. if (inAspect.isAbstract()) {
  74. return ret;
  75. }
  76. Member cflowStackField = new ResolvedMemberImpl(Member.FIELD, inAspect, Modifier.STATIC | Modifier.PUBLIC | Modifier.FINAL,
  77. UnresolvedType.forName(NameMangler.CFLOW_STACK_TYPE), NameMangler.PERCFLOW_FIELD_NAME, UnresolvedType.NONE);
  78. World world = inAspect.getWorld();
  79. CrosscuttingMembers xcut = inAspect.crosscuttingMembers;
  80. Collection<ShadowMunger> previousCflowEntries = xcut.getCflowEntries();
  81. Pointcut concreteEntry = entry.concretize(inAspect, inAspect, 0, null); // IntMap
  82. // .
  83. // EMPTY
  84. // )
  85. // ;
  86. List<ShadowMunger> innerCflowEntries = new ArrayList<ShadowMunger>(xcut.getCflowEntries());
  87. innerCflowEntries.removeAll(previousCflowEntries);
  88. xcut.addConcreteShadowMunger(Advice.makePerCflowEntry(world, concreteEntry, isBelow, cflowStackField, inAspect,
  89. innerCflowEntries));
  90. // ATAJ: add a munger to add the aspectOf(..) to the @AJ aspects
  91. if (inAspect.isAnnotationStyleAspect() && !inAspect.isAbstract()) {
  92. inAspect.crosscuttingMembers.addLateTypeMunger(inAspect.getWorld().getWeavingSupport()
  93. .makePerClauseAspect(inAspect, getKind()));
  94. }
  95. // ATAJ inline around advice support - don't use a late munger to allow
  96. // around inling for itself
  97. if (inAspect.isAnnotationStyleAspect() && !inAspect.getWorld().isXnoInline()) {
  98. inAspect.crosscuttingMembers.addTypeMunger(inAspect.getWorld().getWeavingSupport()
  99. .createAccessForInlineMunger(inAspect));
  100. }
  101. return ret;
  102. }
  103. public void write(CompressingDataOutputStream s) throws IOException {
  104. PERCFLOW.write(s);
  105. entry.write(s);
  106. s.writeBoolean(isBelow);
  107. writeLocation(s);
  108. }
  109. public static PerClause readPerClause(VersionedDataInputStream s, ISourceContext context) throws IOException {
  110. PerCflow ret = new PerCflow(Pointcut.read(s, context), s.readBoolean());
  111. ret.readLocation(context, s);
  112. return ret;
  113. }
  114. public PerClause.Kind getKind() {
  115. return PERCFLOW;
  116. }
  117. public Pointcut getEntry() {
  118. return entry;
  119. }
  120. public String toString() {
  121. return "percflow(" + inAspect + " on " + entry + ")";
  122. }
  123. public String toDeclarationString() {
  124. if (isBelow) {
  125. return "percflowbelow(" + entry + ")";
  126. }
  127. return "percflow(" + entry + ")";
  128. }
  129. public boolean equals(Object other) {
  130. if (!(other instanceof PerCflow)) {
  131. return false;
  132. }
  133. PerCflow pc = (PerCflow) other;
  134. return (pc.isBelow && isBelow) && ((pc.inAspect == null) ? (inAspect == null) : pc.inAspect.equals(inAspect))
  135. && ((pc.entry == null) ? (entry == null) : pc.entry.equals(entry));
  136. }
  137. public int hashCode() {
  138. int result = 17;
  139. result = 37 * result + (isBelow ? 0 : 1);
  140. result = 37 * result + ((inAspect == null) ? 0 : inAspect.hashCode());
  141. result = 37 * result + ((entry == null) ? 0 : entry.hashCode());
  142. return result;
  143. }
  144. }