Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ResolvedType.java 99KB

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