Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

BcelWeaver.java 61KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567
  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. * Alexandre Vasseur support for @AJ aspects
  12. * ******************************************************************/
  13. package org.aspectj.weaver.bcel;
  14. import java.io.ByteArrayInputStream;
  15. import java.io.File;
  16. import java.io.FileFilter;
  17. import java.io.FileInputStream;
  18. import java.io.FileNotFoundException;
  19. import java.io.IOException;
  20. import java.io.InputStream;
  21. import java.io.OutputStream;
  22. import java.util.ArrayList;
  23. import java.util.Collection;
  24. import java.util.Collections;
  25. import java.util.Comparator;
  26. import java.util.Enumeration;
  27. import java.util.HashMap;
  28. import java.util.HashSet;
  29. import java.util.Iterator;
  30. import java.util.List;
  31. import java.util.Map;
  32. import java.util.Set;
  33. import java.util.jar.Attributes;
  34. import java.util.jar.JarEntry;
  35. import java.util.jar.JarFile;
  36. import java.util.jar.Manifest;
  37. import java.util.jar.Attributes.Name;
  38. import java.util.zip.ZipEntry;
  39. import java.util.zip.ZipInputStream;
  40. import java.util.zip.ZipOutputStream;
  41. import org.aspectj.apache.bcel.classfile.ClassParser;
  42. import org.aspectj.apache.bcel.classfile.JavaClass;
  43. import org.aspectj.bridge.IMessage;
  44. import org.aspectj.bridge.IProgressListener;
  45. import org.aspectj.bridge.ISourceLocation;
  46. import org.aspectj.bridge.Message;
  47. import org.aspectj.bridge.MessageUtil;
  48. import org.aspectj.bridge.SourceLocation;
  49. import org.aspectj.bridge.WeaveMessage;
  50. import org.aspectj.bridge.context.CompilationAndWeavingContext;
  51. import org.aspectj.bridge.context.ContextToken;
  52. import org.aspectj.util.FileUtil;
  53. import org.aspectj.util.FuzzyBoolean;
  54. import org.aspectj.weaver.Advice;
  55. import org.aspectj.weaver.AnnotationOnTypeMunger;
  56. import org.aspectj.weaver.AnnotationX;
  57. import org.aspectj.weaver.AsmRelationshipProvider;
  58. import org.aspectj.weaver.ConcreteTypeMunger;
  59. import org.aspectj.weaver.CrosscuttingMembersSet;
  60. import org.aspectj.weaver.IClassFileProvider;
  61. import org.aspectj.weaver.IWeaveRequestor;
  62. import org.aspectj.weaver.IWeaver;
  63. import org.aspectj.weaver.NewParentTypeMunger;
  64. import org.aspectj.weaver.ResolvedTypeMunger;
  65. import org.aspectj.weaver.ResolvedType;
  66. import org.aspectj.weaver.ShadowMunger;
  67. import org.aspectj.weaver.UnresolvedType;
  68. import org.aspectj.weaver.WeaverMessages;
  69. import org.aspectj.weaver.WeaverMetrics;
  70. import org.aspectj.weaver.WeaverStateInfo;
  71. import org.aspectj.weaver.World;
  72. import org.aspectj.weaver.patterns.AndPointcut;
  73. import org.aspectj.weaver.patterns.BindingAnnotationTypePattern;
  74. import org.aspectj.weaver.patterns.BindingTypePattern;
  75. import org.aspectj.weaver.patterns.CflowPointcut;
  76. import org.aspectj.weaver.patterns.ConcreteCflowPointcut;
  77. import org.aspectj.weaver.patterns.DeclareAnnotation;
  78. import org.aspectj.weaver.patterns.DeclareParents;
  79. import org.aspectj.weaver.patterns.FastMatchInfo;
  80. import org.aspectj.weaver.patterns.IfPointcut;
  81. import org.aspectj.weaver.patterns.KindedPointcut;
  82. import org.aspectj.weaver.patterns.NameBindingPointcut;
  83. import org.aspectj.weaver.patterns.NotPointcut;
  84. import org.aspectj.weaver.patterns.OrPointcut;
  85. import org.aspectj.weaver.patterns.Pointcut;
  86. import org.aspectj.weaver.patterns.PointcutRewriter;
  87. import org.aspectj.weaver.patterns.WithinPointcut;
  88. public class BcelWeaver implements IWeaver {
  89. private BcelWorld world;
  90. private CrosscuttingMembersSet xcutSet;
  91. private IProgressListener progressListener = null;
  92. private double progressMade;
  93. private double progressPerClassFile;
  94. private boolean inReweavableMode = false;
  95. public BcelWeaver(BcelWorld world) {
  96. super();
  97. WeaverMetrics.reset();
  98. this.world = world;
  99. this.xcutSet = world.getCrosscuttingMembersSet();
  100. }
  101. public BcelWeaver() {
  102. this(new BcelWorld());
  103. }
  104. // ---- fields
  105. // private Map sourceJavaClasses = new HashMap(); /* String -> UnwovenClassFile */
  106. private List addedClasses = new ArrayList(); /* List<UnovenClassFile> */
  107. private List deletedTypenames = new ArrayList(); /* List<String> */
  108. // private Map resources = new HashMap(); /* String -> UnwovenClassFile */
  109. private Manifest manifest = null;
  110. private boolean needToReweaveWorld = false;
  111. private List shadowMungerList = null; // setup by prepareForWeave
  112. private List typeMungerList = null; // setup by prepareForWeave
  113. private List lateTypeMungerList = null; // setup by prepareForWeave
  114. private List declareParentsList = null; // setup by prepareForWeave
  115. private ZipOutputStream zipOutputStream;
  116. // ----
  117. // only called for testing
  118. public void setShadowMungers(List l) {
  119. shadowMungerList = l;
  120. }
  121. /**
  122. * Add the given aspect to the weaver.
  123. * The type is resolved to support DOT for static inner classes as well as DOLLAR
  124. *
  125. * @param aspectName
  126. */
  127. public void addLibraryAspect(String aspectName) {
  128. // 1 - resolve as is
  129. ResolvedType type = world.resolve(UnresolvedType.forName(aspectName), true);
  130. if (type.equals(ResolvedType.MISSING)) {
  131. // fallback on inner class lookup mechanism
  132. String fixedName = aspectName;
  133. int hasDot = fixedName.lastIndexOf('.');
  134. while (hasDot > 0) {
  135. //System.out.println("BcelWeaver.addLibraryAspect " + fixedName);
  136. char[] fixedNameChars = fixedName.toCharArray();
  137. fixedNameChars[hasDot] = '$';
  138. fixedName = new String(fixedNameChars);
  139. hasDot = fixedName.lastIndexOf('.');
  140. type = world.resolve(UnresolvedType.forName(fixedName), true);
  141. if (!type.equals(ResolvedType.MISSING)) {
  142. break;
  143. }
  144. }
  145. }
  146. //System.out.println("type: " + type + " for " + aspectName);
  147. if (type.isAspect()) {
  148. //TODO AV - happens to reach that a lot of time: for each type flagged reweavable X for each aspect in the weaverstate
  149. //=> mainly for nothing for LTW - pbly for something in incremental build...
  150. xcutSet.addOrReplaceAspect(type);
  151. } else {
  152. // FIXME : Alex: better warning upon no such aspect from aop.xml
  153. throw new RuntimeException("Cannot register non aspect: " + type.getName() + " , " + aspectName);
  154. }
  155. }
  156. /**
  157. *
  158. * @param inFile File path to class directory or zip/jar class archive
  159. * @throws IOException
  160. */
  161. public void addLibraryJarFile(File inFile) throws IOException {
  162. List addedAspects = null;
  163. if (inFile.isDirectory()) {
  164. addedAspects = addAspectsFromDirectory(inFile);
  165. } else {
  166. addedAspects = addAspectsFromJarFile(inFile);
  167. }
  168. for (Iterator i = addedAspects.iterator(); i.hasNext();) {
  169. ResolvedType aspectX = (ResolvedType) i.next();
  170. xcutSet.addOrReplaceAspect(aspectX);
  171. }
  172. }
  173. private List addAspectsFromJarFile(File inFile) throws FileNotFoundException, IOException {
  174. ZipInputStream inStream = new ZipInputStream(new FileInputStream(inFile)); //??? buffered
  175. List addedAspects = new ArrayList();
  176. while (true) {
  177. ZipEntry entry = inStream.getNextEntry();
  178. if (entry == null) break;
  179. if (entry.isDirectory() || !entry.getName().endsWith(".class")) {
  180. continue;
  181. }
  182. // FIXME ASC performance? of this alternative soln.
  183. ClassParser parser = new ClassParser(new ByteArrayInputStream(FileUtil.readAsByteArray(inStream)), entry.getName());
  184. JavaClass jc = parser.parse();
  185. inStream.closeEntry();
  186. ResolvedType type = world.addSourceObjectType(jc).getResolvedTypeX();
  187. if (type.isAspect()) {
  188. addedAspects.add(type);
  189. }
  190. }
  191. inStream.close();
  192. return addedAspects;
  193. }
  194. private List addAspectsFromDirectory(File dir) throws FileNotFoundException, IOException{
  195. List addedAspects = new ArrayList();
  196. File[] classFiles = FileUtil.listFiles(dir,new FileFilter(){
  197. public boolean accept(File pathname) {
  198. return pathname.getName().endsWith(".class");
  199. }
  200. });
  201. for (int i = 0; i < classFiles.length; i++) {
  202. FileInputStream fis = new FileInputStream(classFiles[i]);
  203. byte[] bytes = FileUtil.readAsByteArray(fis);
  204. addIfAspect(bytes,classFiles[i].getAbsolutePath(),addedAspects);
  205. }
  206. return addedAspects;
  207. }
  208. private void addIfAspect(byte[] bytes, String name, List toList) throws IOException {
  209. ClassParser parser = new ClassParser(new ByteArrayInputStream(bytes),name);
  210. JavaClass jc = parser.parse();
  211. ResolvedType type = world.addSourceObjectType(jc).getResolvedTypeX();
  212. if (type.isAspect()) {
  213. toList.add(type);
  214. }
  215. }
  216. // // The ANT copy task should be used to copy resources across.
  217. // private final static boolean CopyResourcesFromInpathDirectoriesToOutput=false;
  218. /**
  219. * Add any .class files in the directory to the outdir. Anything other than .class files in
  220. * the directory (or its subdirectories) are considered resources and are also copied.
  221. *
  222. */
  223. public List addDirectoryContents(File inFile,File outDir) throws IOException {
  224. List addedClassFiles = new ArrayList();
  225. // Get a list of all files (i.e. everything that isnt a directory)
  226. File[] files = FileUtil.listFiles(inFile,new FileFilter() {
  227. public boolean accept(File f) {
  228. boolean accept = !f.isDirectory();
  229. return accept;
  230. }
  231. });
  232. // For each file, add it either as a real .class file or as a resource
  233. for (int i = 0; i < files.length; i++) {
  234. addedClassFiles.add(addClassFile(files[i],inFile,outDir));
  235. }
  236. return addedClassFiles;
  237. }
  238. /** Adds all class files in the jar
  239. */
  240. public List addJarFile(File inFile, File outDir, boolean canBeDirectory){
  241. // System.err.println("? addJarFile(" + inFile + ", " + outDir + ")");
  242. List addedClassFiles = new ArrayList();
  243. needToReweaveWorld = true;
  244. JarFile inJar = null;
  245. try {
  246. // Is this a directory we are looking at?
  247. if (inFile.isDirectory() && canBeDirectory) {
  248. addedClassFiles.addAll(addDirectoryContents(inFile,outDir));
  249. } else {
  250. inJar = new JarFile(inFile);
  251. addManifest(inJar.getManifest());
  252. Enumeration entries = inJar.entries();
  253. while (entries.hasMoreElements()) {
  254. JarEntry entry = (JarEntry)entries.nextElement();
  255. InputStream inStream = inJar.getInputStream(entry);
  256. byte[] bytes = FileUtil.readAsByteArray(inStream);
  257. String filename = entry.getName();
  258. // System.out.println("? addJarFile() filename='" + filename + "'");
  259. UnwovenClassFile classFile = new UnwovenClassFile(new File(outDir, filename).getAbsolutePath(), bytes);
  260. if (filename.endsWith(".class")) {
  261. this.addClassFile(classFile);
  262. addedClassFiles.add(classFile);
  263. }
  264. // else if (!entry.isDirectory()) {
  265. //
  266. // /* bug-44190 Copy meta-data */
  267. // addResource(filename,classFile);
  268. // }
  269. inStream.close();
  270. }
  271. inJar.close();
  272. }
  273. } catch (FileNotFoundException ex) {
  274. IMessage message = new Message(
  275. "Could not find input jar file " + inFile.getPath() + ", ignoring",
  276. new SourceLocation(inFile,0),
  277. false);
  278. world.getMessageHandler().handleMessage(message);
  279. } catch (IOException ex) {
  280. IMessage message = new Message(
  281. "Could not read input jar file " + inFile.getPath() + "(" + ex.getMessage() + ")",
  282. new SourceLocation(inFile,0),
  283. true);
  284. world.getMessageHandler().handleMessage(message);
  285. } finally {
  286. if (inJar != null) {
  287. try {inJar.close();}
  288. catch (IOException ex) {
  289. IMessage message = new Message(
  290. "Could not close input jar file " + inFile.getPath() + "(" + ex.getMessage() + ")",
  291. new SourceLocation(inFile,0),
  292. true);
  293. world.getMessageHandler().handleMessage(message);
  294. }
  295. }
  296. }
  297. return addedClassFiles;
  298. }
  299. // public void addResource(String name, File inPath, File outDir) throws IOException {
  300. //
  301. // /* Eliminate CVS files. Relative paths use "/" */
  302. // if (!name.startsWith("CVS/") && (-1 == name.indexOf("/CVS/")) && !name.endsWith("/CVS")) {
  303. //// System.err.println("? addResource('" + name + "')");
  304. //// BufferedInputStream inStream = new BufferedInputStream(new FileInputStream(inPath));
  305. //// byte[] bytes = new byte[(int)inPath.length()];
  306. //// inStream.read(bytes);
  307. //// inStream.close();
  308. // byte[] bytes = FileUtil.readAsByteArray(inPath);
  309. // UnwovenClassFile resourceFile = new UnwovenClassFile(new File(outDir, name).getAbsolutePath(), bytes);
  310. // addResource(name,resourceFile);
  311. // }
  312. // }
  313. public boolean needToReweaveWorld() {
  314. return needToReweaveWorld;
  315. }
  316. /** Should be addOrReplace
  317. */
  318. public void addClassFile(UnwovenClassFile classFile) {
  319. addedClasses.add(classFile);
  320. // if (null != sourceJavaClasses.put(classFile.getClassName(), classFile)) {
  321. //// throw new RuntimeException(classFile.getClassName());
  322. // }
  323. world.addSourceObjectType(classFile.getJavaClass());
  324. }
  325. public UnwovenClassFile addClassFile(File classFile, File inPathDir, File outDir) throws IOException {
  326. FileInputStream fis = new FileInputStream(classFile);
  327. byte[] bytes = FileUtil.readAsByteArray(fis);
  328. // String relativePath = files[i].getPath();
  329. // ASSERT: files[i].getAbsolutePath().startsWith(inFile.getAbsolutePath()
  330. // or we are in trouble...
  331. String filename = classFile.getAbsolutePath().substring(
  332. inPathDir.getAbsolutePath().length()+1);
  333. UnwovenClassFile ucf = new UnwovenClassFile(new File(outDir,filename).getAbsolutePath(),bytes);
  334. if (filename.endsWith(".class")) {
  335. // System.err.println("BCELWeaver: processing class from input directory "+classFile);
  336. this.addClassFile(ucf);
  337. }
  338. fis.close();
  339. return ucf;
  340. }
  341. public void deleteClassFile(String typename) {
  342. deletedTypenames.add(typename);
  343. // sourceJavaClasses.remove(typename);
  344. world.deleteSourceObjectType(UnresolvedType.forName(typename));
  345. }
  346. // public void addResource (String name, UnwovenClassFile resourceFile) {
  347. // /* bug-44190 Change error to warning and copy first resource */
  348. // if (!resources.containsKey(name)) {
  349. // resources.put(name, resourceFile);
  350. // }
  351. // else {
  352. // world.showMessage(IMessage.WARNING, "duplicate resource: '" + name + "'",
  353. // null, null);
  354. // }
  355. // }
  356. // ---- weave preparation
  357. public void prepareForWeave() {
  358. needToReweaveWorld = false;
  359. CflowPointcut.clearCaches();
  360. // update mungers
  361. for (Iterator i = addedClasses.iterator(); i.hasNext(); ) {
  362. UnwovenClassFile jc = (UnwovenClassFile)i.next();
  363. String name = jc.getClassName();
  364. ResolvedType type = world.resolve(name);
  365. //System.err.println("added: " + type + " aspect? " + type.isAspect());
  366. if (type.isAspect()) {
  367. needToReweaveWorld |= xcutSet.addOrReplaceAspect(type);
  368. }
  369. }
  370. for (Iterator i = deletedTypenames.iterator(); i.hasNext(); ) {
  371. String name = (String)i.next();
  372. if (xcutSet.deleteAspect(UnresolvedType.forName(name))) needToReweaveWorld = true;
  373. }
  374. shadowMungerList = xcutSet.getShadowMungers();
  375. rewritePointcuts(shadowMungerList);
  376. typeMungerList = xcutSet.getTypeMungers();
  377. lateTypeMungerList = xcutSet.getLateTypeMungers();
  378. declareParentsList = xcutSet.getDeclareParents();
  379. // The ordering here used to be based on a string compare on toString() for the two mungers -
  380. // that breaks for the @AJ style where advice names aren't programmatically generated. So we
  381. // have changed the sorting to be based on source location in the file - this is reliable, in
  382. // the case of source locations missing, we assume they are 'sorted' - i.e. the order in
  383. // which they were added to the collection is correct, this enables the @AJ stuff to work properly.
  384. // When @AJ processing starts filling in source locations for mungers, this code may need
  385. // a bit of alteration...
  386. Collections.sort(
  387. shadowMungerList,
  388. new Comparator() {
  389. public int compare(Object o1, Object o2) {
  390. ShadowMunger sm1 = (ShadowMunger)o1;
  391. ShadowMunger sm2 = (ShadowMunger)o2;
  392. if (sm1.getSourceLocation()==null) return (sm2.getSourceLocation()==null?0:1);
  393. if (sm2.getSourceLocation()==null) return -1;
  394. return (sm2.getSourceLocation().getOffset()-sm1.getSourceLocation().getOffset());
  395. }
  396. });
  397. }
  398. /*
  399. * Rewrite all of the pointcuts in the world into their most efficient
  400. * form for subsequent matching. Also ensure that if pc1.equals(pc2)
  401. * then pc1 == pc2 (for non-binding pcds) by making references all
  402. * point to the same instance.
  403. * Since pointcuts remember their match decision on the last shadow,
  404. * this makes matching faster when many pointcuts share common elements,
  405. * or even when one single pointcut has one common element (which can
  406. * be a side-effect of DNF rewriting).
  407. */
  408. private void rewritePointcuts(List/*ShadowMunger*/ shadowMungers) {
  409. PointcutRewriter rewriter = new PointcutRewriter();
  410. for (Iterator iter = shadowMungers.iterator(); iter.hasNext();) {
  411. ShadowMunger munger = (ShadowMunger) iter.next();
  412. Pointcut p = munger.getPointcut();
  413. Pointcut newP = rewriter.rewrite(p);
  414. // validateBindings now whilst we still have around the pointcut
  415. // that resembles what the user actually wrote in their program
  416. // text.
  417. if (munger instanceof Advice) {
  418. Advice advice = (Advice) munger;
  419. if (advice.getSignature() != null) {
  420. final int numFormals;
  421. final String names[];
  422. //ATAJ for @AJ aspect, the formal have to be checked according to the argument number
  423. // since xxxJoinPoint presence or not have side effects
  424. if (advice.getConcreteAspect().isAnnotationStyleAspect()) {
  425. numFormals = advice.getBaseParameterCount();
  426. int numArgs = advice.getSignature().getParameterTypes().length;
  427. if (numFormals > 0) {
  428. names = advice.getSignature().getParameterNames(world);
  429. validateBindings(newP,p,numArgs,names);
  430. }
  431. } else {
  432. numFormals = advice.getBaseParameterCount();
  433. if (numFormals > 0) {
  434. names = advice.getBaseParameterNames(world);
  435. validateBindings(newP,p,numFormals,names);
  436. }
  437. }
  438. }
  439. }
  440. munger.setPointcut(newP);
  441. }
  442. // now that we have optimized individual pointcuts, optimize
  443. // across the set of pointcuts....
  444. // Use a map from key based on pc equality, to value based on
  445. // pc identity.
  446. Map/*<Pointcut,Pointcut>*/ pcMap = new HashMap();
  447. for (Iterator iter = shadowMungers.iterator(); iter.hasNext();) {
  448. ShadowMunger munger = (ShadowMunger) iter.next();
  449. Pointcut p = munger.getPointcut();
  450. munger.setPointcut(shareEntriesFromMap(p,pcMap));
  451. }
  452. }
  453. private Pointcut shareEntriesFromMap(Pointcut p,Map pcMap) {
  454. // some things cant be shared...
  455. if (p instanceof NameBindingPointcut) return p;
  456. if (p instanceof IfPointcut) return p;
  457. if (p instanceof ConcreteCflowPointcut) return p;
  458. if (p instanceof AndPointcut) {
  459. AndPointcut apc = (AndPointcut) p;
  460. Pointcut left = shareEntriesFromMap(apc.getLeft(),pcMap);
  461. Pointcut right = shareEntriesFromMap(apc.getRight(),pcMap);
  462. return new AndPointcut(left,right);
  463. } else if (p instanceof OrPointcut) {
  464. OrPointcut opc = (OrPointcut) p;
  465. Pointcut left = shareEntriesFromMap(opc.getLeft(),pcMap);
  466. Pointcut right = shareEntriesFromMap(opc.getRight(),pcMap);
  467. return new OrPointcut(left,right);
  468. } else if (p instanceof NotPointcut) {
  469. NotPointcut npc = (NotPointcut) p;
  470. Pointcut not = shareEntriesFromMap(npc.getNegatedPointcut(),pcMap);
  471. return new NotPointcut(not);
  472. } else {
  473. // primitive pcd
  474. if (pcMap.containsKey(p)) { // based on equality
  475. return (Pointcut) pcMap.get(p); // same instance (identity)
  476. } else {
  477. pcMap.put(p,p);
  478. return p;
  479. }
  480. }
  481. }
  482. // userPointcut is the pointcut that the user wrote in the program text.
  483. // dnfPointcut is the same pointcut rewritten in DNF
  484. // numFormals is the number of formal parameters in the pointcut
  485. // if numFormals > 0 then every branch of a disjunction must bind each formal once and only once.
  486. // in addition, the left and right branches of a disjunction must hold on join point kinds in
  487. // common.
  488. private void validateBindings(Pointcut dnfPointcut, Pointcut userPointcut, int numFormals, String[] names) {
  489. if (numFormals == 0) return; // nothing to check
  490. if (dnfPointcut.couldMatchKinds().isEmpty()) return; // cant have problems if you dont match!
  491. if (dnfPointcut instanceof OrPointcut) {
  492. OrPointcut orBasedDNFPointcut = (OrPointcut) dnfPointcut;
  493. Pointcut[] leftBindings = new Pointcut[numFormals];
  494. Pointcut[] rightBindings = new Pointcut[numFormals];
  495. validateOrBranch(orBasedDNFPointcut,userPointcut,numFormals,names,leftBindings,rightBindings);
  496. } else {
  497. Pointcut[] bindings = new Pointcut[numFormals];
  498. validateSingleBranch(dnfPointcut, userPointcut, numFormals, names,bindings);
  499. }
  500. }
  501. private void validateOrBranch(OrPointcut pc, Pointcut userPointcut, int numFormals,
  502. String[] names, Pointcut[] leftBindings, Pointcut[] rightBindings) {
  503. Pointcut left = pc.getLeft();
  504. Pointcut right = pc.getRight();
  505. if (left instanceof OrPointcut) {
  506. Pointcut[] newRightBindings = new Pointcut[numFormals];
  507. validateOrBranch((OrPointcut)left,userPointcut,numFormals,names,leftBindings,newRightBindings);
  508. } else {
  509. if (left.couldMatchKinds().size() > 0)
  510. validateSingleBranch(left, userPointcut, numFormals, names, leftBindings);
  511. }
  512. if (right instanceof OrPointcut) {
  513. Pointcut[] newLeftBindings = new Pointcut[numFormals];
  514. validateOrBranch((OrPointcut)right,userPointcut,numFormals,names,newLeftBindings,rightBindings);
  515. } else {
  516. if (right.couldMatchKinds().size() > 0)
  517. validateSingleBranch(right, userPointcut, numFormals, names, rightBindings);
  518. }
  519. Set kindsInCommon = left.couldMatchKinds();
  520. kindsInCommon.retainAll(right.couldMatchKinds());
  521. if (!kindsInCommon.isEmpty() && couldEverMatchSameJoinPoints(left,right)) {
  522. // we know that every branch binds every formal, so there is no ambiguity
  523. // if each branch binds it in exactly the same way...
  524. List ambiguousNames = new ArrayList();
  525. for (int i = 0; i < numFormals; i++) {
  526. if (!leftBindings[i].equals(rightBindings[i])) {
  527. ambiguousNames.add(names[i]);
  528. }
  529. }
  530. if (!ambiguousNames.isEmpty())
  531. raiseAmbiguityInDisjunctionError(userPointcut,ambiguousNames);
  532. }
  533. }
  534. // pc is a pointcut that does not contain any disjunctions
  535. // check that every formal is bound (negation doesn't count).
  536. // we know that numFormals > 0 or else we would not be called
  537. private void validateSingleBranch(Pointcut pc, Pointcut userPointcut, int numFormals, String[] names, Pointcut[] bindings) {
  538. boolean[] foundFormals = new boolean[numFormals];
  539. for (int i = 0; i < foundFormals.length; i++) {
  540. foundFormals[i] = false;
  541. }
  542. validateSingleBranchRecursion(pc, userPointcut, foundFormals, names, bindings);
  543. for (int i = 0; i < foundFormals.length; i++) {
  544. if (!foundFormals[i]) {
  545. boolean ignore = false;
  546. // ATAJ soften the unbound error for implicit bindings like JoinPoint in @AJ style
  547. for (int j = 0; j < userPointcut.m_ignoreUnboundBindingForNames.length; j++) {
  548. if (names[i] != null && names[i].equals(userPointcut.m_ignoreUnboundBindingForNames[j])) {
  549. ignore = true;
  550. break;
  551. }
  552. }
  553. if (!ignore) {
  554. raiseUnboundFormalError(names[i],userPointcut);
  555. }
  556. }
  557. }
  558. }
  559. // each formal must appear exactly once
  560. private void validateSingleBranchRecursion(Pointcut pc, Pointcut userPointcut, boolean[] foundFormals, String[] names, Pointcut[] bindings) {
  561. if (pc instanceof NotPointcut) {
  562. // nots can only appear at leaves in DNF
  563. NotPointcut not = (NotPointcut) pc;
  564. if (not.getNegatedPointcut() instanceof NameBindingPointcut) {
  565. NameBindingPointcut nnbp = (NameBindingPointcut) not.getNegatedPointcut();
  566. if (!nnbp.getBindingAnnotationTypePatterns().isEmpty() && !nnbp.getBindingTypePatterns().isEmpty())
  567. raiseNegationBindingError(userPointcut);
  568. }
  569. } else if (pc instanceof AndPointcut) {
  570. AndPointcut and = (AndPointcut) pc;
  571. validateSingleBranchRecursion(and.getLeft(), userPointcut,foundFormals,names,bindings);
  572. validateSingleBranchRecursion(and.getRight(),userPointcut,foundFormals,names,bindings);
  573. } else if (pc instanceof NameBindingPointcut) {
  574. List/*BindingTypePattern*/ btps = ((NameBindingPointcut)pc).getBindingTypePatterns();
  575. for (Iterator iter = btps.iterator(); iter.hasNext();) {
  576. BindingTypePattern btp = (BindingTypePattern) iter.next();
  577. int index = btp.getFormalIndex();
  578. bindings[index] = pc;
  579. if (foundFormals[index]) {
  580. raiseAmbiguousBindingError(names[index],userPointcut);
  581. } else {
  582. foundFormals[index] = true;
  583. }
  584. }
  585. List/*BindingAnnotationTypePattern*/ baps = ((NameBindingPointcut)pc).getBindingAnnotationTypePatterns();
  586. for (Iterator iter = baps.iterator(); iter.hasNext();) {
  587. BindingAnnotationTypePattern bap = (BindingAnnotationTypePattern) iter.next();
  588. int index = bap.getFormalIndex();
  589. bindings[index] = pc;
  590. if (foundFormals[index]) {
  591. raiseAmbiguousBindingError(names[index],userPointcut);
  592. } else {
  593. foundFormals[index] = true;
  594. }
  595. }
  596. } else if (pc instanceof ConcreteCflowPointcut) {
  597. ConcreteCflowPointcut cfp = (ConcreteCflowPointcut) pc;
  598. int[] slots = cfp.getUsedFormalSlots();
  599. for (int i = 0; i < slots.length; i++) {
  600. bindings[slots[i]] = cfp;
  601. if (foundFormals[slots[i]]) {
  602. raiseAmbiguousBindingError(names[slots[i]],userPointcut);
  603. } else {
  604. foundFormals[slots[i]] = true;
  605. }
  606. }
  607. }
  608. }
  609. // By returning false from this method, we are allowing binding of the same
  610. // variable on either side of an or.
  611. // Be conservative :- have to consider overriding, varargs, autoboxing,
  612. // the effects of itds (on within for example), interfaces, the fact that
  613. // join points can have multiple signatures and so on.
  614. private boolean couldEverMatchSameJoinPoints(Pointcut left, Pointcut right) {
  615. if (left instanceof OrPointcut) {
  616. OrPointcut leftOrPointcut = (OrPointcut)left;
  617. if (couldEverMatchSameJoinPoints(leftOrPointcut.getLeft(),right)) return true;
  618. if (couldEverMatchSameJoinPoints(leftOrPointcut.getRight(),right)) return true;
  619. return false;
  620. }
  621. if (right instanceof OrPointcut) {
  622. OrPointcut rightOrPointcut = (OrPointcut)right;
  623. if (couldEverMatchSameJoinPoints(left,rightOrPointcut.getLeft())) return true;
  624. if (couldEverMatchSameJoinPoints(left,rightOrPointcut.getRight())) return true;
  625. return false;
  626. }
  627. // look for withins
  628. WithinPointcut leftWithin = (WithinPointcut) findFirstPointcutIn(left,WithinPointcut.class);
  629. WithinPointcut rightWithin = (WithinPointcut) findFirstPointcutIn(right,WithinPointcut.class);
  630. if ((leftWithin != null) && (rightWithin != null)) {
  631. if (!leftWithin.couldEverMatchSameJoinPointsAs(rightWithin)) return false;
  632. }
  633. // look for kinded
  634. KindedPointcut leftKind = (KindedPointcut) findFirstPointcutIn(left,KindedPointcut.class);
  635. KindedPointcut rightKind = (KindedPointcut) findFirstPointcutIn(right,KindedPointcut.class);
  636. if ((leftKind != null) && (rightKind != null)) {
  637. if (!leftKind.couldEverMatchSameJoinPointsAs(rightKind)) return false;
  638. }
  639. return true;
  640. }
  641. private Pointcut findFirstPointcutIn(Pointcut toSearch, Class toLookFor) {
  642. if (toSearch instanceof NotPointcut) return null;
  643. if (toLookFor.isInstance(toSearch)) return toSearch;
  644. if (toSearch instanceof AndPointcut) {
  645. AndPointcut apc = (AndPointcut) toSearch;
  646. Pointcut left = findFirstPointcutIn(apc.getLeft(),toLookFor);
  647. if (left != null) return left;
  648. return findFirstPointcutIn(apc.getRight(),toLookFor);
  649. }
  650. return null;
  651. }
  652. /**
  653. * @param userPointcut
  654. */
  655. private void raiseNegationBindingError(Pointcut userPointcut) {
  656. world.showMessage(IMessage.ERROR,
  657. WeaverMessages.format(WeaverMessages.NEGATION_DOESNT_ALLOW_BINDING),
  658. userPointcut.getSourceContext().makeSourceLocation(userPointcut),null);
  659. }
  660. /**
  661. * @param name
  662. * @param userPointcut
  663. */
  664. private void raiseAmbiguousBindingError(String name, Pointcut userPointcut) {
  665. world.showMessage(IMessage.ERROR,
  666. WeaverMessages.format(WeaverMessages.AMBIGUOUS_BINDING,
  667. name),
  668. userPointcut.getSourceContext().makeSourceLocation(userPointcut),null);
  669. }
  670. /**
  671. * @param userPointcut
  672. */
  673. private void raiseAmbiguityInDisjunctionError(Pointcut userPointcut, List names) {
  674. StringBuffer formalNames = new StringBuffer(names.get(0).toString());
  675. for (int i = 1; i < names.size(); i++) {
  676. formalNames.append(", ");
  677. formalNames.append(names.get(i));
  678. }
  679. world.showMessage(IMessage.ERROR,
  680. WeaverMessages.format(WeaverMessages.AMBIGUOUS_BINDING_IN_OR,formalNames),
  681. userPointcut.getSourceContext().makeSourceLocation(userPointcut),null);
  682. }
  683. /**
  684. * @param name
  685. * @param userPointcut
  686. */
  687. private void raiseUnboundFormalError(String name, Pointcut userPointcut) {
  688. world.showMessage(IMessage.ERROR,
  689. WeaverMessages.format(WeaverMessages.UNBOUND_FORMAL,
  690. name),
  691. userPointcut.getSourceContext().makeSourceLocation(userPointcut),null);
  692. }
  693. // public void dumpUnwoven(File file) throws IOException {
  694. // BufferedOutputStream os = FileUtil.makeOutputStream(file);
  695. // this.zipOutputStream = new ZipOutputStream(os);
  696. // dumpUnwoven();
  697. // /* BUG 40943*/
  698. // dumpResourcesToOutJar();
  699. // zipOutputStream.close(); //this flushes and closes the acutal file
  700. // }
  701. //
  702. //
  703. // public void dumpUnwoven() throws IOException {
  704. // Collection filesToDump = new HashSet(sourceJavaClasses.values());
  705. // for (Iterator i = filesToDump.iterator(); i.hasNext(); ) {
  706. // UnwovenClassFile classFile = (UnwovenClassFile)i.next();
  707. // dumpUnchanged(classFile);
  708. // }
  709. // }
  710. // public void dumpResourcesToOutPath() throws IOException {
  711. //// System.err.println("? dumpResourcesToOutPath() resources=" + resources.keySet());
  712. // Iterator i = resources.keySet().iterator();
  713. // while (i.hasNext()) {
  714. // UnwovenClassFile res = (UnwovenClassFile)resources.get(i.next());
  715. // dumpUnchanged(res);
  716. // }
  717. // //resources = new HashMap();
  718. // }
  719. //
  720. /* BUG #40943 */
  721. // public void dumpResourcesToOutJar() throws IOException {
  722. //// System.err.println("? dumpResourcesToOutJar() resources=" + resources.keySet());
  723. // Iterator i = resources.keySet().iterator();
  724. // while (i.hasNext()) {
  725. // String name = (String)i.next();
  726. // UnwovenClassFile res = (UnwovenClassFile)resources.get(name);
  727. // writeZipEntry(name,res.getBytes());
  728. // }
  729. // resources = new HashMap();
  730. // }
  731. //
  732. // // halfway house for when the jar is managed outside of the weaver, but the resources
  733. // // to be copied are known in the weaver.
  734. // public void dumpResourcesToOutJar(ZipOutputStream zos) throws IOException {
  735. // this.zipOutputStream = zos;
  736. // dumpResourcesToOutJar();
  737. // }
  738. public void addManifest (Manifest newManifest) {
  739. // System.out.println("? addManifest() newManifest=" + newManifest);
  740. if (manifest == null) {
  741. manifest = newManifest;
  742. }
  743. }
  744. public static final String MANIFEST_NAME = "META-INF/MANIFEST.MF";
  745. private static final String WEAVER_MANIFEST_VERSION = "1.0";
  746. private static final Attributes.Name CREATED_BY = new Name("Created-By");
  747. private static final String WEAVER_CREATED_BY = "AspectJ Compiler";
  748. public Manifest getManifest (boolean shouldCreate) {
  749. if (manifest == null && shouldCreate) {
  750. manifest = new Manifest();
  751. Attributes attributes = manifest.getMainAttributes();
  752. attributes.put(Name.MANIFEST_VERSION,WEAVER_MANIFEST_VERSION);
  753. attributes.put(CREATED_BY,WEAVER_CREATED_BY);
  754. }
  755. return manifest;
  756. }
  757. // ---- weaving
  758. // Used by some test cases only...
  759. public Collection weave(File file) throws IOException {
  760. OutputStream os = FileUtil.makeOutputStream(file);
  761. this.zipOutputStream = new ZipOutputStream(os);
  762. prepareForWeave();
  763. Collection c = weave( new IClassFileProvider() {
  764. public Iterator getClassFileIterator() {
  765. return addedClasses.iterator();
  766. }
  767. public IWeaveRequestor getRequestor() {
  768. return new IWeaveRequestor() {
  769. public void acceptResult(UnwovenClassFile result) {
  770. try {
  771. writeZipEntry(result.filename, result.bytes);
  772. } catch(IOException ex) {}
  773. }
  774. public void processingReweavableState() {}
  775. public void addingTypeMungers() {}
  776. public void weavingAspects() {}
  777. public void weavingClasses() {}
  778. public void weaveCompleted() {}
  779. };
  780. }
  781. });
  782. // /* BUG 40943*/
  783. // dumpResourcesToOutJar();
  784. zipOutputStream.close(); //this flushes and closes the acutal file
  785. return c;
  786. }
  787. // public Collection weave() throws IOException {
  788. // prepareForWeave();
  789. // Collection filesToWeave;
  790. //
  791. // if (needToReweaveWorld) {
  792. // filesToWeave = sourceJavaClasses.values();
  793. // } else {
  794. // filesToWeave = addedClasses;
  795. // }
  796. //
  797. // Collection wovenClassNames = new ArrayList();
  798. // world.showMessage(IMessage.INFO, "might need to weave " + filesToWeave +
  799. // "(world=" + needToReweaveWorld + ")", null, null);
  800. //
  801. //
  802. // //System.err.println("typeMungers: " + typeMungerList);
  803. //
  804. // prepareToProcessReweavableState();
  805. // // clear all state from files we'll be reweaving
  806. // for (Iterator i = filesToWeave.iterator(); i.hasNext(); ) {
  807. // UnwovenClassFile classFile = (UnwovenClassFile)i.next();
  808. // String className = classFile.getClassName();
  809. // BcelObjectType classType = getClassType(className);
  810. // processReweavableStateIfPresent(className, classType);
  811. // }
  812. //
  813. //
  814. //
  815. // //XXX this isn't quite the right place for this...
  816. // for (Iterator i = filesToWeave.iterator(); i.hasNext(); ) {
  817. // UnwovenClassFile classFile = (UnwovenClassFile)i.next();
  818. // String className = classFile.getClassName();
  819. // addTypeMungers(className);
  820. // }
  821. //
  822. // // first weave into aspects
  823. // for (Iterator i = filesToWeave.iterator(); i.hasNext(); ) {
  824. // UnwovenClassFile classFile = (UnwovenClassFile)i.next();
  825. // String className = classFile.getClassName();
  826. // BcelObjectType classType = BcelWorld.getBcelObjectType(world.resolve(className));
  827. // if (classType.isAspect()) {
  828. // weave(classFile, classType);
  829. // wovenClassNames.add(className);
  830. // }
  831. // }
  832. //
  833. // // then weave into non-aspects
  834. // for (Iterator i = filesToWeave.iterator(); i.hasNext(); ) {
  835. // UnwovenClassFile classFile = (UnwovenClassFile)i.next();
  836. // String className = classFile.getClassName();
  837. // BcelObjectType classType = BcelWorld.getBcelObjectType(world.resolve(className));
  838. // if (! classType.isAspect()) {
  839. // weave(classFile, classType);
  840. // wovenClassNames.add(className);
  841. // }
  842. // }
  843. //
  844. // if (zipOutputStream != null && !needToReweaveWorld) {
  845. // Collection filesToDump = new HashSet(sourceJavaClasses.values());
  846. // filesToDump.removeAll(filesToWeave);
  847. // for (Iterator i = filesToDump.iterator(); i.hasNext(); ) {
  848. // UnwovenClassFile classFile = (UnwovenClassFile)i.next();
  849. // dumpUnchanged(classFile);
  850. // }
  851. // }
  852. //
  853. // addedClasses = new ArrayList();
  854. // deletedTypenames = new ArrayList();
  855. //
  856. // return wovenClassNames;
  857. // }
  858. // variation of "weave" that sources class files from an external source.
  859. public Collection weave(IClassFileProvider input) throws IOException {
  860. ContextToken weaveToken = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.WEAVING, "");
  861. Collection wovenClassNames = new ArrayList();
  862. IWeaveRequestor requestor = input.getRequestor();
  863. requestor.processingReweavableState();
  864. ContextToken reweaveToken = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.PROCESSING_REWEAVABLE_STATE,"");
  865. prepareToProcessReweavableState();
  866. // clear all state from files we'll be reweaving
  867. for (Iterator i = input.getClassFileIterator(); i.hasNext(); ) {
  868. UnwovenClassFile classFile = (UnwovenClassFile)i.next();
  869. String className = classFile.getClassName();
  870. BcelObjectType classType = getClassType(className);
  871. // null return from getClassType() means the delegate is an eclipse source type - so
  872. // there *cant* be any reweavable state... (he bravely claimed...)
  873. if (classType !=null) {
  874. ContextToken tok = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.PROCESSING_REWEAVABLE_STATE, className);
  875. processReweavableStateIfPresent(className, classType);
  876. CompilationAndWeavingContext.leavingPhase(tok);
  877. }
  878. }
  879. CompilationAndWeavingContext.leavingPhase(reweaveToken);
  880. ContextToken typeMungingToken = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.PROCESSING_TYPE_MUNGERS,"");
  881. requestor.addingTypeMungers();
  882. // We process type mungers in two groups, first mungers that change the type
  883. // hierarchy, then 'normal' ITD type mungers.
  884. // Process the types in a predictable order (rather than the order encountered).
  885. // For class A, the order is superclasses of A then superinterfaces of A
  886. // (and this mechanism is applied recursively)
  887. List typesToProcess = new ArrayList();
  888. for (Iterator iter = input.getClassFileIterator(); iter.hasNext();) {
  889. UnwovenClassFile clf = (UnwovenClassFile) iter.next();
  890. typesToProcess.add(clf.getClassName());
  891. }
  892. while (typesToProcess.size()>0) {
  893. weaveParentsFor(typesToProcess,(String)typesToProcess.get(0));
  894. }
  895. for (Iterator i = input.getClassFileIterator(); i.hasNext(); ) {
  896. UnwovenClassFile classFile = (UnwovenClassFile)i.next();
  897. String className = classFile.getClassName();
  898. addNormalTypeMungers(className);
  899. }
  900. CompilationAndWeavingContext.leavingPhase(typeMungingToken);
  901. requestor.weavingAspects();
  902. ContextToken aspectToken = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.WEAVING_ASPECTS, "");
  903. // first weave into aspects
  904. for (Iterator i = input.getClassFileIterator(); i.hasNext(); ) {
  905. UnwovenClassFile classFile = (UnwovenClassFile)i.next();
  906. String className = classFile.getClassName();
  907. BcelObjectType classType = BcelWorld.getBcelObjectType(world.resolve(className));
  908. if (classType.isAspect()) {
  909. weaveAndNotify(classFile, classType,requestor);
  910. wovenClassNames.add(className);
  911. }
  912. }
  913. CompilationAndWeavingContext.leavingPhase(aspectToken);
  914. requestor.weavingClasses();
  915. ContextToken classToken = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.WEAVING_CLASSES, "");
  916. // then weave into non-aspects
  917. for (Iterator i = input.getClassFileIterator(); i.hasNext(); ) {
  918. UnwovenClassFile classFile = (UnwovenClassFile)i.next();
  919. String className = classFile.getClassName();
  920. BcelObjectType classType = BcelWorld.getBcelObjectType(world.resolve(className));
  921. if (! classType.isAspect()) {
  922. weaveAndNotify(classFile, classType, requestor);
  923. wovenClassNames.add(className);
  924. }
  925. }
  926. CompilationAndWeavingContext.leavingPhase(classToken);
  927. addedClasses = new ArrayList();
  928. deletedTypenames = new ArrayList();
  929. warnOnUnmatchedAdvice();
  930. requestor.weaveCompleted();
  931. CompilationAndWeavingContext.leavingPhase(weaveToken);
  932. return wovenClassNames;
  933. }
  934. /**
  935. * In 1.5 mode and with XLint:adviceDidNotMatch enabled, put out messages for any
  936. * mungers that did not match anything.
  937. */
  938. private void warnOnUnmatchedAdvice() {
  939. class AdviceLocation {
  940. private int lineNo;
  941. private UnresolvedType inAspect;
  942. public AdviceLocation(BcelAdvice advice) {
  943. this.lineNo = advice.getSourceLocation().getLine();
  944. this.inAspect = advice.getDeclaringAspect();
  945. }
  946. public boolean equals(Object obj) {
  947. if (!(obj instanceof AdviceLocation)) return false;
  948. AdviceLocation other = (AdviceLocation) obj;
  949. if (this.lineNo != other.lineNo) return false;
  950. if (!this.inAspect.equals(other.inAspect)) return false;
  951. return true;
  952. }
  953. public int hashCode() {
  954. return 37 + 17*lineNo + 17*inAspect.hashCode();
  955. };
  956. }
  957. // FIXME asc Should be factored out into Xlint code and done automatically for all xlint messages, ideally.
  958. // if a piece of advice hasn't matched anywhere and we are in -1.5 mode, put out a warning
  959. if (world.isInJava5Mode() &&
  960. world.getLint().adviceDidNotMatch.isEnabled()) {
  961. List l = world.getCrosscuttingMembersSet().getShadowMungers();
  962. Set alreadyWarnedLocations = new HashSet();
  963. for (Iterator iter = l.iterator(); iter.hasNext();) {
  964. ShadowMunger element = (ShadowMunger) iter.next();
  965. if (element instanceof BcelAdvice) { // This will stop us incorrectly reporting deow Checkers
  966. BcelAdvice ba = (BcelAdvice)element;
  967. if (!ba.hasMatchedSomething()) {
  968. // Because we implement some features of AJ itself by creating our own kind of mungers, you sometimes
  969. // find that ba.getSignature() is not a BcelMethod - for example it might be a cflow entry munger.
  970. if (ba.getSignature()!=null) {
  971. // check we haven't already warned on this advice and line
  972. // (cflow creates multiple mungers for the same advice)
  973. AdviceLocation loc = new AdviceLocation(ba);
  974. if (alreadyWarnedLocations.contains(loc)) {
  975. continue;
  976. } else {
  977. alreadyWarnedLocations.add(loc);
  978. }
  979. if (!(ba.getSignature() instanceof BcelMethod)
  980. || !Utility.isSuppressing((AnnotationX[])ba.getSignature().getAnnotations(),"adviceDidNotMatch")) {
  981. world.getLint().adviceDidNotMatch.signal(ba.getDeclaringAspect().toString(),element.getSourceLocation());
  982. }
  983. }
  984. }
  985. }
  986. }
  987. }
  988. }
  989. /**
  990. * 'typeToWeave' is one from the 'typesForWeaving' list. This routine ensures we process
  991. * supertypes (classes/interfaces) of 'typeToWeave' that are in the
  992. * 'typesForWeaving' list before 'typeToWeave' itself. 'typesToWeave' is then removed from
  993. * the 'typesForWeaving' list.
  994. *
  995. * Note: Future gotcha in here ... when supplying partial hierarchies, this algorithm may
  996. * break down. If you have a hierarchy A>B>C and only give A and C to the weaver, it
  997. * may choose to weave them in either order - but you'll probably have other problems if
  998. * you are supplying partial hierarchies like that !
  999. */
  1000. private void weaveParentsFor(List typesForWeaving,String typeToWeave) {
  1001. // Look at the supertype first
  1002. ResolvedType rtx = world.resolve(typeToWeave);
  1003. ResolvedType superType = rtx.getSuperclass();
  1004. if (superType!=null && typesForWeaving.contains(superType.getName())) {
  1005. weaveParentsFor(typesForWeaving,superType.getName());
  1006. }
  1007. // Then look at the superinterface list
  1008. ResolvedType[] interfaceTypes = rtx.getDeclaredInterfaces();
  1009. for (int i = 0; i < interfaceTypes.length; i++) {
  1010. ResolvedType rtxI = interfaceTypes[i];
  1011. if (typesForWeaving.contains(rtxI.getName())) {
  1012. weaveParentsFor(typesForWeaving,rtxI.getName());
  1013. }
  1014. }
  1015. ContextToken tok = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.PROCESSING_DECLARE_PARENTS,rtx.getName());
  1016. weaveParentTypeMungers(rtx); // Now do this type
  1017. CompilationAndWeavingContext.leavingPhase(tok);
  1018. typesForWeaving.remove(typeToWeave); // and remove it from the list of those to process
  1019. }
  1020. public void prepareToProcessReweavableState() {
  1021. if (inReweavableMode)
  1022. world.showMessage(IMessage.INFO,
  1023. WeaverMessages.format(WeaverMessages.REWEAVABLE_MODE),
  1024. null, null);
  1025. }
  1026. public void processReweavableStateIfPresent(String className, BcelObjectType classType) {
  1027. // If the class is marked reweavable, check any aspects around when it was built are in this world
  1028. WeaverStateInfo wsi = classType.getWeaverState();
  1029. if (wsi!=null && wsi.isReweavable()) { // Check all necessary types are around!
  1030. world.showMessage(IMessage.INFO,
  1031. WeaverMessages.format(WeaverMessages.PROCESSING_REWEAVABLE,className,classType.getSourceLocation().getSourceFile()),
  1032. null,null);
  1033. Set aspectsPreviouslyInWorld = wsi.getAspectsAffectingType();
  1034. if (aspectsPreviouslyInWorld!=null) {
  1035. // keep track of them just to ensure unique missing aspect error reporting
  1036. Set alreadyConfirmedReweavableState = new HashSet();
  1037. for (Iterator iter = aspectsPreviouslyInWorld.iterator(); iter.hasNext();) {
  1038. String requiredTypeName = (String) iter.next();
  1039. if (!alreadyConfirmedReweavableState.contains(requiredTypeName)) {
  1040. ResolvedType rtx = world.resolve(UnresolvedType.forName(requiredTypeName),true);
  1041. boolean exists = rtx!=ResolvedType.MISSING;
  1042. if (!exists) {
  1043. world.showMessage(IMessage.ERROR,
  1044. WeaverMessages.format(WeaverMessages.MISSING_REWEAVABLE_TYPE,requiredTypeName,className),
  1045. classType.getSourceLocation(), null);
  1046. } else {
  1047. if (!world.getMessageHandler().isIgnoring(IMessage.INFO))
  1048. world.showMessage(IMessage.INFO,
  1049. WeaverMessages.format(WeaverMessages.VERIFIED_REWEAVABLE_TYPE,requiredTypeName,rtx.getSourceLocation().getSourceFile()),
  1050. null,null);
  1051. alreadyConfirmedReweavableState.add(requiredTypeName);
  1052. }
  1053. }
  1054. }
  1055. }
  1056. classType.setJavaClass(Utility.makeJavaClass(classType.getJavaClass().getFileName(), wsi.getUnwovenClassFileData()));
  1057. } else {
  1058. classType.resetState();
  1059. }
  1060. }
  1061. private void weaveAndNotify(UnwovenClassFile classFile, BcelObjectType classType,
  1062. IWeaveRequestor requestor) throws IOException {
  1063. ContextToken tok = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.WEAVING_TYPE, classType.getResolvedTypeX().getName());
  1064. LazyClassGen clazz = weaveWithoutDump(classFile,classType);
  1065. classType.finishedWith();
  1066. //clazz is null if the classfile was unchanged by weaving...
  1067. if (clazz != null) {
  1068. UnwovenClassFile[] newClasses = getClassFilesFor(clazz);
  1069. for (int i = 0; i < newClasses.length; i++) {
  1070. requestor.acceptResult(newClasses[i]);
  1071. }
  1072. } else {
  1073. requestor.acceptResult(classFile);
  1074. }
  1075. CompilationAndWeavingContext.leavingPhase(tok);
  1076. }
  1077. /** helper method - will return NULL if the underlying delegate is an EclipseSourceType and not a BcelObjectType */
  1078. public BcelObjectType getClassType(String forClass) {
  1079. return BcelWorld.getBcelObjectType(world.resolve(forClass));
  1080. }
  1081. public void addParentTypeMungers(String typeName) {
  1082. weaveParentTypeMungers(world.resolve(typeName));
  1083. }
  1084. public void addNormalTypeMungers(String typeName) {
  1085. weaveNormalTypeMungers(world.resolve(typeName));
  1086. }
  1087. public UnwovenClassFile[] getClassFilesFor(LazyClassGen clazz) {
  1088. List childClasses = clazz.getChildClasses(world);
  1089. UnwovenClassFile[] ret = new UnwovenClassFile[1 + childClasses.size()];
  1090. ret[0] = new UnwovenClassFile(clazz.getFileName(),clazz.getJavaClass(world).getBytes());
  1091. int index = 1;
  1092. for (Iterator iter = childClasses.iterator(); iter.hasNext();) {
  1093. UnwovenClassFile.ChildClass element = (UnwovenClassFile.ChildClass) iter.next();
  1094. UnwovenClassFile childClass = new UnwovenClassFile(clazz.getFileName() + "$" + element.name, element.bytes);
  1095. ret[index++] = childClass;
  1096. }
  1097. return ret;
  1098. }
  1099. /**
  1100. * Weaves new parents and annotations onto a type ("declare parents" and "declare @type")
  1101. *
  1102. * Algorithm:
  1103. * 1. First pass, do parents then do annotations. During this pass record:
  1104. * - any parent mungers that don't match but have a non-wild annotation type pattern
  1105. * - any annotation mungers that don't match
  1106. * 2. Multiple subsequent passes which go over the munger lists constructed in the first
  1107. * pass, repeatedly applying them until nothing changes.
  1108. * FIXME asc confirm that algorithm is optimal ??
  1109. */
  1110. public void weaveParentTypeMungers(ResolvedType onType) {
  1111. if (onType.isRawType()) onType = onType.getGenericType();
  1112. onType.clearInterTypeMungers();
  1113. List decpToRepeat = new ArrayList();
  1114. boolean aParentChangeOccurred = false;
  1115. boolean anAnnotationChangeOccurred = false;
  1116. // First pass - apply all decp mungers
  1117. for (Iterator i = declareParentsList.iterator(); i.hasNext(); ) {
  1118. DeclareParents decp = (DeclareParents)i.next();
  1119. boolean typeChanged = applyDeclareParents(decp,onType);
  1120. if (typeChanged) {
  1121. aParentChangeOccurred = true;
  1122. } else { // Perhaps it would have matched if a 'dec @type' had modified the type
  1123. if (!decp.getChild().isStarAnnotation()) decpToRepeat.add(decp);
  1124. }
  1125. }
  1126. // Still first pass - apply all dec @type mungers
  1127. for (Iterator i = xcutSet.getDeclareAnnotationOnTypes().iterator();i.hasNext();) {
  1128. DeclareAnnotation decA = (DeclareAnnotation)i.next();
  1129. boolean typeChanged = applyDeclareAtType(decA,onType,true);
  1130. if (typeChanged) {
  1131. anAnnotationChangeOccurred = true;
  1132. }
  1133. }
  1134. while ((aParentChangeOccurred || anAnnotationChangeOccurred) && !decpToRepeat.isEmpty()) {
  1135. anAnnotationChangeOccurred = aParentChangeOccurred = false;
  1136. List decpToRepeatNextTime = new ArrayList();
  1137. for (Iterator iter = decpToRepeat.iterator(); iter.hasNext();) {
  1138. DeclareParents decp = (DeclareParents) iter.next();
  1139. boolean typeChanged = applyDeclareParents(decp,onType);
  1140. if (typeChanged) {
  1141. aParentChangeOccurred = true;
  1142. } else {
  1143. decpToRepeatNextTime.add(decp);
  1144. }
  1145. }
  1146. for (Iterator iter = xcutSet.getDeclareAnnotationOnTypes().iterator(); iter.hasNext();) {
  1147. DeclareAnnotation decA = (DeclareAnnotation) iter.next();
  1148. boolean typeChanged = applyDeclareAtType(decA,onType,false);
  1149. if (typeChanged) {
  1150. anAnnotationChangeOccurred = true;
  1151. }
  1152. }
  1153. decpToRepeat = decpToRepeatNextTime;
  1154. }
  1155. }
  1156. /**
  1157. * Apply a declare @type - return true if we change the type
  1158. */
  1159. private boolean applyDeclareAtType(DeclareAnnotation decA, ResolvedType onType,boolean reportProblems) {
  1160. boolean didSomething = false;
  1161. if (decA.matches(onType)) {
  1162. // FIXME asc important this should be guarded by the 'already has annotation' check below but isn't since the compiler is producing classfiles with deca affected things in...
  1163. AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decA.getSourceLocation(),onType.getSourceLocation());
  1164. // FIXME asc same comment above applies here
  1165. // TAG: WeavingMessage
  1166. if (!getWorld().getMessageHandler().isIgnoring(IMessage.WEAVEINFO)){
  1167. getWorld().getMessageHandler().handleMessage(
  1168. WeaveMessage.constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_ANNOTATES,
  1169. new String[]{
  1170. onType.toString(),
  1171. Utility.beautifyLocation(onType.getSourceLocation()),
  1172. decA.getAnnotationString(),
  1173. "type",
  1174. decA.getAspect().toString(),
  1175. Utility.beautifyLocation(decA.getSourceLocation())
  1176. }));
  1177. }
  1178. if (onType.hasAnnotation(decA.getAnnotationX().getSignature())) {
  1179. // FIXME asc Could put out a lint here for an already annotated type - the problem is that it may have
  1180. // picked up the annotation during 'source weaving' in which case the message is misleading. Leaving it
  1181. // off for now...
  1182. // if (reportProblems) {
  1183. // world.getLint().elementAlreadyAnnotated.signal(
  1184. // new String[]{onType.toString(),decA.getAnnotationTypeX().toString()},
  1185. // onType.getSourceLocation(),new ISourceLocation[]{decA.getSourceLocation()});
  1186. // }
  1187. return false;
  1188. }
  1189. AnnotationX annoX = decA.getAnnotationX();
  1190. // check the annotation is suitable for the target
  1191. boolean problemReported = verifyTargetIsOK(decA, onType, annoX,reportProblems);
  1192. if (!problemReported) {
  1193. didSomething = true;
  1194. ResolvedTypeMunger newAnnotationTM = new AnnotationOnTypeMunger(annoX);
  1195. newAnnotationTM.setSourceLocation(decA.getSourceLocation());
  1196. onType.addInterTypeMunger(new BcelTypeMunger(newAnnotationTM,decA.getAspect().resolve(world)));
  1197. decA.copyAnnotationTo(onType);
  1198. }
  1199. }
  1200. return didSomething;
  1201. }
  1202. /**
  1203. * Checks for an @target() on the annotation and if found ensures it allows the annotation
  1204. * to be attached to the target type that matched.
  1205. */
  1206. private boolean verifyTargetIsOK(DeclareAnnotation decA, ResolvedType onType, AnnotationX annoX,boolean outputProblems) {
  1207. boolean problemReported = false;
  1208. if (annoX.specifiesTarget()) {
  1209. if ( (onType.isAnnotation() && !annoX.allowedOnAnnotationType()) ||
  1210. (!annoX.allowedOnRegularType())) {
  1211. if (outputProblems) {
  1212. if (decA.isExactPattern()) {
  1213. world.getMessageHandler().handleMessage(MessageUtil.error(
  1214. WeaverMessages.format(WeaverMessages.INCORRECT_TARGET_FOR_DECLARE_ANNOTATION,
  1215. onType.getName(),annoX.stringify(),annoX.getValidTargets()),decA.getSourceLocation()));
  1216. } else {
  1217. if (world.getLint().invalidTargetForAnnotation.isEnabled()) {
  1218. world.getLint().invalidTargetForAnnotation.signal(
  1219. new String[]{onType.getName(),annoX.stringify(),annoX.getValidTargets()},decA.getSourceLocation(),new ISourceLocation[]{onType.getSourceLocation()});
  1220. }
  1221. }
  1222. }
  1223. problemReported = true;
  1224. }
  1225. }
  1226. return problemReported;
  1227. }
  1228. /**
  1229. * Apply a single declare parents - return true if we change the type
  1230. */
  1231. private boolean applyDeclareParents(DeclareParents p, ResolvedType onType) {
  1232. boolean didSomething = false;
  1233. List newParents = p.findMatchingNewParents(onType,true);
  1234. if (!newParents.isEmpty()) {
  1235. didSomething=true;
  1236. BcelObjectType classType = BcelWorld.getBcelObjectType(onType);
  1237. //System.err.println("need to do declare parents for: " + onType);
  1238. for (Iterator j = newParents.iterator(); j.hasNext(); ) {
  1239. ResolvedType newParent = (ResolvedType)j.next();
  1240. // We set it here so that the imminent matching for ITDs can succeed - we
  1241. // still haven't done the necessary changes to the class file itself
  1242. // (like transform super calls) - that is done in BcelTypeMunger.mungeNewParent()
  1243. classType.addParent(newParent);
  1244. ResolvedTypeMunger newParentMunger = new NewParentTypeMunger(newParent);
  1245. newParentMunger.setSourceLocation(p.getSourceLocation());
  1246. onType.addInterTypeMunger(new BcelTypeMunger(newParentMunger, xcutSet.findAspectDeclaringParents(p)));
  1247. }
  1248. }
  1249. return didSomething;
  1250. }
  1251. public void weaveNormalTypeMungers(ResolvedType onType) {
  1252. ContextToken tok = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.PROCESSING_TYPE_MUNGERS, onType.getName());
  1253. if (onType.isRawType() || onType.isParameterizedType()) onType = onType.getGenericType();
  1254. for (Iterator i = typeMungerList.iterator(); i.hasNext(); ) {
  1255. ConcreteTypeMunger m = (ConcreteTypeMunger)i.next();
  1256. if (m.matches(onType)) {
  1257. onType.addInterTypeMunger(m);
  1258. }
  1259. }
  1260. CompilationAndWeavingContext.leavingPhase(tok);
  1261. }
  1262. // exposed for ClassLoader dynamic weaving
  1263. public LazyClassGen weaveWithoutDump(UnwovenClassFile classFile, BcelObjectType classType) throws IOException {
  1264. return weave(classFile, classType, false);
  1265. }
  1266. // non-private for testing
  1267. LazyClassGen weave(UnwovenClassFile classFile, BcelObjectType classType) throws IOException {
  1268. LazyClassGen ret = weave(classFile, classType, true);
  1269. if (progressListener != null) {
  1270. progressMade += progressPerClassFile;
  1271. progressListener.setProgress(progressMade);
  1272. progressListener.setText("woven: " + classFile.getFilename());
  1273. }
  1274. return ret;
  1275. }
  1276. private LazyClassGen weave(UnwovenClassFile classFile, BcelObjectType classType, boolean dump) throws IOException {
  1277. if (classType.isSynthetic()) {
  1278. if (dump) dumpUnchanged(classFile);
  1279. return null;
  1280. }
  1281. // JavaClass javaClass = classType.getJavaClass();
  1282. List shadowMungers = fastMatch(shadowMungerList, classType.getResolvedTypeX());
  1283. List typeMungers = classType.getResolvedTypeX().getInterTypeMungers();
  1284. classType.getResolvedTypeX().checkInterTypeMungers();
  1285. LazyClassGen clazz = null;
  1286. if (shadowMungers.size() > 0 || typeMungers.size() > 0 || classType.isAspect() ||
  1287. world.getDeclareAnnotationOnMethods().size()>0 || world.getDeclareAnnotationOnFields().size()>0 ) {
  1288. clazz = classType.getLazyClassGen();
  1289. //System.err.println("got lazy gen: " + clazz + ", " + clazz.getWeaverState());
  1290. try {
  1291. boolean isChanged = BcelClassWeaver.weave(world, clazz, shadowMungers, typeMungers, lateTypeMungerList);
  1292. if (isChanged) {
  1293. if (dump) dump(classFile, clazz);
  1294. return clazz;
  1295. }
  1296. } catch (RuntimeException re) {
  1297. System.err.println("trouble in: ");
  1298. clazz.print(System.err);
  1299. re.printStackTrace();
  1300. throw re;
  1301. } catch (Error re) {
  1302. System.err.println("trouble in: ");
  1303. clazz.print(System.err);
  1304. throw re;
  1305. }
  1306. }
  1307. // this is very odd return behavior trying to keep everyone happy
  1308. if (dump) {
  1309. dumpUnchanged(classFile);
  1310. return clazz;
  1311. } else {
  1312. // ATAJ: the class was not weaved, but since it gets there early it may have new generated inner classes
  1313. // attached to it to support LTW perX aspectOf support (see BcelPerClauseAspectAdder)
  1314. // that aggressively defines the inner <aspect>$mayHaveAspect interface.
  1315. if (clazz != null && !clazz.getChildClasses(world).isEmpty()) {
  1316. return clazz;
  1317. }
  1318. return null;
  1319. }
  1320. }
  1321. // ---- writing
  1322. private void dumpUnchanged(UnwovenClassFile classFile) throws IOException {
  1323. if (zipOutputStream != null) {
  1324. writeZipEntry(getEntryName(classFile.getJavaClass().getClassName()), classFile.getBytes());
  1325. } else {
  1326. classFile.writeUnchangedBytes();
  1327. }
  1328. }
  1329. private String getEntryName(String className) {
  1330. //XXX what does bcel's getClassName do for inner names
  1331. return className.replace('.', '/') + ".class";
  1332. }
  1333. private void dump(UnwovenClassFile classFile, LazyClassGen clazz) throws IOException {
  1334. if (zipOutputStream != null) {
  1335. String mainClassName = classFile.getJavaClass().getClassName();
  1336. writeZipEntry(getEntryName(mainClassName),
  1337. clazz.getJavaClass(world).getBytes());
  1338. if (!clazz.getChildClasses(world).isEmpty()) {
  1339. for (Iterator i = clazz.getChildClasses(world).iterator(); i.hasNext();) {
  1340. UnwovenClassFile.ChildClass c = (UnwovenClassFile.ChildClass) i.next();
  1341. writeZipEntry(getEntryName(mainClassName + "$" + c.name), c.bytes);
  1342. }
  1343. }
  1344. } else {
  1345. classFile.writeWovenBytes(
  1346. clazz.getJavaClass(world).getBytes(),
  1347. clazz.getChildClasses(world)
  1348. );
  1349. }
  1350. }
  1351. private void writeZipEntry(String name, byte[] bytes) throws IOException {
  1352. ZipEntry newEntry = new ZipEntry(name); //??? get compression scheme right
  1353. zipOutputStream.putNextEntry(newEntry);
  1354. zipOutputStream.write(bytes);
  1355. zipOutputStream.closeEntry();
  1356. }
  1357. private List fastMatch(List list, ResolvedType type) {
  1358. if (list == null) return Collections.EMPTY_LIST;
  1359. // here we do the coarsest grained fast match with no kind constraints
  1360. // this will remove all obvious non-matches and see if we need to do any weaving
  1361. FastMatchInfo info = new FastMatchInfo(type, null);
  1362. List result = new ArrayList();
  1363. Iterator iter = list.iterator();
  1364. while (iter.hasNext()) {
  1365. ShadowMunger munger = (ShadowMunger)iter.next();
  1366. FuzzyBoolean fb = munger.getPointcut().fastMatch(info);
  1367. WeaverMetrics.recordFastMatchTypeResult(fb); // Could pass: munger.getPointcut().toString(),info
  1368. if (fb.maybeTrue()) {
  1369. result.add(munger);
  1370. }
  1371. }
  1372. return result;
  1373. }
  1374. public void setProgressListener(IProgressListener listener, double previousProgress, double progressPerClassFile) {
  1375. progressListener = listener;
  1376. this.progressMade = previousProgress;
  1377. this.progressPerClassFile = progressPerClassFile;
  1378. }
  1379. public void setReweavableMode(boolean mode,boolean compress) {
  1380. inReweavableMode = mode;
  1381. WeaverStateInfo.setReweavableModeDefaults(mode,compress);
  1382. BcelClassWeaver.setReweavableMode(mode,compress);
  1383. }
  1384. public boolean isReweavable() {
  1385. return inReweavableMode;
  1386. }
  1387. public World getWorld() {
  1388. return world;
  1389. }
  1390. }