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

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