Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

NewMethodTypeMunger.java 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 v 2.0
  6. * which accompanies this distribution and is available at
  7. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  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.Map;
  16. import java.util.Set;
  17. import org.aspectj.bridge.ISourceLocation;
  18. public class NewMethodTypeMunger extends ResolvedTypeMunger {
  19. public NewMethodTypeMunger(ResolvedMember signature, Set superMethodsCalled, List typeVariableAliases) {
  20. super(Method, signature);
  21. this.typeVariableAliases = typeVariableAliases;
  22. this.setSuperMethodsCalled(superMethodsCalled);
  23. }
  24. public ResolvedMember getInterMethodBody(UnresolvedType aspectType) {
  25. return AjcMemberMaker.interMethodBody(signature, aspectType);
  26. }
  27. /**
  28. * If the munger has a declared signature
  29. */
  30. public ResolvedMember getDeclaredInterMethodBody(UnresolvedType aspectType, World w) {
  31. if (declaredSignature != null) {
  32. ResolvedMember rm = declaredSignature.parameterizedWith(null, signature.getDeclaringType().resolve(w), false,
  33. getTypeVariableAliases());
  34. return AjcMemberMaker.interMethodBody(rm, aspectType);
  35. } else {
  36. return AjcMemberMaker.interMethodBody(signature, aspectType);
  37. }
  38. }
  39. // public ResolvedMember getInterMethodDispatcher(UnresolvedType aspectType) {
  40. // return AjcMemberMaker.interMethodDispatcher(signature, aspectType);
  41. // }
  42. public ResolvedMember getDeclaredInterMethodDispatcher(UnresolvedType aspectType, World w) {
  43. if (declaredSignature != null) {
  44. ResolvedMember rm = declaredSignature.parameterizedWith(null, signature.getDeclaringType().resolve(w), false,
  45. getTypeVariableAliases());
  46. return AjcMemberMaker.interMethodDispatcher(rm, aspectType);
  47. } else {
  48. return AjcMemberMaker.interMethodDispatcher(signature, aspectType);
  49. }
  50. }
  51. public void write(CompressingDataOutputStream s) throws IOException {
  52. kind.write(s);
  53. signature.write(s);
  54. writeSuperMethodsCalled(s);
  55. writeSourceLocation(s);
  56. writeOutTypeAliases(s);
  57. }
  58. public static ResolvedTypeMunger readMethod(VersionedDataInputStream s, ISourceContext context) throws IOException {
  59. ISourceLocation sloc = null;
  60. ResolvedMemberImpl rmImpl = ResolvedMemberImpl.readResolvedMember(s, context);
  61. Set<ResolvedMember> superMethodsCalled = readSuperMethodsCalled(s);
  62. sloc = readSourceLocation(s);
  63. List<String> typeVarAliases = readInTypeAliases(s);
  64. ResolvedTypeMunger munger = new NewMethodTypeMunger(rmImpl, superMethodsCalled, typeVarAliases);
  65. if (sloc != null) {
  66. munger.setSourceLocation(sloc);
  67. }
  68. return munger;
  69. }
  70. public ResolvedMember getMatchingSyntheticMember(Member member, ResolvedType aspectType) {
  71. ResolvedMember ret = AjcMemberMaker.interMethodDispatcher(getSignature(), aspectType);
  72. if (ResolvedType.matches(ret, member)) {
  73. return getSignature();
  74. }
  75. return super.getMatchingSyntheticMember(member, aspectType);
  76. }
  77. /**
  78. * see ResolvedTypeMunger.parameterizedFor(ResolvedType)
  79. */
  80. public ResolvedTypeMunger parameterizedFor(ResolvedType target) {
  81. ResolvedType genericType = target;
  82. if (target.isRawType() || target.isParameterizedType()) {
  83. genericType = genericType.getGenericType();
  84. }
  85. ResolvedMember parameterizedSignature = null;
  86. // If we are parameterizing it for a generic type, we just need to 'swap the letters' from the ones used
  87. // in the original ITD declaration to the ones used in the actual target type declaration.
  88. if (target.isGenericType()) {
  89. TypeVariable vars[] = target.getTypeVariables();
  90. UnresolvedTypeVariableReferenceType[] varRefs = new UnresolvedTypeVariableReferenceType[vars.length];
  91. for (int i = 0; i < vars.length; i++) {
  92. varRefs[i] = new UnresolvedTypeVariableReferenceType(vars[i]);
  93. }
  94. parameterizedSignature = getSignature().parameterizedWith(varRefs, genericType, true, typeVariableAliases);
  95. } else {
  96. // For raw and 'normal' parameterized targets (e.g. Interface, Interface<String>)
  97. parameterizedSignature = getSignature().parameterizedWith(target.getTypeParameters(), genericType,
  98. target.isParameterizedType(), typeVariableAliases);
  99. }
  100. NewMethodTypeMunger nmtm = new NewMethodTypeMunger(parameterizedSignature, getSuperMethodsCalled(), typeVariableAliases);
  101. nmtm.setDeclaredSignature(getSignature());
  102. nmtm.setSourceLocation(getSourceLocation());
  103. return nmtm;
  104. }
  105. public boolean equals(Object other) {
  106. if (!(other instanceof NewMethodTypeMunger)) {
  107. return false;
  108. }
  109. NewMethodTypeMunger o = (NewMethodTypeMunger) other;
  110. return ((kind == null) ? (o.kind == null) : kind.equals(o.kind))
  111. && ((signature == null) ? (o.signature == null) : signature.equals(o.signature))
  112. && ((declaredSignature == null) ? (o.declaredSignature == null) : declaredSignature.equals(o.declaredSignature))
  113. && ((typeVariableAliases == null) ? (o.typeVariableAliases == null) : typeVariableAliases
  114. .equals(o.typeVariableAliases));
  115. }
  116. public int hashCode() {
  117. int result = 17;
  118. result = 37 * result + kind.hashCode();
  119. result = 37 * result + ((signature == null) ? 0 : signature.hashCode());
  120. result = 37 * result + ((declaredSignature == null) ? 0 : declaredSignature.hashCode());
  121. result = 37 * result + ((typeVariableAliases == null) ? 0 : typeVariableAliases.hashCode());
  122. return result;
  123. }
  124. public ResolvedTypeMunger parameterizeWith(Map<String, UnresolvedType> m, World w) {
  125. ResolvedMember parameterizedSignature = getSignature().parameterizedWith(m, w);
  126. NewMethodTypeMunger nmtm = new NewMethodTypeMunger(parameterizedSignature, getSuperMethodsCalled(), typeVariableAliases);
  127. nmtm.setDeclaredSignature(getSignature());
  128. nmtm.setSourceLocation(getSourceLocation());
  129. return nmtm;
  130. }
  131. }