12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736 |
- /* *******************************************************************
- * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
- * All rights reserved.
- * This program and the accompanying materials are made available
- * under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * PARC initial implementation
- * Alexandre Vasseur support for @AJ aspects
- * ******************************************************************/
-
-
- package org.aspectj.weaver.bcel;
-
-
- import java.io.ByteArrayInputStream;
- import java.io.File;
- import java.io.FileFilter;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.util.ArrayList;
- import java.util.Collection;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.Enumeration;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- import java.util.jar.Attributes;
- import java.util.jar.JarEntry;
- import java.util.jar.JarFile;
- import java.util.jar.Manifest;
- import java.util.jar.Attributes.Name;
- import java.util.zip.ZipEntry;
- import java.util.zip.ZipInputStream;
- import java.util.zip.ZipOutputStream;
-
- import org.aspectj.apache.bcel.classfile.ClassParser;
- import org.aspectj.apache.bcel.classfile.JavaClass;
- import org.aspectj.asm.AsmManager;
- import org.aspectj.bridge.IMessage;
- import org.aspectj.bridge.IProgressListener;
- import org.aspectj.bridge.ISourceLocation;
- import org.aspectj.bridge.Message;
- import org.aspectj.bridge.MessageUtil;
- import org.aspectj.bridge.SourceLocation;
- import org.aspectj.bridge.WeaveMessage;
- import org.aspectj.bridge.context.CompilationAndWeavingContext;
- import org.aspectj.bridge.context.ContextToken;
- import org.aspectj.util.FileUtil;
- import org.aspectj.util.FuzzyBoolean;
- import org.aspectj.weaver.Advice;
- import org.aspectj.weaver.AnnotationOnTypeMunger;
- import org.aspectj.weaver.AnnotationX;
- import org.aspectj.weaver.AsmRelationshipProvider;
- import org.aspectj.weaver.BCException;
- import org.aspectj.weaver.ConcreteTypeMunger;
- import org.aspectj.weaver.CrosscuttingMembersSet;
- import org.aspectj.weaver.IClassFileProvider;
- import org.aspectj.weaver.IWeaveRequestor;
- import org.aspectj.weaver.IWeaver;
- import org.aspectj.weaver.NewParentTypeMunger;
- import org.aspectj.weaver.ReferenceType;
- import org.aspectj.weaver.ReferenceTypeDelegate;
- import org.aspectj.weaver.ResolvedTypeMunger;
- import org.aspectj.weaver.ResolvedType;
- import org.aspectj.weaver.Shadow;
- import org.aspectj.weaver.ShadowMunger;
- import org.aspectj.weaver.UnresolvedType;
- import org.aspectj.weaver.WeaverMessages;
- import org.aspectj.weaver.WeaverMetrics;
- import org.aspectj.weaver.WeaverStateInfo;
- import org.aspectj.weaver.World;
- import org.aspectj.weaver.patterns.AndPointcut;
- import org.aspectj.weaver.patterns.BindingAnnotationTypePattern;
- import org.aspectj.weaver.patterns.BindingTypePattern;
- import org.aspectj.weaver.patterns.CflowPointcut;
- import org.aspectj.weaver.patterns.ConcreteCflowPointcut;
- import org.aspectj.weaver.patterns.DeclareAnnotation;
- import org.aspectj.weaver.patterns.DeclareParents;
- import org.aspectj.weaver.patterns.FastMatchInfo;
- import org.aspectj.weaver.patterns.IfPointcut;
- import org.aspectj.weaver.patterns.KindedPointcut;
- import org.aspectj.weaver.patterns.NameBindingPointcut;
- import org.aspectj.weaver.patterns.NotPointcut;
- import org.aspectj.weaver.patterns.OrPointcut;
- import org.aspectj.weaver.patterns.Pointcut;
- import org.aspectj.weaver.patterns.PointcutRewriter;
- import org.aspectj.weaver.patterns.WithinPointcut;
- import org.aspectj.weaver.tools.Trace;
- import org.aspectj.weaver.tools.TraceFactory;
-
-
- public class BcelWeaver implements IWeaver {
- private BcelWorld world;
- private CrosscuttingMembersSet xcutSet;
- private IProgressListener progressListener = null;
- private double progressMade;
- private double progressPerClassFile;
-
- private boolean inReweavableMode = false;
-
- private static Trace trace = TraceFactory.getTraceFactory().getTrace(BcelWeaver.class);
-
- public BcelWeaver(BcelWorld world) {
- super();
- if (trace.isTraceEnabled()) trace.enter("<init>",this,world);
- WeaverMetrics.reset();
- this.world = world;
- this.xcutSet = world.getCrosscuttingMembersSet();
- if (trace.isTraceEnabled()) trace.exit("<init>");
- }
-
- public BcelWeaver() {
- this(new BcelWorld());
- }
-
- // ---- fields
- // private Map sourceJavaClasses = new HashMap(); /* String -> UnwovenClassFile */
- private List addedClasses = new ArrayList(); /* List<UnovenClassFile> */
- private List deletedTypenames = new ArrayList(); /* List<String> */
- // private Map resources = new HashMap(); /* String -> UnwovenClassFile */
- private Manifest manifest = null;
- private boolean needToReweaveWorld = false;
-
- private boolean isBatchWeave = true;
- private List shadowMungerList = null; // setup by prepareForWeave
- private List typeMungerList = null; // setup by prepareForWeave
- private List lateTypeMungerList = null; // setup by prepareForWeave
- private List declareParentsList = null; // setup by prepareForWeave
-
- private ZipOutputStream zipOutputStream;
-
- // ----
-
- // only called for testing
- public void setShadowMungers(List l) {
- shadowMungerList = l;
- }
-
-
- /**
- * Add the given aspect to the weaver.
- * The type is resolved to support DOT for static inner classes as well as DOLLAR
- *
- * @param aspectName
- * @return aspect
- */
- public ResolvedType addLibraryAspect(String aspectName) {
- if (trace.isTraceEnabled()) trace.enter("addLibraryAspect",this,aspectName);
-
- // 1 - resolve as is
- UnresolvedType unresolvedT = UnresolvedType.forName(aspectName);
- unresolvedT.setNeedsModifiableDelegate(true);
- ResolvedType type = world.resolve(unresolvedT, true);
- if (type.isMissing()) {
- // fallback on inner class lookup mechanism
- String fixedName = aspectName;
- int hasDot = fixedName.lastIndexOf('.');
- while (hasDot > 0) {
- //System.out.println("BcelWeaver.addLibraryAspect " + fixedName);
- char[] fixedNameChars = fixedName.toCharArray();
- fixedNameChars[hasDot] = '$';
- fixedName = new String(fixedNameChars);
- hasDot = fixedName.lastIndexOf('.');
- UnresolvedType ut = UnresolvedType.forName(fixedName);
- ut.setNeedsModifiableDelegate(true);
- type = world.resolve(ut, true);
- if (!type.isMissing()) {
- break;
- }
- }
- }
-
- //System.out.println("type: " + type + " for " + aspectName);
- if (type.isAspect()) {
-
- // Bug 119657 ensure we use the unwoven aspect
- WeaverStateInfo wsi = type.getWeaverState();
- if (wsi != null && wsi.isReweavable()) {
- BcelObjectType classType = getClassType(type.getName());
- classType.setJavaClass(Utility.makeJavaClass(classType.getJavaClass().getFileName(), wsi.getUnwovenClassFileData(classType.getJavaClass().getBytes())));
- }
-
- //TODO AV - happens to reach that a lot of time: for each type flagged reweavable X for each aspect in the weaverstate
- //=> mainly for nothing for LTW - pbly for something in incremental build...
- xcutSet.addOrReplaceAspect(type);
- if (trace.isTraceEnabled()) trace.exit("addLibraryAspect",type);
- return type;
- } else {
- // FIXME AV - better warning upon no such aspect from aop.xml
- RuntimeException ex = new RuntimeException("Cannot register non aspect: " + type.getName() + " , " + aspectName);
- if (trace.isTraceEnabled()) trace.exit("addLibraryAspect",ex);
- throw ex;
- }
- }
-
-
-
- /**
- *
- * @param inFile File path to class directory or zip/jar class archive
- * @throws IOException
- */
- public void addLibraryJarFile(File inFile) throws IOException {
- List addedAspects = null;
- if (inFile.isDirectory()) {
- addedAspects = addAspectsFromDirectory(inFile);
- } else {
- addedAspects = addAspectsFromJarFile(inFile);
- }
-
- for (Iterator i = addedAspects.iterator(); i.hasNext();) {
- ResolvedType aspectX = (ResolvedType) i.next();
- xcutSet.addOrReplaceAspect(aspectX);
- }
- }
-
- private List addAspectsFromJarFile(File inFile) throws FileNotFoundException, IOException {
- ZipInputStream inStream = new ZipInputStream(new FileInputStream(inFile)); //??? buffered
- List addedAspects = new ArrayList();
- while (true) {
- ZipEntry entry = inStream.getNextEntry();
- if (entry == null) break;
-
- if (entry.isDirectory() || !entry.getName().endsWith(".class")) {
- continue;
- }
-
- // FIXME ASC performance? of this alternative soln.
- ClassParser parser = new ClassParser(new ByteArrayInputStream(FileUtil.readAsByteArray(inStream)), entry.getName());
- JavaClass jc = parser.parse();
- inStream.closeEntry();
-
- ResolvedType type = world.addSourceObjectType(jc).getResolvedTypeX();
- if (type.isAspect()) {
- addedAspects.add(type);
- }
-
- }
-
- inStream.close();
- return addedAspects;
- }
-
- private List addAspectsFromDirectory(File dir) throws FileNotFoundException, IOException{
- List addedAspects = new ArrayList();
- File[] classFiles = FileUtil.listFiles(dir,new FileFilter(){
-
- public boolean accept(File pathname) {
- return pathname.getName().endsWith(".class");
- }
-
- });
- for (int i = 0; i < classFiles.length; i++) {
- FileInputStream fis = new FileInputStream(classFiles[i]);
- byte[] bytes = FileUtil.readAsByteArray(fis);
- addIfAspect(bytes,classFiles[i].getAbsolutePath(),addedAspects);
- }
- return addedAspects;
- }
-
- private void addIfAspect(byte[] bytes, String name, List toList) throws IOException {
- ClassParser parser = new ClassParser(new ByteArrayInputStream(bytes),name);
- JavaClass jc = parser.parse();
- ResolvedType type = world.addSourceObjectType(jc).getResolvedTypeX();
- if (type.isAspect()) {
- toList.add(type);
- }
- }
-
-
- // // The ANT copy task should be used to copy resources across.
- // private final static boolean CopyResourcesFromInpathDirectoriesToOutput=false;
-
- /**
- * Add any .class files in the directory to the outdir. Anything other than .class files in
- * the directory (or its subdirectories) are considered resources and are also copied.
- *
- */
- public List addDirectoryContents(File inFile,File outDir) throws IOException {
- List addedClassFiles = new ArrayList();
-
- // Get a list of all files (i.e. everything that isnt a directory)
- File[] files = FileUtil.listFiles(inFile,new FileFilter() {
- public boolean accept(File f) {
- boolean accept = !f.isDirectory();
- return accept;
- }
- });
-
- // For each file, add it either as a real .class file or as a resource
- for (int i = 0; i < files.length; i++) {
- addedClassFiles.add(addClassFile(files[i],inFile,outDir));
- }
-
- return addedClassFiles;
- }
-
-
- /** Adds all class files in the jar
- */
- public List addJarFile(File inFile, File outDir, boolean canBeDirectory){
- // System.err.println("? addJarFile(" + inFile + ", " + outDir + ")");
- List addedClassFiles = new ArrayList();
- needToReweaveWorld = true;
- JarFile inJar = null;
-
- try {
- // Is this a directory we are looking at?
- if (inFile.isDirectory() && canBeDirectory) {
- addedClassFiles.addAll(addDirectoryContents(inFile,outDir));
- } else {
-
- inJar = new JarFile(inFile);
- addManifest(inJar.getManifest());
- Enumeration entries = inJar.entries();
-
- while (entries.hasMoreElements()) {
- JarEntry entry = (JarEntry)entries.nextElement();
- InputStream inStream = inJar.getInputStream(entry);
-
- byte[] bytes = FileUtil.readAsByteArray(inStream);
- String filename = entry.getName();
- // System.out.println("? addJarFile() filename='" + filename + "'");
- UnwovenClassFile classFile = new UnwovenClassFile(new File(outDir, filename).getAbsolutePath(), bytes);
-
- if (filename.endsWith(".class")) {
- this.addClassFile(classFile);
- addedClassFiles.add(classFile);
- }
- // else if (!entry.isDirectory()) {
- //
- // /* bug-44190 Copy meta-data */
- // addResource(filename,classFile);
- // }
-
- inStream.close();
- }
- inJar.close();
- }
- } catch (FileNotFoundException ex) {
- IMessage message = new Message(
- "Could not find input jar file " + inFile.getPath() + ", ignoring",
- new SourceLocation(inFile,0),
- false);
- world.getMessageHandler().handleMessage(message);
- } catch (IOException ex) {
- IMessage message = new Message(
- "Could not read input jar file " + inFile.getPath() + "(" + ex.getMessage() + ")",
- new SourceLocation(inFile,0),
- true);
- world.getMessageHandler().handleMessage(message);
- } finally {
- if (inJar != null) {
- try {inJar.close();}
- catch (IOException ex) {
- IMessage message = new Message(
- "Could not close input jar file " + inFile.getPath() + "(" + ex.getMessage() + ")",
- new SourceLocation(inFile,0),
- true);
- world.getMessageHandler().handleMessage(message);
- }
- }
- }
-
- return addedClassFiles;
- }
-
- // public void addResource(String name, File inPath, File outDir) throws IOException {
- //
- // /* Eliminate CVS files. Relative paths use "/" */
- // if (!name.startsWith("CVS/") && (-1 == name.indexOf("/CVS/")) && !name.endsWith("/CVS")) {
- //// System.err.println("? addResource('" + name + "')");
- //// BufferedInputStream inStream = new BufferedInputStream(new FileInputStream(inPath));
- //// byte[] bytes = new byte[(int)inPath.length()];
- //// inStream.read(bytes);
- //// inStream.close();
- // byte[] bytes = FileUtil.readAsByteArray(inPath);
- // UnwovenClassFile resourceFile = new UnwovenClassFile(new File(outDir, name).getAbsolutePath(), bytes);
- // addResource(name,resourceFile);
- // }
- // }
-
- public boolean needToReweaveWorld() {
- return needToReweaveWorld;
- }
-
- /** Should be addOrReplace
- */
- public void addClassFile(UnwovenClassFile classFile) {
- addedClasses.add(classFile);
- // if (null != sourceJavaClasses.put(classFile.getClassName(), classFile)) {
- //// throw new RuntimeException(classFile.getClassName());
- // }
- world.addSourceObjectType(classFile.getJavaClass());
- }
-
- public UnwovenClassFile addClassFile(File classFile, File inPathDir, File outDir) throws IOException {
- FileInputStream fis = new FileInputStream(classFile);
- byte[] bytes = FileUtil.readAsByteArray(fis);
- // String relativePath = files[i].getPath();
-
- // ASSERT: files[i].getAbsolutePath().startsWith(inFile.getAbsolutePath()
- // or we are in trouble...
- String filename = classFile.getAbsolutePath().substring(
- inPathDir.getAbsolutePath().length()+1);
- UnwovenClassFile ucf = new UnwovenClassFile(new File(outDir,filename).getAbsolutePath(),bytes);
- if (filename.endsWith(".class")) {
- // System.err.println("BCELWeaver: processing class from input directory "+classFile);
- this.addClassFile(ucf);
- }
- fis.close();
- return ucf;
- }
-
-
- public void deleteClassFile(String typename) {
- deletedTypenames.add(typename);
- // sourceJavaClasses.remove(typename);
- world.deleteSourceObjectType(UnresolvedType.forName(typename));
- }
-
- // public void addResource (String name, UnwovenClassFile resourceFile) {
- // /* bug-44190 Change error to warning and copy first resource */
- // if (!resources.containsKey(name)) {
- // resources.put(name, resourceFile);
- // }
- // else {
- // world.showMessage(IMessage.WARNING, "duplicate resource: '" + name + "'",
- // null, null);
- // }
- // }
-
- // ---- weave preparation
-
- public void setIsBatchWeave(boolean b) {
- isBatchWeave=b;
- }
-
- public void prepareForWeave() {
- if (trace.isTraceEnabled()) trace.enter("prepareForWeave",this);
- needToReweaveWorld = xcutSet.hasChangedSinceLastReset();
-
- CflowPointcut.clearCaches();
-
- // update mungers
- for (Iterator i = addedClasses.iterator(); i.hasNext(); ) {
- UnwovenClassFile jc = (UnwovenClassFile)i.next();
- String name = jc.getClassName();
- ResolvedType type = world.resolve(name);
- //System.err.println("added: " + type + " aspect? " + type.isAspect());
- if (type.isAspect()) {
- needToReweaveWorld |= xcutSet.addOrReplaceAspect(type);
- }
- }
-
- for (Iterator i = deletedTypenames.iterator(); i.hasNext(); ) {
- String name = (String)i.next();
- if (xcutSet.deleteAspect(UnresolvedType.forName(name))) needToReweaveWorld = true;
- }
-
- shadowMungerList = xcutSet.getShadowMungers();
- // world.debug("shadow mungers=" + shadowMungerList);
- rewritePointcuts(shadowMungerList);
- // Sometimes an error occurs during rewriting pointcuts (for example, if ambiguous bindings
- // are detected) - we ought to fail the prepare when this happens because continuing with
- // inconsistent pointcuts could lead to problems
- typeMungerList = xcutSet.getTypeMungers();
- lateTypeMungerList = xcutSet.getLateTypeMungers();
- declareParentsList = xcutSet.getDeclareParents();
-
- // The ordering here used to be based on a string compare on toString() for the two mungers -
- // that breaks for the @AJ style where advice names aren't programmatically generated. So we
- // have changed the sorting to be based on source location in the file - this is reliable, in
- // the case of source locations missing, we assume they are 'sorted' - i.e. the order in
- // which they were added to the collection is correct, this enables the @AJ stuff to work properly.
-
- // When @AJ processing starts filling in source locations for mungers, this code may need
- // a bit of alteration...
-
- Collections.sort(
- shadowMungerList,
- new Comparator() {
- public int compare(Object o1, Object o2) {
- ShadowMunger sm1 = (ShadowMunger)o1;
- ShadowMunger sm2 = (ShadowMunger)o2;
- if (sm1.getSourceLocation()==null) return (sm2.getSourceLocation()==null?0:1);
- if (sm2.getSourceLocation()==null) return -1;
-
- return (sm2.getSourceLocation().getOffset()-sm1.getSourceLocation().getOffset());
- }
- });
-
- if (trace.isTraceEnabled()) trace.exit("prepareForWeave");
- }
-
- /*
- * Rewrite all of the pointcuts in the world into their most efficient
- * form for subsequent matching. Also ensure that if pc1.equals(pc2)
- * then pc1 == pc2 (for non-binding pcds) by making references all
- * point to the same instance.
- * Since pointcuts remember their match decision on the last shadow,
- * this makes matching faster when many pointcuts share common elements,
- * or even when one single pointcut has one common element (which can
- * be a side-effect of DNF rewriting).
- */
- private void rewritePointcuts(List/*ShadowMunger*/ shadowMungers) {
- PointcutRewriter rewriter = new PointcutRewriter();
- for (Iterator iter = shadowMungers.iterator(); iter.hasNext();) {
- ShadowMunger munger = (ShadowMunger) iter.next();
- Pointcut p = munger.getPointcut();
- Pointcut newP = rewriter.rewrite(p);
- // validateBindings now whilst we still have around the pointcut
- // that resembles what the user actually wrote in their program
- // text.
- if (munger instanceof Advice) {
- Advice advice = (Advice) munger;
- if (advice.getSignature() != null) {
- final int numFormals;
- final String names[];
- // If the advice is being concretized in a @AJ aspect *and* the advice was declared in
- // an @AJ aspect (it could have been inherited from a code style aspect) then
- // evaluate the alternative set of formals. pr125699
- if (advice.getConcreteAspect().isAnnotationStyleAspect()
- && advice.getDeclaringAspect()!=null
- && advice.getDeclaringAspect().resolve(world).isAnnotationStyleAspect()) {
- numFormals = advice.getBaseParameterCount();
- int numArgs = advice.getSignature().getParameterTypes().length;
- if (numFormals > 0) {
- names = advice.getSignature().getParameterNames(world);
- validateBindings(newP,p,numArgs,names);
- }
- } else {
- numFormals = advice.getBaseParameterCount();
- if (numFormals > 0) {
- names = advice.getBaseParameterNames(world);
- validateBindings(newP,p,numFormals,names);
- }
- }
- }
- }
- munger.setPointcut(newP);
- }
- // now that we have optimized individual pointcuts, optimize
- // across the set of pointcuts....
- // Use a map from key based on pc equality, to value based on
- // pc identity.
- Map/*<Pointcut,Pointcut>*/ pcMap = new HashMap();
- for (Iterator iter = shadowMungers.iterator(); iter.hasNext();) {
- ShadowMunger munger = (ShadowMunger) iter.next();
- Pointcut p = munger.getPointcut();
- munger.setPointcut(shareEntriesFromMap(p,pcMap));
- }
- }
-
- private Pointcut shareEntriesFromMap(Pointcut p,Map pcMap) {
- // some things cant be shared...
- if (p instanceof NameBindingPointcut) return p;
- if (p instanceof IfPointcut) return p;
- if (p instanceof ConcreteCflowPointcut) return p;
- if (p instanceof AndPointcut) {
- AndPointcut apc = (AndPointcut) p;
- Pointcut left = shareEntriesFromMap(apc.getLeft(),pcMap);
- Pointcut right = shareEntriesFromMap(apc.getRight(),pcMap);
- return new AndPointcut(left,right);
- } else if (p instanceof OrPointcut) {
- OrPointcut opc = (OrPointcut) p;
- Pointcut left = shareEntriesFromMap(opc.getLeft(),pcMap);
- Pointcut right = shareEntriesFromMap(opc.getRight(),pcMap);
- return new OrPointcut(left,right);
- } else if (p instanceof NotPointcut) {
- NotPointcut npc = (NotPointcut) p;
- Pointcut not = shareEntriesFromMap(npc.getNegatedPointcut(),pcMap);
- return new NotPointcut(not);
- } else {
- // primitive pcd
- if (pcMap.containsKey(p)) { // based on equality
- return (Pointcut) pcMap.get(p); // same instance (identity)
- } else {
- pcMap.put(p,p);
- return p;
- }
- }
- }
-
- // userPointcut is the pointcut that the user wrote in the program text.
- // dnfPointcut is the same pointcut rewritten in DNF
- // numFormals is the number of formal parameters in the pointcut
- // if numFormals > 0 then every branch of a disjunction must bind each formal once and only once.
- // in addition, the left and right branches of a disjunction must hold on join point kinds in
- // common.
- private void validateBindings(Pointcut dnfPointcut, Pointcut userPointcut, int numFormals, String[] names) {
- if (numFormals == 0) return; // nothing to check
- if (dnfPointcut.couldMatchKinds()==Shadow.NO_SHADOW_KINDS_BITS) return; // cant have problems if you dont match!
- if (dnfPointcut instanceof OrPointcut) {
- OrPointcut orBasedDNFPointcut = (OrPointcut) dnfPointcut;
- Pointcut[] leftBindings = new Pointcut[numFormals];
- Pointcut[] rightBindings = new Pointcut[numFormals];
- validateOrBranch(orBasedDNFPointcut,userPointcut,numFormals,names,leftBindings,rightBindings);
- } else {
- Pointcut[] bindings = new Pointcut[numFormals];
- validateSingleBranch(dnfPointcut, userPointcut, numFormals, names,bindings);
- }
- }
-
- private void validateOrBranch(OrPointcut pc, Pointcut userPointcut, int numFormals,
- String[] names, Pointcut[] leftBindings, Pointcut[] rightBindings) {
- Pointcut left = pc.getLeft();
- Pointcut right = pc.getRight();
- if (left instanceof OrPointcut) {
- Pointcut[] newRightBindings = new Pointcut[numFormals];
- validateOrBranch((OrPointcut)left,userPointcut,numFormals,names,leftBindings,newRightBindings);
- } else {
- if (left.couldMatchKinds()!=Shadow.NO_SHADOW_KINDS_BITS)
- validateSingleBranch(left, userPointcut, numFormals, names, leftBindings);
- }
- if (right instanceof OrPointcut) {
- Pointcut[] newLeftBindings = new Pointcut[numFormals];
- validateOrBranch((OrPointcut)right,userPointcut,numFormals,names,newLeftBindings,rightBindings);
- } else {
- if (right.couldMatchKinds()!=Shadow.NO_SHADOW_KINDS_BITS)
- validateSingleBranch(right, userPointcut, numFormals, names, rightBindings);
- }
- int kindsInCommon = left.couldMatchKinds() & right.couldMatchKinds();
- if (kindsInCommon!=Shadow.NO_SHADOW_KINDS_BITS && couldEverMatchSameJoinPoints(left,right)) {
- // we know that every branch binds every formal, so there is no ambiguity
- // if each branch binds it in exactly the same way...
- List ambiguousNames = new ArrayList();
- for (int i = 0; i < numFormals; i++) {
- if (leftBindings[i] == null) {
- if (rightBindings[i] != null) {
- ambiguousNames.add(names[i]);
- }
- } else if (!leftBindings[i].equals(rightBindings[i])) {
- ambiguousNames.add(names[i]);
- }
- }
- if (!ambiguousNames.isEmpty())
- raiseAmbiguityInDisjunctionError(userPointcut,ambiguousNames);
- }
- }
-
- // pc is a pointcut that does not contain any disjunctions
- // check that every formal is bound (negation doesn't count).
- // we know that numFormals > 0 or else we would not be called
- private void validateSingleBranch(Pointcut pc, Pointcut userPointcut, int numFormals, String[] names, Pointcut[] bindings) {
- boolean[] foundFormals = new boolean[numFormals];
- for (int i = 0; i < foundFormals.length; i++) {
- foundFormals[i] = false;
- }
- validateSingleBranchRecursion(pc, userPointcut, foundFormals, names, bindings);
- for (int i = 0; i < foundFormals.length; i++) {
- if (!foundFormals[i]) {
- boolean ignore = false;
- // ATAJ soften the unbound error for implicit bindings like JoinPoint in @AJ style
- for (int j = 0; j < userPointcut.m_ignoreUnboundBindingForNames.length; j++) {
- if (names[i] != null && names[i].equals(userPointcut.m_ignoreUnboundBindingForNames[j])) {
- ignore = true;
- break;
- }
- }
- if (!ignore) {
- raiseUnboundFormalError(names[i],userPointcut);
- }
- }
- }
- }
-
- // each formal must appear exactly once
- private void validateSingleBranchRecursion(Pointcut pc, Pointcut userPointcut, boolean[] foundFormals, String[] names, Pointcut[] bindings) {
- if (pc instanceof NotPointcut) {
- // nots can only appear at leaves in DNF
- NotPointcut not = (NotPointcut) pc;
- if (not.getNegatedPointcut() instanceof NameBindingPointcut) {
- NameBindingPointcut nnbp = (NameBindingPointcut) not.getNegatedPointcut();
- if (!nnbp.getBindingAnnotationTypePatterns().isEmpty() && !nnbp.getBindingTypePatterns().isEmpty())
- raiseNegationBindingError(userPointcut);
- }
- } else if (pc instanceof AndPointcut) {
- AndPointcut and = (AndPointcut) pc;
- validateSingleBranchRecursion(and.getLeft(), userPointcut,foundFormals,names,bindings);
- validateSingleBranchRecursion(and.getRight(),userPointcut,foundFormals,names,bindings);
- } else if (pc instanceof NameBindingPointcut) {
- List/*BindingTypePattern*/ btps = ((NameBindingPointcut)pc).getBindingTypePatterns();
- for (Iterator iter = btps.iterator(); iter.hasNext();) {
- BindingTypePattern btp = (BindingTypePattern) iter.next();
- int index = btp.getFormalIndex();
- bindings[index] = pc;
- if (foundFormals[index]) {
- raiseAmbiguousBindingError(names[index],userPointcut);
- } else {
- foundFormals[index] = true;
- }
- }
- List/*BindingAnnotationTypePattern*/ baps = ((NameBindingPointcut)pc).getBindingAnnotationTypePatterns();
- for (Iterator iter = baps.iterator(); iter.hasNext();) {
- BindingAnnotationTypePattern bap = (BindingAnnotationTypePattern) iter.next();
- int index = bap.getFormalIndex();
- bindings[index] = pc;
- if (foundFormals[index]) {
- raiseAmbiguousBindingError(names[index],userPointcut);
- } else {
- foundFormals[index] = true;
- }
- }
- } else if (pc instanceof ConcreteCflowPointcut) {
- ConcreteCflowPointcut cfp = (ConcreteCflowPointcut) pc;
- int[] slots = cfp.getUsedFormalSlots();
- for (int i = 0; i < slots.length; i++) {
- bindings[slots[i]] = cfp;
- if (foundFormals[slots[i]]) {
- raiseAmbiguousBindingError(names[slots[i]],userPointcut);
- } else {
- foundFormals[slots[i]] = true;
- }
- }
- }
- }
-
-
- // By returning false from this method, we are allowing binding of the same
- // variable on either side of an or.
- // Be conservative :- have to consider overriding, varargs, autoboxing,
- // the effects of itds (on within for example), interfaces, the fact that
- // join points can have multiple signatures and so on.
- private boolean couldEverMatchSameJoinPoints(Pointcut left, Pointcut right) {
-
- if (left instanceof OrPointcut) {
- OrPointcut leftOrPointcut = (OrPointcut)left;
- if (couldEverMatchSameJoinPoints(leftOrPointcut.getLeft(),right)) return true;
- if (couldEverMatchSameJoinPoints(leftOrPointcut.getRight(),right)) return true;
- return false;
- }
-
- if (right instanceof OrPointcut) {
- OrPointcut rightOrPointcut = (OrPointcut)right;
- if (couldEverMatchSameJoinPoints(left,rightOrPointcut.getLeft())) return true;
- if (couldEverMatchSameJoinPoints(left,rightOrPointcut.getRight())) return true;
- return false;
- }
-
- // look for withins
- WithinPointcut leftWithin = (WithinPointcut) findFirstPointcutIn(left,WithinPointcut.class);
- WithinPointcut rightWithin = (WithinPointcut) findFirstPointcutIn(right,WithinPointcut.class);
- if ((leftWithin != null) && (rightWithin != null)) {
- if (!leftWithin.couldEverMatchSameJoinPointsAs(rightWithin)) return false;
- }
- // look for kinded
- KindedPointcut leftKind = (KindedPointcut) findFirstPointcutIn(left,KindedPointcut.class);
- KindedPointcut rightKind = (KindedPointcut) findFirstPointcutIn(right,KindedPointcut.class);
- if ((leftKind != null) && (rightKind != null)) {
- if (!leftKind.couldEverMatchSameJoinPointsAs(rightKind)) return false;
- }
- return true;
- }
-
- private Pointcut findFirstPointcutIn(Pointcut toSearch, Class toLookFor) {
- if (toSearch instanceof NotPointcut) return null;
- if (toLookFor.isInstance(toSearch)) return toSearch;
- if (toSearch instanceof AndPointcut) {
- AndPointcut apc = (AndPointcut) toSearch;
- Pointcut left = findFirstPointcutIn(apc.getLeft(),toLookFor);
- if (left != null) return left;
- return findFirstPointcutIn(apc.getRight(),toLookFor);
- }
- return null;
- }
-
- /**
- * @param userPointcut
- */
- private void raiseNegationBindingError(Pointcut userPointcut) {
- world.showMessage(IMessage.ERROR,
- WeaverMessages.format(WeaverMessages.NEGATION_DOESNT_ALLOW_BINDING),
- userPointcut.getSourceContext().makeSourceLocation(userPointcut),null);
- }
-
- /**
- * @param name
- * @param userPointcut
- */
- private void raiseAmbiguousBindingError(String name, Pointcut userPointcut) {
- world.showMessage(IMessage.ERROR,
- WeaverMessages.format(WeaverMessages.AMBIGUOUS_BINDING,
- name),
- userPointcut.getSourceContext().makeSourceLocation(userPointcut),null);
- }
-
- /**
- * @param userPointcut
- */
- private void raiseAmbiguityInDisjunctionError(Pointcut userPointcut, List names) {
- StringBuffer formalNames = new StringBuffer(names.get(0).toString());
- for (int i = 1; i < names.size(); i++) {
- formalNames.append(", ");
- formalNames.append(names.get(i));
- }
- world.showMessage(IMessage.ERROR,
- WeaverMessages.format(WeaverMessages.AMBIGUOUS_BINDING_IN_OR,formalNames),
- userPointcut.getSourceContext().makeSourceLocation(userPointcut),null);
- }
-
- /**
- * @param name
- * @param userPointcut
- */
- private void raiseUnboundFormalError(String name, Pointcut userPointcut) {
- world.showMessage(IMessage.ERROR,
- WeaverMessages.format(WeaverMessages.UNBOUND_FORMAL,
- name),
- userPointcut.getSourceContext().makeSourceLocation(userPointcut),null);
- }
-
-
- // public void dumpUnwoven(File file) throws IOException {
- // BufferedOutputStream os = FileUtil.makeOutputStream(file);
- // this.zipOutputStream = new ZipOutputStream(os);
- // dumpUnwoven();
- // /* BUG 40943*/
- // dumpResourcesToOutJar();
- // zipOutputStream.close(); //this flushes and closes the acutal file
- // }
- //
- //
- // public void dumpUnwoven() throws IOException {
- // Collection filesToDump = new HashSet(sourceJavaClasses.values());
- // for (Iterator i = filesToDump.iterator(); i.hasNext(); ) {
- // UnwovenClassFile classFile = (UnwovenClassFile)i.next();
- // dumpUnchanged(classFile);
- // }
- // }
-
- // public void dumpResourcesToOutPath() throws IOException {
- //// System.err.println("? dumpResourcesToOutPath() resources=" + resources.keySet());
- // Iterator i = resources.keySet().iterator();
- // while (i.hasNext()) {
- // UnwovenClassFile res = (UnwovenClassFile)resources.get(i.next());
- // dumpUnchanged(res);
- // }
- // //resources = new HashMap();
- // }
- //
- /* BUG #40943 */
- // public void dumpResourcesToOutJar() throws IOException {
- //// System.err.println("? dumpResourcesToOutJar() resources=" + resources.keySet());
- // Iterator i = resources.keySet().iterator();
- // while (i.hasNext()) {
- // String name = (String)i.next();
- // UnwovenClassFile res = (UnwovenClassFile)resources.get(name);
- // writeZipEntry(name,res.getBytes());
- // }
- // resources = new HashMap();
- // }
- //
- // // halfway house for when the jar is managed outside of the weaver, but the resources
- // // to be copied are known in the weaver.
- // public void dumpResourcesToOutJar(ZipOutputStream zos) throws IOException {
- // this.zipOutputStream = zos;
- // dumpResourcesToOutJar();
- // }
-
- public void addManifest (Manifest newManifest) {
- // System.out.println("? addManifest() newManifest=" + newManifest);
- if (manifest == null) {
- manifest = newManifest;
- }
- }
-
- public static final String MANIFEST_NAME = "META-INF/MANIFEST.MF";
-
- private static final String WEAVER_MANIFEST_VERSION = "1.0";
- private static final Attributes.Name CREATED_BY = new Name("Created-By");
- private static final String WEAVER_CREATED_BY = "AspectJ Compiler";
-
- public Manifest getManifest (boolean shouldCreate) {
-
- if (manifest == null && shouldCreate) {
- manifest = new Manifest();
-
- Attributes attributes = manifest.getMainAttributes();
- attributes.put(Name.MANIFEST_VERSION,WEAVER_MANIFEST_VERSION);
- attributes.put(CREATED_BY,WEAVER_CREATED_BY);
- }
-
- return manifest;
- }
-
- // ---- weaving
-
- // Used by some test cases only...
- public Collection weave(File file) throws IOException {
- OutputStream os = FileUtil.makeOutputStream(file);
- this.zipOutputStream = new ZipOutputStream(os);
- prepareForWeave();
- Collection c = weave( new IClassFileProvider() {
-
- public boolean isApplyAtAspectJMungersOnly() {
- return false;
- }
-
- public Iterator getClassFileIterator() {
- return addedClasses.iterator();
- }
-
- public IWeaveRequestor getRequestor() {
- return new IWeaveRequestor() {
- public void acceptResult(UnwovenClassFile result) {
- try {
- writeZipEntry(result.filename, result.bytes);
- } catch(IOException ex) {}
- }
- public void processingReweavableState() {}
- public void addingTypeMungers() {}
- public void weavingAspects() {}
- public void weavingClasses() {}
- public void weaveCompleted() {}
- };
- }
- });
- // /* BUG 40943*/
- // dumpResourcesToOutJar();
- zipOutputStream.close(); //this flushes and closes the acutal file
- return c;
- }
-
- // public Collection weave() throws IOException {
- // prepareForWeave();
- // Collection filesToWeave;
- //
- // if (needToReweaveWorld) {
- // filesToWeave = sourceJavaClasses.values();
- // } else {
- // filesToWeave = addedClasses;
- // }
- //
- // Collection wovenClassNames = new ArrayList();
- // world.showMessage(IMessage.INFO, "might need to weave " + filesToWeave +
- // "(world=" + needToReweaveWorld + ")", null, null);
- //
- //
- // //System.err.println("typeMungers: " + typeMungerList);
- //
- // prepareToProcessReweavableState();
- // // clear all state from files we'll be reweaving
- // for (Iterator i = filesToWeave.iterator(); i.hasNext(); ) {
- // UnwovenClassFile classFile = (UnwovenClassFile)i.next();
- // String className = classFile.getClassName();
- // BcelObjectType classType = getClassType(className);
- // processReweavableStateIfPresent(className, classType);
- // }
- //
- //
- //
- // //XXX this isn't quite the right place for this...
- // for (Iterator i = filesToWeave.iterator(); i.hasNext(); ) {
- // UnwovenClassFile classFile = (UnwovenClassFile)i.next();
- // String className = classFile.getClassName();
- // addTypeMungers(className);
- // }
- //
- // // first weave into aspects
- // for (Iterator i = filesToWeave.iterator(); i.hasNext(); ) {
- // UnwovenClassFile classFile = (UnwovenClassFile)i.next();
- // String className = classFile.getClassName();
- // BcelObjectType classType = BcelWorld.getBcelObjectType(world.resolve(className));
- // if (classType.isAspect()) {
- // weave(classFile, classType);
- // wovenClassNames.add(className);
- // }
- // }
- //
- // // then weave into non-aspects
- // for (Iterator i = filesToWeave.iterator(); i.hasNext(); ) {
- // UnwovenClassFile classFile = (UnwovenClassFile)i.next();
- // String className = classFile.getClassName();
- // BcelObjectType classType = BcelWorld.getBcelObjectType(world.resolve(className));
- // if (! classType.isAspect()) {
- // weave(classFile, classType);
- // wovenClassNames.add(className);
- // }
- // }
- //
- // if (zipOutputStream != null && !needToReweaveWorld) {
- // Collection filesToDump = new HashSet(sourceJavaClasses.values());
- // filesToDump.removeAll(filesToWeave);
- // for (Iterator i = filesToDump.iterator(); i.hasNext(); ) {
- // UnwovenClassFile classFile = (UnwovenClassFile)i.next();
- // dumpUnchanged(classFile);
- // }
- // }
- //
- // addedClasses = new ArrayList();
- // deletedTypenames = new ArrayList();
- //
- // return wovenClassNames;
- // }
-
- // variation of "weave" that sources class files from an external source.
- public Collection weave(IClassFileProvider input) throws IOException {
- if (trace.isTraceEnabled()) trace.enter("weave",this,input);
- ContextToken weaveToken = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.WEAVING, "");
- Collection wovenClassNames = new ArrayList();
- IWeaveRequestor requestor = input.getRequestor();
-
- for (Iterator i = input.getClassFileIterator(); i.hasNext(); ) {
- UnwovenClassFile classFile = (UnwovenClassFile)i.next();
- if (AsmManager.isCreatingModel() && !isBatchWeave) {
- // remove all relationships where this file being woven is the target of the relationship
- AsmManager.getDefault().removeRelationshipsTargettingThisType(classFile.getClassName());
- }
- }
-
- // special case for AtAspectJMungerOnly - see #113587
- if (input.isApplyAtAspectJMungersOnly()) {
- ContextToken atAspectJMungersOnly = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.PROCESSING_ATASPECTJTYPE_MUNGERS_ONLY, "");
- requestor.weavingAspects();
- ContextToken aspectToken = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.WEAVING_ASPECTS, "");
- for (Iterator i = input.getClassFileIterator(); i.hasNext(); ) {
- UnwovenClassFile classFile = (UnwovenClassFile)i.next();
- String className = classFile.getClassName();
- ResolvedType theType = world.resolve(className);
- if (theType.isAnnotationStyleAspect()) {
- BcelObjectType classType = BcelWorld.getBcelObjectType(theType);
- if (classType==null) {
- throw new BCException("Can't find bcel delegate for "+className+" type="+theType.getClass());
- }
- LazyClassGen clazz = classType.getLazyClassGen();
- BcelPerClauseAspectAdder selfMunger = new BcelPerClauseAspectAdder(theType, theType.getPerClause().getKind());
- selfMunger.forceMunge(clazz, true);
- classType.finishedWith();
- UnwovenClassFile[] newClasses = getClassFilesFor(clazz);
- for (int news = 0; news < newClasses.length; news++) {
- requestor.acceptResult(newClasses[news]);
- }
- wovenClassNames.add(classFile.getClassName());
- }
- }
- requestor.weaveCompleted();
- CompilationAndWeavingContext.leavingPhase(atAspectJMungersOnly);
- return wovenClassNames;
- }
-
- requestor.processingReweavableState();
- ContextToken reweaveToken = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.PROCESSING_REWEAVABLE_STATE,"");
- prepareToProcessReweavableState();
- // clear all state from files we'll be reweaving
- for (Iterator i = input.getClassFileIterator(); i.hasNext(); ) {
- UnwovenClassFile classFile = (UnwovenClassFile)i.next();
- String className = classFile.getClassName();
- BcelObjectType classType = getClassType(className);
-
- // null return from getClassType() means the delegate is an eclipse source type - so
- // there *cant* be any reweavable state... (he bravely claimed...)
- if (classType !=null) {
- ContextToken tok = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.PROCESSING_REWEAVABLE_STATE, className);
- processReweavableStateIfPresent(className, classType);
- CompilationAndWeavingContext.leavingPhase(tok);
- }
- }
-
- CompilationAndWeavingContext.leavingPhase(reweaveToken);
-
- ContextToken typeMungingToken = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.PROCESSING_TYPE_MUNGERS,"");
- requestor.addingTypeMungers();
-
- // We process type mungers in two groups, first mungers that change the type
- // hierarchy, then 'normal' ITD type mungers.
-
-
- // Process the types in a predictable order (rather than the order encountered).
- // For class A, the order is superclasses of A then superinterfaces of A
- // (and this mechanism is applied recursively)
- List typesToProcess = new ArrayList();
- for (Iterator iter = input.getClassFileIterator(); iter.hasNext();) {
- UnwovenClassFile clf = (UnwovenClassFile) iter.next();
- typesToProcess.add(clf.getClassName());
- }
- while (typesToProcess.size()>0) {
- weaveParentsFor(typesToProcess,(String)typesToProcess.get(0));
- }
-
- for (Iterator i = input.getClassFileIterator(); i.hasNext(); ) {
- UnwovenClassFile classFile = (UnwovenClassFile)i.next();
- String className = classFile.getClassName();
- addNormalTypeMungers(className);
- }
-
- CompilationAndWeavingContext.leavingPhase(typeMungingToken);
-
- requestor.weavingAspects();
- ContextToken aspectToken = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.WEAVING_ASPECTS, "");
- // first weave into aspects
- for (Iterator i = input.getClassFileIterator(); i.hasNext(); ) {
- UnwovenClassFile classFile = (UnwovenClassFile)i.next();
- String className = classFile.getClassName();
- ResolvedType theType = world.resolve(className);
- if (theType.isAspect()) {
- BcelObjectType classType = BcelWorld.getBcelObjectType(theType);
- if (classType==null) {
-
- // Sometimes.. if the Bcel Delegate couldn't be found then a problem occurred at compile time - on
- // a previous compiler run. In this case I assert the delegate will still be an EclipseSourceType
- // and we can ignore the problem here (the original compile error will be reported again from
- // the eclipse source type) - pr113531
- ReferenceTypeDelegate theDelegate = ((ReferenceType)theType).getDelegate();
- if (theDelegate.getClass().getName().endsWith("EclipseSourceType")) continue;
-
- throw new BCException("Can't find bcel delegate for "+className+" type="+theType.getClass());
- }
- weaveAndNotify(classFile, classType,requestor);
- wovenClassNames.add(className);
- }
- }
-
- CompilationAndWeavingContext.leavingPhase(aspectToken);
-
- requestor.weavingClasses();
- ContextToken classToken = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.WEAVING_CLASSES, "");
- // then weave into non-aspects
- for (Iterator i = input.getClassFileIterator(); i.hasNext(); ) {
- UnwovenClassFile classFile = (UnwovenClassFile)i.next();
- String className = classFile.getClassName();
- ResolvedType theType = world.resolve(className);
- if (!theType.isAspect()) {
- BcelObjectType classType = BcelWorld.getBcelObjectType(theType);
- if (classType==null) {
-
- // bug 119882 - see above comment for bug 113531
- ReferenceTypeDelegate theDelegate = ((ReferenceType)theType).getDelegate();
- if (theDelegate.getClass().getName().endsWith("EclipseSourceType")) continue;
-
- throw new BCException("Can't find bcel delegate for "+className+" type="+theType.getClass());
- }
- weaveAndNotify(classFile, classType, requestor);
- wovenClassNames.add(className);
- }
- }
- CompilationAndWeavingContext.leavingPhase(classToken);
-
- addedClasses = new ArrayList();
- deletedTypenames = new ArrayList();
-
-
- warnOnUnmatchedAdvice();
-
- requestor.weaveCompleted();
- CompilationAndWeavingContext.leavingPhase(weaveToken);
- if (trace.isTraceEnabled()) trace.exit("weave",wovenClassNames);
- return wovenClassNames;
- }
-
- /**
- * In 1.5 mode and with XLint:adviceDidNotMatch enabled, put out messages for any
- * mungers that did not match anything.
- */
- private void warnOnUnmatchedAdvice() {
-
- class AdviceLocation {
- private int lineNo;
- private UnresolvedType inAspect;
-
- public AdviceLocation(BcelAdvice advice) {
- this.lineNo = advice.getSourceLocation().getLine();
- this.inAspect = advice.getDeclaringAspect();
- }
-
- public boolean equals(Object obj) {
- if (!(obj instanceof AdviceLocation)) return false;
- AdviceLocation other = (AdviceLocation) obj;
- if (this.lineNo != other.lineNo) return false;
- if (!this.inAspect.equals(other.inAspect)) return false;
- return true;
- }
-
- public int hashCode() {
- return 37 + 17*lineNo + 17*inAspect.hashCode();
- };
- }
-
- // FIXME asc Should be factored out into Xlint code and done automatically for all xlint messages, ideally.
- // if a piece of advice hasn't matched anywhere and we are in -1.5 mode, put out a warning
- if (world.isInJava5Mode() &&
- world.getLint().adviceDidNotMatch.isEnabled()) {
- List l = world.getCrosscuttingMembersSet().getShadowMungers();
- Set alreadyWarnedLocations = new HashSet();
-
- for (Iterator iter = l.iterator(); iter.hasNext();) {
- ShadowMunger element = (ShadowMunger) iter.next();
- if (element instanceof BcelAdvice) { // This will stop us incorrectly reporting deow Checkers
- BcelAdvice ba = (BcelAdvice)element;
- if (!ba.hasMatchedSomething()) {
- // Because we implement some features of AJ itself by creating our own kind of mungers, you sometimes
- // find that ba.getSignature() is not a BcelMethod - for example it might be a cflow entry munger.
- if (ba.getSignature()!=null) {
-
- // check we haven't already warned on this advice and line
- // (cflow creates multiple mungers for the same advice)
- AdviceLocation loc = new AdviceLocation(ba);
- if (alreadyWarnedLocations.contains(loc)) {
- continue;
- } else {
- alreadyWarnedLocations.add(loc);
- }
-
- if (!(ba.getSignature() instanceof BcelMethod)
- || !Utility.isSuppressing((AnnotationX[])ba.getSignature().getAnnotations(),"adviceDidNotMatch")) {
- world.getLint().adviceDidNotMatch.signal(ba.getDeclaringAspect().toString(),element.getSourceLocation());
- }
- }
- }
- }
- }
- }
- }
-
- /**
- * 'typeToWeave' is one from the 'typesForWeaving' list. This routine ensures we process
- * supertypes (classes/interfaces) of 'typeToWeave' that are in the
- * 'typesForWeaving' list before 'typeToWeave' itself. 'typesToWeave' is then removed from
- * the 'typesForWeaving' list.
- *
- * Note: Future gotcha in here ... when supplying partial hierarchies, this algorithm may
- * break down. If you have a hierarchy A>B>C and only give A and C to the weaver, it
- * may choose to weave them in either order - but you'll probably have other problems if
- * you are supplying partial hierarchies like that !
- */
- private void weaveParentsFor(List typesForWeaving,String typeToWeave) {
- // Look at the supertype first
- ResolvedType rtx = world.resolve(typeToWeave);
- ResolvedType superType = rtx.getSuperclass();
-
- if (superType!=null && typesForWeaving.contains(superType.getName())) {
- weaveParentsFor(typesForWeaving,superType.getName());
- }
-
- // Then look at the superinterface list
- ResolvedType[] interfaceTypes = rtx.getDeclaredInterfaces();
- for (int i = 0; i < interfaceTypes.length; i++) {
- ResolvedType rtxI = interfaceTypes[i];
- if (typesForWeaving.contains(rtxI.getName())) {
- weaveParentsFor(typesForWeaving,rtxI.getName());
- }
- }
- ContextToken tok = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.PROCESSING_DECLARE_PARENTS,rtx.getName());
- weaveParentTypeMungers(rtx); // Now do this type
- CompilationAndWeavingContext.leavingPhase(tok);
- typesForWeaving.remove(typeToWeave); // and remove it from the list of those to process
- }
-
- public void prepareToProcessReweavableState() {
- if (inReweavableMode)
- world.showMessage(IMessage.INFO,
- WeaverMessages.format(WeaverMessages.REWEAVABLE_MODE),
- null, null);
- }
-
- public void processReweavableStateIfPresent(String className, BcelObjectType classType) {
- // If the class is marked reweavable, check any aspects around when it was built are in this world
- WeaverStateInfo wsi = classType.getWeaverState();
- if (wsi!=null && wsi.isReweavable()) { // Check all necessary types are around!
- world.showMessage(IMessage.INFO,
- WeaverMessages.format(WeaverMessages.PROCESSING_REWEAVABLE,className,classType.getSourceLocation().getSourceFile()),
- null,null);
- Set aspectsPreviouslyInWorld = wsi.getAspectsAffectingType();
- if (aspectsPreviouslyInWorld!=null) {
- // keep track of them just to ensure unique missing aspect error reporting
- Set alreadyConfirmedReweavableState = new HashSet();
- for (Iterator iter = aspectsPreviouslyInWorld.iterator(); iter.hasNext();) {
- String requiredTypeName = (String) iter.next();
- if (!alreadyConfirmedReweavableState.contains(requiredTypeName)) {
- ResolvedType rtx = world.resolve(UnresolvedType.forName(requiredTypeName),true);
- boolean exists = !rtx.isMissing();
- if (!exists) {
- world.showMessage(IMessage.ERROR,
- WeaverMessages.format(WeaverMessages.MISSING_REWEAVABLE_TYPE,requiredTypeName,className),
- classType.getSourceLocation(), null);
- } else {
- // weaved in aspect that are not declared in aop.xml trigger an error for now
- // may cause headhache for LTW and packaged lib without aop.xml in
- // see #104218
- if(!xcutSet.containsAspect(rtx)){
- world.showMessage(
- IMessage.ERROR,
- WeaverMessages.format(
- WeaverMessages.REWEAVABLE_ASPECT_NOT_REGISTERED,
- requiredTypeName,
- className
- ),
- null,
- null
- );
- } else if (!world.getMessageHandler().isIgnoring(IMessage.INFO))
- world.showMessage(IMessage.INFO,
- WeaverMessages.format(WeaverMessages.VERIFIED_REWEAVABLE_TYPE,requiredTypeName,rtx.getSourceLocation().getSourceFile()),
- null,null);
- alreadyConfirmedReweavableState.add(requiredTypeName);
- }
- }
- }
- }
- // old:
- //classType.setJavaClass(Utility.makeJavaClass(classType.getJavaClass().getFileName(), wsi.getUnwovenClassFileData()));
- // new: reweavable default with clever diff
- classType.setJavaClass(Utility.makeJavaClass(classType.getJavaClass().getFileName(), wsi.getUnwovenClassFileData(classType.getJavaClass().getBytes())));
- // } else {
- // classType.resetState();
- }
- }
-
- private void weaveAndNotify(UnwovenClassFile classFile, BcelObjectType classType,
- IWeaveRequestor requestor) throws IOException {
- ContextToken tok = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.WEAVING_TYPE, classType.getResolvedTypeX().getName());
- LazyClassGen clazz = weaveWithoutDump(classFile,classType);
- classType.finishedWith();
- //clazz is null if the classfile was unchanged by weaving...
- if (clazz != null) {
- UnwovenClassFile[] newClasses = getClassFilesFor(clazz);
- for (int i = 0; i < newClasses.length; i++) {
- requestor.acceptResult(newClasses[i]);
- }
- } else {
- requestor.acceptResult(classFile);
- }
- classType.weavingCompleted();
- CompilationAndWeavingContext.leavingPhase(tok);
- }
-
- /** helper method - will return NULL if the underlying delegate is an EclipseSourceType and not a BcelObjectType */
- public BcelObjectType getClassType(String forClass) {
- return BcelWorld.getBcelObjectType(world.resolve(forClass));
- }
-
-
- public void addParentTypeMungers(String typeName) {
- weaveParentTypeMungers(world.resolve(typeName));
- }
-
- public void addNormalTypeMungers(String typeName) {
- weaveNormalTypeMungers(world.resolve(typeName));
- }
-
- public UnwovenClassFile[] getClassFilesFor(LazyClassGen clazz) {
- List childClasses = clazz.getChildClasses(world);
- UnwovenClassFile[] ret = new UnwovenClassFile[1 + childClasses.size()];
- ret[0] = new UnwovenClassFile(clazz.getFileName(),clazz.getJavaClassBytesIncludingReweavable(world));
- int index = 1;
- for (Iterator iter = childClasses.iterator(); iter.hasNext();) {
- UnwovenClassFile.ChildClass element = (UnwovenClassFile.ChildClass) iter.next();
- UnwovenClassFile childClass = new UnwovenClassFile(clazz.getFileName() + "$" + element.name, element.bytes);
- ret[index++] = childClass;
- }
- return ret;
- }
-
- /**
- * Weaves new parents and annotations onto a type ("declare parents" and "declare @type")
- *
- * Algorithm:
- * 1. First pass, do parents then do annotations. During this pass record:
- * - any parent mungers that don't match but have a non-wild annotation type pattern
- * - any annotation mungers that don't match
- * 2. Multiple subsequent passes which go over the munger lists constructed in the first
- * pass, repeatedly applying them until nothing changes.
- * FIXME asc confirm that algorithm is optimal ??
- */
- public void weaveParentTypeMungers(ResolvedType onType) {
- if (onType.isRawType()) onType = onType.getGenericType();
- onType.clearInterTypeMungers();
-
- List decpToRepeat = new ArrayList();
-
- boolean aParentChangeOccurred = false;
- boolean anAnnotationChangeOccurred = false;
- // First pass - apply all decp mungers
- for (Iterator i = declareParentsList.iterator(); i.hasNext(); ) {
- DeclareParents decp = (DeclareParents)i.next();
- boolean typeChanged = applyDeclareParents(decp,onType);
- if (typeChanged) {
- aParentChangeOccurred = true;
- } else { // Perhaps it would have matched if a 'dec @type' had modified the type
- if (!decp.getChild().isStarAnnotation()) decpToRepeat.add(decp);
- }
- }
-
- // Still first pass - apply all dec @type mungers
- for (Iterator i = xcutSet.getDeclareAnnotationOnTypes().iterator();i.hasNext();) {
- DeclareAnnotation decA = (DeclareAnnotation)i.next();
- boolean typeChanged = applyDeclareAtType(decA,onType,true);
- if (typeChanged) {
- anAnnotationChangeOccurred = true;
- }
- }
-
- while ((aParentChangeOccurred || anAnnotationChangeOccurred) && !decpToRepeat.isEmpty()) {
- anAnnotationChangeOccurred = aParentChangeOccurred = false;
- List decpToRepeatNextTime = new ArrayList();
- for (Iterator iter = decpToRepeat.iterator(); iter.hasNext();) {
- DeclareParents decp = (DeclareParents) iter.next();
- boolean typeChanged = applyDeclareParents(decp,onType);
- if (typeChanged) {
- aParentChangeOccurred = true;
- } else {
- decpToRepeatNextTime.add(decp);
- }
- }
-
- for (Iterator iter = xcutSet.getDeclareAnnotationOnTypes().iterator(); iter.hasNext();) {
- DeclareAnnotation decA = (DeclareAnnotation) iter.next();
- boolean typeChanged = applyDeclareAtType(decA,onType,false);
- if (typeChanged) {
- anAnnotationChangeOccurred = true;
- }
- }
- decpToRepeat = decpToRepeatNextTime;
- }
- }
-
-
- /**
- * Apply a declare @type - return true if we change the type
- */
- private boolean applyDeclareAtType(DeclareAnnotation decA, ResolvedType onType,boolean reportProblems) {
- boolean didSomething = false;
- if (decA.matches(onType)) {
-
- if (onType.hasAnnotation(decA.getAnnotationX().getSignature())) {
- // Could put out a lint here for an already annotated type ...
- // if (reportProblems) {
- // world.getLint().elementAlreadyAnnotated.signal(
- // new String[]{onType.toString(),decA.getAnnotationTypeX().toString()},
- // onType.getSourceLocation(),new ISourceLocation[]{decA.getSourceLocation()});
- // }
- return false;
- }
-
- AnnotationX annoX = decA.getAnnotationX();
-
- // check the annotation is suitable for the target
- boolean problemReported = verifyTargetIsOK(decA, onType, annoX,reportProblems);
-
- if (!problemReported) {
- AsmRelationshipProvider.getDefault().addDeclareAnnotationRelationship(decA.getSourceLocation(),onType.getSourceLocation());
- // TAG: WeavingMessage
- if (!getWorld().getMessageHandler().isIgnoring(IMessage.WEAVEINFO)){
- getWorld().getMessageHandler().handleMessage(
- WeaveMessage.constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_ANNOTATES,
- new String[]{
- onType.toString(),
- Utility.beautifyLocation(onType.getSourceLocation()),
- decA.getAnnotationString(),
- "type",
- decA.getAspect().toString(),
- Utility.beautifyLocation(decA.getSourceLocation())
- }));
- }
- didSomething = true;
- ResolvedTypeMunger newAnnotationTM = new AnnotationOnTypeMunger(annoX);
- newAnnotationTM.setSourceLocation(decA.getSourceLocation());
- onType.addInterTypeMunger(new BcelTypeMunger(newAnnotationTM,decA.getAspect().resolve(world)));
- decA.copyAnnotationTo(onType);
- }
- }
- return didSomething;
- }
-
- /**
- * Checks for an @target() on the annotation and if found ensures it allows the annotation
- * to be attached to the target type that matched.
- */
- private boolean verifyTargetIsOK(DeclareAnnotation decA, ResolvedType onType, AnnotationX annoX,boolean outputProblems) {
- boolean problemReported = false;
- if (annoX.specifiesTarget()) {
- if ( (onType.isAnnotation() && !annoX.allowedOnAnnotationType()) ||
- (!annoX.allowedOnRegularType())) {
- if (outputProblems) {
- if (decA.isExactPattern()) {
- world.getMessageHandler().handleMessage(MessageUtil.error(
- WeaverMessages.format(WeaverMessages.INCORRECT_TARGET_FOR_DECLARE_ANNOTATION,
- onType.getName(),annoX.stringify(),annoX.getValidTargets()),decA.getSourceLocation()));
- } else {
- if (world.getLint().invalidTargetForAnnotation.isEnabled()) {
- world.getLint().invalidTargetForAnnotation.signal(
- new String[]{onType.getName(),annoX.stringify(),annoX.getValidTargets()},decA.getSourceLocation(),new ISourceLocation[]{onType.getSourceLocation()});
- }
- }
- }
- problemReported = true;
- }
- }
- return problemReported;
- }
-
- /**
- * Apply a single declare parents - return true if we change the type
- */
- private boolean applyDeclareParents(DeclareParents p, ResolvedType onType) {
- boolean didSomething = false;
- List newParents = p.findMatchingNewParents(onType,true);
- if (!newParents.isEmpty()) {
- didSomething=true;
- BcelObjectType classType = BcelWorld.getBcelObjectType(onType);
- //System.err.println("need to do declare parents for: " + onType);
- for (Iterator j = newParents.iterator(); j.hasNext(); ) {
- ResolvedType newParent = (ResolvedType)j.next();
-
- // We set it here so that the imminent matching for ITDs can succeed - we
- // still haven't done the necessary changes to the class file itself
- // (like transform super calls) - that is done in BcelTypeMunger.mungeNewParent()
- classType.addParent(newParent);
- ResolvedTypeMunger newParentMunger = new NewParentTypeMunger(newParent);
- newParentMunger.setSourceLocation(p.getSourceLocation());
- onType.addInterTypeMunger(new BcelTypeMunger(newParentMunger, xcutSet.findAspectDeclaringParents(p)));
- }
- }
- return didSomething;
- }
-
- public void weaveNormalTypeMungers(ResolvedType onType) {
- ContextToken tok = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.PROCESSING_TYPE_MUNGERS, onType.getName());
- if (onType.isRawType() || onType.isParameterizedType()) onType = onType.getGenericType();
- for (Iterator i = typeMungerList.iterator(); i.hasNext(); ) {
- ConcreteTypeMunger m = (ConcreteTypeMunger)i.next();
- if (!m.isLateMunger() && m.matches(onType)) {
- onType.addInterTypeMunger(m);
- }
- }
- CompilationAndWeavingContext.leavingPhase(tok);
- }
-
-
- // exposed for ClassLoader dynamic weaving
- public LazyClassGen weaveWithoutDump(UnwovenClassFile classFile, BcelObjectType classType) throws IOException {
- return weave(classFile, classType, false);
- }
-
- // non-private for testing
- LazyClassGen weave(UnwovenClassFile classFile, BcelObjectType classType) throws IOException {
- LazyClassGen ret = weave(classFile, classType, true);
-
- if (progressListener != null) {
- progressMade += progressPerClassFile;
- progressListener.setProgress(progressMade);
- progressListener.setText("woven: " + classFile.getFilename());
- }
-
- return ret;
- }
-
- private LazyClassGen weave(UnwovenClassFile classFile, BcelObjectType classType, boolean dump) throws IOException {
- if (classType.isSynthetic()) { // Don't touch synthetic classes
- if (dump) dumpUnchanged(classFile);
- return null;
- }
-
- List shadowMungers = fastMatch(shadowMungerList, classType.getResolvedTypeX());
- List typeMungers = classType.getResolvedTypeX().getInterTypeMungers();
-
- classType.getResolvedTypeX().checkInterTypeMungers();
-
- // Decide if we need to do actual weaving for this class
- boolean mightNeedToWeave =
- shadowMungers.size() > 0 ||
- typeMungers.size() > 0 ||
- classType.isAspect() ||
- world.getDeclareAnnotationOnMethods().size()>0 ||
- world.getDeclareAnnotationOnFields().size()>0;
-
- // May need bridge methods if on 1.5 and something in our hierarchy is affected by ITDs
- boolean mightNeedBridgeMethods =
- world.isInJava5Mode() &&
- !classType.isInterface() &&
- classType.getResolvedTypeX().getInterTypeMungersIncludingSupers().size()>0;
-
- LazyClassGen clazz = null;
- if (mightNeedToWeave || mightNeedBridgeMethods) {
- clazz = classType.getLazyClassGen();
- //System.err.println("got lazy gen: " + clazz + ", " + clazz.getWeaverState());
- try {
- boolean isChanged = false;
-
- if (mightNeedToWeave)
- isChanged = BcelClassWeaver.weave(world, clazz, shadowMungers, typeMungers, lateTypeMungerList);
-
- if (mightNeedBridgeMethods)
- isChanged = BcelClassWeaver.calculateAnyRequiredBridgeMethods(world,clazz) || isChanged;
-
- if (isChanged) {
- if (dump) dump(classFile, clazz);
- return clazz;
- }
- } catch (RuntimeException re) {
- String classDebugInfo = null;
- try {
- classDebugInfo = clazz.toLongString();
- } catch (Exception e) {
- // recover from crash whilst producing debug string
- classDebugInfo = clazz.getClassName();
- }
- String messageText = "trouble in: \n" + classDebugInfo;
- getWorld().getMessageHandler().handleMessage(
- new Message(messageText,IMessage.ABORT,re,null)
- );
- } catch (Error re) {
- String classDebugInfo = null;
- try {
- classDebugInfo = clazz.toLongString();
- } catch (Exception e) {
- // recover from crash whilst producing debug string
- classDebugInfo = clazz.getClassName();
- }
- String messageText = "trouble in: \n" + classDebugInfo;
- getWorld().getMessageHandler().handleMessage(
- new Message(messageText,IMessage.ABORT,re,null)
- );
- }
- }
-
- // this is very odd return behavior trying to keep everyone happy
- if (dump) {
- dumpUnchanged(classFile);
- return clazz;
- } else {
- // ATAJ: the class was not weaved, but since it gets there early it may have new generated inner classes
- // attached to it to support LTW perX aspectOf support (see BcelPerClauseAspectAdder)
- // that aggressively defines the inner <aspect>$mayHaveAspect interface.
- if (clazz != null && !clazz.getChildClasses(world).isEmpty()) {
- return clazz;
- }
- return null;
- }
- }
-
-
-
- // ---- writing
-
- private void dumpUnchanged(UnwovenClassFile classFile) throws IOException {
- if (zipOutputStream != null) {
- writeZipEntry(getEntryName(classFile.getJavaClass().getClassName()), classFile.getBytes());
- } else {
- classFile.writeUnchangedBytes();
- }
- }
-
- private String getEntryName(String className) {
- //XXX what does bcel's getClassName do for inner names
- return className.replace('.', '/') + ".class";
- }
-
- private void dump(UnwovenClassFile classFile, LazyClassGen clazz) throws IOException {
- if (zipOutputStream != null) {
- String mainClassName = classFile.getJavaClass().getClassName();
- writeZipEntry(getEntryName(mainClassName),
- clazz.getJavaClass(world).getBytes());
- if (!clazz.getChildClasses(world).isEmpty()) {
- for (Iterator i = clazz.getChildClasses(world).iterator(); i.hasNext();) {
- UnwovenClassFile.ChildClass c = (UnwovenClassFile.ChildClass) i.next();
- writeZipEntry(getEntryName(mainClassName + "$" + c.name), c.bytes);
- }
- }
- } else {
- classFile.writeWovenBytes(
- clazz.getJavaClass(world).getBytes(),
- clazz.getChildClasses(world)
- );
- }
- }
-
- private void writeZipEntry(String name, byte[] bytes) throws IOException {
- ZipEntry newEntry = new ZipEntry(name); //??? get compression scheme right
-
- zipOutputStream.putNextEntry(newEntry);
- zipOutputStream.write(bytes);
- zipOutputStream.closeEntry();
- }
-
- private List fastMatch(List list, ResolvedType type) {
- if (list == null) return Collections.EMPTY_LIST;
-
- // here we do the coarsest grained fast match with no kind constraints
- // this will remove all obvious non-matches and see if we need to do any weaving
- FastMatchInfo info = new FastMatchInfo(type, null);
-
- List result = new ArrayList();
- Iterator iter = list.iterator();
- while (iter.hasNext()) {
- ShadowMunger munger = (ShadowMunger)iter.next();
- FuzzyBoolean fb = munger.getPointcut().fastMatch(info);
- WeaverMetrics.recordFastMatchTypeResult(fb); // Could pass: munger.getPointcut().toString(),info
- if (fb.maybeTrue()) {
- result.add(munger);
- }
- }
- return result;
- }
-
- public void setProgressListener(IProgressListener listener, double previousProgress, double progressPerClassFile) {
- progressListener = listener;
- this.progressMade = previousProgress;
- this.progressPerClassFile = progressPerClassFile;
- }
-
- public void setReweavableMode(boolean xNotReweavable) {
- if (trace.isTraceEnabled()) trace.enter("setReweavableMode",this,xNotReweavable);
- inReweavableMode = !xNotReweavable;
- WeaverStateInfo.setReweavableModeDefaults(!xNotReweavable,false,true);
- BcelClassWeaver.setReweavableMode(!xNotReweavable);
- if (trace.isTraceEnabled()) trace.exit("setReweavableMode");
- }
-
- public boolean isReweavable() {
- return inReweavableMode;
- }
-
- public World getWorld() {
- return world;
- }
-
- public void tidyUp() {
- if (trace.isTraceEnabled()) trace.enter("tidyUp",this);
- shadowMungerList = null; // setup by prepareForWeave
- typeMungerList = null; // setup by prepareForWeave
- lateTypeMungerList = null; // setup by prepareForWeave
- declareParentsList = null; // setup by prepareForWeave
- if (trace.isTraceEnabled()) trace.exit("tidyUp");
- }
- }
|