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.

ResolvedType.java 100KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933
  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. * Alexandre Vasseur @AspectJ ITDs
  12. * ******************************************************************/
  13. package org.aspectj.weaver;
  14. import java.lang.reflect.Modifier;
  15. import java.util.ArrayList;
  16. import java.util.Arrays;
  17. import java.util.Collection;
  18. import java.util.Collections;
  19. import java.util.HashMap;
  20. import java.util.HashSet;
  21. import java.util.Iterator;
  22. import java.util.LinkedList;
  23. import java.util.List;
  24. import java.util.Map;
  25. import java.util.Queue;
  26. import java.util.Set;
  27. import org.aspectj.bridge.IMessage;
  28. import org.aspectj.bridge.ISourceLocation;
  29. import org.aspectj.bridge.Message;
  30. import org.aspectj.bridge.MessageUtil;
  31. import org.aspectj.util.FuzzyBoolean;
  32. import org.aspectj.weaver.AjAttribute.WeaverVersionInfo;
  33. import org.aspectj.weaver.Iterators.Getter;
  34. import org.aspectj.weaver.patterns.Declare;
  35. import org.aspectj.weaver.patterns.PerClause;
  36. public abstract class ResolvedType extends UnresolvedType implements AnnotatedElement {
  37. public static final ResolvedType[] EMPTY_RESOLVED_TYPE_ARRAY = new ResolvedType[0];
  38. public static final String PARAMETERIZED_TYPE_IDENTIFIER = "P";
  39. // Set temporarily during a type pattern match call - this currently used to hold the
  40. // annotations that may be attached to a type when it used as a parameter
  41. public ResolvedType[] temporaryAnnotationTypes;
  42. private ResolvedType[] resolvedTypeParams;
  43. private String binaryPath;
  44. protected World world;
  45. protected int bits;
  46. private static int AnnotationBitsInitialized = 0x0001;
  47. private static int AnnotationMarkedInherited = 0x0002;
  48. private static int MungersAnalyzed = 0x0004;
  49. private static int HasParentMunger = 0x0008;
  50. private static int TypeHierarchyCompleteBit = 0x0010;
  51. private static int GroovyObjectInitialized = 0x0020;
  52. private static int IsGroovyObject = 0x0040;
  53. private static int IsPrivilegedBitInitialized = 0x0080;
  54. private static int IsPrivilegedAspect = 0x0100;
  55. protected ResolvedType(String signature, World world) {
  56. super(signature);
  57. this.world = world;
  58. }
  59. protected ResolvedType(String signature, String signatureErasure, World world) {
  60. super(signature, signatureErasure);
  61. this.world = world;
  62. }
  63. @Override
  64. public int getSize() {
  65. return 1;
  66. }
  67. /**
  68. * Returns an iterator through ResolvedType objects representing all the direct supertypes of this type. That is, through the
  69. * superclass, if any, and all declared interfaces.
  70. */
  71. public final Iterator<ResolvedType> getDirectSupertypes() {
  72. Iterator<ResolvedType> interfacesIterator = Iterators.array(getDeclaredInterfaces());
  73. ResolvedType superclass = getSuperclass();
  74. if (superclass == null) {
  75. return interfacesIterator;
  76. } else {
  77. return Iterators.snoc(interfacesIterator, superclass);
  78. }
  79. }
  80. public abstract ResolvedMember[] getDeclaredFields();
  81. public abstract ResolvedMember[] getDeclaredMethods();
  82. public abstract ResolvedType[] getDeclaredInterfaces();
  83. public abstract ResolvedMember[] getDeclaredPointcuts();
  84. public boolean isCacheable() {
  85. return true;
  86. }
  87. /**
  88. * @return the superclass of this type, or null (if this represents a jlObject, primitive, or void)
  89. */
  90. public abstract ResolvedType getSuperclass();
  91. public abstract int getModifiers();
  92. public boolean canBeSeenBy(ResolvedType from) {
  93. int targetMods = getModifiers();
  94. if (Modifier.isPublic(targetMods)) {
  95. return true;
  96. }
  97. if (Modifier.isPrivate(targetMods)) {
  98. return false;
  99. }
  100. // isProtected() or isDefault()
  101. return getPackageName().equals(from.getPackageName());
  102. }
  103. // return true if this resolved type couldn't be found (but we know it's name maybe)
  104. public boolean isMissing() {
  105. return false;
  106. }
  107. // FIXME asc I wonder if in some circumstances MissingWithKnownSignature
  108. // should not be considered
  109. // 'really' missing as some code can continue based solely on the signature
  110. public static boolean isMissing(UnresolvedType unresolved) {
  111. if (unresolved instanceof ResolvedType) {
  112. ResolvedType resolved = (ResolvedType) unresolved;
  113. return resolved.isMissing();
  114. } else {
  115. return (unresolved == MISSING);
  116. }
  117. }
  118. @Override
  119. public ResolvedType[] getAnnotationTypes() {
  120. return EMPTY_RESOLVED_TYPE_ARRAY;
  121. }
  122. @Override
  123. public AnnotationAJ getAnnotationOfType(UnresolvedType ofType) {
  124. return null;
  125. }
  126. // public final UnresolvedType getSuperclass(World world) {
  127. // return getSuperclass();
  128. // }
  129. // This set contains pairs of types whose signatures are concatenated
  130. // together, this means with a fast lookup we can tell if two types
  131. // are equivalent.
  132. protected static Set<String> validBoxing = new HashSet<String>();
  133. static {
  134. validBoxing.add("Ljava/lang/Byte;B");
  135. validBoxing.add("Ljava/lang/Character;C");
  136. validBoxing.add("Ljava/lang/Double;D");
  137. validBoxing.add("Ljava/lang/Float;F");
  138. validBoxing.add("Ljava/lang/Integer;I");
  139. validBoxing.add("Ljava/lang/Long;J");
  140. validBoxing.add("Ljava/lang/Short;S");
  141. validBoxing.add("Ljava/lang/Boolean;Z");
  142. validBoxing.add("BLjava/lang/Byte;");
  143. validBoxing.add("CLjava/lang/Character;");
  144. validBoxing.add("DLjava/lang/Double;");
  145. validBoxing.add("FLjava/lang/Float;");
  146. validBoxing.add("ILjava/lang/Integer;");
  147. validBoxing.add("JLjava/lang/Long;");
  148. validBoxing.add("SLjava/lang/Short;");
  149. validBoxing.add("ZLjava/lang/Boolean;");
  150. }
  151. // utilities
  152. public ResolvedType getResolvedComponentType() {
  153. return null;
  154. }
  155. public World getWorld() {
  156. return world;
  157. }
  158. // ---- things from object
  159. @Override
  160. public boolean equals(Object other) {
  161. if (other instanceof ResolvedType) {
  162. return this == other;
  163. } else {
  164. return super.equals(other);
  165. }
  166. }
  167. // ---- difficult things
  168. /**
  169. * returns an iterator through all of the fields of this type, in order for checking from JVM spec 2ed 5.4.3.2. This means that
  170. * the order is
  171. * <p/>
  172. * <ul>
  173. * <li>fields from current class</li>
  174. * <li>recur into direct superinterfaces</li>
  175. * <li>recur into superclass</li>
  176. * </ul>
  177. * <p/>
  178. * We keep a hashSet of interfaces that we've visited so we don't spiral out into 2^n land.
  179. */
  180. public Iterator<ResolvedMember> getFields() {
  181. final Iterators.Filter<ResolvedType> dupFilter = Iterators.dupFilter();
  182. Iterators.Getter<ResolvedType, ResolvedType> typeGetter = new Iterators.Getter<ResolvedType, ResolvedType>() {
  183. @Override
  184. public Iterator<ResolvedType> get(ResolvedType o) {
  185. return dupFilter.filter(o.getDirectSupertypes());
  186. }
  187. };
  188. return Iterators.mapOver(Iterators.recur(this, typeGetter), FieldGetterInstance);
  189. }
  190. /**
  191. * returns an iterator through all of the methods of this type, in order for checking from JVM spec 2ed 5.4.3.3. This means that
  192. * the order is
  193. * <p/>
  194. * <ul>
  195. * <li>methods from current class</li>
  196. * <li>recur into superclass, all the way up, not touching interfaces</li>
  197. * <li>recur into all superinterfaces, in some unspecified order (but those 'closest' to this type are first)</li>
  198. * </ul>
  199. * <p/>
  200. *
  201. * @param wantGenerics is true if the caller would like all generics information, otherwise those methods are collapsed to their
  202. * erasure
  203. */
  204. public Iterator<ResolvedMember> getMethods(boolean wantGenerics, boolean wantDeclaredParents) {
  205. return Iterators.mapOver(getHierarchy(wantGenerics, wantDeclaredParents), MethodGetterInstance);
  206. }
  207. public Iterator<ResolvedMember> getMethodsIncludingIntertypeDeclarations(boolean wantGenerics, boolean wantDeclaredParents) {
  208. return Iterators.mapOver(getHierarchy(wantGenerics, wantDeclaredParents), MethodGetterWithItdsInstance);
  209. }
  210. /**
  211. * An Iterators.Getter that returns an iterator over all methods declared on some resolved type.
  212. */
  213. private static class MethodGetter implements Iterators.Getter<ResolvedType, ResolvedMember> {
  214. @Override
  215. public Iterator<ResolvedMember> get(ResolvedType type) {
  216. return Iterators.array(type.getDeclaredMethods());
  217. }
  218. }
  219. /**
  220. * An Iterators.Getter that returns an iterator over all pointcuts declared on some resolved type.
  221. */
  222. private static class PointcutGetter implements Iterators.Getter<ResolvedType, ResolvedMember> {
  223. @Override
  224. public Iterator<ResolvedMember> get(ResolvedType o) {
  225. return Iterators.array(o.getDeclaredPointcuts());
  226. }
  227. }
  228. // OPTIMIZE could cache the result of discovering ITDs
  229. // Getter that returns all declared methods for a type through an iterator - including intertype declarations
  230. private static class MethodGetterIncludingItds implements Iterators.Getter<ResolvedType, ResolvedMember> {
  231. @Override
  232. public Iterator<ResolvedMember> get(ResolvedType type) {
  233. ResolvedMember[] methods = type.getDeclaredMethods();
  234. if (type.interTypeMungers != null) {
  235. int additional = 0;
  236. for (ConcreteTypeMunger typeTransformer : type.interTypeMungers) {
  237. ResolvedMember rm = typeTransformer.getSignature();
  238. // BUG won't this include fields? When we are looking for methods
  239. if (rm != null) { // new parent type munger can have null signature
  240. additional++;
  241. }
  242. }
  243. if (additional > 0) {
  244. ResolvedMember[] methods2 = new ResolvedMember[methods.length + additional];
  245. System.arraycopy(methods, 0, methods2, 0, methods.length);
  246. additional = methods.length;
  247. for (ConcreteTypeMunger typeTransformer : type.interTypeMungers) {
  248. ResolvedMember rm = typeTransformer.getSignature();
  249. if (rm != null) { // new parent type munger can have null signature
  250. methods2[additional++] = typeTransformer.getSignature();
  251. }
  252. }
  253. methods = methods2;
  254. }
  255. }
  256. return Iterators.array(methods);
  257. }
  258. }
  259. /**
  260. * An Iterators.Getter that returns an iterator over all fields declared on some resolved type.
  261. */
  262. private static class FieldGetter implements Iterators.Getter<ResolvedType, ResolvedMember> {
  263. @Override
  264. public Iterator<ResolvedMember> get(ResolvedType type) {
  265. return Iterators.array(type.getDeclaredFields());
  266. }
  267. }
  268. private final static MethodGetter MethodGetterInstance = new MethodGetter();
  269. private final static MethodGetterIncludingItds MethodGetterWithItdsInstance = new MethodGetterIncludingItds();
  270. private final static PointcutGetter PointcutGetterInstance = new PointcutGetter();
  271. private final static FieldGetter FieldGetterInstance = new FieldGetter();
  272. /**
  273. * Return an iterator over the types in this types hierarchy - starting with this type first, then all superclasses up to Object
  274. * and then all interfaces (starting with those 'nearest' this type).
  275. *
  276. * @param wantGenerics true if the caller wants full generic information
  277. * @param wantDeclaredParents true if the caller even wants those parents introduced via declare parents
  278. * @return an iterator over all types in the hierarchy of this type
  279. */
  280. public Iterator<ResolvedType> getHierarchy() {
  281. return getHierarchy(false, false);
  282. }
  283. public Iterator<ResolvedType> getHierarchy(final boolean wantGenerics, final boolean wantDeclaredParents) {
  284. final Iterators.Getter<ResolvedType, ResolvedType> interfaceGetter = new Iterators.Getter<ResolvedType, ResolvedType>() {
  285. List<String> alreadySeen = new ArrayList<String>(); // Strings are signatures (ResolvedType.getSignature())
  286. @Override
  287. public Iterator<ResolvedType> get(ResolvedType type) {
  288. ResolvedType[] interfaces = type.getDeclaredInterfaces();
  289. // remove interfaces introduced by declare parents
  290. // relatively expensive but hopefully uncommon
  291. if (!wantDeclaredParents && type.hasNewParentMungers()) {
  292. // Throw away interfaces from that array if they were decp'd onto here
  293. List<Integer> forRemoval = new ArrayList<Integer>();
  294. for (ConcreteTypeMunger munger : type.interTypeMungers) {
  295. if (munger.getMunger() != null) {
  296. ResolvedTypeMunger m = munger.getMunger();
  297. if (m.getKind() == ResolvedTypeMunger.Parent) {
  298. ResolvedType newType = ((NewParentTypeMunger) m).getNewParent();
  299. if (!wantGenerics && newType.isParameterizedOrGenericType()) {
  300. newType = newType.getRawType();
  301. }
  302. for (int ii = 0; ii < interfaces.length; ii++) {
  303. ResolvedType iface = interfaces[ii];
  304. if (!wantGenerics && iface.isParameterizedOrGenericType()) {
  305. iface = iface.getRawType();
  306. }
  307. if (newType.getSignature().equals(iface.getSignature())) { // pr171953
  308. forRemoval.add(ii);
  309. }
  310. }
  311. }
  312. }
  313. }
  314. // Found some to remove from those we are going to iterate over
  315. if (forRemoval.size() > 0) {
  316. ResolvedType[] interfaces2 = new ResolvedType[interfaces.length - forRemoval.size()];
  317. int p = 0;
  318. for (int ii = 0; ii < interfaces.length; ii++) {
  319. if (!forRemoval.contains(ii)) {
  320. interfaces2[p++] = interfaces[ii];
  321. }
  322. }
  323. interfaces = interfaces2;
  324. }
  325. }
  326. return new Iterators.ResolvedTypeArrayIterator(interfaces, alreadySeen, wantGenerics);
  327. }
  328. };
  329. // If this type is an interface, there are only interfaces to walk
  330. if (this.isInterface()) {
  331. return new SuperInterfaceWalker(interfaceGetter, this);
  332. } else {
  333. SuperInterfaceWalker superInterfaceWalker = new SuperInterfaceWalker(interfaceGetter);
  334. Iterator<ResolvedType> superClassesIterator = new SuperClassWalker(this, superInterfaceWalker, wantGenerics);
  335. // append() will check if the second iterator is empty before appending - but the types which the superInterfaceWalker
  336. // needs to visit are only accumulated whilst the superClassesIterator is in progress
  337. return Iterators.append1(superClassesIterator, superInterfaceWalker);
  338. }
  339. }
  340. /**
  341. * Return a list of methods, first those declared on this class, then those declared on the superclass (recurse) and then those
  342. * declared on the superinterfaces. This is expensive - use the getMethods() method if you can!
  343. */
  344. public List<ResolvedMember> getMethodsWithoutIterator(boolean includeITDs, boolean allowMissing, boolean genericsAware) {
  345. List<ResolvedMember> methods = new ArrayList<ResolvedMember>();
  346. Set<String> knowninterfaces = new HashSet<String>();
  347. addAndRecurse(knowninterfaces, methods, this, includeITDs, allowMissing, genericsAware);
  348. return methods;
  349. }
  350. /**
  351. * Return a list of the types in the hierarchy of this type, starting with this type. The order in the list is the superclasses
  352. * followed by the super interfaces.
  353. *
  354. * @param genericsAware should the list include parameterized/generic types (if not, they will be collapsed to raw)?
  355. * @return list of resolvedtypes in this types hierarchy, including this type first
  356. */
  357. public List<ResolvedType> getHierarchyWithoutIterator(boolean includeITDs, boolean allowMissing, boolean genericsAware) {
  358. List<ResolvedType> types = new ArrayList<ResolvedType>();
  359. Set<String> visited = new HashSet<String>();
  360. recurseHierarchy(visited, types, this, includeITDs, allowMissing, genericsAware);
  361. return types;
  362. }
  363. private void addAndRecurse(Set<String> knowninterfaces, List<ResolvedMember> collector, ResolvedType resolvedType,
  364. boolean includeITDs, boolean allowMissing, boolean genericsAware) {
  365. // Add the methods declared on this type
  366. collector.addAll(Arrays.asList(resolvedType.getDeclaredMethods()));
  367. // now add all the inter-typed members too
  368. if (includeITDs && resolvedType.interTypeMungers != null) {
  369. for (ConcreteTypeMunger typeTransformer : interTypeMungers) {
  370. ResolvedMember rm = typeTransformer.getSignature();
  371. if (rm != null) { // new parent type munger can have null signature
  372. collector.add(typeTransformer.getSignature());
  373. }
  374. }
  375. }
  376. // BUG? interface type superclass is Object - is that correct?
  377. if (!resolvedType.isInterface() && !resolvedType.equals(ResolvedType.OBJECT)) {
  378. ResolvedType superType = resolvedType.getSuperclass();
  379. if (superType != null && !superType.isMissing()) {
  380. if (!genericsAware && superType.isParameterizedOrGenericType()) {
  381. superType = superType.getRawType();
  382. }
  383. // Recurse if we are not at the top
  384. addAndRecurse(knowninterfaces, collector, superType, includeITDs, allowMissing, genericsAware);
  385. }
  386. }
  387. // Go through the interfaces on the way back down
  388. ResolvedType[] interfaces = resolvedType.getDeclaredInterfaces();
  389. for (int i = 0; i < interfaces.length; i++) {
  390. ResolvedType iface = interfaces[i];
  391. if (!genericsAware && iface.isParameterizedOrGenericType()) {
  392. iface = iface.getRawType();
  393. }
  394. // we need to know if it is an interface from Parent kind munger
  395. // as those are used for @AJ ITD and we precisely want to skip those
  396. boolean shouldSkip = false;
  397. for (int j = 0; j < resolvedType.interTypeMungers.size(); j++) {
  398. ConcreteTypeMunger munger = resolvedType.interTypeMungers.get(j);
  399. if (munger.getMunger() != null && munger.getMunger().getKind() == ResolvedTypeMunger.Parent
  400. && ((NewParentTypeMunger) munger.getMunger()).getNewParent().equals(iface) // pr171953
  401. ) {
  402. shouldSkip = true;
  403. break;
  404. }
  405. }
  406. // Do not do interfaces more than once
  407. if (!shouldSkip && !knowninterfaces.contains(iface.getSignature())) {
  408. knowninterfaces.add(iface.getSignature());
  409. if (allowMissing && iface.isMissing()) {
  410. if (iface instanceof MissingResolvedTypeWithKnownSignature) {
  411. ((MissingResolvedTypeWithKnownSignature) iface).raiseWarningOnMissingInterfaceWhilstFindingMethods();
  412. }
  413. } else {
  414. addAndRecurse(knowninterfaces, collector, iface, includeITDs, allowMissing, genericsAware);
  415. }
  416. }
  417. }
  418. }
  419. /**
  420. * Recurse up a type hierarchy, first the superclasses then the super interfaces.
  421. */
  422. private void recurseHierarchy(Set<String> knowninterfaces, List<ResolvedType> collector, ResolvedType resolvedType,
  423. boolean includeITDs, boolean allowMissing, boolean genericsAware) {
  424. collector.add(resolvedType);
  425. if (!resolvedType.isInterface() && !resolvedType.equals(ResolvedType.OBJECT)) {
  426. ResolvedType superType = resolvedType.getSuperclass();
  427. if (superType != null && !superType.isMissing()) {
  428. if (!genericsAware && (superType.isParameterizedType() || superType.isGenericType())) {
  429. superType = superType.getRawType();
  430. }
  431. // Recurse if we are not at the top
  432. recurseHierarchy(knowninterfaces, collector, superType, includeITDs, allowMissing, genericsAware);
  433. }
  434. }
  435. // Go through the interfaces on the way back down
  436. ResolvedType[] interfaces = resolvedType.getDeclaredInterfaces();
  437. for (int i = 0; i < interfaces.length; i++) {
  438. ResolvedType iface = interfaces[i];
  439. if (!genericsAware && (iface.isParameterizedType() || iface.isGenericType())) {
  440. iface = iface.getRawType();
  441. }
  442. // we need to know if it is an interface from Parent kind munger
  443. // as those are used for @AJ ITD and we precisely want to skip those
  444. boolean shouldSkip = false;
  445. for (int j = 0; j < resolvedType.interTypeMungers.size(); j++) {
  446. ConcreteTypeMunger munger = resolvedType.interTypeMungers.get(j);
  447. if (munger.getMunger() != null && munger.getMunger().getKind() == ResolvedTypeMunger.Parent
  448. && ((NewParentTypeMunger) munger.getMunger()).getNewParent().equals(iface) // pr171953
  449. ) {
  450. shouldSkip = true;
  451. break;
  452. }
  453. }
  454. // Do not do interfaces more than once
  455. if (!shouldSkip && !knowninterfaces.contains(iface.getSignature())) {
  456. knowninterfaces.add(iface.getSignature());
  457. if (allowMissing && iface.isMissing()) {
  458. if (iface instanceof MissingResolvedTypeWithKnownSignature) {
  459. ((MissingResolvedTypeWithKnownSignature) iface).raiseWarningOnMissingInterfaceWhilstFindingMethods();
  460. }
  461. } else {
  462. recurseHierarchy(knowninterfaces, collector, iface, includeITDs, allowMissing, genericsAware);
  463. }
  464. }
  465. }
  466. }
  467. public ResolvedType[] getResolvedTypeParameters() {
  468. if (resolvedTypeParams == null) {
  469. resolvedTypeParams = world.resolve(typeParameters);
  470. }
  471. return resolvedTypeParams;
  472. }
  473. /**
  474. * described in JVM spec 2ed 5.4.3.2
  475. */
  476. public ResolvedMember lookupField(Member field) {
  477. Iterator<ResolvedMember> i = getFields();
  478. while (i.hasNext()) {
  479. ResolvedMember resolvedMember = i.next();
  480. if (matches(resolvedMember, field)) {
  481. return resolvedMember;
  482. }
  483. if (resolvedMember.hasBackingGenericMember() && field.getName().equals(resolvedMember.getName())) {
  484. // might be worth checking the member behind the parameterized member (see pr137496)
  485. if (matches(resolvedMember.getBackingGenericMember(), field)) {
  486. return resolvedMember;
  487. }
  488. }
  489. }
  490. return null;
  491. }
  492. /**
  493. * described in JVM spec 2ed 5.4.3.3. Doesnt check ITDs.
  494. *
  495. * <p>
  496. * Check the current type for the method. If it is not found, check the super class and any super interfaces. Taking care not to
  497. * process interfaces multiple times.
  498. */
  499. public ResolvedMember lookupMethod(Member m) {
  500. List<ResolvedType> typesTolookat = new ArrayList<ResolvedType>();
  501. typesTolookat.add(this);
  502. int pos = 0;
  503. while (pos < typesTolookat.size()) {
  504. ResolvedType type = typesTolookat.get(pos++);
  505. if (!type.isMissing()) {
  506. ResolvedMember[] methods = type.getDeclaredMethods();
  507. if (methods != null) {
  508. for (int i = 0; i < methods.length; i++) {
  509. ResolvedMember method = methods[i];
  510. if (matches(method, m)) {
  511. return method;
  512. }
  513. // might be worth checking the method behind the parameterized method (137496)
  514. if (method.hasBackingGenericMember() && m.getName().equals(method.getName())) {
  515. if (matches(method.getBackingGenericMember(), m)) {
  516. return method;
  517. }
  518. }
  519. }
  520. }
  521. }
  522. // Queue the superclass:
  523. ResolvedType superclass = type.getSuperclass();
  524. if (superclass != null) {
  525. typesTolookat.add(superclass);
  526. }
  527. // Queue any interfaces not already checked:
  528. ResolvedType[] superinterfaces = type.getDeclaredInterfaces();
  529. if (superinterfaces != null) {
  530. for (int i = 0; i < superinterfaces.length; i++) {
  531. ResolvedType interf = superinterfaces[i];
  532. if (!typesTolookat.contains(interf)) {
  533. typesTolookat.add(interf);
  534. }
  535. }
  536. }
  537. }
  538. return null;
  539. }
  540. /**
  541. * @param member the member to lookup in intertype declarations affecting this type
  542. * @return the real signature defined by any matching intertype declaration, otherwise null
  543. */
  544. public ResolvedMember lookupMethodInITDs(Member member) {
  545. for (ConcreteTypeMunger typeTransformer : interTypeMungers) {
  546. if (matches(typeTransformer.getSignature(), member)) {
  547. return typeTransformer.getSignature();
  548. }
  549. }
  550. return null;
  551. }
  552. /**
  553. * return null if not found
  554. */
  555. private ResolvedMember lookupMember(Member m, ResolvedMember[] a) {
  556. for (int i = 0; i < a.length; i++) {
  557. ResolvedMember f = a[i];
  558. if (matches(f, m)) {
  559. return f;
  560. }
  561. }
  562. return null;
  563. }
  564. // Bug (1) Do callers expect ITDs to be involved in the lookup? or do they do their own walk over ITDs?
  565. /**
  566. * Looks for the first member in the hierarchy matching aMember. This method differs from lookupMember(Member) in that it takes
  567. * into account parameters which are type variables - which clearly an unresolved Member cannot do since it does not know
  568. * anything about type variables.
  569. */
  570. public ResolvedMember lookupResolvedMember(ResolvedMember aMember, boolean allowMissing, boolean eraseGenerics) {
  571. Iterator<ResolvedMember> toSearch = null;
  572. ResolvedMember found = null;
  573. if ((aMember.getKind() == Member.METHOD) || (aMember.getKind() == Member.CONSTRUCTOR)) {
  574. // toSearch = getMethodsWithoutIterator(true, allowMissing, !eraseGenerics).iterator();
  575. toSearch = getMethodsIncludingIntertypeDeclarations(!eraseGenerics, true);
  576. } else if (aMember.getKind()==Member.ADVICE) {
  577. return null;
  578. } else {
  579. assert aMember.getKind() == Member.FIELD;
  580. toSearch = getFields();
  581. }
  582. while (toSearch.hasNext()) {
  583. ResolvedMember candidate = toSearch.next();
  584. if (eraseGenerics) {
  585. if (candidate.hasBackingGenericMember()) {
  586. candidate = candidate.getBackingGenericMember();
  587. }
  588. }
  589. // OPTIMIZE speed up matches? optimize order of checks
  590. if (candidate.matches(aMember, eraseGenerics)) {
  591. found = candidate;
  592. break;
  593. }
  594. }
  595. return found;
  596. }
  597. public static boolean matches(Member m1, Member m2) {
  598. if (m1 == null) {
  599. return m2 == null;
  600. }
  601. if (m2 == null) {
  602. return false;
  603. }
  604. // Check the names
  605. boolean equalNames = m1.getName().equals(m2.getName());
  606. if (!equalNames) {
  607. return false;
  608. }
  609. // Check the signatures
  610. boolean equalSignatures = m1.getSignature().equals(m2.getSignature());
  611. if (equalSignatures) {
  612. return true;
  613. }
  614. // If they aren't the same, we need to allow for covariance ... where
  615. // one sig might be ()LCar; and
  616. // the subsig might be ()LFastCar; - where FastCar is a subclass of Car
  617. boolean equalCovariantSignatures = m1.getParameterSignature().equals(m2.getParameterSignature());
  618. if (equalCovariantSignatures) {
  619. return true;
  620. }
  621. return false;
  622. }
  623. public static boolean conflictingSignature(Member m1, Member m2) {
  624. return conflictingSignature(m1,m2,true);
  625. }
  626. /**
  627. * Do the two members conflict? Due to the change in 1.7.1, field itds on interfaces now act like 'default' fields - so types implementing
  628. * those fields get the field if they don't have it already, otherwise they keep what they have. The conflict detection below had to be
  629. * altered. Previously (<1.7.1) it is not a conflict if the declaring types are different. With v2itds it may still be a conflict if the
  630. * declaring types are different.
  631. */
  632. public static boolean conflictingSignature(Member m1, Member m2, boolean v2itds) {
  633. if (m1 == null || m2 == null) {
  634. return false;
  635. }
  636. if (!m1.getName().equals(m2.getName())) {
  637. return false;
  638. }
  639. if (m1.getKind() != m2.getKind()) {
  640. return false;
  641. }
  642. if (m1.getKind() == Member.FIELD) {
  643. if (v2itds) {
  644. if (m1.getDeclaringType().equals(m2.getDeclaringType())) {
  645. return true;
  646. }
  647. } else {
  648. return m1.getDeclaringType().equals(m2.getDeclaringType());
  649. }
  650. } else if (m1.getKind() == Member.POINTCUT) {
  651. return true;
  652. }
  653. UnresolvedType[] p1 = m1.getGenericParameterTypes();
  654. UnresolvedType[] p2 = m2.getGenericParameterTypes();
  655. if (p1 == null) {
  656. p1 = m1.getParameterTypes();
  657. }
  658. if (p2 == null) {
  659. p2 = m2.getParameterTypes();
  660. }
  661. int n = p1.length;
  662. if (n != p2.length) {
  663. return false;
  664. }
  665. for (int i = 0; i < n; i++) {
  666. if (!p1[i].equals(p2[i])) {
  667. return false;
  668. }
  669. }
  670. return true;
  671. }
  672. /**
  673. * returns an iterator through all of the pointcuts of this type, in order for checking from JVM spec 2ed 5.4.3.2 (as for
  674. * fields). This means that the order is
  675. * <p/>
  676. * <ul>
  677. * <li>pointcuts from current class</li>
  678. * <li>recur into direct superinterfaces</li>
  679. * <li>recur into superclass</li>
  680. * </ul>
  681. * <p/>
  682. * We keep a hashSet of interfaces that we've visited so we don't spiral out into 2^n land.
  683. */
  684. public Iterator<ResolvedMember> getPointcuts() {
  685. final Iterators.Filter<ResolvedType> dupFilter = Iterators.dupFilter();
  686. // same order as fields
  687. Iterators.Getter<ResolvedType, ResolvedType> typeGetter = new Iterators.Getter<ResolvedType, ResolvedType>() {
  688. @Override
  689. public Iterator<ResolvedType> get(ResolvedType o) {
  690. return dupFilter.filter(o.getDirectSupertypes());
  691. }
  692. };
  693. return Iterators.mapOver(Iterators.recur(this, typeGetter), PointcutGetterInstance);
  694. }
  695. public ResolvedPointcutDefinition findPointcut(String name) {
  696. for (Iterator<ResolvedMember> i = getPointcuts(); i.hasNext();) {
  697. ResolvedPointcutDefinition f = (ResolvedPointcutDefinition) i.next();
  698. // the ResolvedPointcutDefinition can be null if there are other problems that prevented its resolution
  699. if (f != null && name.equals(f.getName())) {
  700. return f;
  701. }
  702. }
  703. // pr120521
  704. if (!getOutermostType().equals(this)) {
  705. ResolvedType outerType = getOutermostType().resolve(world);
  706. ResolvedPointcutDefinition rpd = outerType.findPointcut(name);
  707. return rpd;
  708. }
  709. return null; // should we throw an exception here?
  710. }
  711. // all about collecting CrosscuttingMembers
  712. // ??? collecting data-structure, shouldn't really be a field
  713. public CrosscuttingMembers crosscuttingMembers;
  714. public CrosscuttingMembers collectCrosscuttingMembers(boolean shouldConcretizeIfNeeded) {
  715. crosscuttingMembers = new CrosscuttingMembers(this, shouldConcretizeIfNeeded);
  716. if (getPerClause() == null) {
  717. return crosscuttingMembers;
  718. }
  719. crosscuttingMembers.setPerClause(getPerClause());
  720. crosscuttingMembers.addShadowMungers(collectShadowMungers());
  721. // GENERICITDFIX
  722. // crosscuttingMembers.addTypeMungers(collectTypeMungers());
  723. crosscuttingMembers.addTypeMungers(getTypeMungers());
  724. // FIXME AV - skip but needed ?? or ??
  725. // crosscuttingMembers.addLateTypeMungers(getLateTypeMungers());
  726. crosscuttingMembers.addDeclares(collectDeclares(!this.doesNotExposeShadowMungers()));
  727. crosscuttingMembers.addPrivilegedAccesses(getPrivilegedAccesses());
  728. // System.err.println("collected cc members: " + this + ", " +
  729. // collectDeclares());
  730. return crosscuttingMembers;
  731. }
  732. public final List<Declare> collectDeclares(boolean includeAdviceLike) {
  733. if (!this.isAspect()) {
  734. return Collections.emptyList();
  735. }
  736. List<Declare> ret = new ArrayList<Declare>();
  737. // if (this.isAbstract()) {
  738. // for (Iterator i = getDeclares().iterator(); i.hasNext();) {
  739. // Declare dec = (Declare) i.next();
  740. // if (!dec.isAdviceLike()) ret.add(dec);
  741. // }
  742. //
  743. // if (!includeAdviceLike) return ret;
  744. if (!this.isAbstract()) {
  745. // ret.addAll(getDeclares());
  746. final Iterators.Filter<ResolvedType> dupFilter = Iterators.dupFilter();
  747. Iterators.Getter<ResolvedType, ResolvedType> typeGetter = new Iterators.Getter<ResolvedType, ResolvedType>() {
  748. @Override
  749. public Iterator<ResolvedType> get(ResolvedType o) {
  750. return dupFilter.filter((o).getDirectSupertypes());
  751. }
  752. };
  753. Iterator<ResolvedType> typeIterator = Iterators.recur(this, typeGetter);
  754. while (typeIterator.hasNext()) {
  755. ResolvedType ty = typeIterator.next();
  756. // System.out.println("super: " + ty + ", " + );
  757. for (Iterator<Declare> i = ty.getDeclares().iterator(); i.hasNext();) {
  758. Declare dec = i.next();
  759. if (dec.isAdviceLike()) {
  760. if (includeAdviceLike) {
  761. ret.add(dec);
  762. }
  763. } else {
  764. ret.add(dec);
  765. }
  766. }
  767. }
  768. }
  769. return ret;
  770. }
  771. private final List<ShadowMunger> collectShadowMungers() {
  772. if (!this.isAspect() || this.isAbstract() || this.doesNotExposeShadowMungers()) {
  773. return Collections.emptyList();
  774. }
  775. List<ShadowMunger> acc = new ArrayList<ShadowMunger>();
  776. final Iterators.Filter<ResolvedType> dupFilter = Iterators.dupFilter();
  777. Iterators.Getter<ResolvedType, ResolvedType> typeGetter = new Iterators.Getter<ResolvedType, ResolvedType>() {
  778. @Override
  779. public Iterator<ResolvedType> get(ResolvedType o) {
  780. return dupFilter.filter((o).getDirectSupertypes());
  781. }
  782. };
  783. Iterator<ResolvedType> typeIterator = Iterators.recur(this, typeGetter);
  784. while (typeIterator.hasNext()) {
  785. ResolvedType ty = typeIterator.next();
  786. acc.addAll(ty.getDeclaredShadowMungers());
  787. }
  788. return acc;
  789. }
  790. public void addParent(ResolvedType newParent) {
  791. // Nothing to do for anything except a ReferenceType
  792. }
  793. protected boolean doesNotExposeShadowMungers() {
  794. return false;
  795. }
  796. public PerClause getPerClause() {
  797. return null;
  798. }
  799. public Collection<Declare> getDeclares() {
  800. return Collections.emptyList();
  801. }
  802. public Collection<ConcreteTypeMunger> getTypeMungers() {
  803. return Collections.emptyList();
  804. }
  805. public Collection<ResolvedMember> getPrivilegedAccesses() {
  806. return Collections.emptyList();
  807. }
  808. // ---- useful things
  809. public final boolean isInterface() {
  810. return Modifier.isInterface(getModifiers());
  811. }
  812. public final boolean isAbstract() {
  813. return Modifier.isAbstract(getModifiers());
  814. }
  815. public boolean isClass() {
  816. return false;
  817. }
  818. public boolean isAspect() {
  819. return false;
  820. }
  821. public boolean isAnnotationStyleAspect() {
  822. return false;
  823. }
  824. /**
  825. * Note: Only overridden by Name subtype.
  826. */
  827. public boolean isEnum() {
  828. return false;
  829. }
  830. /**
  831. * Note: Only overridden by Name subtype.
  832. */
  833. public boolean isAnnotation() {
  834. return false;
  835. }
  836. public boolean isAnonymous() {
  837. return false;
  838. }
  839. public boolean isNested() {
  840. return false;
  841. }
  842. public ResolvedType getOuterClass() {
  843. return null;
  844. }
  845. public void addAnnotation(AnnotationAJ annotationX) {
  846. throw new RuntimeException("ResolvedType.addAnnotation() should never be called");
  847. }
  848. public AnnotationAJ[] getAnnotations() {
  849. throw new RuntimeException("ResolvedType.getAnnotations() should never be called");
  850. }
  851. public boolean hasAnnotations() {
  852. throw new RuntimeException("ResolvedType.getAnnotations() should never be called");
  853. }
  854. /**
  855. * Note: Only overridden by ReferenceType subtype
  856. */
  857. public boolean canAnnotationTargetType() {
  858. return false;
  859. }
  860. /**
  861. * Note: Only overridden by ReferenceType subtype
  862. */
  863. public AnnotationTargetKind[] getAnnotationTargetKinds() {
  864. return null;
  865. }
  866. /**
  867. * Note: Only overridden by Name subtype.
  868. */
  869. public boolean isAnnotationWithRuntimeRetention() {
  870. return false;
  871. }
  872. public boolean isSynthetic() {
  873. return signature.indexOf("$ajc") != -1;
  874. }
  875. public final boolean isFinal() {
  876. return Modifier.isFinal(getModifiers());
  877. }
  878. protected Map<String, UnresolvedType> getMemberParameterizationMap() {
  879. if (!isParameterizedType()) {
  880. return Collections.emptyMap();
  881. }
  882. TypeVariable[] tvs = getGenericType().getTypeVariables();
  883. Map<String, UnresolvedType> parameterizationMap = new HashMap<String, UnresolvedType>();
  884. if (tvs.length != typeParameters.length) {
  885. world.getMessageHandler()
  886. .handleMessage(
  887. new Message("Mismatch when building parameterization map. For type '" + this.signature +
  888. "' expecting "+tvs.length+":["+toString(tvs)+"] type parameters but found "+typeParameters.length+
  889. ":["+toString(typeParameters)+"]", "",
  890. IMessage.ERROR, getSourceLocation(), null,
  891. new ISourceLocation[] { getSourceLocation() }));
  892. } else {
  893. for (int i = 0; i < tvs.length; i++) {
  894. parameterizationMap.put(tvs[i].getName(), typeParameters[i]);
  895. }
  896. }
  897. return parameterizationMap;
  898. }
  899. private String toString(UnresolvedType[] typeParameters) {
  900. StringBuilder s = new StringBuilder();
  901. for (UnresolvedType tv: typeParameters) {
  902. s.append(tv.getSignature()).append(" ");
  903. }
  904. return s.toString().trim();
  905. }
  906. private String toString(TypeVariable[] tvs) {
  907. StringBuilder s = new StringBuilder();
  908. for (TypeVariable tv: tvs) {
  909. s.append(tv.getName()).append(" ");
  910. }
  911. return s.toString().trim();
  912. }
  913. public List<ShadowMunger> getDeclaredAdvice() {
  914. List<ShadowMunger> l = new ArrayList<ShadowMunger>();
  915. ResolvedMember[] methods = getDeclaredMethods();
  916. if (isParameterizedType()) {
  917. methods = getGenericType().getDeclaredMethods();
  918. }
  919. Map<String, UnresolvedType> typeVariableMap = getAjMemberParameterizationMap();
  920. for (int i = 0, len = methods.length; i < len; i++) {
  921. ShadowMunger munger = methods[i].getAssociatedShadowMunger();
  922. if (munger != null) {
  923. if (ajMembersNeedParameterization()) {
  924. // munger.setPointcut(munger.getPointcut().parameterizeWith(
  925. // typeVariableMap));
  926. munger = munger.parameterizeWith(this, typeVariableMap);
  927. if (munger instanceof Advice) {
  928. Advice advice = (Advice) munger;
  929. // update to use the parameterized signature...
  930. UnresolvedType[] ptypes = methods[i].getGenericParameterTypes();
  931. UnresolvedType[] newPTypes = new UnresolvedType[ptypes.length];
  932. for (int j = 0; j < ptypes.length; j++) {
  933. if (ptypes[j] instanceof TypeVariableReferenceType) {
  934. TypeVariableReferenceType tvrt = (TypeVariableReferenceType) ptypes[j];
  935. if (typeVariableMap.containsKey(tvrt.getTypeVariable().getName())) {
  936. newPTypes[j] = typeVariableMap.get(tvrt.getTypeVariable().getName());
  937. } else {
  938. newPTypes[j] = ptypes[j];
  939. }
  940. } else {
  941. newPTypes[j] = ptypes[j];
  942. }
  943. }
  944. advice.setBindingParameterTypes(newPTypes);
  945. }
  946. }
  947. munger.setDeclaringType(this);
  948. l.add(munger);
  949. }
  950. }
  951. return l;
  952. }
  953. public List<ShadowMunger> getDeclaredShadowMungers() {
  954. return getDeclaredAdvice();
  955. }
  956. // ---- only for testing!
  957. public ResolvedMember[] getDeclaredJavaFields() {
  958. return filterInJavaVisible(getDeclaredFields());
  959. }
  960. public ResolvedMember[] getDeclaredJavaMethods() {
  961. return filterInJavaVisible(getDeclaredMethods());
  962. }
  963. private ResolvedMember[] filterInJavaVisible(ResolvedMember[] ms) {
  964. List<ResolvedMember> l = new ArrayList<ResolvedMember>();
  965. for (int i = 0, len = ms.length; i < len; i++) {
  966. if (!ms[i].isAjSynthetic() && ms[i].getAssociatedShadowMunger() == null) {
  967. l.add(ms[i]);
  968. }
  969. }
  970. return l.toArray(new ResolvedMember[l.size()]);
  971. }
  972. public abstract ISourceContext getSourceContext();
  973. // ---- fields
  974. public static final ResolvedType[] NONE = new ResolvedType[0];
  975. public static final ResolvedType[] EMPTY_ARRAY = NONE;
  976. public static final Missing MISSING = new Missing();
  977. // ---- types
  978. public static ResolvedType makeArray(ResolvedType type, int dim) {
  979. if (dim == 0) {
  980. return type;
  981. }
  982. ResolvedType array = new ArrayReferenceType("[" + type.getSignature(), "[" + type.getErasureSignature(), type.getWorld(),
  983. type);
  984. return makeArray(array, dim - 1);
  985. }
  986. static class Primitive extends ResolvedType {
  987. private final int size;
  988. private final int index;
  989. Primitive(String signature, int size, int index) {
  990. super(signature, null);
  991. this.size = size;
  992. this.index = index;
  993. this.typeKind = TypeKind.PRIMITIVE;
  994. }
  995. @Override
  996. public final int getSize() {
  997. return size;
  998. }
  999. @Override
  1000. public final int getModifiers() {
  1001. return Modifier.PUBLIC | Modifier.FINAL;
  1002. }
  1003. @Override
  1004. public final boolean isPrimitiveType() {
  1005. return true;
  1006. }
  1007. @Override
  1008. public boolean hasAnnotation(UnresolvedType ofType) {
  1009. return false;
  1010. }
  1011. @Override
  1012. public final boolean isAssignableFrom(ResolvedType other) {
  1013. if (!other.isPrimitiveType()) {
  1014. if (!world.isInJava5Mode()) {
  1015. return false;
  1016. }
  1017. return validBoxing.contains(this.getSignature() + other.getSignature());
  1018. }
  1019. return assignTable[((Primitive) other).index][index];
  1020. }
  1021. @Override
  1022. public final boolean isAssignableFrom(ResolvedType other, boolean allowMissing) {
  1023. return isAssignableFrom(other);
  1024. }
  1025. @Override
  1026. public final boolean isCoerceableFrom(ResolvedType other) {
  1027. if (this == other) {
  1028. return true;
  1029. }
  1030. if (!other.isPrimitiveType()) {
  1031. return false;
  1032. }
  1033. if (index > 6 || ((Primitive) other).index > 6) {
  1034. return false;
  1035. }
  1036. return true;
  1037. }
  1038. @Override
  1039. public ResolvedType resolve(World world) {
  1040. if (this.world != world) {
  1041. throw new IllegalStateException();
  1042. }
  1043. this.world = world;
  1044. return super.resolve(world);
  1045. }
  1046. @Override
  1047. public final boolean needsNoConversionFrom(ResolvedType other) {
  1048. if (!other.isPrimitiveType()) {
  1049. return false;
  1050. }
  1051. return noConvertTable[((Primitive) other).index][index];
  1052. }
  1053. private static final boolean[][] assignTable = {// to: B C D F I J S V Z
  1054. // from
  1055. { true, true, true, true, true, true, true, false, false }, // B
  1056. { false, true, true, true, true, true, false, false, false }, // C
  1057. { false, false, true, false, false, false, false, false, false }, // D
  1058. { false, false, true, true, false, false, false, false, false }, // F
  1059. { false, false, true, true, true, true, false, false, false }, // I
  1060. { false, false, true, true, false, true, false, false, false }, // J
  1061. { false, false, true, true, true, true, true, false, false }, // S
  1062. { false, false, false, false, false, false, false, true, false }, // V
  1063. { false, false, false, false, false, false, false, false, true }, // Z
  1064. };
  1065. private static final boolean[][] noConvertTable = {// to: B C D F I J S
  1066. // V Z from
  1067. { true, true, false, false, true, false, true, false, false }, // B
  1068. { false, true, false, false, true, false, false, false, false }, // C
  1069. { false, false, true, false, false, false, false, false, false }, // D
  1070. { false, false, false, true, false, false, false, false, false }, // F
  1071. { false, false, false, false, true, false, false, false, false }, // I
  1072. { false, false, false, false, false, true, false, false, false }, // J
  1073. { false, false, false, false, true, false, true, false, false }, // S
  1074. { false, false, false, false, false, false, false, true, false }, // V
  1075. { false, false, false, false, false, false, false, false, true }, // Z
  1076. };
  1077. // ----
  1078. @Override
  1079. public final ResolvedMember[] getDeclaredFields() {
  1080. return ResolvedMember.NONE;
  1081. }
  1082. @Override
  1083. public final ResolvedMember[] getDeclaredMethods() {
  1084. return ResolvedMember.NONE;
  1085. }
  1086. @Override
  1087. public final ResolvedType[] getDeclaredInterfaces() {
  1088. return ResolvedType.NONE;
  1089. }
  1090. @Override
  1091. public final ResolvedMember[] getDeclaredPointcuts() {
  1092. return ResolvedMember.NONE;
  1093. }
  1094. @Override
  1095. public final ResolvedType getSuperclass() {
  1096. return null;
  1097. }
  1098. @Override
  1099. public ISourceContext getSourceContext() {
  1100. return null;
  1101. }
  1102. }
  1103. static class Missing extends ResolvedType {
  1104. Missing() {
  1105. super(MISSING_NAME, null);
  1106. }
  1107. // public final String toString() {
  1108. // return "<missing>";
  1109. // }
  1110. @Override
  1111. public final String getName() {
  1112. return MISSING_NAME;
  1113. }
  1114. @Override
  1115. public final boolean isMissing() {
  1116. return true;
  1117. }
  1118. @Override
  1119. public boolean hasAnnotation(UnresolvedType ofType) {
  1120. return false;
  1121. }
  1122. @Override
  1123. public final ResolvedMember[] getDeclaredFields() {
  1124. return ResolvedMember.NONE;
  1125. }
  1126. @Override
  1127. public final ResolvedMember[] getDeclaredMethods() {
  1128. return ResolvedMember.NONE;
  1129. }
  1130. @Override
  1131. public final ResolvedType[] getDeclaredInterfaces() {
  1132. return ResolvedType.NONE;
  1133. }
  1134. @Override
  1135. public final ResolvedMember[] getDeclaredPointcuts() {
  1136. return ResolvedMember.NONE;
  1137. }
  1138. @Override
  1139. public final ResolvedType getSuperclass() {
  1140. return null;
  1141. }
  1142. @Override
  1143. public final int getModifiers() {
  1144. return 0;
  1145. }
  1146. @Override
  1147. public final boolean isAssignableFrom(ResolvedType other) {
  1148. return false;
  1149. }
  1150. @Override
  1151. public final boolean isAssignableFrom(ResolvedType other, boolean allowMissing) {
  1152. return false;
  1153. }
  1154. @Override
  1155. public final boolean isCoerceableFrom(ResolvedType other) {
  1156. return false;
  1157. }
  1158. @Override
  1159. public boolean needsNoConversionFrom(ResolvedType other) {
  1160. return false;
  1161. }
  1162. @Override
  1163. public ISourceContext getSourceContext() {
  1164. return null;
  1165. }
  1166. }
  1167. /**
  1168. * Look up a member, takes into account any ITDs on this type. return null if not found
  1169. */
  1170. public ResolvedMember lookupMemberNoSupers(Member member) {
  1171. ResolvedMember ret = lookupDirectlyDeclaredMemberNoSupers(member);
  1172. if (ret == null && interTypeMungers != null) {
  1173. for (ConcreteTypeMunger tm : interTypeMungers) {
  1174. if (matches(tm.getSignature(), member)) {
  1175. return tm.getSignature();
  1176. }
  1177. }
  1178. }
  1179. return ret;
  1180. }
  1181. public ResolvedMember lookupMemberWithSupersAndITDs(Member member) {
  1182. ResolvedMember ret = lookupMemberNoSupers(member);
  1183. if (ret != null) {
  1184. return ret;
  1185. }
  1186. ResolvedType supert = getSuperclass();
  1187. while (ret == null && supert != null) {
  1188. ret = supert.lookupMemberNoSupers(member);
  1189. if (ret == null) {
  1190. supert = supert.getSuperclass();
  1191. }
  1192. }
  1193. return ret;
  1194. }
  1195. /**
  1196. * as lookupMemberNoSupers, but does not include ITDs
  1197. *
  1198. * @param member
  1199. * @return
  1200. */
  1201. public ResolvedMember lookupDirectlyDeclaredMemberNoSupers(Member member) {
  1202. ResolvedMember ret;
  1203. if (member.getKind() == Member.FIELD) {
  1204. ret = lookupMember(member, getDeclaredFields());
  1205. } else {
  1206. // assert member.getKind() == Member.METHOD || member.getKind() ==
  1207. // Member.CONSTRUCTOR
  1208. ret = lookupMember(member, getDeclaredMethods());
  1209. }
  1210. return ret;
  1211. }
  1212. /**
  1213. * This lookup has specialized behaviour - a null result tells the EclipseTypeMunger that it should make a default
  1214. * implementation of a method on this type.
  1215. *
  1216. * @param member
  1217. * @return
  1218. */
  1219. public ResolvedMember lookupMemberIncludingITDsOnInterfaces(Member member) {
  1220. return lookupMemberIncludingITDsOnInterfaces(member, this);
  1221. }
  1222. private ResolvedMember lookupMemberIncludingITDsOnInterfaces(Member member, ResolvedType onType) {
  1223. ResolvedMember ret = onType.lookupMemberNoSupers(member);
  1224. if (ret != null) {
  1225. return ret;
  1226. } else {
  1227. ResolvedType superType = onType.getSuperclass();
  1228. if (superType != null) {
  1229. ret = lookupMemberIncludingITDsOnInterfaces(member, superType);
  1230. }
  1231. if (ret == null) {
  1232. // try interfaces then, but only ITDs now...
  1233. ResolvedType[] superInterfaces = onType.getDeclaredInterfaces();
  1234. for (int i = 0; i < superInterfaces.length; i++) {
  1235. ret = superInterfaces[i].lookupMethodInITDs(member);
  1236. if (ret != null) {
  1237. return ret;
  1238. }
  1239. }
  1240. }
  1241. }
  1242. return ret;
  1243. }
  1244. protected List<ConcreteTypeMunger> interTypeMungers = new ArrayList<ConcreteTypeMunger>();
  1245. public List<ConcreteTypeMunger> getInterTypeMungers() {
  1246. return interTypeMungers;
  1247. }
  1248. public List<ConcreteTypeMunger> getInterTypeParentMungers() {
  1249. List<ConcreteTypeMunger> l = new ArrayList<ConcreteTypeMunger>();
  1250. for (ConcreteTypeMunger element : interTypeMungers) {
  1251. if (element.getMunger() instanceof NewParentTypeMunger) {
  1252. l.add(element);
  1253. }
  1254. }
  1255. return l;
  1256. }
  1257. /**
  1258. * ??? This method is O(N*M) where N = number of methods and M is number of inter-type declarations in my super
  1259. */
  1260. public List<ConcreteTypeMunger> getInterTypeMungersIncludingSupers() {
  1261. ArrayList<ConcreteTypeMunger> ret = new ArrayList<ConcreteTypeMunger>();
  1262. collectInterTypeMungers(ret);
  1263. return ret;
  1264. }
  1265. public List<ConcreteTypeMunger> getInterTypeParentMungersIncludingSupers() {
  1266. ArrayList<ConcreteTypeMunger> ret = new ArrayList<ConcreteTypeMunger>();
  1267. collectInterTypeParentMungers(ret);
  1268. return ret;
  1269. }
  1270. private void collectInterTypeParentMungers(List<ConcreteTypeMunger> collector) {
  1271. for (Iterator<ResolvedType> iter = getDirectSupertypes(); iter.hasNext();) {
  1272. ResolvedType superType = iter.next();
  1273. superType.collectInterTypeParentMungers(collector);
  1274. }
  1275. collector.addAll(getInterTypeParentMungers());
  1276. }
  1277. protected void collectInterTypeMungers(List<ConcreteTypeMunger> collector) {
  1278. for (Iterator<ResolvedType> iter = getDirectSupertypes(); iter.hasNext();) {
  1279. ResolvedType superType = iter.next();
  1280. if (superType == null) {
  1281. throw new BCException("UnexpectedProblem: a supertype in the hierarchy for " + this.getName() + " is null");
  1282. }
  1283. superType.collectInterTypeMungers(collector);
  1284. }
  1285. outer: for (Iterator<ConcreteTypeMunger> iter1 = collector.iterator(); iter1.hasNext();) {
  1286. ConcreteTypeMunger superMunger = iter1.next();
  1287. if (superMunger.getSignature() == null) {
  1288. continue;
  1289. }
  1290. if (!superMunger.getSignature().isAbstract()) {
  1291. continue;
  1292. }
  1293. for (ConcreteTypeMunger myMunger : getInterTypeMungers()) {
  1294. if (conflictingSignature(myMunger.getSignature(), superMunger.getSignature())) {
  1295. iter1.remove();
  1296. continue outer;
  1297. }
  1298. }
  1299. if (!superMunger.getSignature().isPublic()) {
  1300. continue;
  1301. }
  1302. for (Iterator<ResolvedMember> iter = getMethods(true, true); iter.hasNext();) {
  1303. ResolvedMember method = iter.next();
  1304. if (conflictingSignature(method, superMunger.getSignature())) {
  1305. iter1.remove();
  1306. continue outer;
  1307. }
  1308. }
  1309. }
  1310. collector.addAll(getInterTypeMungers());
  1311. }
  1312. /**
  1313. * Check: 1) That we don't have any abstract type mungers unless this type is abstract. 2) That an abstract ITDM on an interface
  1314. * is declared public. (Compiler limitation) (PR70794)
  1315. */
  1316. public void checkInterTypeMungers() {
  1317. if (isAbstract()) {
  1318. return;
  1319. }
  1320. boolean itdProblem = false;
  1321. for (ConcreteTypeMunger munger : getInterTypeMungersIncludingSupers()) {
  1322. itdProblem = checkAbstractDeclaration(munger) || itdProblem; // Rule 2
  1323. }
  1324. if (itdProblem) {
  1325. return; // If the rules above are broken, return right now
  1326. }
  1327. for (ConcreteTypeMunger munger : getInterTypeMungersIncludingSupers()) {
  1328. if (munger.getSignature() != null && munger.getSignature().isAbstract() && munger.getMunger().getKind()!=ResolvedTypeMunger.PrivilegedAccess) { // Rule 1
  1329. if (munger.getMunger().getKind() == ResolvedTypeMunger.MethodDelegate2) {
  1330. // ignore for @AJ ITD as munger.getSignature() is the
  1331. // interface method hence abstract
  1332. } else {
  1333. world.getMessageHandler()
  1334. .handleMessage(
  1335. new Message("must implement abstract inter-type declaration: " + munger.getSignature(), "",
  1336. IMessage.ERROR, getSourceLocation(), null,
  1337. new ISourceLocation[] { getMungerLocation(munger) }));
  1338. }
  1339. }
  1340. }
  1341. }
  1342. /**
  1343. * See PR70794. This method checks that if an abstract inter-type method declaration is made on an interface then it must also
  1344. * be public. This is a compiler limitation that could be made to work in the future (if someone provides a worthwhile usecase)
  1345. *
  1346. * @return indicates if the munger failed the check
  1347. */
  1348. private boolean checkAbstractDeclaration(ConcreteTypeMunger munger) {
  1349. if (munger.getMunger() != null && (munger.getMunger() instanceof NewMethodTypeMunger)) {
  1350. ResolvedMember itdMember = munger.getSignature();
  1351. ResolvedType onType = itdMember.getDeclaringType().resolve(world);
  1352. if (onType.isInterface() && itdMember.isAbstract() && !itdMember.isPublic()) {
  1353. world.getMessageHandler().handleMessage(
  1354. new Message(WeaverMessages.format(WeaverMessages.ITD_ABSTRACT_MUST_BE_PUBLIC_ON_INTERFACE,
  1355. munger.getSignature(), onType), "", Message.ERROR, getSourceLocation(), null,
  1356. new ISourceLocation[] { getMungerLocation(munger) }));
  1357. return true;
  1358. }
  1359. }
  1360. return false;
  1361. }
  1362. /**
  1363. * Get a source location for the munger. Until intertype mungers remember where they came from, the source location for the
  1364. * munger itself is null. In these cases use the source location for the aspect containing the ITD.
  1365. */
  1366. private ISourceLocation getMungerLocation(ConcreteTypeMunger munger) {
  1367. ISourceLocation sloc = munger.getSourceLocation();
  1368. if (sloc == null) {
  1369. sloc = munger.getAspectType().getSourceLocation();
  1370. }
  1371. return sloc;
  1372. }
  1373. /**
  1374. * Returns a ResolvedType object representing the declaring type of this type, or null if this type does not represent a
  1375. * non-package-level-type.
  1376. * <p/>
  1377. * <strong>Warning</strong>: This is guaranteed to work for all member types. For anonymous/local types, the only guarantee is
  1378. * given in JLS 13.1, where it guarantees that if you call getDeclaringType() repeatedly, you will eventually get the top-level
  1379. * class, but it does not say anything about classes in between.
  1380. *
  1381. * @return the declaring type, or null if it is not an nested type.
  1382. */
  1383. public ResolvedType getDeclaringType() {
  1384. if (isArray()) {
  1385. return null;
  1386. }
  1387. if (isNested() || isAnonymous()) {
  1388. return getOuterClass();
  1389. }
  1390. return null;
  1391. }
  1392. public static boolean isVisible(int modifiers, ResolvedType targetType, ResolvedType fromType) {
  1393. // System.err.println("mod: " + modifiers + ", " + targetType + " and "
  1394. // + fromType);
  1395. if (Modifier.isPublic(modifiers)) {
  1396. return true;
  1397. } else if (Modifier.isPrivate(modifiers)) {
  1398. return targetType.getOutermostType().equals(fromType.getOutermostType());
  1399. } else if (Modifier.isProtected(modifiers)) {
  1400. return samePackage(targetType, fromType) || targetType.isAssignableFrom(fromType);
  1401. } else { // package-visible
  1402. return samePackage(targetType, fromType);
  1403. }
  1404. }
  1405. private static boolean samePackage(ResolvedType targetType, ResolvedType fromType) {
  1406. String p1 = targetType.getPackageName();
  1407. String p2 = fromType.getPackageName();
  1408. if (p1 == null) {
  1409. return p2 == null;
  1410. }
  1411. if (p2 == null) {
  1412. return false;
  1413. }
  1414. return p1.equals(p2);
  1415. }
  1416. /**
  1417. * Checks if the generic type for 'this' and the generic type for 'other' are the same - it can be passed raw or parameterized
  1418. * versions and will just compare the underlying generic type.
  1419. */
  1420. private boolean genericTypeEquals(ResolvedType other) {
  1421. ResolvedType rt = other;
  1422. if (rt.isParameterizedType() || rt.isRawType()) {
  1423. rt.getGenericType();
  1424. }
  1425. if (((isParameterizedType() || isRawType()) && getGenericType().equals(rt)) || (this.equals(other))) {
  1426. return true;
  1427. }
  1428. return false;
  1429. }
  1430. /**
  1431. * Look up the actual occurence of a particular type in the hierarchy for 'this' type. The input is going to be a generic type,
  1432. * and the caller wants to know if it was used in its RAW or a PARAMETERIZED form in this hierarchy.
  1433. *
  1434. * returns null if it can't be found.
  1435. */
  1436. public ResolvedType discoverActualOccurrenceOfTypeInHierarchy(ResolvedType lookingFor) {
  1437. if (!lookingFor.isGenericType()) {
  1438. throw new BCException("assertion failed: method should only be called with generic type, but " + lookingFor + " is "
  1439. + lookingFor.typeKind);
  1440. }
  1441. if (this.equals(ResolvedType.OBJECT)) {
  1442. return null;
  1443. }
  1444. if (genericTypeEquals(lookingFor)) {
  1445. return this;
  1446. }
  1447. ResolvedType superT = getSuperclass();
  1448. if (superT.genericTypeEquals(lookingFor)) {
  1449. return superT;
  1450. }
  1451. ResolvedType[] superIs = getDeclaredInterfaces();
  1452. for (int i = 0; i < superIs.length; i++) {
  1453. ResolvedType superI = superIs[i];
  1454. if (superI.genericTypeEquals(lookingFor)) {
  1455. return superI;
  1456. }
  1457. ResolvedType checkTheSuperI = superI.discoverActualOccurrenceOfTypeInHierarchy(lookingFor);
  1458. if (checkTheSuperI != null) {
  1459. return checkTheSuperI;
  1460. }
  1461. }
  1462. return superT.discoverActualOccurrenceOfTypeInHierarchy(lookingFor);
  1463. }
  1464. /**
  1465. * Called for all type mungers but only does something if they share type variables with a generic type which they target. When
  1466. * this happens this routine will check for the target type in the target hierarchy and 'bind' any type parameters as
  1467. * appropriate. For example, for the ITD "List<T> I<T>.x" against a type like this: "class A implements I<String>" this routine
  1468. * will return a parameterized form of the ITD "List<String> I.x"
  1469. */
  1470. public ConcreteTypeMunger fillInAnyTypeParameters(ConcreteTypeMunger munger) {
  1471. boolean debug = false;
  1472. ResolvedMember member = munger.getSignature();
  1473. if (munger.isTargetTypeParameterized()) {
  1474. if (debug) {
  1475. System.err.println("Processing attempted parameterization of " + munger + " targetting type " + this);
  1476. }
  1477. if (debug) {
  1478. System.err.println(" This type is " + this + " (" + typeKind + ")");
  1479. }
  1480. // need to tailor this munger instance for the particular target...
  1481. if (debug) {
  1482. System.err.println(" Signature that needs parameterizing: " + member);
  1483. }
  1484. // Retrieve the generic type
  1485. ResolvedType onTypeResolved = world.resolve(member.getDeclaringType());
  1486. ResolvedType onType = onTypeResolved.getGenericType();
  1487. if (onType == null) {
  1488. // The target is not generic
  1489. getWorld().getMessageHandler().handleMessage(
  1490. MessageUtil.error("The target type for the intertype declaration is not generic",
  1491. munger.getSourceLocation()));
  1492. return munger;
  1493. }
  1494. member.resolve(world); // Ensure all parts of the member are resolved
  1495. if (debug) {
  1496. System.err.println(" Actual target ontype: " + onType + " (" + onType.typeKind + ")");
  1497. }
  1498. // quickly find the targettype in the type hierarchy for this type
  1499. // (it will be either RAW or PARAMETERIZED)
  1500. ResolvedType actualTarget = discoverActualOccurrenceOfTypeInHierarchy(onType);
  1501. if (actualTarget == null) {
  1502. throw new BCException("assertion failed: asked " + this + " for occurrence of " + onType + " in its hierarchy??");
  1503. }
  1504. // only bind the tvars if its a parameterized type or the raw type
  1505. // (in which case they collapse to bounds) - don't do it
  1506. // for generic types ;)
  1507. if (!actualTarget.isGenericType()) {
  1508. if (debug) {
  1509. System.err.println("Occurrence in " + this + " is actually " + actualTarget + " (" + actualTarget.typeKind
  1510. + ")");
  1511. // parameterize the signature
  1512. // ResolvedMember newOne =
  1513. // member.parameterizedWith(actualTarget.getTypeParameters(),
  1514. // onType,actualTarget.isParameterizedType());
  1515. }
  1516. }
  1517. // if (!actualTarget.isRawType())
  1518. munger = munger.parameterizedFor(actualTarget);
  1519. if (debug) {
  1520. System.err.println("New sig: " + munger.getSignature());
  1521. }
  1522. if (debug) {
  1523. System.err.println("=====================================");
  1524. }
  1525. }
  1526. return munger;
  1527. }
  1528. /**
  1529. * Add an intertype munger to this type. isDuringCompilation tells us if we should be checking for an error scenario where two
  1530. * ITD fields are trying to use the same name. When this happens during compilation one of them is altered to get mangled name
  1531. * but when it happens during weaving it is too late and we need to put out an error asking them to recompile.
  1532. */
  1533. public void addInterTypeMunger(ConcreteTypeMunger munger, boolean isDuringCompilation) {
  1534. ResolvedMember sig = munger.getSignature();
  1535. bits = (bits & ~MungersAnalyzed); // clear the bit - as the mungers have changed
  1536. if (sig == null || munger.getMunger() == null || munger.getMunger().getKind() == ResolvedTypeMunger.PrivilegedAccess) {
  1537. interTypeMungers.add(munger);
  1538. return;
  1539. }
  1540. // ConcreteTypeMunger originalMunger = munger;
  1541. // we will use the 'parameterized' ITD for all the comparisons but we
  1542. // say the original
  1543. // one passed in actually matched as it will be added to the intertype
  1544. // member finder
  1545. // for the target type. It is possible we only want to do this if a
  1546. // generic type
  1547. // is discovered and the tvar is collapsed to a bound?
  1548. munger = fillInAnyTypeParameters(munger);
  1549. sig = munger.getSignature(); // possibly changed when type parms filled in
  1550. if (sig.getKind() == Member.METHOD) {
  1551. // OPTIMIZE can this be sped up?
  1552. if (clashesWithExistingMember(munger, getMethods(true, false))) { // ITDs checked below
  1553. return;
  1554. }
  1555. if (this.isInterface()) {
  1556. // OPTIMIZE this set of methods are always the same - must we keep creating them as a list?
  1557. if (clashesWithExistingMember(munger, Arrays.asList(world.getCoreType(OBJECT).getDeclaredMethods()).iterator())) {
  1558. return;
  1559. }
  1560. }
  1561. } else if (sig.getKind() == Member.FIELD) {
  1562. if (clashesWithExistingMember(munger, Arrays.asList(getDeclaredFields()).iterator())) {
  1563. return;
  1564. }
  1565. // Cannot cope with two version '2' style mungers for the same field on the same type
  1566. // Must error and request the user recompile at least one aspect with the
  1567. // -Xset:itdStyle=1 option
  1568. if (!isDuringCompilation) {
  1569. ResolvedTypeMunger thisRealMunger = munger.getMunger();
  1570. if (thisRealMunger instanceof NewFieldTypeMunger) {
  1571. NewFieldTypeMunger newFieldTypeMunger = (NewFieldTypeMunger) thisRealMunger;
  1572. if (newFieldTypeMunger.version == NewFieldTypeMunger.VersionTwo) {
  1573. String thisRealMungerSignatureName = newFieldTypeMunger.getSignature().getName();
  1574. for (ConcreteTypeMunger typeMunger : interTypeMungers) {
  1575. if (typeMunger.getMunger() instanceof NewFieldTypeMunger) {
  1576. if (typeMunger.getSignature().getKind() == Member.FIELD) {
  1577. NewFieldTypeMunger existing = (NewFieldTypeMunger) typeMunger.getMunger();
  1578. if (existing.getSignature().getName().equals(thisRealMungerSignatureName)
  1579. && existing.version == NewFieldTypeMunger.VersionTwo
  1580. // this check ensures no problem for a clash with an ITD on an interface
  1581. && existing.getSignature().getDeclaringType()
  1582. .equals(newFieldTypeMunger.getSignature().getDeclaringType())) {
  1583. // report error on the aspect
  1584. StringBuffer sb = new StringBuffer();
  1585. sb.append("Cannot handle two aspects both attempting to use new style ITDs for the same named field ");
  1586. sb.append("on the same target type. Please recompile at least one aspect with '-Xset:itdVersion=1'.");
  1587. sb.append(" Aspects involved: " + munger.getAspectType().getName() + " and "
  1588. + typeMunger.getAspectType().getName() + ".");
  1589. sb.append(" Field is named '" + existing.getSignature().getName() + "'");
  1590. getWorld().getMessageHandler().handleMessage(
  1591. new Message(sb.toString(), getSourceLocation(), true));
  1592. return;
  1593. }
  1594. }
  1595. }
  1596. }
  1597. }
  1598. }
  1599. }
  1600. } else {
  1601. if (clashesWithExistingMember(munger, Arrays.asList(getDeclaredMethods()).iterator())) {
  1602. return;
  1603. }
  1604. }
  1605. boolean needsAdding =true;
  1606. boolean needsToBeAddedEarlier =false;
  1607. // now compare to existingMungers
  1608. for (Iterator<ConcreteTypeMunger> i = interTypeMungers.iterator(); i.hasNext();) {
  1609. ConcreteTypeMunger existingMunger = i.next();
  1610. boolean v2itds = munger.getSignature().getKind()== Member.FIELD && (munger.getMunger() instanceof NewFieldTypeMunger) && ((NewFieldTypeMunger)munger.getMunger()).version==NewFieldTypeMunger.VersionTwo;
  1611. if (conflictingSignature(existingMunger.getSignature(), munger.getSignature(),v2itds)) {
  1612. // System.err.println("match " + munger + " with " + existingMunger);
  1613. if (isVisible(munger.getSignature().getModifiers(), munger.getAspectType(), existingMunger.getAspectType())) {
  1614. // System.err.println(" is visible");
  1615. int c = compareMemberPrecedence(sig, existingMunger.getSignature());
  1616. if (c == 0) {
  1617. c = getWorld().compareByPrecedenceAndHierarchy(munger.getAspectType(), existingMunger.getAspectType());
  1618. }
  1619. // System.err.println(" compare: " + c);
  1620. if (c < 0) {
  1621. // the existing munger dominates the new munger
  1622. checkLegalOverride(munger.getSignature(), existingMunger.getSignature(), 0x11, null);
  1623. needsAdding = false;
  1624. if (munger.getSignature().getKind()== Member.FIELD && munger.getSignature().getDeclaringType().resolve(world).isInterface() && ((NewFieldTypeMunger)munger.getMunger()).version==NewFieldTypeMunger.VersionTwo) {
  1625. // still need to add it
  1626. needsAdding=true;
  1627. }
  1628. break;
  1629. } else if (c > 0) {
  1630. // the new munger dominates the existing one
  1631. checkLegalOverride(existingMunger.getSignature(), munger.getSignature(), 0x11, null);
  1632. // i.remove();
  1633. if (existingMunger.getSignature().getKind()==Member.FIELD &&
  1634. existingMunger.getSignature().getDeclaringType().resolve(world).isInterface()
  1635. && ((NewFieldTypeMunger)existingMunger.getMunger()).version==NewFieldTypeMunger.VersionTwo) {
  1636. needsToBeAddedEarlier=true;
  1637. } else {
  1638. i.remove();
  1639. }
  1640. break;
  1641. } else {
  1642. interTypeConflictError(munger, existingMunger);
  1643. interTypeConflictError(existingMunger, munger);
  1644. return;
  1645. }
  1646. }
  1647. }
  1648. }
  1649. // System.err.println("adding: " + munger + " to " + this);
  1650. // we are adding the parameterized form of the ITD to the list of
  1651. // mungers. Within it, the munger knows the original declared
  1652. // signature for the ITD so it can be retrieved.
  1653. if (needsAdding) {
  1654. if (!needsToBeAddedEarlier) {
  1655. interTypeMungers.add(munger);
  1656. } else {
  1657. interTypeMungers.add(0,munger);
  1658. }
  1659. }
  1660. }
  1661. /**
  1662. * Compare the type transformer with the existing members. A clash may not be an error (the ITD may be the 'default
  1663. * implementation') so returning false is not always a sign of an error.
  1664. *
  1665. * @return true if there is a clash
  1666. */
  1667. private boolean clashesWithExistingMember(ConcreteTypeMunger typeTransformer, Iterator<ResolvedMember> existingMembers) {
  1668. ResolvedMember typeTransformerSignature = typeTransformer.getSignature();
  1669. // ResolvedType declaringAspectType = munger.getAspectType();
  1670. // if (declaringAspectType.isRawType()) declaringAspectType =
  1671. // declaringAspectType.getGenericType();
  1672. // if (declaringAspectType.isGenericType()) {
  1673. //
  1674. // ResolvedType genericOnType =
  1675. // getWorld().resolve(sig.getDeclaringType()).getGenericType();
  1676. // ConcreteTypeMunger ctm =
  1677. // munger.parameterizedFor(discoverActualOccurrenceOfTypeInHierarchy
  1678. // (genericOnType));
  1679. // sig = ctm.getSignature(); // possible sig change when type
  1680. // }
  1681. // if (munger.getMunger().hasTypeVariableAliases()) {
  1682. // ResolvedType genericOnType =
  1683. // getWorld().resolve(sig.getDeclaringType()).getGenericType();
  1684. // ConcreteTypeMunger ctm =
  1685. // munger.parameterizedFor(discoverActualOccurrenceOfTypeInHierarchy(
  1686. // genericOnType));
  1687. // sig = ctm.getSignature(); // possible sig change when type parameters
  1688. // filled in
  1689. // }
  1690. ResolvedTypeMunger rtm = typeTransformer.getMunger();
  1691. boolean v2itds = true;
  1692. if (rtm instanceof NewFieldTypeMunger && ((NewFieldTypeMunger)rtm).version==NewFieldTypeMunger.VersionOne) {
  1693. v2itds = false;
  1694. }
  1695. while (existingMembers.hasNext()) {
  1696. ResolvedMember existingMember = existingMembers.next();
  1697. // don't worry about clashing with bridge methods
  1698. if (existingMember.isBridgeMethod()) {
  1699. continue;
  1700. }
  1701. if (conflictingSignature(existingMember, typeTransformerSignature,v2itds)) {
  1702. // System.err.println("conflict: existingMember=" +
  1703. // existingMember + " typeMunger=" + munger);
  1704. // System.err.println(munger.getSourceLocation() + ", " +
  1705. // munger.getSignature() + ", " +
  1706. // munger.getSignature().getSourceLocation());
  1707. if (isVisible(existingMember.getModifiers(), this, typeTransformer.getAspectType())) {
  1708. int c = compareMemberPrecedence(typeTransformerSignature, existingMember);
  1709. // System.err.println(" c: " + c);
  1710. if (c < 0) {
  1711. ResolvedType typeTransformerTargetType = typeTransformerSignature.getDeclaringType().resolve(world);
  1712. if (typeTransformerTargetType.isInterface()) {
  1713. ResolvedType existingMemberType = existingMember.getDeclaringType().resolve(world);
  1714. if ((rtm instanceof NewMethodTypeMunger) && !typeTransformerTargetType.equals(existingMemberType)) {
  1715. // Might be pr404601. ITD is on an interface with a different visibility to the real member
  1716. if (Modifier.isPrivate(typeTransformerSignature.getModifiers()) &&
  1717. Modifier.isPublic(existingMember.getModifiers())) {
  1718. world.getMessageHandler().handleMessage(new Message("private intertype declaration '"+typeTransformerSignature.toString()+"' clashes with public member '"+existingMember.toString()+"'",existingMember.getSourceLocation(),true));
  1719. }
  1720. }
  1721. }
  1722. // existingMember dominates munger
  1723. checkLegalOverride(typeTransformerSignature, existingMember, 0x10, typeTransformer.getAspectType());
  1724. return true;
  1725. } else if (c > 0) {
  1726. // munger dominates existingMember
  1727. checkLegalOverride(existingMember, typeTransformerSignature, 0x01, typeTransformer.getAspectType());
  1728. // interTypeMungers.add(munger);
  1729. // ??? might need list of these overridden abstracts
  1730. continue;
  1731. } else {
  1732. // bridge methods can differ solely in return type.
  1733. // FIXME this whole method seems very hokey - unaware of covariance/varargs/bridging - it
  1734. // could do with a rewrite !
  1735. boolean sameReturnTypes = (existingMember.getReturnType().equals(typeTransformerSignature.getReturnType()));
  1736. if (sameReturnTypes) {
  1737. // pr206732 - if the existingMember is due to a
  1738. // previous application of this same ITD (which can
  1739. // happen if this is a binary type being brought in
  1740. // from the aspectpath). The 'better' fix is
  1741. // to recognize it is from the aspectpath at a
  1742. // higher level and dont do this, but that is rather
  1743. // more work.
  1744. boolean isDuplicateOfPreviousITD = false;
  1745. ResolvedType declaringRt = existingMember.getDeclaringType().resolve(world);
  1746. WeaverStateInfo wsi = declaringRt.getWeaverState();
  1747. if (wsi != null) {
  1748. List<ConcreteTypeMunger> mungersAffectingThisType = wsi.getTypeMungers(declaringRt);
  1749. if (mungersAffectingThisType != null) {
  1750. for (Iterator<ConcreteTypeMunger> iterator = mungersAffectingThisType.iterator(); iterator
  1751. .hasNext() && !isDuplicateOfPreviousITD;) {
  1752. ConcreteTypeMunger ctMunger = iterator.next();
  1753. // relatively crude check - is the ITD
  1754. // for the same as the existingmember
  1755. // and does it come
  1756. // from the same aspect
  1757. if (ctMunger.getSignature().equals(existingMember)
  1758. && ctMunger.aspectType.equals(typeTransformer.getAspectType())) {
  1759. isDuplicateOfPreviousITD = true;
  1760. }
  1761. }
  1762. }
  1763. }
  1764. if (!isDuplicateOfPreviousITD) {
  1765. // b275032 - this is OK if it is the default ctor and that default ctor was generated
  1766. // at compile time, otherwise we cannot overwrite it
  1767. if (!(typeTransformerSignature.getName().equals("<init>") && existingMember.isDefaultConstructor())) {
  1768. String aspectName = typeTransformer.getAspectType().getName();
  1769. ISourceLocation typeTransformerLocation = typeTransformer.getSourceLocation();
  1770. ISourceLocation existingMemberLocation = existingMember.getSourceLocation();
  1771. String msg = WeaverMessages.format(WeaverMessages.ITD_MEMBER_CONFLICT, aspectName,
  1772. existingMember);
  1773. // this isn't quite right really... as I think the errors should only be recorded against
  1774. // what is currently being processed or they may get lost or reported twice
  1775. // report error on the aspect
  1776. getWorld().getMessageHandler().handleMessage(new Message(msg, typeTransformerLocation, true));
  1777. // report error on the affected type, if we can
  1778. if (existingMemberLocation != null) {
  1779. getWorld().getMessageHandler()
  1780. .handleMessage(new Message(msg, existingMemberLocation, true));
  1781. }
  1782. return true; // clash - so ignore this itd
  1783. }
  1784. }
  1785. }
  1786. }
  1787. } else if (isDuplicateMemberWithinTargetType(existingMember, this, typeTransformerSignature)) {
  1788. getWorld().getMessageHandler().handleMessage(
  1789. MessageUtil.error(WeaverMessages.format(WeaverMessages.ITD_MEMBER_CONFLICT, typeTransformer
  1790. .getAspectType().getName(), existingMember), typeTransformer.getSourceLocation()));
  1791. return true;
  1792. }
  1793. }
  1794. }
  1795. return false;
  1796. }
  1797. // we know that the member signature matches, but that the member in the
  1798. // target type is not visible to the aspect.
  1799. // this may still be disallowed if it would result in two members within the
  1800. // same declaring type with the same
  1801. // signature AND more than one of them is concrete AND they are both visible
  1802. // within the target type.
  1803. private boolean isDuplicateMemberWithinTargetType(ResolvedMember existingMember, ResolvedType targetType,
  1804. ResolvedMember itdMember) {
  1805. if ((existingMember.isAbstract() || itdMember.isAbstract())) {
  1806. return false;
  1807. }
  1808. UnresolvedType declaringType = existingMember.getDeclaringType();
  1809. if (!targetType.equals(declaringType)) {
  1810. return false;
  1811. }
  1812. // now have to test that itdMember is visible from targetType
  1813. if (Modifier.isPrivate(itdMember.getModifiers())) {
  1814. return false;
  1815. }
  1816. if (itdMember.isPublic()) {
  1817. return true;
  1818. }
  1819. // must be in same package to be visible then...
  1820. if (!targetType.getPackageName().equals(itdMember.getDeclaringType().getPackageName())) {
  1821. return false;
  1822. }
  1823. // trying to put two members with the same signature into the exact same
  1824. // type..., and both visible in that type.
  1825. return true;
  1826. }
  1827. /**
  1828. * @param transformerPosition which parameter is the type transformer (0x10 for first, 0x01 for second, 0x11 for both, 0x00 for
  1829. * neither)
  1830. * @param aspectType the declaring type of aspect defining the *first* type transformer
  1831. * @return true if the override is legal note: calling showMessage with two locations issues TWO messages, not ONE message with
  1832. * an additional source location.
  1833. */
  1834. public boolean checkLegalOverride(ResolvedMember parent, ResolvedMember child, int transformerPosition, ResolvedType aspectType) {
  1835. // System.err.println("check: " + child.getDeclaringType() + " overrides " + parent.getDeclaringType());
  1836. if (Modifier.isFinal(parent.getModifiers())) {
  1837. // If the ITD matching is occurring due to pulling in a BinaryTypeBinding then this check can incorrectly
  1838. // signal an error because the ITD transformer being examined here will exactly match the member it added
  1839. // during the first round of compilation. This situation can only occur if the ITD is on an interface whilst
  1840. // the class is the top most implementor. If the ITD is on the same type that received it during compilation,
  1841. // this method won't be called as the previous check for precedence level will return 0.
  1842. if (transformerPosition == 0x10 && aspectType != null) {
  1843. ResolvedType nonItdDeclaringType = child.getDeclaringType().resolve(world);
  1844. WeaverStateInfo wsi = nonItdDeclaringType.getWeaverState();
  1845. if (wsi != null) {
  1846. List<ConcreteTypeMunger> transformersOnThisType = wsi.getTypeMungers(nonItdDeclaringType);
  1847. if (transformersOnThisType != null) {
  1848. for (ConcreteTypeMunger transformer : transformersOnThisType) {
  1849. // relatively crude check - is the ITD for the same as the existingmember
  1850. // and does it come from the same aspect
  1851. if (transformer.aspectType.equals(aspectType)) {
  1852. if (parent.equalsApartFromDeclaringType(transformer.getSignature())) {
  1853. return true;
  1854. }
  1855. }
  1856. }
  1857. }
  1858. }
  1859. }
  1860. world.showMessage(Message.ERROR, WeaverMessages.format(WeaverMessages.CANT_OVERRIDE_FINAL_MEMBER, parent),
  1861. child.getSourceLocation(), null);
  1862. return false;
  1863. }
  1864. boolean incompatibleReturnTypes = false;
  1865. // In 1.5 mode, allow for covariance on return type
  1866. if (world.isInJava5Mode() && parent.getKind() == Member.METHOD) {
  1867. // Look at the generic types when doing this comparison
  1868. ResolvedType rtParentReturnType = parent.resolve(world).getGenericReturnType().resolve(world);
  1869. ResolvedType rtChildReturnType = child.resolve(world).getGenericReturnType().resolve(world);
  1870. incompatibleReturnTypes = !rtParentReturnType.isAssignableFrom(rtChildReturnType);
  1871. // For debug, uncomment this bit and we'll repeat the check - stick
  1872. // a breakpoint on the call
  1873. // if (incompatibleReturnTypes) {
  1874. // incompatibleReturnTypes =
  1875. // !rtParentReturnType.isAssignableFrom(rtChildReturnType);
  1876. // }
  1877. } else {
  1878. ResolvedType rtParentReturnType = parent.resolve(world).getGenericReturnType().resolve(world);
  1879. ResolvedType rtChildReturnType = child.resolve(world).getGenericReturnType().resolve(world);
  1880. incompatibleReturnTypes = !rtParentReturnType.equals(rtChildReturnType);
  1881. }
  1882. if (incompatibleReturnTypes) {
  1883. world.showMessage(IMessage.ERROR, WeaverMessages.format(WeaverMessages.ITD_RETURN_TYPE_MISMATCH, parent, child),
  1884. child.getSourceLocation(), parent.getSourceLocation());
  1885. return false;
  1886. }
  1887. if (parent.getKind() == Member.POINTCUT) {
  1888. UnresolvedType[] pTypes = parent.getParameterTypes();
  1889. UnresolvedType[] cTypes = child.getParameterTypes();
  1890. if (!Arrays.equals(pTypes, cTypes)) {
  1891. world.showMessage(IMessage.ERROR, WeaverMessages.format(WeaverMessages.ITD_PARAM_TYPE_MISMATCH, parent, child),
  1892. child.getSourceLocation(), parent.getSourceLocation());
  1893. return false;
  1894. }
  1895. }
  1896. // System.err.println("check: " + child.getModifiers() +
  1897. // " more visible " + parent.getModifiers());
  1898. if (isMoreVisible(parent.getModifiers(), child.getModifiers())) {
  1899. world.showMessage(IMessage.ERROR, WeaverMessages.format(WeaverMessages.ITD_VISIBILITY_REDUCTION, parent, child),
  1900. child.getSourceLocation(), parent.getSourceLocation());
  1901. return false;
  1902. }
  1903. // check declared exceptions
  1904. ResolvedType[] childExceptions = world.resolve(child.getExceptions());
  1905. ResolvedType[] parentExceptions = world.resolve(parent.getExceptions());
  1906. ResolvedType runtimeException = world.resolve("java.lang.RuntimeException");
  1907. ResolvedType error = world.resolve("java.lang.Error");
  1908. outer: for (int i = 0, leni = childExceptions.length; i < leni; i++) {
  1909. // System.err.println("checking: " + childExceptions[i]);
  1910. if (runtimeException.isAssignableFrom(childExceptions[i])) {
  1911. continue;
  1912. }
  1913. if (error.isAssignableFrom(childExceptions[i])) {
  1914. continue;
  1915. }
  1916. for (int j = 0, lenj = parentExceptions.length; j < lenj; j++) {
  1917. if (parentExceptions[j].isAssignableFrom(childExceptions[i])) {
  1918. continue outer;
  1919. }
  1920. }
  1921. // this message is now better handled my MethodVerifier in JDT core.
  1922. // world.showMessage(IMessage.ERROR,
  1923. // WeaverMessages.format(WeaverMessages.ITD_DOESNT_THROW,
  1924. // childExceptions[i].getName()),
  1925. // child.getSourceLocation(), null);
  1926. return false;
  1927. }
  1928. boolean parentStatic = Modifier.isStatic(parent.getModifiers());
  1929. boolean childStatic = Modifier.isStatic(child.getModifiers());
  1930. if (parentStatic && !childStatic) {
  1931. world.showMessage(IMessage.ERROR, WeaverMessages.format(WeaverMessages.ITD_OVERRIDDEN_STATIC, child, parent),
  1932. child.getSourceLocation(), null);
  1933. return false;
  1934. } else if (childStatic && !parentStatic) {
  1935. world.showMessage(IMessage.ERROR, WeaverMessages.format(WeaverMessages.ITD_OVERIDDING_STATIC, child, parent),
  1936. child.getSourceLocation(), null);
  1937. return false;
  1938. }
  1939. return true;
  1940. }
  1941. private int compareMemberPrecedence(ResolvedMember m1, ResolvedMember m2) {
  1942. // if (!m1.getReturnType().equals(m2.getReturnType())) return 0;
  1943. // need to allow for the special case of 'clone' - which is like
  1944. // abstract but is
  1945. // not marked abstract. The code below this next line seems to make
  1946. // assumptions
  1947. // about what will have gotten through the compiler based on the normal
  1948. // java rules. clone goes against these...
  1949. if (Modifier.isProtected(m2.getModifiers()) && m2.getName().charAt(0) == 'c') {
  1950. UnresolvedType declaring = m2.getDeclaringType();
  1951. if (declaring != null) {
  1952. if (declaring.getName().equals("java.lang.Object") && m2.getName().equals("clone")) {
  1953. return +1;
  1954. }
  1955. }
  1956. }
  1957. if (Modifier.isAbstract(m1.getModifiers())) {
  1958. return -1;
  1959. }
  1960. if (Modifier.isAbstract(m2.getModifiers())) {
  1961. return +1;
  1962. }
  1963. if (m1.getDeclaringType().equals(m2.getDeclaringType())) {
  1964. return 0;
  1965. }
  1966. ResolvedType t1 = m1.getDeclaringType().resolve(world);
  1967. ResolvedType t2 = m2.getDeclaringType().resolve(world);
  1968. if (t1.isAssignableFrom(t2)) {
  1969. return -1;
  1970. }
  1971. if (t2.isAssignableFrom(t1)) {
  1972. return +1;
  1973. }
  1974. return 0;
  1975. }
  1976. public static boolean isMoreVisible(int m1, int m2) {
  1977. if (Modifier.isPrivate(m1)) {
  1978. return false;
  1979. }
  1980. if (isPackage(m1)) {
  1981. return Modifier.isPrivate(m2);
  1982. }
  1983. if (Modifier.isProtected(m1)) {
  1984. return /* private package */(Modifier.isPrivate(m2) || isPackage(m2));
  1985. }
  1986. if (Modifier.isPublic(m1)) {
  1987. return /* private package protected */!Modifier.isPublic(m2);
  1988. }
  1989. throw new RuntimeException("bad modifier: " + m1);
  1990. }
  1991. private static boolean isPackage(int i) {
  1992. return (0 == (i & (Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED)));
  1993. }
  1994. private void interTypeConflictError(ConcreteTypeMunger m1, ConcreteTypeMunger m2) {
  1995. // XXX this works only if we ignore separate compilation issues
  1996. // XXX dual errors possible if (this instanceof BcelObjectType) return;
  1997. /*
  1998. * if (m1.getMunger().getKind() == ResolvedTypeMunger.Field && m2.getMunger().getKind() == ResolvedTypeMunger.Field) { // if
  1999. * *exactly* the same, it's ok return true; }
  2000. */
  2001. // System.err.println("conflict at " + m2.getSourceLocation());
  2002. getWorld().showMessage(
  2003. IMessage.ERROR,
  2004. WeaverMessages.format(WeaverMessages.ITD_CONFLICT, m1.getAspectType().getName(), m2.getSignature(), m2
  2005. .getAspectType().getName()), m2.getSourceLocation(), getSourceLocation());
  2006. // return false;
  2007. }
  2008. public ResolvedMember lookupSyntheticMember(Member member) {
  2009. // ??? horribly inefficient
  2010. // for (Iterator i =
  2011. // System.err.println("lookup " + member + " in " + interTypeMungers);
  2012. for (ConcreteTypeMunger m : interTypeMungers) {
  2013. ResolvedMember ret = m.getMatchingSyntheticMember(member);
  2014. if (ret != null) {
  2015. // System.err.println(" found: " + ret);
  2016. return ret;
  2017. }
  2018. }
  2019. // Handling members for the new array join point
  2020. if (world.isJoinpointArrayConstructionEnabled() && this.isArray()) {
  2021. if (member.getKind() == Member.CONSTRUCTOR) {
  2022. ResolvedMemberImpl ret = new ResolvedMemberImpl(Member.CONSTRUCTOR, this, Modifier.PUBLIC, UnresolvedType.VOID,
  2023. "<init>", world.resolve(member.getParameterTypes()));
  2024. // Give the parameters names - they are going to be the dimensions uses to build the array (dim0 > dimN)
  2025. int count = ret.getParameterTypes().length;
  2026. String[] paramNames = new String[count];
  2027. for (int i = 0; i < count; i++) {
  2028. paramNames[i] = new StringBuffer("dim").append(i).toString();
  2029. }
  2030. ret.setParameterNames(paramNames);
  2031. return ret;
  2032. }
  2033. }
  2034. // if (this.getSuperclass() != ResolvedType.OBJECT &&
  2035. // this.getSuperclass() != null) {
  2036. // return getSuperclass().lookupSyntheticMember(member);
  2037. // }
  2038. return null;
  2039. }
  2040. static class SuperClassWalker implements Iterator<ResolvedType> {
  2041. private ResolvedType curr;
  2042. private SuperInterfaceWalker iwalker;
  2043. private boolean wantGenerics;
  2044. public SuperClassWalker(ResolvedType type, SuperInterfaceWalker iwalker, boolean genericsAware) {
  2045. this.curr = type;
  2046. this.iwalker = iwalker;
  2047. this.wantGenerics = genericsAware;
  2048. }
  2049. @Override
  2050. public boolean hasNext() {
  2051. return curr != null;
  2052. }
  2053. @Override
  2054. public ResolvedType next() {
  2055. ResolvedType ret = curr;
  2056. if (!wantGenerics && ret.isParameterizedOrGenericType()) {
  2057. ret = ret.getRawType();
  2058. }
  2059. iwalker.push(ret); // tell the interface walker about another class whose interfaces need visiting
  2060. curr = curr.getSuperclass();
  2061. return ret;
  2062. }
  2063. @Override
  2064. public void remove() {
  2065. throw new UnsupportedOperationException();
  2066. }
  2067. }
  2068. static class SuperInterfaceWalker implements Iterator<ResolvedType> {
  2069. private Getter<ResolvedType, ResolvedType> ifaceGetter;
  2070. Iterator<ResolvedType> delegate = null;
  2071. public Queue<ResolvedType> toPersue = new LinkedList<ResolvedType>();
  2072. public Set<ResolvedType> visited = new HashSet<ResolvedType>();
  2073. SuperInterfaceWalker(Iterators.Getter<ResolvedType, ResolvedType> ifaceGetter) {
  2074. this.ifaceGetter = ifaceGetter;
  2075. }
  2076. SuperInterfaceWalker(Iterators.Getter<ResolvedType, ResolvedType> ifaceGetter, ResolvedType interfaceType) {
  2077. this.ifaceGetter = ifaceGetter;
  2078. this.delegate = Iterators.one(interfaceType);
  2079. }
  2080. @Override
  2081. public boolean hasNext() {
  2082. if (delegate == null || !delegate.hasNext()) {
  2083. // either we set it up or we have run out, is there anything else to look at?
  2084. if (toPersue.isEmpty()) {
  2085. return false;
  2086. }
  2087. do {
  2088. ResolvedType next = toPersue.remove();
  2089. visited.add(next);
  2090. delegate = ifaceGetter.get(next); // retrieve interfaces from a class or another interface
  2091. } while (!delegate.hasNext() && !toPersue.isEmpty());
  2092. }
  2093. return delegate.hasNext();
  2094. }
  2095. public void push(ResolvedType ret) {
  2096. toPersue.add(ret);
  2097. }
  2098. @Override
  2099. public ResolvedType next() {
  2100. ResolvedType next = delegate.next();
  2101. // BUG should check for generics and erase?
  2102. // if (!visited.contains(next)) {
  2103. // visited.add(next);
  2104. if (visited.add(next)) {
  2105. toPersue.add(next); // pushes on interfaces already visited?
  2106. }
  2107. return next;
  2108. }
  2109. @Override
  2110. public void remove() {
  2111. throw new UnsupportedOperationException();
  2112. }
  2113. }
  2114. public void clearInterTypeMungers() {
  2115. if (isRawType()) {
  2116. ResolvedType genericType = getGenericType();
  2117. if (genericType.isRawType()) { // ERROR SITUATION: PR341926
  2118. // For some reason the raw type is pointing to another raw form (possibly itself)
  2119. System.err.println("DebugFor341926: Type " + this.getName() + " has an incorrect generic form");
  2120. } else {
  2121. genericType.clearInterTypeMungers();
  2122. }
  2123. }
  2124. // interTypeMungers.clear();
  2125. // BUG? Why can't this be clear() instead: 293620 c6
  2126. interTypeMungers = new ArrayList<ConcreteTypeMunger>();
  2127. }
  2128. public boolean isTopmostImplementor(ResolvedType interfaceType) {
  2129. boolean b = true;
  2130. if (isInterface()) {
  2131. b = false;
  2132. } else if (!interfaceType.isAssignableFrom(this, true)) {
  2133. b = false;
  2134. } else {
  2135. ResolvedType superclass = this.getSuperclass();
  2136. if (superclass.isMissing()) {
  2137. b = true; // we don't know anything about supertype, and it can't be exposed to weaver
  2138. } else if (interfaceType.isAssignableFrom(superclass, true)) { // check that I'm truly the topmost implementor
  2139. b = false;
  2140. }
  2141. }
  2142. // System.out.println("is " + getName() + " topmostimplementor of " + interfaceType + "? " + b);
  2143. return b;
  2144. }
  2145. public ResolvedType getTopmostImplementor(ResolvedType interfaceType) {
  2146. if (isInterface()) {
  2147. return null;
  2148. }
  2149. if (!interfaceType.isAssignableFrom(this)) {
  2150. return null;
  2151. }
  2152. // Check if my super class is an implementor?
  2153. ResolvedType higherType = this.getSuperclass().getTopmostImplementor(interfaceType);
  2154. if (higherType != null) {
  2155. return higherType;
  2156. }
  2157. return this;
  2158. }
  2159. public List<ResolvedMember> getExposedPointcuts() {
  2160. List<ResolvedMember> ret = new ArrayList<ResolvedMember>();
  2161. if (getSuperclass() != null) {
  2162. ret.addAll(getSuperclass().getExposedPointcuts());
  2163. }
  2164. for (ResolvedType type : getDeclaredInterfaces()) {
  2165. addPointcutsResolvingConflicts(ret, Arrays.asList(type.getDeclaredPointcuts()), false);
  2166. }
  2167. addPointcutsResolvingConflicts(ret, Arrays.asList(getDeclaredPointcuts()), true);
  2168. for (ResolvedMember member : ret) {
  2169. ResolvedPointcutDefinition inherited = (ResolvedPointcutDefinition) member;
  2170. if (inherited != null && inherited.isAbstract()) {
  2171. if (!this.isAbstract()) {
  2172. getWorld().showMessage(IMessage.ERROR,
  2173. WeaverMessages.format(WeaverMessages.POINCUT_NOT_CONCRETE, inherited, this.getName()),
  2174. inherited.getSourceLocation(), this.getSourceLocation());
  2175. }
  2176. }
  2177. }
  2178. return ret;
  2179. }
  2180. private void addPointcutsResolvingConflicts(List<ResolvedMember> acc, List<ResolvedMember> added, boolean isOverriding) {
  2181. for (Iterator<ResolvedMember> i = added.iterator(); i.hasNext();) {
  2182. ResolvedPointcutDefinition toAdd = (ResolvedPointcutDefinition) i.next();
  2183. for (Iterator<ResolvedMember> j = acc.iterator(); j.hasNext();) {
  2184. ResolvedPointcutDefinition existing = (ResolvedPointcutDefinition) j.next();
  2185. if (toAdd == null || existing == null || existing == toAdd) {
  2186. continue;
  2187. }
  2188. UnresolvedType pointcutDeclaringTypeUT = existing.getDeclaringType();
  2189. if (pointcutDeclaringTypeUT != null) {
  2190. ResolvedType pointcutDeclaringType = pointcutDeclaringTypeUT.resolve(getWorld());
  2191. if (!isVisible(existing.getModifiers(), pointcutDeclaringType, this)) {
  2192. // if they intended to override it but it is not visible,
  2193. // give them a nicer message
  2194. if (existing.isAbstract() && conflictingSignature(existing, toAdd)) {
  2195. getWorld().showMessage(
  2196. IMessage.ERROR,
  2197. WeaverMessages.format(WeaverMessages.POINTCUT_NOT_VISIBLE, existing.getDeclaringType()
  2198. .getName() + "." + existing.getName() + "()", this.getName()),
  2199. toAdd.getSourceLocation(), null);
  2200. j.remove();
  2201. }
  2202. continue;
  2203. }
  2204. }
  2205. if (conflictingSignature(existing, toAdd)) {
  2206. if (isOverriding) {
  2207. checkLegalOverride(existing, toAdd, 0x00, null);
  2208. j.remove();
  2209. } else {
  2210. getWorld().showMessage(
  2211. IMessage.ERROR,
  2212. WeaverMessages.format(WeaverMessages.CONFLICTING_INHERITED_POINTCUTS,
  2213. this.getName() + toAdd.getSignature()), existing.getSourceLocation(),
  2214. toAdd.getSourceLocation());
  2215. j.remove();
  2216. }
  2217. }
  2218. }
  2219. acc.add(toAdd);
  2220. }
  2221. }
  2222. public ISourceLocation getSourceLocation() {
  2223. return null;
  2224. }
  2225. public boolean isExposedToWeaver() {
  2226. return false;
  2227. }
  2228. public WeaverStateInfo getWeaverState() {
  2229. return null;
  2230. }
  2231. /**
  2232. * Overridden by ReferenceType to return a sensible answer for parameterized and raw types.
  2233. *
  2234. * @return
  2235. */
  2236. public ReferenceType getGenericType() {
  2237. // if (!(isParameterizedType() || isRawType()))
  2238. // throw new BCException("The type " + getBaseName() + " is not parameterized or raw - it has no generic type");
  2239. return null;
  2240. }
  2241. @Override
  2242. public ResolvedType getRawType() {
  2243. return super.getRawType().resolve(world);
  2244. }
  2245. public ResolvedType parameterizedWith(UnresolvedType[] typeParameters) {
  2246. if (!(isGenericType() || isParameterizedType())) {
  2247. return this;
  2248. }
  2249. return TypeFactory.createParameterizedType(this.getGenericType(), typeParameters, getWorld());
  2250. }
  2251. /**
  2252. * Iff I am a parameterized type, and any of my parameters are type variable references (or nested parameterized types),
  2253. * return a version with those type parameters replaced in accordance with the passed bindings.
  2254. */
  2255. @Override
  2256. public UnresolvedType parameterize(Map<String, UnresolvedType> typeBindings) {
  2257. if (!isParameterizedType()) {
  2258. // throw new IllegalStateException("Can't parameterize a type that is not a parameterized type");
  2259. return this;
  2260. }
  2261. boolean workToDo = false;
  2262. for (int i = 0; i < typeParameters.length; i++) {
  2263. if (typeParameters[i].isTypeVariableReference() || (typeParameters[i] instanceof BoundedReferenceType) || typeParameters[i].isParameterizedType()) {
  2264. workToDo = true;
  2265. }
  2266. }
  2267. if (!workToDo) {
  2268. return this;
  2269. } else {
  2270. UnresolvedType[] newTypeParams = new UnresolvedType[typeParameters.length];
  2271. for (int i = 0; i < newTypeParams.length; i++) {
  2272. newTypeParams[i] = typeParameters[i];
  2273. if (newTypeParams[i].isTypeVariableReference()) {
  2274. TypeVariableReferenceType tvrt = (TypeVariableReferenceType) newTypeParams[i];
  2275. UnresolvedType binding = typeBindings.get(tvrt.getTypeVariable().getName());
  2276. if (binding != null) {
  2277. newTypeParams[i] = binding;
  2278. }
  2279. } else if (newTypeParams[i] instanceof BoundedReferenceType) {
  2280. BoundedReferenceType brType = (BoundedReferenceType) newTypeParams[i];
  2281. newTypeParams[i] = brType.parameterize(typeBindings);
  2282. // brType.parameterize(typeBindings)
  2283. } else if (newTypeParams[i].isParameterizedType()) {
  2284. newTypeParams[i] = newTypeParams[i].parameterize(typeBindings);
  2285. }
  2286. }
  2287. return TypeFactory.createParameterizedType(getGenericType(), newTypeParams, getWorld());
  2288. }
  2289. }
  2290. // public boolean hasParameterizedSuperType() {
  2291. // getParameterizedSuperTypes();
  2292. // return parameterizedSuperTypes.length > 0;
  2293. // }
  2294. // public boolean hasGenericSuperType() {
  2295. // ResolvedType[] superTypes = getDeclaredInterfaces();
  2296. // for (int i = 0; i < superTypes.length; i++) {
  2297. // if (superTypes[i].isGenericType())
  2298. // return true;
  2299. // }
  2300. // return false;
  2301. // }
  2302. // private ResolvedType[] parameterizedSuperTypes = null;
  2303. /**
  2304. * Similar to the above method, but accumulates the super types
  2305. *
  2306. * @return
  2307. */
  2308. // public ResolvedType[] getParameterizedSuperTypes() {
  2309. // if (parameterizedSuperTypes != null)
  2310. // return parameterizedSuperTypes;
  2311. // List accumulatedTypes = new ArrayList();
  2312. // accumulateParameterizedSuperTypes(this, accumulatedTypes);
  2313. // ResolvedType[] ret = new ResolvedType[accumulatedTypes.size()];
  2314. // parameterizedSuperTypes = (ResolvedType[]) accumulatedTypes.toArray(ret);
  2315. // return parameterizedSuperTypes;
  2316. // }
  2317. // private void accumulateParameterizedSuperTypes(ResolvedType forType, List
  2318. // parameterizedTypeList) {
  2319. // if (forType.isParameterizedType()) {
  2320. // parameterizedTypeList.add(forType);
  2321. // }
  2322. // if (forType.getSuperclass() != null) {
  2323. // accumulateParameterizedSuperTypes(forType.getSuperclass(),
  2324. // parameterizedTypeList);
  2325. // }
  2326. // ResolvedType[] interfaces = forType.getDeclaredInterfaces();
  2327. // for (int i = 0; i < interfaces.length; i++) {
  2328. // accumulateParameterizedSuperTypes(interfaces[i], parameterizedTypeList);
  2329. // }
  2330. // }
  2331. /**
  2332. * @return true if assignable to java.lang.Exception
  2333. */
  2334. public boolean isException() {
  2335. return (world.getCoreType(UnresolvedType.JL_EXCEPTION).isAssignableFrom(this));
  2336. }
  2337. /**
  2338. * @return true if it is an exception and it is a checked one, false otherwise.
  2339. */
  2340. public boolean isCheckedException() {
  2341. if (!isException()) {
  2342. return false;
  2343. }
  2344. if (world.getCoreType(UnresolvedType.RUNTIME_EXCEPTION).isAssignableFrom(this)) {
  2345. return false;
  2346. }
  2347. return true;
  2348. }
  2349. /**
  2350. * Determines if variables of this type could be assigned values of another with lots of help. java.lang.Object is convertable
  2351. * from all types. A primitive type is convertable from X iff it's assignable from X. A reference type is convertable from X iff
  2352. * it's coerceable from X. In other words, X isConvertableFrom Y iff the compiler thinks that _some_ value of Y could be
  2353. * assignable to a variable of type X without loss of precision.
  2354. *
  2355. * @param other the other type
  2356. * @param world the {@link World} in which the possible assignment should be checked.
  2357. * @return true iff variables of this type could be assigned values of other with possible conversion
  2358. */
  2359. public final boolean isConvertableFrom(ResolvedType other) {
  2360. // // version from TypeX
  2361. // if (this.equals(OBJECT)) return true;
  2362. // if (this.isPrimitiveType() || other.isPrimitiveType()) return
  2363. // this.isAssignableFrom(other);
  2364. // return this.isCoerceableFrom(other);
  2365. //
  2366. // version from ResolvedTypeX
  2367. if (this.equals(OBJECT)) {
  2368. return true;
  2369. }
  2370. if (world.isInJava5Mode()) {
  2371. if (this.isPrimitiveType() ^ other.isPrimitiveType()) { // If one is
  2372. // primitive
  2373. // and the
  2374. // other
  2375. // isnt
  2376. if (validBoxing.contains(this.getSignature() + other.getSignature())) {
  2377. return true;
  2378. }
  2379. }
  2380. }
  2381. if (this.isPrimitiveType() || other.isPrimitiveType()) {
  2382. return this.isAssignableFrom(other);
  2383. }
  2384. return this.isCoerceableFrom(other);
  2385. }
  2386. /**
  2387. * Determines if the variables of this type could be assigned values of another type without casting. This still allows for
  2388. * assignment conversion as per JLS 2ed 5.2. For object types, this means supertypeOrEqual(THIS, OTHER).
  2389. *
  2390. * @param other the other type
  2391. * @param world the {@link World} in which the possible assignment should be checked.
  2392. * @return true iff variables of this type could be assigned values of other without casting
  2393. * @throws NullPointerException if other is null
  2394. */
  2395. public abstract boolean isAssignableFrom(ResolvedType other);
  2396. public abstract boolean isAssignableFrom(ResolvedType other, boolean allowMissing);
  2397. /**
  2398. * Determines if values of another type could possibly be cast to this type. The rules followed are from JLS 2ed 5.5,
  2399. * "Casting Conversion".
  2400. * <p/>
  2401. * <p>
  2402. * This method should be commutative, i.e., for all UnresolvedType a, b and all World w:
  2403. * <p/>
  2404. * <blockquote>
  2405. *
  2406. * <pre>
  2407. * a.isCoerceableFrom(b, w) == b.isCoerceableFrom(a, w)
  2408. * </pre>
  2409. *
  2410. * </blockquote>
  2411. *
  2412. * @param other the other type
  2413. * @param world the {@link World} in which the possible coersion should be checked.
  2414. * @return true iff values of other could possibly be cast to this type.
  2415. * @throws NullPointerException if other is null.
  2416. */
  2417. public abstract boolean isCoerceableFrom(ResolvedType other);
  2418. public boolean needsNoConversionFrom(ResolvedType o) {
  2419. return isAssignableFrom(o);
  2420. }
  2421. public String getSignatureForAttribute() {
  2422. return signature; // Assume if this is being called that it is for a
  2423. // simple type (eg. void, int, etc)
  2424. }
  2425. private FuzzyBoolean parameterizedWithTypeVariable = FuzzyBoolean.MAYBE;
  2426. /**
  2427. * return true if the parameterization of this type includes a member type variable. Member type variables occur in generic
  2428. * methods/ctors.
  2429. */
  2430. public boolean isParameterizedWithTypeVariable() {
  2431. // MAYBE means we haven't worked it out yet...
  2432. if (parameterizedWithTypeVariable == FuzzyBoolean.MAYBE) {
  2433. // if there are no type parameters then we cant be...
  2434. if (typeParameters == null || typeParameters.length == 0) {
  2435. parameterizedWithTypeVariable = FuzzyBoolean.NO;
  2436. return false;
  2437. }
  2438. for (int i = 0; i < typeParameters.length; i++) {
  2439. ResolvedType aType = (ResolvedType) typeParameters[i];
  2440. if (aType.isTypeVariableReference()
  2441. // Changed according to the problems covered in bug 222648
  2442. // Don't care what kind of type variable - the fact that there
  2443. // is one
  2444. // at all means we can't risk caching it against we get confused
  2445. // later
  2446. // by another variation of the parameterization that just
  2447. // happens to
  2448. // use the same type variable name
  2449. // assume the worst - if its definetly not a type declared one,
  2450. // it could be anything
  2451. // && ((TypeVariableReference)aType).getTypeVariable().
  2452. // getDeclaringElementKind()!=TypeVariable.TYPE
  2453. ) {
  2454. parameterizedWithTypeVariable = FuzzyBoolean.YES;
  2455. return true;
  2456. }
  2457. if (aType.isParameterizedType()) {
  2458. boolean b = aType.isParameterizedWithTypeVariable();
  2459. if (b) {
  2460. parameterizedWithTypeVariable = FuzzyBoolean.YES;
  2461. return true;
  2462. }
  2463. }
  2464. if (aType.isGenericWildcard()) {
  2465. BoundedReferenceType boundedRT = (BoundedReferenceType) aType;
  2466. if (boundedRT.isExtends()) {
  2467. boolean b = false;
  2468. UnresolvedType upperBound = boundedRT.getUpperBound();
  2469. if (upperBound.isParameterizedType()) {
  2470. b = ((ResolvedType) upperBound).isParameterizedWithTypeVariable();
  2471. } else if (upperBound.isTypeVariableReference()
  2472. && ((TypeVariableReference) upperBound).getTypeVariable().getDeclaringElementKind() == TypeVariable.METHOD) {
  2473. b = true;
  2474. }
  2475. if (b) {
  2476. parameterizedWithTypeVariable = FuzzyBoolean.YES;
  2477. return true;
  2478. }
  2479. // FIXME asc need to check additional interface bounds
  2480. }
  2481. if (boundedRT.isSuper()) {
  2482. boolean b = false;
  2483. UnresolvedType lowerBound = boundedRT.getLowerBound();
  2484. if (lowerBound.isParameterizedType()) {
  2485. b = ((ResolvedType) lowerBound).isParameterizedWithTypeVariable();
  2486. } else if (lowerBound.isTypeVariableReference()
  2487. && ((TypeVariableReference) lowerBound).getTypeVariable().getDeclaringElementKind() == TypeVariable.METHOD) {
  2488. b = true;
  2489. }
  2490. if (b) {
  2491. parameterizedWithTypeVariable = FuzzyBoolean.YES;
  2492. return true;
  2493. }
  2494. }
  2495. }
  2496. }
  2497. parameterizedWithTypeVariable = FuzzyBoolean.NO;
  2498. }
  2499. return parameterizedWithTypeVariable.alwaysTrue();
  2500. }
  2501. protected boolean ajMembersNeedParameterization() {
  2502. if (isParameterizedType()) {
  2503. return true;
  2504. }
  2505. ResolvedType superclass = getSuperclass();
  2506. if (superclass != null && !superclass.isMissing()) {
  2507. return superclass.ajMembersNeedParameterization();
  2508. }
  2509. return false;
  2510. }
  2511. protected Map<String, UnresolvedType> getAjMemberParameterizationMap() {
  2512. Map<String, UnresolvedType> myMap = getMemberParameterizationMap();
  2513. if (myMap.isEmpty()) {
  2514. // might extend a parameterized aspect that we also need to
  2515. // consider...
  2516. if (getSuperclass() != null) {
  2517. return getSuperclass().getAjMemberParameterizationMap();
  2518. }
  2519. }
  2520. return myMap;
  2521. }
  2522. public void setBinaryPath(String binaryPath) {
  2523. this.binaryPath = binaryPath;
  2524. }
  2525. /**
  2526. * Returns the path to the jar or class file from which this binary aspect came or null if not a binary aspect
  2527. */
  2528. public String getBinaryPath() {
  2529. return binaryPath;
  2530. }
  2531. /**
  2532. * Undo any temporary modifications to the type (for example it may be holding annotations temporarily whilst some matching is
  2533. * occurring - These annotations will be added properly during weaving but sometimes for type completion they need to be held
  2534. * here for a while).
  2535. */
  2536. public void ensureConsistent() {
  2537. // Nothing to do for anything except a ReferenceType
  2538. }
  2539. /**
  2540. * For an annotation type, this will return if it is marked with @Inherited
  2541. */
  2542. public boolean isInheritedAnnotation() {
  2543. ensureAnnotationBitsInitialized();
  2544. return (bits & AnnotationMarkedInherited) != 0;
  2545. }
  2546. /*
  2547. * Setup the bitflags if they have not already been done.
  2548. */
  2549. private void ensureAnnotationBitsInitialized() {
  2550. if ((bits & AnnotationBitsInitialized) == 0) {
  2551. bits |= AnnotationBitsInitialized;
  2552. // Is it marked @Inherited?
  2553. if (hasAnnotation(UnresolvedType.AT_INHERITED)) {
  2554. bits |= AnnotationMarkedInherited;
  2555. }
  2556. }
  2557. }
  2558. private boolean hasNewParentMungers() {
  2559. if ((bits & MungersAnalyzed) == 0) {
  2560. bits |= MungersAnalyzed;
  2561. for (ConcreteTypeMunger munger : interTypeMungers) {
  2562. ResolvedTypeMunger resolvedTypeMunger = munger.getMunger();
  2563. if (resolvedTypeMunger != null && resolvedTypeMunger.getKind() == ResolvedTypeMunger.Parent) {
  2564. bits |= HasParentMunger;
  2565. }
  2566. }
  2567. }
  2568. return (bits & HasParentMunger) != 0;
  2569. }
  2570. public void tagAsTypeHierarchyComplete() {
  2571. if (isParameterizedOrRawType()) {
  2572. ReferenceType genericType = this.getGenericType();
  2573. genericType.tagAsTypeHierarchyComplete();
  2574. return;
  2575. }
  2576. bits |= TypeHierarchyCompleteBit;
  2577. }
  2578. public boolean isTypeHierarchyComplete() {
  2579. if (isParameterizedOrRawType()) {
  2580. return this.getGenericType().isTypeHierarchyComplete();
  2581. }
  2582. return (bits & TypeHierarchyCompleteBit) != 0;
  2583. }
  2584. /**
  2585. * return the weaver version used to build this type - defaults to the most recent version unless discovered otherwise.
  2586. *
  2587. * @return the (major) version, {@link WeaverVersionInfo}
  2588. */
  2589. public int getCompilerVersion() {
  2590. return WeaverVersionInfo.getCurrentWeaverMajorVersion();
  2591. }
  2592. public boolean isPrimitiveArray() {
  2593. return false;
  2594. }
  2595. public boolean isGroovyObject() {
  2596. if ((bits & GroovyObjectInitialized) == 0) {
  2597. ResolvedType[] intfaces = getDeclaredInterfaces();
  2598. boolean done = false;
  2599. // TODO do we need to walk more of these? (i.e. the interfaces interfaces and supertypes supertype). Check what groovy
  2600. // does in the case where a hierarchy is involved and there are types in between GroovyObject/GroovyObjectSupport and
  2601. // the type
  2602. if (intfaces != null) {
  2603. for (ResolvedType intface : intfaces) {
  2604. if (intface.getName().equals("groovy.lang.GroovyObject")) {
  2605. bits |= IsGroovyObject;
  2606. done = true;
  2607. break;
  2608. }
  2609. }
  2610. }
  2611. if (!done) {
  2612. // take a look at the supertype
  2613. if (getSuperclass().getName().equals("groovy.lang.GroovyObjectSupport")) {
  2614. bits |= IsGroovyObject;
  2615. }
  2616. }
  2617. bits |= GroovyObjectInitialized;
  2618. }
  2619. return (bits & IsGroovyObject) != 0;
  2620. }
  2621. public boolean isPrivilegedAspect() {
  2622. if ((bits & IsPrivilegedBitInitialized) == 0) {
  2623. AnnotationAJ privilegedAnnotation = getAnnotationOfType(UnresolvedType.AJC_PRIVILEGED);
  2624. if (privilegedAnnotation != null) {
  2625. bits |= IsPrivilegedAspect;
  2626. }
  2627. // TODO do we need to reset this bit if the annotations are set again ?
  2628. bits |= IsPrivilegedBitInitialized;
  2629. }
  2630. return (bits & IsPrivilegedAspect) != 0;
  2631. }
  2632. }