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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. // An EclipseTypeMunger and a BcelTypeMunger may say TRUE for equivalentTo()...
  24. public boolean equivalentTo(Object other) {
  25. if (! (other instanceof ConcreteTypeMunger)) return false;
  26. ConcreteTypeMunger o = (ConcreteTypeMunger) other;
  27. return ((o.getMunger() == null) ? (getMunger() == null) : o.getMunger().equals(getMunger()))
  28. && ((o.getAspectType() == null) ? (getAspectType() == null) : o.getAspectType().equals(getAspectType()));
  29. }
  30. //public abstract boolean munge(LazyClassGen gen);
  31. /** returns null for mungers that are used internally, but were not part of a declared
  32. * thing in source code.
  33. */
  34. public ResolvedTypeMunger getMunger() {
  35. return munger;
  36. }
  37. public ResolvedType getAspectType() {
  38. return aspectType;
  39. }
  40. public ResolvedMember getSignature() {
  41. return munger.getSignature();
  42. }
  43. public World getWorld() {
  44. return aspectType.getWorld();
  45. }
  46. public ISourceLocation getSourceLocation() {
  47. if (munger == null) return null;
  48. return munger.getSourceLocation(); //XXX
  49. }
  50. public boolean matches(ResolvedType onType) {
  51. if (munger == null) throw new RuntimeException("huh: " + this);
  52. return munger.matches(onType, aspectType);
  53. }
  54. public ResolvedMember getMatchingSyntheticMember(Member member) {
  55. return munger.getMatchingSyntheticMember(member, aspectType);
  56. }
  57. public int compareTo(Object other) {
  58. ConcreteTypeMunger o = (ConcreteTypeMunger) other;
  59. ResolvedType otherAspect = o.aspectType;
  60. if (aspectType.equals(otherAspect)) {
  61. return getSignature().getStart() < o.getSignature().getStart() ? -1: +1;
  62. } else if (aspectType.isAssignableFrom(o.aspectType)) {
  63. return +1;
  64. } else if (o.aspectType.isAssignableFrom(aspectType)) {
  65. return -1;
  66. } else {
  67. return 0;
  68. }
  69. }
  70. public int fallbackCompareTo(Object other) {
  71. // ConcreteTypeMunger o = (ConcreteTypeMunger) other;
  72. return 0;
  73. }
  74. /**
  75. * returns true if the ITD target type used type variables, for example I<T>.
  76. * When they are specified like this, the ITDs 'share' type variables with
  77. * the generic type. Usually this method is called because we need to know
  78. * whether to tailor the munger for addition to a particular type. For example:
  79. * <code>
  80. * interface I<T> {}
  81. *
  82. * aspect X implements I<String> {
  83. * List<T> I<T>.foo { return null; }
  84. * }
  85. * </code>
  86. * In this case the munger matches X but it matches with the form
  87. * <code>
  88. * List<String> foo() { return null; }
  89. * </code>
  90. */
  91. public boolean isTargetTypeParameterized() {
  92. if (munger==null) return false;
  93. return munger.sharesTypeVariablesWithGenericType();
  94. }
  95. /**
  96. * For an ITD made on a generic type that shares type variables with
  97. * that target type, this method will tailor the ITD for a particular usage
  98. * of the generic type - either in its raw or parameterized form.
  99. */
  100. public abstract ConcreteTypeMunger parameterizedFor(ResolvedType targetType);
  101. public boolean isLateMunger() {
  102. if (munger==null) return false;
  103. return munger.isLateMunger();
  104. }
  105. public abstract ConcreteTypeMunger parameterizeWith(Map parameterizationMap, World world);
  106. }