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.

PerSingleton.java 5.2KB

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.util.Map;
  15. import org.aspectj.util.FuzzyBoolean;
  16. import org.aspectj.weaver.AjcMemberMaker;
  17. import org.aspectj.weaver.CompressingDataOutputStream;
  18. import org.aspectj.weaver.ISourceContext;
  19. import org.aspectj.weaver.ResolvedMember;
  20. import org.aspectj.weaver.ResolvedType;
  21. import org.aspectj.weaver.Shadow;
  22. import org.aspectj.weaver.UnresolvedType;
  23. import org.aspectj.weaver.VersionedDataInputStream;
  24. import org.aspectj.weaver.World;
  25. import org.aspectj.weaver.ast.Expr;
  26. import org.aspectj.weaver.ast.Literal;
  27. import org.aspectj.weaver.ast.Test;
  28. public class PerSingleton extends PerClause {
  29. private ResolvedMember perSingletonAspectOfMethod;
  30. public PerSingleton() {
  31. }
  32. public Object accept(PatternNodeVisitor visitor, Object data) {
  33. return visitor.visit(this, data);
  34. }
  35. public int couldMatchKinds() {
  36. return Shadow.ALL_SHADOW_KINDS_BITS;
  37. }
  38. public FuzzyBoolean fastMatch(FastMatchInfo type) {
  39. return FuzzyBoolean.YES;
  40. }
  41. protected FuzzyBoolean matchInternal(Shadow shadow) {
  42. return FuzzyBoolean.YES;
  43. }
  44. public void resolveBindings(IScope scope, Bindings bindings) {
  45. // this method intentionally left blank
  46. }
  47. public Pointcut parameterizeWith(Map<String,UnresolvedType> typeVariableMap, World w) {
  48. return this;
  49. }
  50. public Test findResidueInternal(Shadow shadow, ExposedState state) {
  51. // TODO: the commented code is for slow Aspects.aspectOf() style - keep
  52. // or remove
  53. //
  54. // Expr myInstance =
  55. // Expr.makeCallExpr(AjcMemberMaker.perSingletonAspectOfMethod(inAspect),
  56. // Expr.NONE, inAspect);
  57. //
  58. // state.setAspectInstance(myInstance);
  59. //
  60. // // we have no test
  61. // // a NoAspectBoundException will be thrown if we need an instance of
  62. // this
  63. // // aspect before we are bound
  64. // return Literal.TRUE;
  65. // if (!Ajc5MemberMaker.isSlowAspect(inAspect)) {
  66. if (perSingletonAspectOfMethod == null) {
  67. // Build this just once
  68. perSingletonAspectOfMethod = AjcMemberMaker.perSingletonAspectOfMethod(inAspect);
  69. }
  70. Expr myInstance = Expr.makeCallExpr(perSingletonAspectOfMethod, Expr.NONE, inAspect);
  71. state.setAspectInstance(myInstance);
  72. // we have no test
  73. // a NoAspectBoundException will be thrown if we need an instance of
  74. // this
  75. // aspect before we are bound
  76. return Literal.TRUE;
  77. // } else {
  78. // CallExpr callAspectOf =Expr.makeCallExpr(
  79. // Ajc5MemberMaker.perSingletonAspectOfMethod(inAspect),
  80. // new Expr[]{
  81. // Expr.makeStringConstantExpr(inAspect.getName(), inAspect),
  82. // //FieldGet is using ResolvedType and I don't need that here
  83. // new FieldGetOn(Member.ajClassField, shadow.getEnclosingType())
  84. // },
  85. // inAspect
  86. // );
  87. // Expr castedCallAspectOf = new CastExpr(callAspectOf,
  88. // inAspect.getName());
  89. // state.setAspectInstance(castedCallAspectOf);
  90. // return Literal.TRUE;
  91. // }
  92. }
  93. public PerClause concretize(ResolvedType inAspect) {
  94. PerSingleton ret = new PerSingleton();
  95. ret.copyLocationFrom(this);
  96. World world = inAspect.getWorld();
  97. ret.inAspect = inAspect;
  98. // ATAJ: add a munger to add the aspectOf(..) to the @AJ aspects
  99. if (inAspect.isAnnotationStyleAspect() && !inAspect.isAbstract()) {
  100. // TODO will those change be ok if we add a serializable aspect ?
  101. // dig:
  102. // "can't be Serializable/Cloneable unless -XserializableAspects"
  103. if (getKind() == SINGLETON) { // pr149560
  104. inAspect.crosscuttingMembers.addTypeMunger(world.getWeavingSupport().makePerClauseAspect(inAspect, getKind()));
  105. } else {
  106. inAspect.crosscuttingMembers.addLateTypeMunger(world.getWeavingSupport().makePerClauseAspect(inAspect, getKind()));
  107. }
  108. }
  109. // ATAJ inline around advice support
  110. if (inAspect.isAnnotationStyleAspect() && !inAspect.getWorld().isXnoInline()) {
  111. inAspect.crosscuttingMembers.addTypeMunger(world.getWeavingSupport().createAccessForInlineMunger(inAspect));
  112. }
  113. return ret;
  114. }
  115. public void write(CompressingDataOutputStream s) throws IOException {
  116. SINGLETON.write(s);
  117. writeLocation(s);
  118. }
  119. public static PerClause readPerClause(VersionedDataInputStream s, ISourceContext context) throws IOException {
  120. PerSingleton ret = new PerSingleton();
  121. ret.readLocation(context, s);
  122. return ret;
  123. }
  124. public PerClause.Kind getKind() {
  125. return SINGLETON;
  126. }
  127. public String toString() {
  128. return "persingleton(" + inAspect + ")";
  129. }
  130. public String toDeclarationString() {
  131. return "";
  132. }
  133. public boolean equals(Object other) {
  134. if (!(other instanceof PerSingleton)) {
  135. return false;
  136. }
  137. PerSingleton pc = (PerSingleton) other;
  138. return ((pc.inAspect == null) ? (inAspect == null) : pc.inAspect.equals(inAspect));
  139. }
  140. public int hashCode() {
  141. int result = 17;
  142. result = 37 * result + ((inAspect == null) ? 0 : inAspect.hashCode());
  143. return result;
  144. }
  145. }