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 99KB

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