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.

ConcreteTypeMunger.java 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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;
  13. import java.util.Map;
  14. import org.aspectj.bridge.ISourceLocation;
  15. import org.aspectj.util.PartialOrder;
  16. public abstract class ConcreteTypeMunger implements PartialOrder.PartialComparable {
  17. protected ResolvedTypeMunger munger;
  18. protected ResolvedType aspectType;
  19. public ConcreteTypeMunger(ResolvedTypeMunger munger, ResolvedType aspectType) {
  20. this.munger = munger;
  21. this.aspectType = aspectType;
  22. }
  23. /**
  24. * Equivalence can be true for an EclipseTypeMunger and a BcelTypeMunger that represent the same transformation (just at
  25. * different points in the pipeline).
  26. */
  27. public boolean equivalentTo(Object other) {
  28. if (!(other instanceof ConcreteTypeMunger)) {
  29. return false;
  30. }
  31. ConcreteTypeMunger o = (ConcreteTypeMunger) other;
  32. ResolvedTypeMunger otherTypeMunger = o.getMunger();
  33. ResolvedTypeMunger thisTypeMunger = getMunger();
  34. if (thisTypeMunger instanceof NewConstructorTypeMunger && otherTypeMunger instanceof NewConstructorTypeMunger) {
  35. return (((NewConstructorTypeMunger) otherTypeMunger).equivalentTo(thisTypeMunger))
  36. && ((o.getAspectType() == null) ? (getAspectType() == null) : o.getAspectType().equals(getAspectType()));
  37. } else {
  38. return ((otherTypeMunger == null) ? (thisTypeMunger == null) : otherTypeMunger.equals(thisTypeMunger))
  39. && ((o.getAspectType() == null) ? (getAspectType() == null) : o.getAspectType().equals(getAspectType()));
  40. }
  41. }
  42. // public abstract boolean munge(LazyClassGen gen);
  43. /**
  44. * returns null for mungers that are used internally, but were not part of a declared thing in source code.
  45. */
  46. public ResolvedTypeMunger getMunger() {
  47. return munger;
  48. }
  49. public ResolvedType getAspectType() {
  50. return aspectType;
  51. }
  52. public ResolvedMember getSignature() {
  53. return munger.getSignature();
  54. }
  55. public World getWorld() {
  56. return aspectType.getWorld();
  57. }
  58. public ISourceLocation getSourceLocation() {
  59. if (munger == null) {
  60. return null;
  61. }
  62. return munger.getSourceLocation(); // XXX
  63. }
  64. public boolean matches(ResolvedType onType) {
  65. if (munger == null) {
  66. throw new RuntimeException("huh: " + this);
  67. }
  68. return munger.matches(onType, aspectType);
  69. }
  70. public ResolvedMember getMatchingSyntheticMember(Member member) {
  71. return munger.getMatchingSyntheticMember(member, aspectType);
  72. }
  73. public int compareTo(Object other) {
  74. ConcreteTypeMunger o = (ConcreteTypeMunger) other;
  75. ResolvedType otherAspect = o.aspectType;
  76. if (aspectType.equals(otherAspect)) {
  77. return getSignature().getStart() < o.getSignature().getStart() ? -1 : +1;
  78. } else if (aspectType.isAssignableFrom(o.aspectType)) {
  79. return +1;
  80. } else if (o.aspectType.isAssignableFrom(aspectType)) {
  81. return -1;
  82. } else {
  83. return 0;
  84. }
  85. }
  86. public int fallbackCompareTo(Object other) {
  87. // ConcreteTypeMunger o = (ConcreteTypeMunger) other;
  88. return 0;
  89. }
  90. /**
  91. * returns true if the ITD target type used type variables, for example I&lt;T&gt;. When they are specified like this, the ITDs
  92. * 'share' type variables with the generic type. Usually this method is called because we need to know whether to tailor the
  93. * munger for addition to a particular type. For example: <code>
  94. * interface I&lt;T&gt; {}
  95. *
  96. * aspect X implements I&lt;String&gt; {
  97. * List&lt;T&gt; I&lt;T&gt;.foo { return null; }
  98. * }
  99. * </code> In this case the munger matches X but it matches with the form <code>
  100. * List&lt;String&gt; foo() { return null; }
  101. * </code>
  102. */
  103. public boolean isTargetTypeParameterized() {
  104. if (munger == null) {
  105. return false;
  106. }
  107. return munger.sharesTypeVariablesWithGenericType();
  108. }
  109. /**
  110. * For an ITD made on a generic type that shares type variables with that target type, this method will tailor the ITD for a
  111. * particular usage of the generic type - either in its raw or parameterized form.
  112. */
  113. public abstract ConcreteTypeMunger parameterizedFor(ResolvedType targetType);
  114. public boolean isLateMunger() {
  115. if (munger == null) {
  116. return false;
  117. }
  118. return munger.isLateMunger();
  119. }
  120. public abstract ConcreteTypeMunger parameterizeWith(Map<String, UnresolvedType> parameterizationMap, World world);
  121. /**
  122. * Some type mungers are created purely to help with the implementation of shadow mungers. For example to support the cflow()
  123. * pointcut we create a new cflow field in the aspect, and that is added via a BcelCflowCounterFieldAdder.
  124. *
  125. * During compilation we need to compare sets of type mungers, and if some only come into existence after the 'shadowy' type
  126. * things have been processed, we need to ignore them during the comparison.
  127. *
  128. * Returning true from this method indicates the type munger exists to support 'shadowy' stuff - and so can be ignored in some
  129. * comparison.
  130. */
  131. public boolean existsToSupportShadowMunging() {
  132. if (munger != null) {
  133. return munger.existsToSupportShadowMunging();
  134. }
  135. return false;
  136. }
  137. public boolean shouldOverwrite() {
  138. return true;
  139. }
  140. }