Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

MethodDelegateTypeMunger.java 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /* *******************************************************************
  2. * Copyright (c) 2005 Contributors.
  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://eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Alexandre Vasseur initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver;
  13. import java.io.DataOutputStream;
  14. import java.io.IOException;
  15. import org.aspectj.weaver.patterns.TypePattern;
  16. /**
  17. * Type munger for @AspectJ ITD declare parents ie with an interface AND an implementation.
  18. * Given the aspect that has a field public static Interface fieldI = ... // impl.
  19. * we will weave in the Interface' methods and delegate to the aspect public static field fieldI
  20. *
  21. * Note: this munger DOES NOT handles the interface addition to the target classes - a regular Parent kinded munger
  22. * must be added in coordination.
  23. */
  24. public class MethodDelegateTypeMunger extends ResolvedTypeMunger {
  25. private final UnresolvedType aspect;
  26. /**
  27. * The mixin impl (no arg ctor)
  28. */
  29. private final String implClassName;
  30. /**
  31. * Type pattern this munger applies to
  32. */
  33. private final TypePattern typePattern;
  34. /**
  35. * Construct a new type munger for @AspectJ ITD
  36. *
  37. * @param signature
  38. * @param aspect
  39. * @param implClassName
  40. * @param typePattern
  41. */
  42. public MethodDelegateTypeMunger(ResolvedMember signature, UnresolvedType aspect, String implClassName, TypePattern typePattern) {
  43. super(MethodDelegate, signature);
  44. this.aspect = aspect;
  45. this.typePattern = typePattern;
  46. this.implClassName = implClassName;
  47. }
  48. public ResolvedMember getDelegate(ResolvedType targetType) {
  49. return AjcMemberMaker.itdAtDeclareParentsField(
  50. targetType,
  51. signature.getDeclaringType(),
  52. aspect
  53. );
  54. }
  55. public String getImplClassName() {
  56. return implClassName;
  57. }
  58. public void write(DataOutputStream s) throws IOException {
  59. kind.write(s);
  60. signature.write(s);
  61. aspect.write(s);
  62. s.writeUTF(implClassName);
  63. typePattern.write(s);
  64. }
  65. public static ResolvedTypeMunger readMethod(VersionedDataInputStream s, ISourceContext context) throws IOException {
  66. ResolvedMemberImpl signature = ResolvedMemberImpl.readResolvedMember(s, context);
  67. UnresolvedType aspect = UnresolvedType.read(s);
  68. String implClassName = s.readUTF();
  69. TypePattern tp = TypePattern.read(s, context);
  70. return new MethodDelegateTypeMunger(signature, aspect, implClassName, tp);
  71. }
  72. /**
  73. * Match based on given type pattern, only classes can be matched
  74. *
  75. * @param matchType
  76. * @param aspectType
  77. * @return true if match
  78. */
  79. public boolean matches(ResolvedType matchType, ResolvedType aspectType) {
  80. // match only on class
  81. if (matchType.isEnum() || matchType.isInterface() || matchType.isAnnotation()) {
  82. return false;
  83. }
  84. return typePattern.matchesStatically(matchType);
  85. }
  86. /**
  87. * Needed for reweavable
  88. *
  89. * @return true
  90. */
  91. public boolean changesPublicSignature() {
  92. return true;
  93. }
  94. public static class FieldHostTypeMunger extends ResolvedTypeMunger {
  95. private UnresolvedType aspect;
  96. /**
  97. * Type pattern this munger applies to
  98. */
  99. private final TypePattern typePattern;
  100. /**
  101. * Construct a new type munger for @AspectJ ITD
  102. *
  103. * @param field
  104. * @param aspect
  105. * @param typePattern
  106. */
  107. public FieldHostTypeMunger(ResolvedMember field, UnresolvedType aspect, TypePattern typePattern) {
  108. super(FieldHost, field);
  109. this.aspect = aspect;
  110. this.typePattern = typePattern;
  111. }
  112. public void write(DataOutputStream s) throws IOException {
  113. kind.write(s);
  114. signature.write(s);
  115. aspect.write(s);
  116. typePattern.write(s);
  117. }
  118. public static ResolvedTypeMunger readFieldHost(VersionedDataInputStream s, ISourceContext context) throws IOException {
  119. ResolvedMemberImpl signature = ResolvedMemberImpl.readResolvedMember(s, context);
  120. UnresolvedType aspect = UnresolvedType.read(s);
  121. TypePattern tp = TypePattern.read(s, context);
  122. return new FieldHostTypeMunger(signature, aspect, tp);
  123. }
  124. /**
  125. * Match based on given type pattern, only classes can be matched
  126. *
  127. * @param matchType
  128. * @param aspectType
  129. * @return true if match
  130. */
  131. public boolean matches(ResolvedType matchType, ResolvedType aspectType) {
  132. // match only on class
  133. if (matchType.isEnum() || matchType.isInterface() || matchType.isAnnotation()) {
  134. return false;
  135. }
  136. return typePattern.matchesStatically(matchType);
  137. }
  138. public boolean changesPublicSignature() {
  139. return false;
  140. }
  141. }
  142. }