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.

MethodDelegateTypeMunger.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 org.aspectj.bridge.ISourceLocation;
  14. import org.aspectj.weaver.patterns.TypePattern;
  15. import java.io.DataOutputStream;
  16. import java.io.IOException;
  17. import java.util.Set;
  18. import java.util.Iterator;
  19. /**
  20. * Type munger for @AspectJ ITD declare parents ie with an interface AND an implementation.
  21. * Given the aspect that has a field public static Interface fieldI = ... // impl.
  22. * we will weave in the Interface' methods and delegate to the aspect public static field fieldI
  23. *
  24. * Note: this munger DOES NOT handles the interface addition to the target classes - a regular Parent kinded munger
  25. * must be added in coordination.
  26. */
  27. public class MethodDelegateTypeMunger extends ResolvedTypeMunger {
  28. /**
  29. * The field in the aspect that hosts the mixin instance
  30. */
  31. private final ResolvedMember aspectFieldDelegate;
  32. /**
  33. * Type pattern this munger applies to
  34. */
  35. private final TypePattern typePattern;
  36. /**
  37. * Construct a new type munger for @AspectJ ITD
  38. *
  39. * @param signature
  40. * @param aspect
  41. * @param fieldName
  42. * @param typePattern
  43. */
  44. public MethodDelegateTypeMunger(ResolvedMember signature, ResolvedType aspect, String fieldName, TypePattern typePattern) {
  45. super(MethodDelegate, signature);
  46. this.typePattern = typePattern;
  47. ResolvedMember[] fields = aspect.getDeclaredFields();//note: will unpack attributes
  48. ResolvedMember field = null;
  49. for (int i = 0; i < fields.length; i++) {
  50. if (fieldName.equals(fields[i].getName())) {
  51. field = fields[i];
  52. break;
  53. }
  54. }
  55. if (field == null) {
  56. throw new RuntimeException("Should not happen: aspect field not found for @DeclareParents delegate");
  57. } else {
  58. aspectFieldDelegate = field;
  59. }
  60. }
  61. public ResolvedMember getDelegate() {
  62. return aspectFieldDelegate;
  63. }
  64. public void write(DataOutputStream s) throws IOException {
  65. ;//FIXME AVITD needed as changes public signature throw new RuntimeException("unimplemented");
  66. }
  67. // public static ResolvedTypeMunger readMethod(VersionedDataInputStream s, ISourceContext context) throws IOException {
  68. // ResolvedMemberImpl rmi = ResolvedMemberImpl.readResolvedMember(s, context);
  69. // Set superMethodsCalled = readSuperMethodsCalled(s);
  70. // ISourceLocation sLoc = readSourceLocation(s);
  71. // ResolvedTypeMunger munger = new MethodDelegateTypeMunger(rmi, superMethodsCalled);
  72. // if (sLoc != null) munger.setSourceLocation(sLoc);
  73. // return munger;
  74. // }
  75. /**
  76. * Match based on given type pattern, only classes can be matched
  77. *
  78. * @param matchType
  79. * @param aspectType
  80. * @return true if match
  81. */
  82. public boolean matches(ResolvedType matchType, ResolvedType aspectType) {
  83. // match only on class
  84. if (matchType.isEnum() || matchType.isInterface() || matchType.isAnnotation()) {
  85. return false;
  86. }
  87. return typePattern.matchesStatically(matchType);
  88. }
  89. /**
  90. * Needed for reweavable
  91. *
  92. * @return true
  93. */
  94. public boolean changesPublicSignature() {
  95. return true;
  96. }
  97. }