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 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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.patterns;
  13. import java.io.DataOutputStream;
  14. import java.io.IOException;
  15. import java.util.Set;
  16. import org.aspectj.util.FuzzyBoolean;
  17. import org.aspectj.weaver.AjcMemberMaker;
  18. import org.aspectj.weaver.ISourceContext;
  19. import org.aspectj.weaver.ResolvedTypeX;
  20. import org.aspectj.weaver.Shadow;
  21. import org.aspectj.weaver.VersionedDataInputStream;
  22. import org.aspectj.weaver.bcel.BcelAccessForInlineMunger;
  23. import org.aspectj.weaver.ast.Expr;
  24. import org.aspectj.weaver.ast.Literal;
  25. import org.aspectj.weaver.ast.Test;
  26. import org.aspectj.weaver.ataspectj.Ajc5MemberMaker;
  27. public class PerSingleton extends PerClause {
  28. public PerSingleton() {
  29. }
  30. public Set couldMatchKinds() {
  31. return Shadow.ALL_SHADOW_KINDS;
  32. }
  33. public FuzzyBoolean fastMatch(FastMatchInfo type) {
  34. return FuzzyBoolean.YES;
  35. }
  36. protected FuzzyBoolean matchInternal(Shadow shadow) {
  37. return FuzzyBoolean.YES;
  38. }
  39. public void resolveBindings(IScope scope, Bindings bindings) {
  40. // this method intentionally left blank
  41. }
  42. public Test findResidueInternal(Shadow shadow, ExposedState state) {
  43. // TODO: the commented code is for slow Aspects.aspectOf() style - keep or remove
  44. //
  45. // Expr myInstance =
  46. // Expr.makeCallExpr(AjcMemberMaker.perSingletonAspectOfMethod(inAspect),
  47. // Expr.NONE, inAspect);
  48. //
  49. // state.setAspectInstance(myInstance);
  50. //
  51. // // we have no test
  52. // // a NoAspectBoundException will be thrown if we need an instance of this
  53. // // aspect before we are bound
  54. // return Literal.TRUE;
  55. // if (!Ajc5MemberMaker.isSlowAspect(inAspect)) {
  56. Expr myInstance =
  57. Expr.makeCallExpr(AjcMemberMaker.perSingletonAspectOfMethod(inAspect),
  58. Expr.NONE, inAspect);
  59. state.setAspectInstance(myInstance);
  60. // we have no test
  61. // a NoAspectBoundException will be thrown if we need an instance of this
  62. // aspect before we are bound
  63. return Literal.TRUE;
  64. // } else {
  65. // CallExpr callAspectOf =Expr.makeCallExpr(
  66. // Ajc5MemberMaker.perSingletonAspectOfMethod(inAspect),
  67. // new Expr[]{
  68. // Expr.makeStringConstantExpr(inAspect.getName(), inAspect),
  69. // //FieldGet is using ResolvedType and I don't need that here
  70. // new FieldGetOn(Member.ajClassField, shadow.getEnclosingType())
  71. // },
  72. // inAspect
  73. // );
  74. // Expr castedCallAspectOf = new CastExpr(callAspectOf, inAspect.getName());
  75. // state.setAspectInstance(castedCallAspectOf);
  76. // return Literal.TRUE;
  77. // }
  78. }
  79. public PerClause concretize(ResolvedTypeX inAspect) {
  80. PerSingleton ret = new PerSingleton();
  81. ret.copyLocationFrom(this);
  82. ret.inAspect = inAspect;
  83. //ATAJ: add a munger to add the aspectOf(..) to the @AJ aspects
  84. if (!inAspect.isAbstract() && Ajc5MemberMaker.isAnnotationStyleAspect(inAspect)) {
  85. //TODO will those change be ok if we add a serializable aspect ?
  86. // dig: "can't be Serializable/Cloneable unless -XserializableAspects"
  87. inAspect.crosscuttingMembers.addLateTypeMunger(
  88. inAspect.getWorld().makePerClauseAspect(inAspect, getKind())
  89. );
  90. }
  91. //ATAJ inline around advice support
  92. if (Ajc5MemberMaker.isAnnotationStyleAspect(inAspect)) {
  93. inAspect.crosscuttingMembers.addLateTypeMunger(new BcelAccessForInlineMunger(inAspect));
  94. }
  95. return ret;
  96. }
  97. public void write(DataOutputStream s) throws IOException {
  98. SINGLETON.write(s);
  99. writeLocation(s);
  100. }
  101. public static PerClause readPerClause(VersionedDataInputStream s, ISourceContext context) throws IOException {
  102. PerSingleton ret = new PerSingleton();
  103. ret.readLocation(context, s);
  104. return ret;
  105. }
  106. public PerClause.Kind getKind() {
  107. return SINGLETON;
  108. }
  109. public String toString() {
  110. return "persingleton(" + inAspect + ")";
  111. }
  112. public String toDeclarationString() {
  113. return "";
  114. }
  115. }