Top Fields Constructors Methods
org.aspectj.weaver.bcel

public Class BcelWeaver

extends Object
Class Inheritance
Imports
java.io.ByteArrayInputStream, .File, .FileFilter, .FileInputStream, .FileNotFoundException, .IOException, .InputStream, .OutputStream, java.util.ArrayList, .Collection, .Collections, .Comparator, .Enumeration, .HashMap, .HashSet, .Iterator, .List, .Map, .Set, java.util.jar.Attributes, .Attributes.Name, .JarEntry, .JarFile, .Manifest, java.util.zip.ZipEntry, .ZipInputStream, .ZipOutputStream, org.aspectj.apache.bcel.classfile.ClassParser, .JavaClass, org.aspectj.asm.AsmManager, .IProgramElement, org.aspectj.asm.internal.AspectJElementHierarchy, org.aspectj.bridge.IMessage, .ISourceLocation, .Message, .MessageUtil, .SourceLocation, .WeaveMessage, org.aspectj.bridge.context.CompilationAndWeavingContext, .ContextToken, org.aspectj.util.FileUtil, .FuzzyBoolean, org.aspectj.weaver.Advice, .AdviceKind, .AnnotationAJ, .AnnotationOnTypeMunger, .BCException, .CompressingDataOutputStream, .ConcreteTypeMunger, .CrosscuttingMembersSet, .CustomMungerFactory, .IClassFileProvider, .IUnwovenClassFile, .IWeaveRequestor, .NewParentTypeMunger, .ReferenceType, .ReferenceTypeDelegate, .ResolvedType, .ResolvedTypeMunger, .Shadow, .ShadowMunger, .UnresolvedType, .WeaverMessages, .WeaverStateInfo, .World, org.aspectj.weaver.model.AsmRelationshipProvider, org.aspectj.weaver.patterns.AndPointcut, .BindingPattern, .BindingTypePattern, .ConcreteCflowPointcut, .DeclareAnnotation, .DeclareParents, .DeclareTypeErrorOrWarning, .FastMatchInfo, .IfPointcut, .KindedPointcut, .NameBindingPointcut, .NotPointcut, .OrPointcut, .Pointcut, .PointcutRewriter, .WithinPointcut, org.aspectj.weaver.tools.Trace, .TraceFactory

Authors
PARC, Andy Clement, Alexandre Vasseur

Field Summary

Modifier and TypeField and Description
private transient List<UnwovenClassFile>
private Set<IProgramElement>
public static final String
private CustomMungerFactory
private transient List<DeclareParents>
private transient List<String>
private boolean
private boolean
private transient List<ConcreteTypeMunger>
private Manifest
private boolean
private transient List<ShadowMunger>
public static final String
private static Trace
private transient List<ConcreteTypeMunger>
private final transient BcelWorld
private final CrosscuttingMembersSet
private ZipOutputStream

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private List<ResolvedType>

Returns:

the list of discovered aspects
addAspectsFromDirectory
(File
the directory in which to look for Aspect .class files
directory
)

Look for .class files that represent aspects in the supplied directory - return the list of accumulated aspects.

private List<ResolvedType>
public ReferenceType
addClassFile(UnwovenClassFile classFile, boolean fromInpath)

Should be addOrReplace

public UnwovenClassFile
addClassFile(File classFile, File inPathDir, File outDir)

private void
public List<UnwovenClassFile>
addDirectoryContents(File inFile, File outDir)

Add any .class files in the directory to the outdir.

public List<UnwovenClassFile>
addJarFile(File inFile, File outDir, boolean canBeDirectory)

Adds all class files in the jar

public ResolvedType

Returns:

aspect
addLibraryAspect
(String aspectName)

Add the given aspect to the weaver.

public void
addLibraryJarFile(File
directory containing classes or zip/jar class archive
inFile
)

public void
addManifest(Manifest newManifest)

public void
public void
public void
private boolean
applyDeclareAtType(DeclareAnnotation decA, ResolvedType onType, boolean reportProblems)

Apply a declare @type - return true if we change the type

private boolean
applyDeclareParents(DeclareParents p, ResolvedType onType)

Apply a single declare parents - return true if we change the type

private void
private boolean
public void
private void
private void
private List<ShadowMunger>

Returns:

a list of shadow mungers that might match with those that cannot (according to fast match rules) removed
fastMatch
(List<ShadowMunger>
list of all shadow mungers that might match
list
,
ResolvedType
the target type
type
)

Perform a fast match of the specified list of shadowmungers against the specified type.

private Pointcut
findFirstPointcutIn(Pointcut toSearch, Class<?> toLookFor)

public UnwovenClassFile[]
public BcelObjectType
getClassType(String forClass)

helper method - will return NULL if the underlying delegate is an EclipseSourceType and not a BcelObjectType

private String
getEntryName(String className)

public Manifest
getManifest(boolean shouldCreate)

public World
private boolean
private ResolvedType

Returns:

a ResolvedType if the classbytes represent an aspect, otherwise null
isAspect
(byte[]
the classbytes that might represent an aspect
classbytes
,
String
the name of the class
name
,
File
directory which contained the class file
dir
)

Determine if the supplied bytes represent an aspect, if they do then create a ResolvedType instance for the aspect and return it, otherwise return null

public boolean
public boolean
public void
public void
public void
private void
private void
private void
private void
private void
private void
public void
public void
setIsBatchWeave(boolean b)

public void
setReweavableMode(boolean xNotReweavable)

public void
private Pointcut
public void
private void
validateBindings(Pointcut dnfPointcut, Pointcut userPointcut, int numFormals, String[] names)

private void
validateOrBranch(OrPointcut pc, Pointcut userPointcut, int numFormals, String[] names, Pointcut[] leftBindings, Pointcut[] rightBindings)

private void
validateSingleBranch(Pointcut pc, Pointcut userPointcut, int numFormals, String[] names, Pointcut[] bindings)

private void
validateSingleBranchRecursion(Pointcut pc, Pointcut userPointcut, boolean[] foundFormals, String[] names, Pointcut[] bindings)

private boolean
verifyTargetIsOK(DeclareAnnotation decA, ResolvedType onType, AnnotationAJ annoX, boolean outputProblems)

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 void
private void
warnOnUnmatchedAdvice()

In 1.5 mode and with XLint:adviceDidNotMatch enabled, put out messages for any mungers that did not match anything.

public Collection<String>
weave(File file)

public Collection<String>
pack-priv LazyClassGen
weave(UnwovenClassFile classFile, BcelObjectType classType)

private LazyClassGen
weave(UnwovenClassFile classFile, BcelObjectType classType, boolean dump)

private void
public void
private void
weaveParentsFor(List<String> typesForWeaving, String typeToWeave, ResolvedType resolvedTypeToWeave)

'typeToWeave' is one from the 'typesForWeaving' list.

public void
weaveParentTypeMungers(ResolvedType onType)

Weaves new parents and annotations onto a type ("declare parents" and "declare @type") Algorithm: 1.

public LazyClassGen
public void
private void
writeZipEntry(String name, byte[] bytes)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

addedClassesback to summary
private transient List<UnwovenClassFile> addedClasses
candidatesForRemovalback to summary
private Set<IProgramElement> candidatesForRemoval
CLOSURE_CLASS_PREFIXback to summary
public static final String CLOSURE_CLASS_PREFIX
customMungerFactoryback to summary
private CustomMungerFactory customMungerFactory
declareParentsListback to summary
private transient List<DeclareParents> declareParentsList
deletedTypenamesback to summary
private transient List<String> deletedTypenames
inReweavableModeback to summary
private boolean inReweavableMode
isBatchWeaveback to summary
private boolean isBatchWeave
lateTypeMungerListback to summary
private transient List<ConcreteTypeMunger> lateTypeMungerList
manifestback to summary
private Manifest manifest
needToReweaveWorldback to summary
private boolean needToReweaveWorld
shadowMungerListback to summary
private transient List<ShadowMunger> shadowMungerList
SYNTHETIC_CLASS_POSTFIXback to summary
public static final String SYNTHETIC_CLASS_POSTFIX
traceback to summary
private static Trace trace
typeMungerListback to summary
private transient List<ConcreteTypeMunger> typeMungerList
worldback to summary
private final transient BcelWorld world
xcutSetback to summary
private final CrosscuttingMembersSet xcutSet
zipOutputStreamback to summary
private ZipOutputStream zipOutputStream

Constructor Detail

BcelWeaverback to summary
public BcelWeaver(BcelWorld world)

Method Detail

addAspectsFromDirectoryback to summary
private List<ResolvedType> addAspectsFromDirectory(File directory) throws FileNotFoundException, IOException

Look for .class files that represent aspects in the supplied directory - return the list of accumulated aspects.

Parameters
directory:File

the directory in which to look for Aspect .class files

Returns:List<ResolvedType>

the list of discovered aspects

addAspectsFromJarFileback to summary
private List<ResolvedType> addAspectsFromJarFile(File inFile) throws FileNotFoundException, IOException
addClassFileback to summary
public ReferenceType addClassFile(UnwovenClassFile classFile, boolean fromInpath)

Should be addOrReplace

addClassFileback to summary
public UnwovenClassFile addClassFile(File classFile, File inPathDir, File outDir) throws IOException
addCustomMungersback to summary
private void addCustomMungers()
addDirectoryContentsback to summary
public List<UnwovenClassFile> addDirectoryContents(File inFile, File outDir) throws IOException

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.

addJarFileback to summary
public List<UnwovenClassFile> addJarFile(File inFile, File outDir, boolean canBeDirectory)

Adds all class files in the jar

addLibraryAspectback to summary
public ResolvedType addLibraryAspect(String aspectName)

Add the given aspect to the weaver. The type is resolved to support DOT for static inner classes as well as DOLLAR

Returns:ResolvedType

aspect

addLibraryJarFileback to summary
public void addLibraryJarFile(File inFile) throws IOException
Parameters
inFile:File

directory containing classes or zip/jar class archive

addManifestback to summary
public void addManifest(Manifest newManifest)
addNormalTypeMungersback to summary
public void addNormalTypeMungers(String typeName)
addParentTypeMungersback to summary
public void addParentTypeMungers(String typeName)
allWeavingCompleteback to summary
public void allWeavingComplete()
applyDeclareAtTypeback to summary
private boolean applyDeclareAtType(DeclareAnnotation decA, ResolvedType onType, boolean reportProblems)

Apply a declare @type - return true if we change the type

applyDeclareParentsback to summary
private boolean applyDeclareParents(DeclareParents p, ResolvedType onType)

Apply a single declare parents - return true if we change the type

checkDeclareTypeErrorOrWarningback to summary
private void checkDeclareTypeErrorOrWarning(BcelWorld world2, BcelObjectType classType)
couldEverMatchSameJoinPointsback to summary
private boolean couldEverMatchSameJoinPoints(Pointcut left, Pointcut right)
deleteClassFileback to summary
public void deleteClassFile(String typename)
dumpback to summary
private void dump(UnwovenClassFile classFile, LazyClassGen clazz) throws IOException
dumpUnchangedback to summary
private void dumpUnchanged(UnwovenClassFile classFile) throws IOException
fastMatchback to summary
private List<ShadowMunger> fastMatch(List<ShadowMunger> list, ResolvedType type)

Perform a fast match of the specified list of shadowmungers against the specified type. A subset of those that might match is returned.

Parameters
list:List<ShadowMunger>

list of all shadow mungers that might match

type:ResolvedType

the target type

Returns:List<ShadowMunger>

a list of shadow mungers that might match with those that cannot (according to fast match rules) removed

findFirstPointcutInback to summary
private Pointcut findFirstPointcutIn(Pointcut toSearch, Class<?> toLookFor)
getClassFilesForback to summary
public UnwovenClassFile[] getClassFilesFor(LazyClassGen clazz)
getClassTypeback to summary
public BcelObjectType getClassType(String forClass)

helper method - will return NULL if the underlying delegate is an EclipseSourceType and not a BcelObjectType

getEntryNameback to summary
private String getEntryName(String className)
getManifestback to summary
public Manifest getManifest(boolean shouldCreate)
getWorldback to summary
public World getWorld()
hasInnerTypeback to summary
private boolean hasInnerType(IProgramElement typeNode)
isAspectback to summary
private ResolvedType isAspect(byte[] classbytes, String name, File dir) throws IOException

Determine if the supplied bytes represent an aspect, if they do then create a ResolvedType instance for the aspect and return it, otherwise return null

Parameters
classbytes:byte[]

the classbytes that might represent an aspect

name:String

the name of the class

dir:File

directory which contained the class file

Returns:ResolvedType

a ResolvedType if the classbytes represent an aspect, otherwise null

isReweavableback to summary
public boolean isReweavable()
needToReweaveWorldback to summary
public boolean needToReweaveWorld()
prepareForWeaveback to summary
public void prepareForWeave()
prepareToProcessReweavableStateback to summary
public void prepareToProcessReweavableState()
processReweavableStateIfPresentback to summary
public void processReweavableStateIfPresent(String className, BcelObjectType classType)
raiseAmbiguityInDisjunctionErrorback to summary
private void raiseAmbiguityInDisjunctionError(Pointcut userPointcut, List<String> names)
raiseAmbiguousBindingErrorback to summary
private void raiseAmbiguousBindingError(String name, Pointcut pointcut)
raiseNegationBindingErrorback to summary
private void raiseNegationBindingError(Pointcut userPointcut)
raiseUnboundFormalErrorback to summary
private void raiseUnboundFormalError(String name, Pointcut userPointcut)
removeSourceFileIfNoMoreTypeDeclarationsInsideback to summary
private void removeSourceFileIfNoMoreTypeDeclarationsInside(AspectJElementHierarchy hierarchy, IProgramElement typeElement, IProgramElement sourceFileNode)
rewritePointcutsback to summary
private void rewritePointcuts(List<ShadowMunger> shadowMungers)
setCustomMungerFactoryback to summary
public void setCustomMungerFactory(CustomMungerFactory factory)
setIsBatchWeaveback to summary
public void setIsBatchWeave(boolean b)
setReweavableModeback to summary
public void setReweavableMode(boolean xNotReweavable)
setShadowMungersback to summary
public void setShadowMungers(List<ShadowMunger> shadowMungers)
shareEntriesFromMapback to summary
private Pointcut shareEntriesFromMap(Pointcut p, Map<Pointcut, Pointcut> pcMap)
tidyUpback to summary
public void tidyUp()
validateBindingsback to summary
private void validateBindings(Pointcut dnfPointcut, Pointcut userPointcut, int numFormals, String[] names)
validateOrBranchback to summary
private void validateOrBranch(OrPointcut pc, Pointcut userPointcut, int numFormals, String[] names, Pointcut[] leftBindings, Pointcut[] rightBindings)
validateSingleBranchback to summary
private void validateSingleBranch(Pointcut pc, Pointcut userPointcut, int numFormals, String[] names, Pointcut[] bindings)
validateSingleBranchRecursionback to summary
private void validateSingleBranchRecursion(Pointcut pc, Pointcut userPointcut, boolean[] foundFormals, String[] names, Pointcut[] bindings)
verifyTargetIsOKback to summary
private boolean verifyTargetIsOK(DeclareAnnotation decA, ResolvedType onType, AnnotationAJ annoX, boolean outputProblems)

Checks for an @target() on the annotation and if found ensures it allows the annotation to be attached to the target type that matched.

walkUpRemovingEmptyTypesAndPossiblyEmptySourceFileback to summary
private void walkUpRemovingEmptyTypesAndPossiblyEmptySourceFile(AspectJElementHierarchy hierarchy, String tname, IProgramElement typeThatHasChildRemoved)
warnOnUnmatchedAdviceback to summary
private void warnOnUnmatchedAdvice()

In 1.5 mode and with XLint:adviceDidNotMatch enabled, put out messages for any mungers that did not match anything.

weaveback to summary
public Collection<String> weave(File file) throws IOException
weaveback to summary
public Collection<String> weave(IClassFileProvider input) throws IOException
weaveback to summary
pack-priv LazyClassGen weave(UnwovenClassFile classFile, BcelObjectType classType) throws IOException
weaveback to summary
private LazyClassGen weave(UnwovenClassFile classFile, BcelObjectType classType, boolean dump) throws IOException
weaveAndNotifyback to summary
private void weaveAndNotify(UnwovenClassFile classFile, BcelObjectType classType, IWeaveRequestor requestor) throws IOException
weaveNormalTypeMungersback to summary
public void weaveNormalTypeMungers(ResolvedType onType)
weaveParentsForback to summary
private void weaveParentsFor(List<String> typesForWeaving, String typeToWeave, ResolvedType resolvedTypeToWeave)

'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 !

weaveParentTypeMungersback to summary
public void weaveParentTypeMungers(ResolvedType onType)

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 ??

weaveWithoutDumpback to summary
public LazyClassGen weaveWithoutDump(UnwovenClassFile classFile, BcelObjectType classType) throws IOException
writeback to summary
public void write(CompressingDataOutputStream dos) throws IOException
writeZipEntryback to summary
private void writeZipEntry(String name, byte[] bytes) throws IOException