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.

NewConstructorTypeMunger.java 6.0KB

15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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.io.IOException;
  14. import java.util.List;
  15. import java.util.Set;
  16. import org.aspectj.bridge.IMessage;
  17. import org.aspectj.bridge.ISourceLocation;
  18. public class NewConstructorTypeMunger extends ResolvedTypeMunger {
  19. private ResolvedMember syntheticConstructor;
  20. private ResolvedMember explicitConstructor;
  21. public NewConstructorTypeMunger(ResolvedMember signature, ResolvedMember syntheticConstructor,
  22. ResolvedMember explicitConstructor, Set superMethodsCalled, List typeVariableAliases) {
  23. super(Constructor, signature);
  24. this.syntheticConstructor = syntheticConstructor;
  25. this.typeVariableAliases = typeVariableAliases;
  26. this.explicitConstructor = explicitConstructor;
  27. this.setSuperMethodsCalled(superMethodsCalled);
  28. }
  29. @Override
  30. public boolean equals(Object other) {
  31. if (!(other instanceof NewConstructorTypeMunger)) {
  32. return false;
  33. }
  34. NewConstructorTypeMunger o = (NewConstructorTypeMunger) other;
  35. return ((syntheticConstructor == null) ? (o.syntheticConstructor == null) : syntheticConstructor
  36. .equals(o.syntheticConstructor))
  37. & ((explicitConstructor == null) ? (o.explicitConstructor == null) : explicitConstructor
  38. .equals(o.explicitConstructor));
  39. }
  40. // pr262218 - equivalence ignores the explicit constructor since that won't have yet been set for an EclipseTypeMunger
  41. public boolean equivalentTo(Object other) {
  42. if (!(other instanceof NewConstructorTypeMunger)) {
  43. return false;
  44. }
  45. NewConstructorTypeMunger o = (NewConstructorTypeMunger) other;
  46. return ((syntheticConstructor == null) ? (o.syntheticConstructor == null) : syntheticConstructor
  47. .equals(o.syntheticConstructor));
  48. }
  49. private volatile int hashCode = 0;
  50. @Override
  51. public int hashCode() {
  52. if (hashCode == 0) {
  53. int result = 17;
  54. result = 37 * result + ((syntheticConstructor == null) ? 0 : syntheticConstructor.hashCode());
  55. result = 37 * result + ((explicitConstructor == null) ? 0 : explicitConstructor.hashCode());
  56. hashCode = result;
  57. }
  58. return hashCode;
  59. }
  60. // doesnt seem required....
  61. // public ResolvedMember getDispatchMethod(UnresolvedType aspectType) {
  62. // return AjcMemberMaker.interMethodBody(signature, aspectType);
  63. // }
  64. @Override
  65. public void write(CompressingDataOutputStream s) throws IOException {
  66. kind.write(s);
  67. signature.write(s);
  68. syntheticConstructor.write(s);
  69. explicitConstructor.write(s);
  70. writeSuperMethodsCalled(s);
  71. writeSourceLocation(s);
  72. writeOutTypeAliases(s);
  73. }
  74. public static ResolvedTypeMunger readConstructor(VersionedDataInputStream s, ISourceContext context) throws IOException {
  75. ISourceLocation sloc = null;
  76. ResolvedMember sig = ResolvedMemberImpl.readResolvedMember(s, context);
  77. ResolvedMember syntheticCtor = ResolvedMemberImpl.readResolvedMember(s, context);
  78. ResolvedMember explicitCtor = ResolvedMemberImpl.readResolvedMember(s, context);
  79. Set superMethodsCalled = readSuperMethodsCalled(s);
  80. sloc = readSourceLocation(s);
  81. List typeVarAliases = readInTypeAliases(s);
  82. ResolvedTypeMunger munger = new NewConstructorTypeMunger(sig, syntheticCtor, explicitCtor, superMethodsCalled,
  83. typeVarAliases);
  84. if (sloc != null) {
  85. munger.setSourceLocation(sloc);
  86. }
  87. return munger;
  88. }
  89. public ResolvedMember getExplicitConstructor() {
  90. return explicitConstructor;
  91. }
  92. public ResolvedMember getSyntheticConstructor() {
  93. return syntheticConstructor;
  94. }
  95. public void setExplicitConstructor(ResolvedMember explicitConstructor) {
  96. this.explicitConstructor = explicitConstructor;
  97. // reset hashCode so that its recalculated with new value
  98. hashCode = 0;
  99. }
  100. @Override
  101. public ResolvedMember getMatchingSyntheticMember(Member member, ResolvedType aspectType) {
  102. ResolvedMember ret = getSyntheticConstructor();
  103. if (ResolvedType.matches(ret, member)) {
  104. return getSignature();
  105. }
  106. return super.getMatchingSyntheticMember(member, aspectType);
  107. }
  108. public void check(World world) {
  109. if (getSignature().getDeclaringType().resolve(world).isAspect()) {
  110. world.showMessage(IMessage.ERROR, WeaverMessages.format(WeaverMessages.ITD_CONS_ON_ASPECT), getSignature()
  111. .getSourceLocation(), null);
  112. }
  113. }
  114. /**
  115. * see ResolvedTypeMunger.parameterizedFor(ResolvedType)
  116. */
  117. @Override
  118. public ResolvedTypeMunger parameterizedFor(ResolvedType target) {
  119. ResolvedType genericType = target;
  120. if (target.isRawType() || target.isParameterizedType()) {
  121. genericType = genericType.getGenericType();
  122. }
  123. ResolvedMember parameterizedSignature = null;
  124. // If we are parameterizing it for a generic type, we just need to 'swap the letters' from the ones used
  125. // in the original ITD declaration to the ones used in the actual target type declaration.
  126. if (target.isGenericType()) {
  127. TypeVariable vars[] = target.getTypeVariables();
  128. UnresolvedTypeVariableReferenceType[] varRefs = new UnresolvedTypeVariableReferenceType[vars.length];
  129. for (int i = 0; i < vars.length; i++) {
  130. varRefs[i] = new UnresolvedTypeVariableReferenceType(vars[i]);
  131. }
  132. parameterizedSignature = getSignature().parameterizedWith(varRefs, genericType, true, typeVariableAliases);
  133. } else {
  134. // For raw and 'normal' parameterized targets (e.g. Interface, Interface<String>)
  135. parameterizedSignature = getSignature().parameterizedWith(target.getTypeParameters(), genericType,
  136. target.isParameterizedType(), typeVariableAliases);
  137. }
  138. NewConstructorTypeMunger nctm = new NewConstructorTypeMunger(parameterizedSignature, syntheticConstructor,
  139. explicitConstructor, getSuperMethodsCalled(), typeVariableAliases);
  140. nctm.setSourceLocation(getSourceLocation());
  141. return nctm;
  142. }
  143. }