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.

BcelTypeMunger.java 41KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055
  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 Common Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/cpl-v10.html
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.weaver.bcel;
  13. import java.lang.reflect.Modifier;
  14. import java.util.Iterator;
  15. import java.util.List;
  16. import java.util.Set;
  17. import org.aspectj.apache.bcel.Constants;
  18. import org.aspectj.apache.bcel.generic.ConstantPoolGen;
  19. import org.aspectj.apache.bcel.generic.FieldGen;
  20. import org.aspectj.apache.bcel.generic.INVOKESPECIAL;
  21. import org.aspectj.apache.bcel.generic.InstructionConstants;
  22. import org.aspectj.apache.bcel.generic.InstructionFactory;
  23. import org.aspectj.apache.bcel.generic.InstructionHandle;
  24. import org.aspectj.apache.bcel.generic.InstructionList;
  25. import org.aspectj.apache.bcel.generic.Type;
  26. import org.aspectj.bridge.IMessage;
  27. import org.aspectj.bridge.ISourceLocation;
  28. import org.aspectj.bridge.Message;
  29. import org.aspectj.bridge.MessageUtil;
  30. import org.aspectj.bridge.WeaveMessage;
  31. import org.aspectj.weaver.AjcMemberMaker;
  32. import org.aspectj.weaver.AsmRelationshipProvider;
  33. import org.aspectj.weaver.ConcreteTypeMunger;
  34. import org.aspectj.weaver.Member;
  35. import org.aspectj.weaver.NameMangler;
  36. import org.aspectj.weaver.NewConstructorTypeMunger;
  37. import org.aspectj.weaver.NewFieldTypeMunger;
  38. import org.aspectj.weaver.NewMethodTypeMunger;
  39. import org.aspectj.weaver.NewParentTypeMunger;
  40. import org.aspectj.weaver.PerObjectInterfaceTypeMunger;
  41. import org.aspectj.weaver.PrivilegedAccessMunger;
  42. import org.aspectj.weaver.ResolvedMember;
  43. import org.aspectj.weaver.ResolvedTypeMunger;
  44. import org.aspectj.weaver.ResolvedTypeX;
  45. import org.aspectj.weaver.TypeX;
  46. import org.aspectj.weaver.WeaverMessages;
  47. import org.aspectj.weaver.WeaverStateInfo;
  48. import org.aspectj.weaver.patterns.Pointcut;
  49. //XXX addLazyMethodGen is probably bad everywhere
  50. public class BcelTypeMunger extends ConcreteTypeMunger {
  51. public BcelTypeMunger(ResolvedTypeMunger munger, ResolvedTypeX aspectType) {
  52. super(munger, aspectType);
  53. }
  54. public String toString() {
  55. return "(BcelTypeMunger " + getMunger() + ")";
  56. }
  57. public boolean munge(BcelClassWeaver weaver) {
  58. boolean changed = false;
  59. boolean worthReporting = true;
  60. if (munger.getKind() == ResolvedTypeMunger.Field) {
  61. changed = mungeNewField(weaver, (NewFieldTypeMunger)munger);
  62. } else if (munger.getKind() == ResolvedTypeMunger.Method) {
  63. changed = mungeNewMethod(weaver, (NewMethodTypeMunger)munger);
  64. } else if (munger.getKind() == ResolvedTypeMunger.PerObjectInterface) {
  65. changed = mungePerObjectInterface(weaver, (PerObjectInterfaceTypeMunger)munger);
  66. worthReporting = false;
  67. } else if (munger.getKind() == ResolvedTypeMunger.PrivilegedAccess) {
  68. changed = mungePrivilegedAccess(weaver, (PrivilegedAccessMunger)munger);
  69. worthReporting = false;
  70. } else if (munger.getKind() == ResolvedTypeMunger.Constructor) {
  71. changed = mungeNewConstructor(weaver, (NewConstructorTypeMunger)munger);
  72. } else if (munger.getKind() == ResolvedTypeMunger.Parent) {
  73. changed = mungeNewParent(weaver, (NewParentTypeMunger)munger);
  74. } else {
  75. throw new RuntimeException("unimplemented");
  76. }
  77. if (changed && munger.changesPublicSignature()) {
  78. WeaverStateInfo info =
  79. weaver.getLazyClassGen().getOrCreateWeaverStateInfo();
  80. info.addConcreteMunger(this);
  81. }
  82. // Whilst type mungers aren't persisting their source locations, we add this relationship during
  83. // compilation time (see other reference to ResolvedTypeMunger.persist)
  84. if (ResolvedTypeMunger.persistSourceLocation) {
  85. if (changed) {
  86. if (munger.getKind().equals(ResolvedTypeMunger.Parent)) {
  87. AsmRelationshipProvider.getDefault().addRelationship(weaver.getLazyClassGen().getType(), munger,getAspectType());
  88. } else {
  89. AsmRelationshipProvider.getDefault().addRelationship(weaver.getLazyClassGen().getType(), munger,getAspectType());
  90. }
  91. }
  92. }
  93. // TAG: WeavingMessage
  94. if (changed && worthReporting && munger!=null && !weaver.getWorld().getMessageHandler().isIgnoring(IMessage.WEAVEINFO)) {
  95. String tName = weaver.getLazyClassGen().getType().getSourceLocation().getSourceFile().getName();
  96. if (tName.indexOf("no debug info available")!=-1) tName = "no debug info available";
  97. else tName = getShortname(weaver.getLazyClassGen().getType().getSourceLocation().getSourceFile().getPath());
  98. String fName = getShortname(getAspectType().getSourceLocation().getSourceFile().getPath());
  99. if (munger.getKind().equals(ResolvedTypeMunger.Parent)) {
  100. // This message could come out of AjLookupEnvironment.addParent if doing parents
  101. // munging at compile time only...
  102. NewParentTypeMunger parentTM = (NewParentTypeMunger)munger;
  103. if (parentTM.getNewParent().isInterface()) {
  104. weaver.getWorld().getMessageHandler().handleMessage(WeaveMessage.constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_DECLAREPARENTSIMPLEMENTS,
  105. new String[]{weaver.getLazyClassGen().getType().getName(),
  106. tName,parentTM.getNewParent().getName(),fName},
  107. weaver.getLazyClassGen().getClassName(), getAspectType().getName()));
  108. } else {
  109. weaver.getWorld().getMessageHandler().handleMessage(
  110. WeaveMessage.constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_DECLAREPARENTSEXTENDS,
  111. new String[]{weaver.getLazyClassGen().getType().getName(),
  112. tName,parentTM.getNewParent().getName(),fName
  113. }));
  114. // TAG: WeavingMessage DECLARE PARENTS: EXTENDS
  115. // reportDeclareParentsMessage(WeaveMessage.WEAVEMESSAGE_DECLAREPARENTSEXTENDS,sourceType,parent);
  116. }
  117. } else {
  118. weaver.getWorld().getMessageHandler().handleMessage(WeaveMessage.constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_ITD,
  119. new String[]{weaver.getLazyClassGen().getType().getName(),
  120. tName,munger.getKind().toString().toLowerCase(),
  121. getAspectType().getName(),
  122. fName+":'"+munger.getSignature()+"'"},
  123. weaver.getLazyClassGen().getClassName(), getAspectType().getName()));
  124. }
  125. }
  126. return changed;
  127. }
  128. private String getShortname(String path) {
  129. int takefrom = path.lastIndexOf('/');
  130. if (takefrom == -1) {
  131. takefrom = path.lastIndexOf('\\');
  132. }
  133. return path.substring(takefrom+1);
  134. }
  135. /**
  136. * For a long time, AspectJ did not allow binary weaving of declare parents. This restriction is now lifted
  137. * but could do with more testing!
  138. */
  139. private boolean mungeNewParent(BcelClassWeaver weaver, NewParentTypeMunger munger) {
  140. LazyClassGen newParentTarget = weaver.getLazyClassGen();
  141. ResolvedTypeX newParent = munger.getNewParent();
  142. boolean cont = true; // Set to false when we error, so we don't actually *do* the munge
  143. cont = enforceDecpRule1_abstractMethodsImplemented(weaver, munger.getSourceLocation(),newParentTarget, newParent);
  144. cont = enforceDecpRule2_cantExtendFinalClass(weaver,munger.getSourceLocation(),newParentTarget,newParent) && cont;
  145. List methods = newParent.getMethodsWithoutIterator();
  146. for (Iterator iter = methods.iterator(); iter.hasNext();) {
  147. BcelMethod superMethod = (BcelMethod) iter.next();
  148. if (!superMethod.getName().equals("<init>")) {
  149. LazyMethodGen subMethod = findMatchingMethod(newParentTarget, superMethod);
  150. if (subMethod!=null) {
  151. cont = enforceDecpRule3_visibilityChanges(weaver, newParent, superMethod, subMethod) && cont;
  152. cont = enforceDecpRule4_compatibleReturnTypes(weaver, superMethod, subMethod) && cont;
  153. cont = enforceDecpRule5_cantChangeFromStaticToNonstatic(weaver,munger.getSourceLocation(),superMethod,subMethod) && cont;
  154. }
  155. }
  156. }
  157. if (!cont) return false; // A rule was violated and an error message already reported
  158. if (newParent.isClass()) { // Changing the supertype
  159. if (!attemptToModifySuperCalls(weaver,newParentTarget,newParent)) return false;
  160. newParentTarget.setSuperClass(newParent);
  161. } else { // Adding a new interface
  162. newParentTarget.addInterface(newParent,getSourceLocation());
  163. }
  164. return true;
  165. }
  166. /**
  167. * Rule 1: For the declare parents to be allowed, the target type must override and implement
  168. * inherited abstract methods (if the type is not declared abstract)
  169. */
  170. private boolean enforceDecpRule1_abstractMethodsImplemented(BcelClassWeaver weaver, ISourceLocation mungerLoc,LazyClassGen newParentTarget, ResolvedTypeX newParent) {
  171. boolean ruleCheckingSucceeded = true;
  172. if (!(newParentTarget.isAbstract() || newParentTarget.isInterface())) { // Ignore abstract classes or interfaces
  173. List methods = newParent.getMethodsWithoutIterator();
  174. for (Iterator i = methods.iterator(); i.hasNext();) {
  175. BcelMethod o = (BcelMethod)i.next();
  176. if (o.isAbstract() && !o.getName().startsWith("ajc$interField")) { // Ignore abstract methods of ajc$interField prefixed methods
  177. BcelMethod discoveredImpl = null;
  178. List newParentTargetMethods = newParentTarget.getType().getMethodsWithoutIterator();
  179. for (Iterator ii = newParentTargetMethods.iterator(); ii.hasNext() && discoveredImpl==null;) {
  180. BcelMethod gen2 = (BcelMethod) ii.next();
  181. if (gen2.getName().equals(o.getName()) &&
  182. gen2.getParameterSignature().equals(o.getParameterSignature()) && !gen2.isAbstract()) {
  183. discoveredImpl = gen2; // Found a valid implementation !
  184. }
  185. }
  186. if (discoveredImpl == null) {
  187. // didnt find a valid implementation, lets check the ITDs on this type to see if they satisfy it
  188. boolean satisfiedByITD = false;
  189. for (Iterator ii = newParentTarget.getType().getInterTypeMungersIncludingSupers().iterator(); ii.hasNext(); ) {
  190. ConcreteTypeMunger m = (ConcreteTypeMunger)ii.next();
  191. if (m.getMunger() instanceof NewMethodTypeMunger) {
  192. ResolvedMember sig = m.getSignature();
  193. if (!Modifier.isAbstract(sig.getModifiers())) {
  194. if (ResolvedTypeX
  195. .matches(
  196. AjcMemberMaker.interMethod(
  197. sig,m.getAspectType(),sig.getDeclaringType().isInterface(weaver.getWorld())),o)) {
  198. satisfiedByITD = true;
  199. }
  200. }
  201. }
  202. }
  203. if (!satisfiedByITD) {
  204. error(weaver,
  205. "The type " + newParentTarget.getName() + " must implement the inherited abstract method "+o.getDeclaringType()+"."+o.getName()+o.getParameterSignature(),
  206. newParentTarget.getType().getSourceLocation(),new ISourceLocation[]{o.getSourceLocation(),mungerLoc});
  207. ruleCheckingSucceeded=false;
  208. }
  209. }
  210. }
  211. }
  212. }
  213. return ruleCheckingSucceeded;
  214. }
  215. /**
  216. * Rule 2. Can't extend final types
  217. */
  218. private boolean enforceDecpRule2_cantExtendFinalClass(BcelClassWeaver weaver, ISourceLocation mungerLoc,
  219. LazyClassGen newParentTarget, ResolvedTypeX newParent) {
  220. if (newParent.isFinal()) {
  221. error(weaver,"Cannot make type "+newParentTarget.getName()+" extend final class "+newParent.getName(),
  222. newParentTarget.getType().getSourceLocation(),
  223. new ISourceLocation[]{mungerLoc});
  224. return false;
  225. }
  226. return true;
  227. }
  228. /**
  229. * Rule 3. Can't narrow visibility of methods when overriding
  230. */
  231. private boolean enforceDecpRule3_visibilityChanges(BcelClassWeaver weaver, ResolvedTypeX newParent, BcelMethod superMethod, LazyMethodGen subMethod) {
  232. boolean cont = true;
  233. if (superMethod.isPublic()) {
  234. if (subMethod.isProtected() || subMethod.isDefault() || subMethod.isPrivate()) {
  235. weaver.getWorld().getMessageHandler().handleMessage(MessageUtil.error(
  236. "Cannot reduce the visibility of the inherited method '"+superMethod+"' from "+newParent.getName(),
  237. superMethod.getSourceLocation()));
  238. cont=false;
  239. }
  240. } else if (superMethod.isProtected()) {
  241. if (subMethod.isDefault() || subMethod.isPrivate()) {
  242. weaver.getWorld().getMessageHandler().handleMessage(MessageUtil.error(
  243. "Cannot reduce the visibility of the inherited method '"+superMethod+"' from "+newParent.getName(),
  244. superMethod.getSourceLocation()));
  245. cont=false;
  246. }
  247. } else if (superMethod.isDefault()) {
  248. if (subMethod.isPrivate()) {
  249. weaver.getWorld().getMessageHandler().handleMessage(MessageUtil.error(
  250. "Cannot reduce the visibility of the inherited method '"+superMethod+"' from "+newParent.getName(),
  251. superMethod.getSourceLocation()));
  252. cont=false;
  253. }
  254. }
  255. return cont;
  256. }
  257. /**
  258. * Rule 4. Can't have incompatible return types
  259. */
  260. private boolean enforceDecpRule4_compatibleReturnTypes(BcelClassWeaver weaver, BcelMethod superMethod, LazyMethodGen subMethod) {
  261. boolean cont = true;
  262. String superReturnTypeSig = superMethod.getReturnType().getSignature();
  263. String subReturnTypeSig = subMethod.getReturnType().getSignature();
  264. if (!superReturnTypeSig.equals(subReturnTypeSig)) {
  265. // Allow for covariance - wish I could test this (need Java5...)
  266. ResolvedTypeX subType = weaver.getWorld().resolve(subMethod.getReturnType());
  267. ResolvedTypeX superType = weaver.getWorld().resolve(superMethod.getReturnType());
  268. if (!subType.isAssignableFrom(superType)) {
  269. ISourceLocation sloc = subMethod.getSourceLocation();
  270. weaver.getWorld().getMessageHandler().handleMessage(MessageUtil.error(
  271. "The return type is incompatible with "+superMethod.getDeclaringType()+"."+superMethod.getName()+superMethod.getParameterSignature(),
  272. subMethod.getSourceLocation()));
  273. cont=false;
  274. }
  275. }
  276. return cont;
  277. }
  278. /**
  279. * Rule5. Method overrides can't change the staticality (word?) - you can't override and make an instance
  280. * method static or override and make a static method an instance method.
  281. */
  282. private boolean enforceDecpRule5_cantChangeFromStaticToNonstatic(BcelClassWeaver weaver,ISourceLocation mungerLoc,BcelMethod superMethod, LazyMethodGen subMethod ) {
  283. if (superMethod.isStatic() && !subMethod.isStatic()) {
  284. error(weaver,"This instance method "+subMethod.getName()+subMethod.getParameterSignature()+
  285. " cannot override the static method from "+superMethod.getDeclaringType().getName(),
  286. subMethod.getSourceLocation(),new ISourceLocation[]{mungerLoc});
  287. return false;
  288. } else if (!superMethod.isStatic() && subMethod.isStatic()) {
  289. error(weaver,"The static method "+subMethod.getName()+subMethod.getParameterSignature()+
  290. " cannot hide the instance method from "+superMethod.getDeclaringType().getName(),
  291. subMethod.getSourceLocation(),new ISourceLocation[]{mungerLoc});
  292. return false;
  293. }
  294. return true;
  295. }
  296. public void error(BcelClassWeaver weaver,String text,ISourceLocation primaryLoc,ISourceLocation[] extraLocs) {
  297. IMessage msg = new Message(text, primaryLoc, true, extraLocs);
  298. weaver.getWorld().getMessageHandler().handleMessage(msg);
  299. }
  300. private LazyMethodGen findMatchingMethod(LazyClassGen newParentTarget, BcelMethod m) {
  301. LazyMethodGen found = null;
  302. // Search the type for methods overriding super methods (methods that come from the new parent)
  303. // Don't use the return value in the comparison as overriding doesnt
  304. for (Iterator i = newParentTarget.getMethodGens().iterator(); i.hasNext() && found==null;) {
  305. LazyMethodGen gen = (LazyMethodGen) i.next();
  306. if (gen.getName().equals(m.getName()) &&
  307. gen.getParameterSignature().equals(m.getParameterSignature())) {
  308. found = gen;
  309. }
  310. }
  311. return found;
  312. }
  313. /**
  314. * The main part of implementing declare parents extends. Modify super ctor calls to target the new type.
  315. */
  316. public boolean attemptToModifySuperCalls(BcelClassWeaver weaver,LazyClassGen newParentTarget, ResolvedTypeX newParent) {
  317. String currentParent = newParentTarget.getSuperClassname();
  318. List mgs = newParentTarget.getMethodGens();
  319. // Look for ctors to modify
  320. for (Iterator iter = mgs.iterator(); iter.hasNext();) {
  321. LazyMethodGen aMethod = (LazyMethodGen) iter.next();
  322. if (aMethod.getName().equals("<init>")) {
  323. InstructionList insList = aMethod.getBody();
  324. InstructionHandle handle = insList.getStart();
  325. while (handle!= null) {
  326. if (handle.getInstruction() instanceof INVOKESPECIAL) {
  327. ConstantPoolGen cpg = newParentTarget.getConstantPoolGen();
  328. INVOKESPECIAL invokeSpecial = (INVOKESPECIAL)handle.getInstruction();
  329. if (invokeSpecial.getClassName(cpg).equals(currentParent) && invokeSpecial.getMethodName(cpg).equals("<init>")) {
  330. // System.err.println("Transforming super call '<init>"+sp.getSignature(cpg)+"'");
  331. // 1. Check there is a ctor in the new parent with the same signature
  332. ResolvedMember newCtor = getConstructorWithSignature(newParent,invokeSpecial.getSignature(cpg));
  333. if (newCtor == null) {
  334. // 2. Check ITDCs to see if the necessary ctor is provided that way
  335. boolean satisfiedByITDC = false;
  336. for (Iterator ii = newParentTarget.getType().getInterTypeMungersIncludingSupers().iterator(); ii.hasNext() && !satisfiedByITDC; ) {
  337. ConcreteTypeMunger m = (ConcreteTypeMunger)ii.next();
  338. if (m.getMunger() instanceof NewConstructorTypeMunger) {
  339. if (m.getSignature().getSignature().equals(invokeSpecial.getSignature(cpg))) {
  340. satisfiedByITDC = true;
  341. }
  342. }
  343. }
  344. if (!satisfiedByITDC) {
  345. String csig = createReadableCtorSig(newParent, cpg, invokeSpecial);
  346. weaver.getWorld().getMessageHandler().handleMessage(MessageUtil.error(
  347. "Unable to modify hierarchy for "+newParentTarget.getClassName()+" - the constructor "+
  348. csig+" is missing",this.getSourceLocation()));
  349. return false;
  350. }
  351. }
  352. int idx = cpg.addMethodref(newParent.getClassName(), invokeSpecial.getMethodName(cpg), invokeSpecial.getSignature(cpg));
  353. invokeSpecial.setIndex(idx);
  354. }
  355. }
  356. handle = handle.getNext();
  357. }
  358. }
  359. }
  360. return true;
  361. }
  362. /**
  363. * Creates a nice signature for the ctor, something like "(int,Integer,String)"
  364. */
  365. private String createReadableCtorSig(ResolvedTypeX newParent, ConstantPoolGen cpg, INVOKESPECIAL invokeSpecial) {
  366. StringBuffer sb = new StringBuffer();
  367. Type[] ctorArgs = invokeSpecial.getArgumentTypes(cpg);
  368. sb.append(newParent.getClassName());
  369. sb.append("(");
  370. for (int i = 0; i < ctorArgs.length; i++) {
  371. String argtype = ctorArgs[i].toString();
  372. if (argtype.lastIndexOf(".")!=-1)
  373. sb.append(argtype.substring(argtype.lastIndexOf(".")+1));
  374. else
  375. sb.append(argtype);
  376. if (i+1<ctorArgs.length) sb.append(",");
  377. }
  378. sb.append(")");
  379. return sb.toString();
  380. }
  381. private ResolvedMember getConstructorWithSignature(ResolvedTypeX tx,String signature) {
  382. ResolvedMember[] mems = tx.getDeclaredJavaMethods();
  383. for (int i = 0; i < mems.length; i++) {
  384. ResolvedMember rm = mems[i];
  385. if (rm.getName().equals("<init>")) {
  386. if (rm.getSignature().equals(signature)) return rm;
  387. }
  388. }
  389. return null;
  390. }
  391. private boolean mungePrivilegedAccess(
  392. BcelClassWeaver weaver,
  393. PrivilegedAccessMunger munger)
  394. {
  395. LazyClassGen gen = weaver.getLazyClassGen();
  396. ResolvedMember member = munger.getMember();
  397. ResolvedTypeX onType = weaver.getWorld().resolve(member.getDeclaringType(),munger.getSourceLocation());
  398. //System.out.println("munging: " + gen + " with " + member);
  399. if (onType.equals(gen.getType())) {
  400. if (member.getKind() == Member.FIELD) {
  401. //System.out.println("matched: " + gen);
  402. addFieldGetter(gen, member,
  403. AjcMemberMaker.privilegedAccessMethodForFieldGet(aspectType, member));
  404. addFieldSetter(gen, member,
  405. AjcMemberMaker.privilegedAccessMethodForFieldSet(aspectType, member));
  406. return true;
  407. } else if (member.getKind() == Member.METHOD) {
  408. addMethodDispatch(gen, member,
  409. AjcMemberMaker.privilegedAccessMethodForMethod(aspectType, member));
  410. return true;
  411. } else if (member.getKind() == Member.CONSTRUCTOR) {
  412. for (Iterator i = gen.getMethodGens().iterator(); i.hasNext(); ) {
  413. LazyMethodGen m = (LazyMethodGen)i.next();
  414. if (m.getMemberView() != null
  415. && m.getMemberView().getKind() == Member.CONSTRUCTOR) {
  416. // m.getMemberView().equals(member)) {
  417. m.forcePublic();
  418. //return true;
  419. }
  420. }
  421. return true;
  422. //throw new BCException("no match for " + member + " in " + gen);
  423. } else if (member.getKind() == Member.STATIC_INITIALIZATION) {
  424. gen.forcePublic();
  425. return true;
  426. } else {
  427. throw new RuntimeException("unimplemented");
  428. }
  429. }
  430. return false;
  431. }
  432. private void addFieldGetter(
  433. LazyClassGen gen,
  434. ResolvedMember field,
  435. ResolvedMember accessMethod)
  436. {
  437. LazyMethodGen mg = makeMethodGen(gen, accessMethod);
  438. InstructionList il = new InstructionList();
  439. InstructionFactory fact = gen.getFactory();
  440. if (field.isStatic()) {
  441. il.append(fact.createFieldAccess(
  442. gen.getClassName(),
  443. field.getName(),
  444. BcelWorld.makeBcelType(field.getType()), Constants.GETSTATIC));
  445. } else {
  446. il.append(InstructionConstants.ALOAD_0);
  447. il.append(fact.createFieldAccess(
  448. gen.getClassName(),
  449. field.getName(),
  450. BcelWorld.makeBcelType(field.getType()), Constants.GETFIELD));
  451. }
  452. il.append(InstructionFactory.createReturn(BcelWorld.makeBcelType(field.getType())));
  453. mg.getBody().insert(il);
  454. gen.addMethodGen(mg,getSignature().getSourceLocation());
  455. }
  456. private void addFieldSetter(
  457. LazyClassGen gen,
  458. ResolvedMember field,
  459. ResolvedMember accessMethod)
  460. {
  461. LazyMethodGen mg = makeMethodGen(gen, accessMethod);
  462. InstructionList il = new InstructionList();
  463. InstructionFactory fact = gen.getFactory();
  464. Type fieldType = BcelWorld.makeBcelType(field.getType());
  465. if (field.isStatic()) {
  466. il.append(InstructionFactory.createLoad(fieldType, 0));
  467. il.append(fact.createFieldAccess(
  468. gen.getClassName(),
  469. field.getName(),
  470. fieldType, Constants.PUTSTATIC));
  471. } else {
  472. il.append(InstructionConstants.ALOAD_0);
  473. il.append(InstructionFactory.createLoad(fieldType, 1));
  474. il.append(fact.createFieldAccess(
  475. gen.getClassName(),
  476. field.getName(),
  477. fieldType, Constants.PUTFIELD));
  478. }
  479. il.append(InstructionFactory.createReturn(Type.VOID));
  480. mg.getBody().insert(il);
  481. gen.addMethodGen(mg,getSignature().getSourceLocation());
  482. }
  483. private void addMethodDispatch(
  484. LazyClassGen gen,
  485. ResolvedMember method,
  486. ResolvedMember accessMethod)
  487. {
  488. LazyMethodGen mg = makeMethodGen(gen, accessMethod);
  489. InstructionList il = new InstructionList();
  490. InstructionFactory fact = gen.getFactory();
  491. //Type fieldType = BcelWorld.makeBcelType(field.getType());
  492. Type[] paramTypes = BcelWorld.makeBcelTypes(method.getParameterTypes());
  493. int pos = 0;
  494. if (!method.isStatic()) {
  495. il.append(InstructionConstants.ALOAD_0);
  496. pos++;
  497. }
  498. for (int i = 0, len = paramTypes.length; i < len; i++) {
  499. Type paramType = paramTypes[i];
  500. il.append(InstructionFactory.createLoad(paramType, pos));
  501. pos+=paramType.getSize();
  502. }
  503. il.append(Utility.createInvoke(fact, (BcelWorld)aspectType.getWorld(),
  504. method));
  505. il.append(InstructionFactory.createReturn(BcelWorld.makeBcelType(method.getReturnType())));
  506. mg.getBody().insert(il);
  507. gen.addMethodGen(mg);
  508. }
  509. private LazyMethodGen makeMethodGen(LazyClassGen gen, ResolvedMember member) {
  510. LazyMethodGen ret = new LazyMethodGen(
  511. member.getModifiers(),
  512. BcelWorld.makeBcelType(member.getReturnType()),
  513. member.getName(),
  514. BcelWorld.makeBcelTypes(member.getParameterTypes()),
  515. TypeX.getNames(member.getExceptions()),
  516. gen);
  517. // 43972 : Static crosscutting makes interfaces unusable for javac
  518. // ret.makeSynthetic();
  519. return ret;
  520. }
  521. private FieldGen makeFieldGen(LazyClassGen gen, ResolvedMember member) {
  522. return new FieldGen(
  523. member.getModifiers(),
  524. BcelWorld.makeBcelType(member.getReturnType()),
  525. member.getName(),
  526. gen.getConstantPoolGen());
  527. }
  528. private boolean mungePerObjectInterface(
  529. BcelClassWeaver weaver,
  530. PerObjectInterfaceTypeMunger munger)
  531. {
  532. LazyClassGen gen = weaver.getLazyClassGen();
  533. if (couldMatch(gen.getBcelObjectType(), munger.getTestPointcut())) {
  534. FieldGen fg = makeFieldGen(gen,
  535. AjcMemberMaker.perObjectField(gen.getType(), aspectType));
  536. gen.addField(fg.getField(),getSourceLocation());
  537. Type fieldType = BcelWorld.makeBcelType(aspectType);
  538. LazyMethodGen mg = new LazyMethodGen(
  539. Modifier.PUBLIC,
  540. fieldType,
  541. NameMangler.perObjectInterfaceGet(aspectType),
  542. new Type[0], new String[0],
  543. gen);
  544. InstructionList il = new InstructionList();
  545. InstructionFactory fact = gen.getFactory();
  546. il.append(InstructionConstants.ALOAD_0);
  547. il.append(fact.createFieldAccess(
  548. gen.getClassName(),
  549. fg.getName(),
  550. fieldType, Constants.GETFIELD));
  551. il.append(InstructionFactory.createReturn(fieldType));
  552. mg.getBody().insert(il);
  553. gen.addMethodGen(mg);
  554. LazyMethodGen mg1 = new LazyMethodGen(
  555. Modifier.PUBLIC,
  556. Type.VOID,
  557. NameMangler.perObjectInterfaceSet(aspectType),
  558. new Type[]{fieldType,}, new String[0],
  559. gen);
  560. InstructionList il1 = new InstructionList();
  561. il1.append(InstructionConstants.ALOAD_0);
  562. il1.append(InstructionFactory.createLoad(fieldType, 1));
  563. il1.append(fact.createFieldAccess(
  564. gen.getClassName(),
  565. fg.getName(),
  566. fieldType, Constants.PUTFIELD));
  567. il1.append(InstructionFactory.createReturn(Type.VOID));
  568. mg1.getBody().insert(il1);
  569. gen.addMethodGen(mg1);
  570. gen.addInterface(munger.getInterfaceType(),getSourceLocation());
  571. return true;
  572. } else {
  573. return false;
  574. }
  575. }
  576. private boolean couldMatch(
  577. BcelObjectType bcelObjectType,
  578. Pointcut pointcut) {
  579. return !bcelObjectType.isInterface();
  580. }
  581. private boolean mungeNewMethod(BcelClassWeaver weaver, NewMethodTypeMunger munger) {
  582. ResolvedMember signature = munger.getSignature();
  583. ResolvedMember dispatchMethod = munger.getDispatchMethod(aspectType);
  584. LazyClassGen gen = weaver.getLazyClassGen();
  585. ResolvedTypeX onType = weaver.getWorld().resolve(signature.getDeclaringType(),munger.getSourceLocation());
  586. boolean onInterface = onType.isInterface();
  587. if (onType.isAnnotation(weaver.getWorld())) {
  588. signalError(WeaverMessages.ITDM_ON_ANNOTATION_NOT_ALLOWED,weaver,onType);
  589. return false;
  590. }
  591. if (onType.isEnum(weaver.getWorld())) {
  592. signalError(WeaverMessages.ITDM_ON_ENUM_NOT_ALLOWED,weaver,onType);
  593. return false;
  594. }
  595. if (onType.equals(gen.getType())) {
  596. ResolvedMember introMethod =
  597. AjcMemberMaker.interMethod(signature, aspectType, onInterface);
  598. LazyMethodGen mg = makeMethodGen(gen, introMethod);
  599. if (!onInterface && !Modifier.isAbstract(introMethod.getModifiers())) {
  600. InstructionList body = mg.getBody();
  601. InstructionFactory fact = gen.getFactory();
  602. int pos = 0;
  603. if (!signature.isStatic()) {
  604. body.append(InstructionFactory.createThis());
  605. pos++;
  606. }
  607. Type[] paramTypes = BcelWorld.makeBcelTypes(introMethod.getParameterTypes());
  608. for (int i = 0, len = paramTypes.length; i < len; i++) {
  609. Type paramType = paramTypes[i];
  610. body.append(InstructionFactory.createLoad(paramType, pos));
  611. pos+=paramType.getSize();
  612. }
  613. body.append(Utility.createInvoke(fact, weaver.getWorld(), dispatchMethod));
  614. body.append(
  615. InstructionFactory.createReturn(
  616. BcelWorld.makeBcelType(introMethod.getReturnType())));
  617. } else {
  618. //??? this is okay
  619. //if (!(mg.getBody() == null)) throw new RuntimeException("bas");
  620. }
  621. // XXX make sure to check that we set exceptions properly on this guy.
  622. weaver.addLazyMethodGen(mg);
  623. weaver.getLazyClassGen().warnOnAddedMethod(mg.getMethod(),getSignature().getSourceLocation());
  624. addNeededSuperCallMethods(weaver, onType, munger.getSuperMethodsCalled());
  625. return true;
  626. } else if (onInterface && !Modifier.isAbstract(signature.getModifiers())) {
  627. // This means the 'gen' should be the top most implementor
  628. // - if it is *not* then something went wrong after we worked
  629. // out that it was the top most implementor (see pr49657)
  630. if (!gen.getType().isTopmostImplementor(onType)) {
  631. ResolvedTypeX rtx = gen.getType().getTopmostImplementor(onType);
  632. if (!rtx.isExposedToWeaver()) {
  633. ISourceLocation sLoc = munger.getSourceLocation();
  634. weaver.getWorld().getMessageHandler().handleMessage(MessageUtil.error(
  635. WeaverMessages.format(WeaverMessages.ITD_NON_EXPOSED_IMPLEMENTOR,rtx,getAspectType().getName()),
  636. (sLoc==null?getAspectType().getSourceLocation():sLoc)));
  637. } else {
  638. // XXX what does this state mean?
  639. // We have incorrectly identified what is the top most implementor and its not because
  640. // a type wasn't exposed to the weaver
  641. }
  642. return false;
  643. } else {
  644. ResolvedMember introMethod =
  645. AjcMemberMaker.interMethod(signature, aspectType, false);
  646. LazyMethodGen mg = makeMethodGen(gen, introMethod);
  647. Type[] paramTypes = BcelWorld.makeBcelTypes(introMethod.getParameterTypes());
  648. Type returnType = BcelWorld.makeBcelType(introMethod.getReturnType());
  649. InstructionList body = mg.getBody();
  650. InstructionFactory fact = gen.getFactory();
  651. int pos = 0;
  652. if (!introMethod.isStatic()) {
  653. body.append(InstructionFactory.createThis());
  654. pos++;
  655. }
  656. for (int i = 0, len = paramTypes.length; i < len; i++) {
  657. Type paramType = paramTypes[i];
  658. body.append(InstructionFactory.createLoad(paramType, pos));
  659. pos+=paramType.getSize();
  660. }
  661. body.append(Utility.createInvoke(fact, weaver.getWorld(), dispatchMethod));
  662. body.append(InstructionFactory.createReturn(returnType));
  663. mg.definingType = onType;
  664. weaver.addOrReplaceLazyMethodGen(mg);
  665. addNeededSuperCallMethods(weaver, onType, munger.getSuperMethodsCalled());
  666. return true;
  667. }
  668. } else {
  669. return false;
  670. }
  671. }
  672. private void addNeededSuperCallMethods(
  673. BcelClassWeaver weaver,
  674. ResolvedTypeX onType,
  675. Set neededSuperCalls)
  676. {
  677. LazyClassGen gen = weaver.getLazyClassGen();
  678. for (Iterator iter = neededSuperCalls.iterator(); iter.hasNext();) {
  679. ResolvedMember superMethod = (ResolvedMember) iter.next();
  680. if (weaver.addDispatchTarget(superMethod)) {
  681. //System.err.println("super type: " + superMethod.getDeclaringType() + ", " + gen.getType());
  682. boolean isSuper = !superMethod.getDeclaringType().equals(gen.getType());
  683. String dispatchName;
  684. if (isSuper)
  685. dispatchName =
  686. NameMangler.superDispatchMethod(onType, superMethod.getName());
  687. else
  688. dispatchName =
  689. NameMangler.protectedDispatchMethod(
  690. onType,
  691. superMethod.getName());
  692. LazyMethodGen dispatcher =
  693. makeDispatcher(
  694. gen,
  695. dispatchName,
  696. superMethod,
  697. weaver.getWorld(),
  698. isSuper);
  699. weaver.addLazyMethodGen(dispatcher);
  700. }
  701. }
  702. }
  703. private void signalError(String msgid,BcelClassWeaver weaver,TypeX onType) {
  704. IMessage msg = MessageUtil.error(
  705. WeaverMessages.format(msgid,onType.getName()),getSourceLocation());
  706. weaver.getWorld().getMessageHandler().handleMessage(msg);
  707. }
  708. private boolean mungeNewConstructor(
  709. BcelClassWeaver weaver,
  710. NewConstructorTypeMunger newConstructorTypeMunger)
  711. {
  712. final LazyClassGen currentClass = weaver.getLazyClassGen();
  713. final InstructionFactory fact = currentClass.getFactory();
  714. ResolvedMember newConstructorMember = newConstructorTypeMunger.getSyntheticConstructor();
  715. TypeX onType = newConstructorMember.getDeclaringType();
  716. if (onType.isAnnotation(weaver.getWorld())) {
  717. signalError(WeaverMessages.ITDC_ON_ANNOTATION_NOT_ALLOWED,weaver,onType);
  718. return false;
  719. }
  720. if (onType.isEnum(weaver.getWorld())) {
  721. signalError(WeaverMessages.ITDC_ON_ENUM_NOT_ALLOWED,weaver,onType);
  722. return false;
  723. }
  724. if (! onType.equals(currentClass.getType())) return false;
  725. ResolvedMember explicitConstructor = newConstructorTypeMunger.getExplicitConstructor();
  726. //int declaredParameterCount = newConstructorTypeMunger.getDeclaredParameterCount();
  727. LazyMethodGen freshConstructor =
  728. makeMethodGen(currentClass, newConstructorMember);
  729. currentClass.addMethodGen(freshConstructor);
  730. //weaver.addLazyMethodGen(freshConstructor);
  731. InstructionList body = freshConstructor.getBody();
  732. // add to body: push arts for call to pre, from actual args starting at 1 (skipping this), going to
  733. // declared argcount + 1
  734. TypeX[] declaredParams = newConstructorTypeMunger.getSignature().getParameterTypes();
  735. Type[] paramTypes = freshConstructor.getArgumentTypes();
  736. int frameIndex = 1;
  737. for (int i = 0, len = declaredParams.length; i < len; i++) {
  738. body.append(InstructionFactory.createLoad(paramTypes[i], frameIndex));
  739. frameIndex += paramTypes[i].getSize();
  740. }
  741. // do call to pre
  742. Member preMethod =
  743. AjcMemberMaker.preIntroducedConstructor(aspectType, onType, declaredParams);
  744. body.append(Utility.createInvoke(fact, null, preMethod));
  745. // create a local, and store return pre stuff into it.
  746. int arraySlot = freshConstructor.allocateLocal(1);
  747. body.append(InstructionFactory.createStore(Type.OBJECT, arraySlot));
  748. // put this on the stack
  749. body.append(InstructionConstants.ALOAD_0);
  750. // unpack pre args onto stack
  751. TypeX[] superParamTypes = explicitConstructor.getParameterTypes();
  752. for (int i = 0, len = superParamTypes.length; i < len; i++) {
  753. body.append(InstructionFactory.createLoad(Type.OBJECT, arraySlot));
  754. body.append(Utility.createConstant(fact, i));
  755. body.append(InstructionFactory.createArrayLoad(Type.OBJECT));
  756. body.append(
  757. Utility.createConversion(
  758. fact,
  759. Type.OBJECT,
  760. BcelWorld.makeBcelType(superParamTypes[i])));
  761. }
  762. // call super/this
  763. body.append(Utility.createInvoke(fact, null, explicitConstructor));
  764. // put this back on the stack
  765. body.append(InstructionConstants.ALOAD_0);
  766. // unpack params onto stack
  767. Member postMethod =
  768. AjcMemberMaker.postIntroducedConstructor(aspectType, onType, declaredParams);
  769. TypeX[] postParamTypes = postMethod.getParameterTypes();
  770. for (int i = 1, len = postParamTypes.length; i < len; i++) {
  771. body.append(InstructionFactory.createLoad(Type.OBJECT, arraySlot));
  772. body.append(Utility.createConstant(fact, superParamTypes.length + i-1));
  773. body.append(InstructionFactory.createArrayLoad(Type.OBJECT));
  774. body.append(
  775. Utility.createConversion(
  776. fact,
  777. Type.OBJECT,
  778. BcelWorld.makeBcelType(postParamTypes[i])));
  779. }
  780. // call post
  781. body.append(Utility.createInvoke(fact, null, postMethod));
  782. // don't forget to return!!
  783. body.append(InstructionConstants.RETURN);
  784. return true;
  785. }
  786. private static LazyMethodGen makeDispatcher(
  787. LazyClassGen onGen,
  788. String dispatchName,
  789. ResolvedMember superMethod,
  790. BcelWorld world,
  791. boolean isSuper)
  792. {
  793. Type[] paramTypes = BcelWorld.makeBcelTypes(superMethod.getParameterTypes());
  794. Type returnType = BcelWorld.makeBcelType(superMethod.getReturnType());
  795. int modifiers = Modifier.PUBLIC;
  796. if (onGen.isInterface()) modifiers |= Modifier.ABSTRACT;
  797. LazyMethodGen mg =
  798. new LazyMethodGen(
  799. modifiers,
  800. returnType,
  801. dispatchName,
  802. paramTypes,
  803. TypeX.getNames(superMethod.getExceptions()),
  804. onGen);
  805. InstructionList body = mg.getBody();
  806. if (onGen.isInterface()) return mg;
  807. // assert (!superMethod.isStatic())
  808. InstructionFactory fact = onGen.getFactory();
  809. int pos = 0;
  810. body.append(InstructionFactory.createThis());
  811. pos++;
  812. for (int i = 0, len = paramTypes.length; i < len; i++) {
  813. Type paramType = paramTypes[i];
  814. body.append(InstructionFactory.createLoad(paramType, pos));
  815. pos+=paramType.getSize();
  816. }
  817. if (isSuper) {
  818. body.append(Utility.createSuperInvoke(fact, world, superMethod));
  819. } else {
  820. body.append(Utility.createInvoke(fact, world, superMethod));
  821. }
  822. body.append(InstructionFactory.createReturn(returnType));
  823. return mg;
  824. }
  825. private boolean mungeNewField(BcelClassWeaver weaver, NewFieldTypeMunger munger) {
  826. /*ResolvedMember initMethod = */munger.getInitMethod(aspectType);
  827. LazyClassGen gen = weaver.getLazyClassGen();
  828. ResolvedMember field = munger.getSignature();
  829. ResolvedTypeX onType = weaver.getWorld().resolve(field.getDeclaringType(),munger.getSourceLocation());
  830. boolean onInterface = onType.isInterface();
  831. if (onType.isAnnotation(weaver.getWorld())) {
  832. signalError(WeaverMessages.ITDF_ON_ANNOTATION_NOT_ALLOWED,weaver,onType);
  833. return false;
  834. }
  835. if (onType.isEnum(weaver.getWorld())) {
  836. signalError(WeaverMessages.ITDF_ON_ENUM_NOT_ALLOWED,weaver,onType);
  837. return false;
  838. }
  839. if (onType.equals(gen.getType())) {
  840. if (onInterface) {
  841. LazyMethodGen mg = makeMethodGen(gen,
  842. AjcMemberMaker.interFieldInterfaceGetter(field, onType, aspectType));
  843. gen.addMethodGen(mg);
  844. LazyMethodGen mg1 = makeMethodGen(gen,
  845. AjcMemberMaker.interFieldInterfaceSetter(field, onType, aspectType));
  846. gen.addMethodGen(mg1);
  847. } else {
  848. weaver.addInitializer(this);
  849. FieldGen fg = makeFieldGen(gen,
  850. AjcMemberMaker.interFieldClassField(field, aspectType));
  851. gen.addField(fg.getField(),getSourceLocation());
  852. }
  853. return true;
  854. } else if (onInterface && gen.getType().isTopmostImplementor(onType)) {
  855. // wew know that we can't be static since we don't allow statics on interfaces
  856. if (field.isStatic()) throw new RuntimeException("unimplemented");
  857. weaver.addInitializer(this);
  858. //System.err.println("impl body on " + gen.getType() + " for " + munger);
  859. Type fieldType = BcelWorld.makeBcelType(field.getType());
  860. FieldGen fg = makeFieldGen(gen,
  861. AjcMemberMaker.interFieldInterfaceField(field, onType, aspectType));
  862. gen.addField(fg.getField(),getSourceLocation());
  863. //this uses a shadow munger to add init method to constructors
  864. //weaver.getShadowMungers().add(makeInitCallShadowMunger(initMethod));
  865. LazyMethodGen mg = makeMethodGen(gen,
  866. AjcMemberMaker.interFieldInterfaceGetter(field, gen.getType(), aspectType));
  867. InstructionList il = new InstructionList();
  868. InstructionFactory fact = gen.getFactory();
  869. if (field.isStatic()) {
  870. il.append(fact.createFieldAccess(
  871. gen.getClassName(),
  872. fg.getName(),
  873. fieldType, Constants.GETSTATIC));
  874. } else {
  875. il.append(InstructionConstants.ALOAD_0);
  876. il.append(fact.createFieldAccess(
  877. gen.getClassName(),
  878. fg.getName(),
  879. fieldType, Constants.GETFIELD));
  880. }
  881. il.append(InstructionFactory.createReturn(fieldType));
  882. mg.getBody().insert(il);
  883. gen.addMethodGen(mg);
  884. LazyMethodGen mg1 = makeMethodGen(gen,
  885. AjcMemberMaker.interFieldInterfaceSetter(field, gen.getType(), aspectType));
  886. InstructionList il1 = new InstructionList();
  887. if (field.isStatic()) {
  888. il1.append(InstructionFactory.createLoad(fieldType, 0));
  889. il1.append(fact.createFieldAccess(
  890. gen.getClassName(),
  891. fg.getName(),
  892. fieldType, Constants.PUTSTATIC));
  893. } else {
  894. il1.append(InstructionConstants.ALOAD_0);
  895. il1.append(InstructionFactory.createLoad(fieldType, 1));
  896. il1.append(fact.createFieldAccess(
  897. gen.getClassName(),
  898. fg.getName(),
  899. fieldType, Constants.PUTFIELD));
  900. }
  901. il1.append(InstructionFactory.createReturn(Type.VOID));
  902. mg1.getBody().insert(il1);
  903. gen.addMethodGen(mg1);
  904. return true;
  905. } else {
  906. return false;
  907. }
  908. }
  909. }