Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ReferenceType.java 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. /* *******************************************************************
  2. * Copyright (c) 2002 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://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * Andy Clement - June 2005 - separated out from ResolvedType
  12. * ******************************************************************/
  13. package org.aspectj.weaver;
  14. import java.util.ArrayList;
  15. import java.util.Collection;
  16. import java.util.Iterator;
  17. import java.util.List;
  18. import java.util.Map;
  19. import org.aspectj.bridge.ISourceLocation;
  20. import org.aspectj.weaver.bcel.BcelObjectType;
  21. import org.aspectj.weaver.patterns.Declare;
  22. import org.aspectj.weaver.patterns.PerClause;
  23. /**
  24. * A reference type represents some 'real' type, not a primitive, not an array - but
  25. * a real type, for example java.util.List. Each ReferenceType has a delegate
  26. * that is the underlying artifact - either an eclipse artifact or a
  27. * bcel artifact. If the type represents a raw type (i.e. there is
  28. * a generic form) then the genericType field is set to point to the
  29. * generic type. If it is for a parameterized type then the generic type
  30. * is also set to point to the generic form.
  31. */
  32. public class ReferenceType extends ResolvedType {
  33. /**
  34. * For generic types, this list holds references to all the derived raw
  35. * and parameterized versions. We need this so that if the generic delegate
  36. * is swapped during incremental compilation, the delegate of the derivatives
  37. * is swapped also.
  38. */
  39. private List/*ReferenceType*/ derivativeTypes = new ArrayList();
  40. /**
  41. * For parameterized types (or the raw type) - this field points to the actual
  42. * reference type from which they are derived.
  43. */
  44. ReferenceType genericType = null;
  45. ReferenceTypeDelegate delegate = null;
  46. int startPos = 0;
  47. int endPos = 0;
  48. public static ReferenceType fromTypeX(UnresolvedType tx, World world) {
  49. ReferenceType rt = new ReferenceType(tx.getErasureSignature(),world);
  50. rt.typeKind = tx.typeKind;
  51. return rt;
  52. }
  53. // cached values for members
  54. ResolvedMember[] parameterizedMethods = null;
  55. ResolvedMember[] parameterizedFields = null;
  56. ResolvedMember[] parameterizedPointcuts = null;
  57. ResolvedType[] parameterizedInterfaces = null;
  58. Collection parameterizedDeclares = null;
  59. Collection parameterizedTypeMungers = null;
  60. //??? should set delegate before any use
  61. public ReferenceType(String signature, World world) {
  62. super(signature, world);
  63. }
  64. public ReferenceType(String signature, String signatureErasure, World world) {
  65. super(signature,signatureErasure, world);
  66. }
  67. /**
  68. * Constructor used when creating a parameterized type.
  69. */
  70. public ReferenceType(
  71. ResolvedType theGenericType,
  72. ResolvedType[] theParameters,
  73. World aWorld) {
  74. super(makeParameterizedSignature(theGenericType,theParameters),
  75. theGenericType.signatureErasure,
  76. aWorld);
  77. ReferenceType genericReferenceType = (ReferenceType) theGenericType;
  78. this.typeParameters = theParameters;
  79. this.genericType = genericReferenceType;
  80. this.typeKind = TypeKind.PARAMETERIZED;
  81. this.delegate = genericReferenceType.getDelegate();
  82. genericReferenceType.addDependentType(this);
  83. }
  84. /**
  85. * Constructor used when creating a raw type.
  86. */
  87. public ReferenceType(
  88. ResolvedType theGenericType,
  89. World aWorld) {
  90. super(theGenericType.getErasureSignature(),
  91. theGenericType.getErasureSignature(),
  92. aWorld);
  93. ReferenceType genericReferenceType = (ReferenceType) theGenericType;
  94. this.typeParameters = null;
  95. this.genericType = genericReferenceType;
  96. this.typeKind = TypeKind.RAW;
  97. this.delegate = genericReferenceType.getDelegate();
  98. genericReferenceType.addDependentType(this);
  99. }
  100. private void addDependentType(ReferenceType dependent) {
  101. this.derivativeTypes.add(dependent);
  102. }
  103. public String getSignatureForAttribute() {
  104. if (genericType == null || typeParameters == null) return getSignature();
  105. return makeDeclaredSignature(genericType,typeParameters);
  106. }
  107. /**
  108. * Create a reference type for a generic type
  109. */
  110. public ReferenceType(UnresolvedType genericType, World world) {
  111. super(genericType.getSignature(),world);
  112. typeKind=TypeKind.GENERIC;
  113. }
  114. public boolean isClass() {
  115. return delegate.isClass();
  116. }
  117. public boolean isGenericType() {
  118. return !isParameterizedType() && !isRawType() && delegate.isGeneric();
  119. }
  120. public String getGenericSignature() {
  121. String sig = delegate.getDeclaredGenericSignature();
  122. return (sig == null) ? "" : sig;
  123. }
  124. public AnnotationX[] getAnnotations() {
  125. return delegate.getAnnotations();
  126. }
  127. public void addAnnotation(AnnotationX annotationX) {
  128. delegate.addAnnotation(annotationX);
  129. }
  130. public boolean hasAnnotation(UnresolvedType ofType) {
  131. return delegate.hasAnnotation(ofType);
  132. }
  133. public ResolvedType[] getAnnotationTypes() {
  134. return delegate.getAnnotationTypes();
  135. }
  136. public boolean isAspect() {
  137. return delegate.isAspect();
  138. }
  139. public boolean isAnnotationStyleAspect() {
  140. return delegate.isAnnotationStyleAspect();
  141. }
  142. public boolean isEnum() {
  143. return delegate.isEnum();
  144. }
  145. public boolean isAnnotation() {
  146. return delegate.isAnnotation();
  147. }
  148. public boolean isAnonymous() {
  149. return delegate.isAnonymous();
  150. }
  151. public boolean isNested() {
  152. return delegate.isNested();
  153. }
  154. public ResolvedType getOuterClass() {
  155. return delegate.getOuterClass();
  156. }
  157. public String getRetentionPolicy() {
  158. return delegate.getRetentionPolicy();
  159. }
  160. public boolean isAnnotationWithRuntimeRetention() {
  161. return delegate.isAnnotationWithRuntimeRetention();
  162. }
  163. public boolean canAnnotationTargetType() {
  164. return delegate.canAnnotationTargetType();
  165. }
  166. public AnnotationTargetKind[] getAnnotationTargetKinds() {
  167. return delegate.getAnnotationTargetKinds();
  168. }
  169. // true iff the statement "this = (ThisType) other" would compile
  170. public boolean isCoerceableFrom(ResolvedType o) {
  171. ResolvedType other = o.resolve(world);
  172. if (this.isAssignableFrom(other) || other.isAssignableFrom(this)) {
  173. return true;
  174. }
  175. if (this.isParameterizedType() && other.isParameterizedType()) {
  176. return isCoerceableFromParameterizedType(other);
  177. }
  178. if (!this.isInterface() && !other.isInterface()) {
  179. return false;
  180. }
  181. if (this.isFinal() || other.isFinal()) {
  182. return false;
  183. }
  184. // ??? needs to be Methods, not just declared methods? JLS 5.5 unclear
  185. ResolvedMember[] a = getDeclaredMethods();
  186. ResolvedMember[] b = other.getDeclaredMethods(); //??? is this cast always safe
  187. for (int ai = 0, alen = a.length; ai < alen; ai++) {
  188. for (int bi = 0, blen = b.length; bi < blen; bi++) {
  189. if (! b[bi].isCompatibleWith(a[ai])) return false;
  190. }
  191. }
  192. return true;
  193. }
  194. private final boolean isCoerceableFromParameterizedType(ResolvedType other) {
  195. if (!other.isParameterizedType()) return false;
  196. ResolvedType myRawType = (ResolvedType) getRawType();
  197. ResolvedType theirRawType = (ResolvedType) other.getRawType();
  198. if (myRawType == theirRawType) {
  199. if (getTypeParameters().length == other.getTypeParameters().length) {
  200. // there's a chance it can be done
  201. ResolvedType[] myTypeParameters = getResolvedTypeParameters();
  202. ResolvedType[] theirTypeParameters = other.getResolvedTypeParameters();
  203. for (int i = 0; i < myTypeParameters.length; i++) {
  204. if (myTypeParameters[i] != theirTypeParameters[i]) {
  205. // thin ice now... but List<String> may still be coerceable from e.g. List<T>
  206. if (myTypeParameters[i].isGenericWildcard()) {
  207. BoundedReferenceType wildcard = (BoundedReferenceType) myTypeParameters[i];
  208. if (!wildcard.canBeCoercedTo(theirTypeParameters[i])) return false;
  209. } else if (myTypeParameters[i].isTypeVariableReference()) {
  210. TypeVariableReferenceType tvrt = (TypeVariableReferenceType) myTypeParameters[i];
  211. TypeVariable tv = tvrt.getTypeVariable();
  212. tv.resolve(world);
  213. if (!tv.canBeBoundTo(theirTypeParameters[i])) return false;
  214. } else if (theirTypeParameters[i].isTypeVariableReference()) {
  215. TypeVariableReferenceType tvrt = (TypeVariableReferenceType) theirTypeParameters[i];
  216. TypeVariable tv = tvrt.getTypeVariable();
  217. tv.resolve(world);
  218. if (!tv.canBeBoundTo(myTypeParameters[i])) return false;
  219. } else {
  220. return false;
  221. }
  222. }
  223. }
  224. return true;
  225. }
  226. } else {
  227. // we do this walk for situations like the following:
  228. // Base<T>, Sub<S,T> extends Base<S>
  229. // is Sub<Y,Z> coerceable from Base<X> ???
  230. for(Iterator i = getDirectSupertypes(); i.hasNext(); ) {
  231. ReferenceType parent = (ReferenceType) i.next();
  232. if (parent.isCoerceableFromParameterizedType(other)) return true;
  233. }
  234. }
  235. return false;
  236. }
  237. public boolean isAssignableFrom(ResolvedType other) {
  238. return isAssignableFrom(other,false);
  239. }
  240. // true iff the statement "this = other" would compile.
  241. public boolean isAssignableFrom(ResolvedType other,boolean allowMissing) {
  242. if (other.isPrimitiveType()) {
  243. if (!world.isInJava5Mode()) return false;
  244. if (ResolvedType.validBoxing.contains(this.getSignature()+other.getSignature())) return true;
  245. }
  246. if (this == other) return true;
  247. if (this.getSignature().equals(ResolvedType.OBJECT.getSignature())) return true;
  248. if ((this.isRawType() || this.isGenericType()) && other.isParameterizedType()) {
  249. if (isAssignableFrom((ResolvedType)other.getRawType())) return true;
  250. }
  251. if (this.isRawType() && other.isGenericType()) {
  252. if (isAssignableFrom((ResolvedType)other.getRawType())) return true;
  253. }
  254. if (this.isGenericType() && other.isRawType()) {
  255. if (isAssignableFrom((ResolvedType)other.getGenericType())) return true;
  256. }
  257. if (this.isParameterizedType()) {
  258. // look at wildcards...
  259. if (((ReferenceType)this.getRawType()).isAssignableFrom(other)) {
  260. boolean wildcardsAllTheWay = true;
  261. ResolvedType[] myParameters = this.getResolvedTypeParameters();
  262. for (int i = 0; i < myParameters.length; i++) {
  263. if (!myParameters[i].isGenericWildcard()) {
  264. wildcardsAllTheWay = false;
  265. } else if (myParameters[i].isExtends() || myParameters[i].isSuper()) {
  266. wildcardsAllTheWay = false;
  267. }
  268. }
  269. if (wildcardsAllTheWay && !other.isParameterizedType()) return true;
  270. // we have to match by parameters one at a time
  271. ResolvedType[] theirParameters = other.getResolvedTypeParameters();
  272. boolean parametersAssignable = true;
  273. if (myParameters.length == theirParameters.length) {
  274. for (int i = 0; i < myParameters.length; i++) {
  275. if (myParameters[i] == theirParameters[i]) continue;
  276. if (myParameters[i].isAssignableFrom(theirParameters[i],allowMissing)) {
  277. continue;
  278. }
  279. if (!myParameters[i].isGenericWildcard()) {
  280. parametersAssignable = false;
  281. break;
  282. } else {
  283. BoundedReferenceType wildcardType = (BoundedReferenceType) myParameters[i];
  284. if (!wildcardType.alwaysMatches(theirParameters[i])) {
  285. parametersAssignable = false;
  286. break;
  287. }
  288. }
  289. }
  290. } else {
  291. parametersAssignable = false;
  292. }
  293. if (parametersAssignable) return true;
  294. }
  295. }
  296. if (isTypeVariableReference() && !other.isTypeVariableReference()) { // eg. this=T other=Ljava/lang/Object;
  297. TypeVariable aVar = ((TypeVariableReference)this).getTypeVariable();
  298. return aVar.resolve(world).canBeBoundTo(other);
  299. }
  300. if (other.isTypeVariableReference()) {
  301. TypeVariableReferenceType otherType = (TypeVariableReferenceType) other;
  302. if (this instanceof TypeVariableReference) {
  303. return ((TypeVariableReference)this).getTypeVariable().canBeBoundTo(otherType.getTypeVariable().getFirstBound().resolve(world));// pr171952
  304. // return ((TypeVariableReference)this).getTypeVariable()==otherType.getTypeVariable();
  305. } else {
  306. // FIXME asc should this say canBeBoundTo??
  307. return this.isAssignableFrom(otherType.getTypeVariable().getFirstBound().resolve(world));
  308. }
  309. }
  310. if (allowMissing && other.isMissing()) return false;
  311. for(Iterator i = other.getDirectSupertypes(); i.hasNext(); ) {
  312. if (this.isAssignableFrom((ResolvedType) i.next(),allowMissing)) return true;
  313. }
  314. return false;
  315. }
  316. public ISourceContext getSourceContext() {
  317. return delegate.getSourceContext();
  318. }
  319. public ISourceLocation getSourceLocation() {
  320. ISourceContext isc = delegate.getSourceContext();
  321. return isc.makeSourceLocation(new Position(startPos, endPos));
  322. }
  323. public boolean isExposedToWeaver() {
  324. return (delegate == null) || delegate.isExposedToWeaver(); //??? where does this belong
  325. }
  326. public WeaverStateInfo getWeaverState() {
  327. return delegate.getWeaverState();
  328. }
  329. public ResolvedMember[] getDeclaredFields() {
  330. if (parameterizedFields != null) return parameterizedFields;
  331. if (isParameterizedType() || isRawType()) {
  332. ResolvedMember[] delegateFields = delegate.getDeclaredFields();
  333. parameterizedFields = new ResolvedMember[delegateFields.length];
  334. for (int i = 0; i < delegateFields.length; i++) {
  335. parameterizedFields[i] =
  336. delegateFields[i].parameterizedWith(getTypesForMemberParameterization(),this, isParameterizedType());
  337. }
  338. return parameterizedFields;
  339. } else {
  340. return delegate.getDeclaredFields();
  341. }
  342. }
  343. /**
  344. * Find out from the generic signature the true signature of any interfaces
  345. * I implement. If I am parameterized, these may then need to be parameterized
  346. * before returning.
  347. */
  348. public ResolvedType[] getDeclaredInterfaces() {
  349. if (parameterizedInterfaces != null) return parameterizedInterfaces;
  350. if (isParameterizedType()) {
  351. ResolvedType[] delegateInterfaces = delegate.getDeclaredInterfaces();
  352. UnresolvedType[] paramTypes = getTypesForMemberParameterization();
  353. parameterizedInterfaces = new ResolvedType[delegateInterfaces.length];
  354. for (int i = 0; i < delegateInterfaces.length; i++) {
  355. // We may have to sub/super set the set of parametertypes if the implemented interface
  356. // needs more or less than this type does. (pr124803/pr125080)
  357. if (delegateInterfaces[i].isParameterizedType()) {
  358. parameterizedInterfaces[i] = delegateInterfaces[i].parameterize(getMemberParameterizationMap()).resolve(world);
  359. } else {
  360. parameterizedInterfaces[i] = delegateInterfaces[i];
  361. }
  362. }
  363. return parameterizedInterfaces;
  364. } else if (isRawType()){
  365. ResolvedType[] delegateInterfaces = delegate.getDeclaredInterfaces();
  366. UnresolvedType[] paramTypes = getTypesForMemberParameterization();
  367. parameterizedInterfaces = new ResolvedType[delegateInterfaces.length];
  368. for (int i = 0; i < parameterizedInterfaces.length; i++) {
  369. parameterizedInterfaces[i] = delegateInterfaces[i];
  370. if (parameterizedInterfaces[i].isGenericType()) {
  371. // a generic supertype of a raw type is replaced by its raw equivalent
  372. parameterizedInterfaces[i] =
  373. parameterizedInterfaces[i].getRawType().resolve(getWorld());
  374. } else if (parameterizedInterfaces[i].isParameterizedType()) {
  375. // a parameterized supertype collapses any type vars to their upper bounds
  376. UnresolvedType[] toUseForParameterization = determineThoseTypesToUse(parameterizedInterfaces[i],paramTypes);
  377. parameterizedInterfaces[i] = parameterizedInterfaces[i].parameterizedWith(toUseForParameterization);
  378. }
  379. }
  380. return parameterizedInterfaces;
  381. }
  382. return delegate.getDeclaredInterfaces();
  383. }
  384. /**
  385. * Locates the named type variable in the list of those on this generic type and returns
  386. * the type parameter from the second list supplied. Returns null if it can't be found
  387. */
  388. private UnresolvedType findTypeParameterInList(String name, TypeVariable[] tvarsOnThisGenericType, UnresolvedType[] paramTypes) {
  389. int position = -1;
  390. for (int i = 0; i < tvarsOnThisGenericType.length; i++) {
  391. TypeVariable tv = tvarsOnThisGenericType[i];
  392. if (tv.getName().equals(name)) position = i;
  393. }
  394. if (position == -1 ) return null;
  395. return paramTypes[position];
  396. }
  397. /**
  398. * It is possible this type has multiple type variables but the interface we are about to parameterize
  399. * only uses a subset - this method determines the subset to use by looking at the type variable names
  400. * used. For example:
  401. * <code>
  402. * class Foo<T extends String,E extends Number> implements SuperInterface<T> {}
  403. * </code>
  404. * where
  405. * <code>
  406. * interface SuperInterface<Z> {}
  407. * </code>
  408. * In that example, a use of the 'Foo' raw type should know that it implements
  409. * the SuperInterface<String>.
  410. */
  411. private UnresolvedType[] determineThoseTypesToUse(ResolvedType parameterizedInterface,UnresolvedType[] paramTypes) {
  412. // What are the type parameters for the supertype?
  413. UnresolvedType[] tParms = parameterizedInterface.getTypeParameters();
  414. UnresolvedType[] retVal = new UnresolvedType[tParms.length];
  415. // Go through the supertypes type parameters, if any of them is a type variable, use the
  416. // real type variable on the declaring type.
  417. // it is possibly overkill to look up the type variable - ideally the entry in the type parameter list for the
  418. // interface should be the a ref to the type variable in the current type ... but I'm not 100% confident right now.
  419. for (int i = 0; i < tParms.length; i++) {
  420. UnresolvedType tParm = tParms[i];
  421. if (tParm.isTypeVariableReference()) {
  422. TypeVariableReference tvrt = (TypeVariableReference)tParm;
  423. TypeVariable tv = tvrt.getTypeVariable();
  424. int rank = getRank(tv.getName());
  425. // -1 probably means it is a reference to a type variable on the outer generic type (see pr129566)
  426. if (rank!=-1) {
  427. retVal[i] = paramTypes[rank];
  428. } else {
  429. retVal[i] = tParms[i];
  430. }
  431. } else {
  432. retVal[i] = tParms[i];
  433. }
  434. }
  435. return retVal;
  436. }
  437. /**
  438. * Returns the position within the set of type variables for this type for the specified type variable name.
  439. * Returns -1 if there is no type variable with the specified name.
  440. */
  441. private int getRank(String tvname) {
  442. TypeVariable[] thisTypesTVars = getGenericType().getTypeVariables();
  443. for (int i = 0; i < thisTypesTVars.length; i++) {
  444. TypeVariable tv = thisTypesTVars[i];
  445. if (tv.getName().equals(tvname)) return i;
  446. }
  447. return -1;
  448. }
  449. public ResolvedMember[] getDeclaredMethods() {
  450. if (parameterizedMethods != null) return parameterizedMethods;
  451. if (isParameterizedType() || isRawType()) {
  452. ResolvedMember[] delegateMethods = delegate.getDeclaredMethods();
  453. UnresolvedType[] parameters = getTypesForMemberParameterization();
  454. parameterizedMethods = new ResolvedMember[delegateMethods.length];
  455. for (int i = 0; i < delegateMethods.length; i++) {
  456. parameterizedMethods[i] = delegateMethods[i].parameterizedWith(parameters,this,isParameterizedType());
  457. }
  458. return parameterizedMethods;
  459. } else {
  460. return delegate.getDeclaredMethods();
  461. }
  462. }
  463. public ResolvedMember[] getDeclaredPointcuts() {
  464. if (parameterizedPointcuts != null) return parameterizedPointcuts;
  465. if (isParameterizedType()) {
  466. ResolvedMember[] delegatePointcuts = delegate.getDeclaredPointcuts();
  467. parameterizedPointcuts = new ResolvedMember[delegatePointcuts.length];
  468. for (int i = 0; i < delegatePointcuts.length; i++) {
  469. parameterizedPointcuts[i] = delegatePointcuts[i].parameterizedWith(getTypesForMemberParameterization(),this,isParameterizedType());
  470. }
  471. return parameterizedPointcuts;
  472. } else {
  473. return delegate.getDeclaredPointcuts();
  474. }
  475. }
  476. private UnresolvedType[] getTypesForMemberParameterization() {
  477. UnresolvedType[] parameters = null;
  478. if (isParameterizedType()) {
  479. parameters = getTypeParameters();
  480. } else if (isRawType()){
  481. // raw type, use upper bounds of type variables on generic type
  482. TypeVariable[] tvs = getGenericType().getTypeVariables();
  483. parameters = new UnresolvedType[tvs.length];
  484. for (int i = 0; i < tvs.length; i++) {
  485. parameters[i] = tvs[i].getFirstBound();
  486. }
  487. }
  488. return parameters;
  489. }
  490. public UnresolvedType getRawType() {
  491. return super.getRawType().resolve(getWorld());
  492. }
  493. public TypeVariable[] getTypeVariables() {
  494. if (this.typeVariables == null) {
  495. this.typeVariables = delegate.getTypeVariables();
  496. for (int i = 0; i < this.typeVariables.length; i++) {
  497. this.typeVariables[i].resolve(world);
  498. }
  499. }
  500. return this.typeVariables;
  501. }
  502. public PerClause getPerClause() {
  503. PerClause pclause = delegate.getPerClause();
  504. if (isParameterizedType()) { // could cache the result here...
  505. Map parameterizationMap = getAjMemberParameterizationMap();
  506. pclause = (PerClause)pclause.parameterizeWith(parameterizationMap,world);
  507. }
  508. return pclause;
  509. }
  510. protected Collection getDeclares() {
  511. if (parameterizedDeclares != null) return parameterizedDeclares;
  512. Collection declares = null;
  513. if (ajMembersNeedParameterization()) {
  514. Collection genericDeclares = delegate.getDeclares();
  515. parameterizedDeclares = new ArrayList();
  516. Map parameterizationMap = getAjMemberParameterizationMap();
  517. for (Iterator iter = genericDeclares.iterator(); iter.hasNext();) {
  518. Declare declareStatement = (Declare) iter.next();
  519. parameterizedDeclares.add(declareStatement.parameterizeWith(parameterizationMap,world));
  520. }
  521. declares = parameterizedDeclares;
  522. } else {
  523. declares = delegate.getDeclares();
  524. }
  525. for (Iterator iter = declares.iterator(); iter.hasNext();) {
  526. Declare d = (Declare) iter.next();
  527. d.setDeclaringType(this);
  528. }
  529. return declares;
  530. }
  531. protected Collection getTypeMungers() {
  532. return delegate.getTypeMungers();
  533. }
  534. // GENERICITDFIX
  535. //// Map parameterizationMap = getAjMemberParameterizationMap();
  536. //
  537. // // if (parameterizedTypeMungers != null) return parameterizedTypeMungers;
  538. // Collection ret = null;
  539. // if (ajMembersNeedParameterization()) {
  540. // Collection genericDeclares = delegate.getTypeMungers();
  541. // parameterizedTypeMungers = new ArrayList();
  542. // Map parameterizationMap = getAjMemberParameterizationMap();
  543. // for (Iterator iter = genericDeclares.iterator(); iter.hasNext();) {
  544. // ConcreteTypeMunger munger = (ConcreteTypeMunger)iter.next();
  545. // parameterizedTypeMungers.add(munger.parameterizeWith(parameterizationMap,world));
  546. // }
  547. // ret = parameterizedTypeMungers;
  548. // } else {
  549. // ret = delegate.getTypeMungers();
  550. // }
  551. // return ret;
  552. // }
  553. protected Collection getPrivilegedAccesses() { return delegate.getPrivilegedAccesses(); }
  554. public int getModifiers() {
  555. return delegate.getModifiers();
  556. }
  557. public ResolvedType getSuperclass() {
  558. ResolvedType ret = delegate.getSuperclass();
  559. if (this.isParameterizedType() && ret.isParameterizedType()) {
  560. ret = ret.parameterize(getMemberParameterizationMap()).resolve(getWorld());
  561. }
  562. return ret;
  563. }
  564. public ReferenceTypeDelegate getDelegate() {
  565. return delegate;
  566. }
  567. public void setDelegate(ReferenceTypeDelegate delegate) {
  568. // Don't copy from BcelObjectType to EclipseSourceType - the context may be tidied (result null'd) after previous weaving
  569. if (this.delegate!=null && !(this.delegate instanceof BcelObjectType) && this.delegate.getSourceContext()!=SourceContextImpl.UNKNOWN_SOURCE_CONTEXT)
  570. ((AbstractReferenceTypeDelegate)delegate).setSourceContext(this.delegate.getSourceContext());
  571. this.delegate = delegate;
  572. for(Iterator it = this.derivativeTypes.iterator(); it.hasNext(); ) {
  573. ReferenceType dependent = (ReferenceType) it.next();
  574. dependent.setDelegate(delegate);
  575. }
  576. // If we are raw, we have a generic type - we should ensure it uses the
  577. // same delegate
  578. if (isRawType() && getGenericType()!=null ) {
  579. ReferenceType genType = (ReferenceType) getGenericType();
  580. if (genType.getDelegate() != delegate) { // avoids circular updates
  581. genType.setDelegate(delegate);
  582. }
  583. }
  584. clearParameterizationCaches();
  585. }
  586. private void clearParameterizationCaches() {
  587. parameterizedFields = null;
  588. parameterizedInterfaces = null;
  589. parameterizedMethods = null;
  590. parameterizedPointcuts = null;
  591. }
  592. public int getEndPos() {
  593. return endPos;
  594. }
  595. public int getStartPos() {
  596. return startPos;
  597. }
  598. public void setEndPos(int endPos) {
  599. this.endPos = endPos;
  600. }
  601. public void setStartPos(int startPos) {
  602. this.startPos = startPos;
  603. }
  604. public boolean doesNotExposeShadowMungers() {
  605. return delegate.doesNotExposeShadowMungers();
  606. }
  607. public String getDeclaredGenericSignature() {
  608. return delegate.getDeclaredGenericSignature();
  609. }
  610. public void setGenericType(ReferenceType rt) {
  611. genericType = rt;
  612. // Should we 'promote' this reference type from simple to raw?
  613. // makes sense if someone is specifying that it has a generic form
  614. if ( typeKind == TypeKind.SIMPLE ) {
  615. typeKind = TypeKind.RAW;
  616. signatureErasure = signature;
  617. }
  618. }
  619. public void demoteToSimpleType() {
  620. genericType = null;
  621. typeKind = TypeKind.SIMPLE;
  622. signatureErasure = null;
  623. }
  624. public ResolvedType getGenericType() {
  625. if (isGenericType()) return this;
  626. return genericType;
  627. }
  628. /**
  629. * a parameterized signature starts with a "P" in place of the "L",
  630. * see the comment on signatures in UnresolvedType.
  631. * @param aGenericType
  632. * @param someParameters
  633. * @return
  634. */
  635. private static String makeParameterizedSignature(ResolvedType aGenericType, ResolvedType[] someParameters) {
  636. String rawSignature = aGenericType.getErasureSignature();
  637. String prefix = PARAMETERIZED_TYPE_IDENTIFIER + rawSignature.substring(1,rawSignature.length()-1);
  638. StringBuffer ret = new StringBuffer();
  639. ret.append(prefix);
  640. ret.append("<");
  641. for (int i = 0; i < someParameters.length; i++) {
  642. ret.append(someParameters[i].getSignature());
  643. }
  644. ret.append(">;");
  645. return ret.toString();
  646. }
  647. private static String makeDeclaredSignature(ResolvedType aGenericType, UnresolvedType[] someParameters) {
  648. StringBuffer ret = new StringBuffer();
  649. String rawSig = aGenericType.getErasureSignature();
  650. ret.append(rawSig.substring(0,rawSig.length()-1));
  651. ret.append("<");
  652. for (int i = 0; i < someParameters.length; i++) {
  653. ret.append(((ReferenceType)someParameters[i]).getSignatureForAttribute());
  654. }
  655. ret.append(">;");
  656. return ret.toString();
  657. }
  658. }