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