選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ReferenceType.java 26KB

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