You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ResolvedType.java 100KB

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