From: aclement Date: Wed, 24 Sep 2008 20:08:22 +0000 (+0000) Subject: 247742:c27 X-Git-Tag: V1_6_2~34 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=96961535f6353b1e96de55eb3223476883533dc3;p=aspectj.git 247742:c27 --- diff --git a/weaver/src/org/aspectj/weaver/ShadowMunger.java b/weaver/src/org/aspectj/weaver/ShadowMunger.java index f98760c8d..2f5dcbc73 100644 --- a/weaver/src/org/aspectj/weaver/ShadowMunger.java +++ b/weaver/src/org/aspectj/weaver/ShadowMunger.java @@ -30,17 +30,14 @@ import org.aspectj.weaver.patterns.PerClause; import org.aspectj.weaver.patterns.Pointcut; /** - * For every shadow munger, nothing can be done with it until it is concretized. - * Then... + * For every shadow munger, nothing can be done with it until it is concretized. Then... * * (Then we call fast match.) * - * For every shadow munger, for every shadow, first match is called, then (if - * match returned true) the shadow munger is specialized for the shadow, which - * may modify state. Then implement is called. + * For every shadow munger, for every shadow, first match is called, then (if match returned true) the shadow munger is specialized + * for the shadow, which may modify state. Then implement is called. */ -public abstract class ShadowMunger implements PartialOrder.PartialComparable, - IHasPosition { +public abstract class ShadowMunger implements PartialOrder.PartialComparable, IHasPosition { protected Pointcut pointcut; @@ -53,16 +50,14 @@ public abstract class ShadowMunger implements PartialOrder.PartialComparable, private String handle = null; private ResolvedType declaringType; // the type that declared this munger. - public ShadowMunger(Pointcut pointcut, int start, int end, - ISourceContext sourceContext) { + public ShadowMunger(Pointcut pointcut, int start, int end, ISourceContext sourceContext) { this.pointcut = pointcut; this.start = start; this.end = end; this.sourceContext = sourceContext; } - public abstract ShadowMunger concretize(ResolvedType fromType, World world, - PerClause clause); + public abstract ShadowMunger concretize(ResolvedType fromType, World world, PerClause clause); public abstract void specializeOn(Shadow shadow); @@ -75,8 +70,7 @@ public abstract class ShadowMunger implements PartialOrder.PartialComparable, return pointcut.match(shadow).maybeTrue(); } - public abstract ShadowMunger parameterizeWith(ResolvedType declaringType, - Map typeVariableMap); + public abstract ShadowMunger parameterizeWith(ResolvedType declaringType, Map typeVariableMap); public int fallbackCompareTo(Object other) { return toString().compareTo(toString()); @@ -109,10 +103,8 @@ public abstract class ShadowMunger implements PartialOrder.PartialComparable, if (null == handle) { ISourceLocation sl = getSourceLocation(); if (sl != null) { - IProgramElement ipe = AsmManager.getDefault().getHierarchy() - .findElementForSourceLine(sl); - handle = AsmManager.getDefault().getHandleProvider() - .createHandleIdentifier(ipe); + IProgramElement ipe = AsmManager.getDefault().getHierarchy().findElementForSourceLine(sl); + handle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(ipe); } } return handle; @@ -145,19 +137,15 @@ public abstract class ShadowMunger implements PartialOrder.PartialComparable, } /** - * @return a Collection of ResolvedType for all checked exceptions that - * might be thrown by this munger + * @return a Collection of ResolvedType for all checked exceptions that might be thrown by this munger */ public abstract Collection getThrownExceptions(); /** - * Does the munger has to check that its exception are accepted by the - * shadow ? ATAJ: It s not the case for @AJ around advice f.e. that can - * throw Throwable, even if the advised method does not throw any - * exceptions. + * Does the munger has to check that its exception are accepted by the shadow ? ATAJ: It s not the case for @AJ around advice + * f.e. that can throw Throwable, even if the advised method does not throw any exceptions. * - * @return true if munger has to check that its exceptions can be throwned - * based on the shadow + * @return true if munger has to check that its exceptions can be throwned based on the shadow */ public abstract boolean mustCheckExceptions(); @@ -168,8 +156,7 @@ public abstract class ShadowMunger implements PartialOrder.PartialComparable, if (!isBinary()) return; - IProgramElement sourceFileNode = AsmManager.getDefault().getHierarchy() - .findElementForSourceLine(getSourceLocation()); + IProgramElement sourceFileNode = AsmManager.getDefault().getHierarchy().findElementForSourceLine(getSourceLocation()); // the call to findElementForSourceLine(ISourceLocation) returns a file // node // if it can't find a node in the hierarchy for the given @@ -183,70 +170,65 @@ public abstract class ShadowMunger implements PartialOrder.PartialComparable, ResolvedType aspect = getDeclaringType(); // create the class file node - IProgramElement classFileNode = new ProgramElement(sourceFileNode - .getName() - + " (binary)", IProgramElement.Kind.CLASS, - getBinarySourceLocation(aspect.getSourceLocation()), 0, null, - null); + IProgramElement classFileNode = new ProgramElement(sourceFileNode.getName(), IProgramElement.Kind.FILE, + getBinarySourceLocation(aspect.getSourceLocation()), 0, null, null); // create package ipe if one exists.... IProgramElement root = AsmManager.getDefault().getHierarchy().getRoot(); - if (aspect.getPackageName() != null) { - // check that there doesn't already exist a node with this name - IProgramElement pkgNode = AsmManager.getDefault().getHierarchy() - .findElementForLabel(root, IProgramElement.Kind.PACKAGE, - aspect.getPackageName()); - // note packages themselves have no source location - if (pkgNode == null) { - pkgNode = new ProgramElement(aspect.getPackageName(), - IProgramElement.Kind.PACKAGE, new ArrayList()); - root.addChild(pkgNode); - pkgNode.addChild(classFileNode); - } else { - // need to add it first otherwise the handle for classFileNode - // may not be generated correctly if it uses information from - // it's parent node - pkgNode.addChild(classFileNode); - for (Iterator iter = pkgNode.getChildren().iterator(); iter - .hasNext();) { - IProgramElement element = (IProgramElement) iter.next(); - if (!element.equals(classFileNode) - && element.getHandleIdentifier().equals( - classFileNode.getHandleIdentifier())) { - // already added the classfile so have already - // added the structure for this aspect - pkgNode.removeChild(classFileNode); - return; - } - } - } + IProgramElement binaries = AsmManager.getDefault().getHierarchy().findElementForLabel(root, + IProgramElement.Kind.SOURCE_FOLDER, "binaries"); + if (binaries == null) { + binaries = new ProgramElement("binaries", IProgramElement.Kind.SOURCE_FOLDER, new ArrayList()); + root.addChild(binaries); + } + // if (aspect.getPackageName() != null) { + String packagename = aspect.getPackageName() == null ? "" : aspect.getPackageName(); + // check that there doesn't already exist a node with this name + IProgramElement pkgNode = AsmManager.getDefault().getHierarchy().findElementForLabel(binaries, + IProgramElement.Kind.PACKAGE, packagename); + // note packages themselves have no source location + if (pkgNode == null) { + pkgNode = new ProgramElement(packagename, IProgramElement.Kind.PACKAGE, new ArrayList()); + binaries.addChild(pkgNode); + pkgNode.addChild(classFileNode); } else { // need to add it first otherwise the handle for classFileNode // may not be generated correctly if it uses information from // it's parent node - root.addChild(classFileNode); - for (Iterator iter = root.getChildren().iterator(); iter.hasNext();) { + pkgNode.addChild(classFileNode); + for (Iterator iter = pkgNode.getChildren().iterator(); iter.hasNext();) { IProgramElement element = (IProgramElement) iter.next(); - if (!element.equals(classFileNode) - && element.getHandleIdentifier().equals( - classFileNode.getHandleIdentifier())) { - // already added the sourcefile so have already + if (!element.equals(classFileNode) && element.getHandleIdentifier().equals(classFileNode.getHandleIdentifier())) { + // already added the classfile so have already // added the structure for this aspect - root.removeChild(classFileNode); + pkgNode.removeChild(classFileNode); return; } } } + // } else { + // // need to add it first otherwise the handle for classFileNode + // // may not be generated correctly if it uses information from + // // it's parent node + // root.addChild(classFileNode); + // for (Iterator iter = root.getChildren().iterator(); iter.hasNext();) { + // IProgramElement element = (IProgramElement) iter.next(); + // if (!element.equals(classFileNode) && element.getHandleIdentifier().equals(classFileNode.getHandleIdentifier())) { + // // already added the sourcefile so have already + // // added the structure for this aspect + // root.removeChild(classFileNode); + // return; + // } + // } + // } // add and create empty import declaration ipe - classFileNode.addChild(new ProgramElement("import declarations", - IProgramElement.Kind.IMPORT_REFERENCE, null, 0, null, null)); + classFileNode + .addChild(new ProgramElement("import declarations", IProgramElement.Kind.IMPORT_REFERENCE, null, 0, null, null)); // add and create aspect ipe - IProgramElement aspectNode = new ProgramElement(aspect.getSimpleName(), - IProgramElement.Kind.ASPECT, getBinarySourceLocation(aspect - .getSourceLocation()), aspect.getModifiers(), null, - null); + IProgramElement aspectNode = new ProgramElement(aspect.getSimpleName(), IProgramElement.Kind.ASPECT, + getBinarySourceLocation(aspect.getSourceLocation()), aspect.getModifiers(), null, null); classFileNode.addChild(aspectNode); addChildNodes(aspectNode, aspect.getDeclaredPointcuts()); @@ -264,10 +246,8 @@ public abstract class ShadowMunger implements PartialOrder.PartialComparable, if (sLoc == null) { sLoc = rpcd.getSourceLocation(); } - parent.addChild(new ProgramElement(pcd.getName(), - IProgramElement.Kind.POINTCUT, - getBinarySourceLocation(sLoc), pcd.getModifiers(), - null, Collections.EMPTY_LIST)); + parent.addChild(new ProgramElement(pcd.getName(), IProgramElement.Kind.POINTCUT, getBinarySourceLocation(sLoc), pcd + .getModifiers(), null, Collections.EMPTY_LIST)); } } } @@ -285,9 +265,7 @@ public abstract class ShadowMunger implements PartialOrder.PartialComparable, } else { counter = dwCtr++; } - parent - .addChild(createDeclareErrorOrWarningChild(decl, - counter)); + parent.addChild(createDeclareErrorOrWarningChild(decl, counter)); } else if (element instanceof Advice) { Advice advice = (Advice) element; parent.addChild(createAdviceChild(advice)); @@ -295,16 +273,11 @@ public abstract class ShadowMunger implements PartialOrder.PartialComparable, } } - private IProgramElement createDeclareErrorOrWarningChild( - DeclareErrorOrWarning decl, int count) { - IProgramElement deowNode = new ProgramElement(decl.getName(), decl - .isError() ? IProgramElement.Kind.DECLARE_ERROR - : IProgramElement.Kind.DECLARE_WARNING, - getBinarySourceLocation(decl.getSourceLocation()), decl - .getDeclaringType().getModifiers(), null, null); - deowNode.setDetails("\"" - + AsmRelationshipUtils.genDeclareMessage(decl.getMessage()) - + "\""); + private IProgramElement createDeclareErrorOrWarningChild(DeclareErrorOrWarning decl, int count) { + IProgramElement deowNode = new ProgramElement(decl.getName(), decl.isError() ? IProgramElement.Kind.DECLARE_ERROR + : IProgramElement.Kind.DECLARE_WARNING, getBinarySourceLocation(decl.getSourceLocation()), decl.getDeclaringType() + .getModifiers(), null, null); + deowNode.setDetails("\"" + AsmRelationshipUtils.genDeclareMessage(decl.getMessage()) + "\""); if (count != -1) { deowNode.setBytecodeName(decl.getName() + "_" + count); } @@ -312,12 +285,9 @@ public abstract class ShadowMunger implements PartialOrder.PartialComparable, } private IProgramElement createAdviceChild(Advice advice) { - IProgramElement adviceNode = new ProgramElement(advice.kind.getName(), - IProgramElement.Kind.ADVICE, getBinarySourceLocation(advice - .getSourceLocation()), advice.signature.getModifiers(), - null, Collections.EMPTY_LIST); - adviceNode.setDetails(AsmRelationshipUtils.genPointcutDetails(advice - .getPointcut())); + IProgramElement adviceNode = new ProgramElement(advice.kind.getName(), IProgramElement.Kind.ADVICE, + getBinarySourceLocation(advice.getSourceLocation()), advice.signature.getModifiers(), null, Collections.EMPTY_LIST); + adviceNode.setDetails(AsmRelationshipUtils.genPointcutDetails(advice.getPointcut())); adviceNode.setBytecodeName(advice.getSignature().getName()); // String nn = advice.getSignature().getName(); // if (counter != 1) { @@ -328,18 +298,16 @@ public abstract class ShadowMunger implements PartialOrder.PartialComparable, } /** - * Returns the binarySourceLocation for the given sourcelocation. This isn't - * cached because it's used when faulting in the binary nodes and is called - * with ISourceLocations for all advice, pointcuts and deows contained - * within the resolvedDeclaringAspect. + * Returns the binarySourceLocation for the given sourcelocation. This isn't cached because it's used when faulting in the + * binary nodes and is called with ISourceLocations for all advice, pointcuts and deows contained within the + * resolvedDeclaringAspect. */ private ISourceLocation getBinarySourceLocation(ISourceLocation sl) { if (sl == null) return null; String sourceFileName = null; if (getDeclaringType() instanceof ReferenceType) { - String s = ((ReferenceType) getDeclaringType()).getDelegate() - .getSourcefilename(); + String s = ((ReferenceType) getDeclaringType()).getDelegate().getSourcefilename(); int i = s.lastIndexOf('/'); if (i != -1) { sourceFileName = s.substring(i + 1); @@ -347,20 +315,15 @@ public abstract class ShadowMunger implements PartialOrder.PartialComparable, sourceFileName = s; } } - ISourceLocation sLoc = new SourceLocation(getBinaryFile(), - sl.getLine(), sl.getEndLine(), - ((sl.getColumn() == 0) ? ISourceLocation.NO_COLUMN : sl - .getColumn()), sl.getContext(), sourceFileName); + ISourceLocation sLoc = new SourceLocation(getBinaryFile(), sl.getLine(), sl.getEndLine(), + ((sl.getColumn() == 0) ? ISourceLocation.NO_COLUMN : sl.getColumn()), sl.getContext(), sourceFileName); return sLoc; } /** - * Returns the File with pathname to the class file, for example either - * C:\temp - * \ajcSandbox\workspace\ajcTest16957.tmp\simple.jar!pkg\BinaryAspect.class - * if the class file is in a jar file, or - * C:\temp\ajcSandbox\workspace\ajcTest16957.tmp!pkg\BinaryAspect.class if - * the class file is in a directory + * Returns the File with pathname to the class file, for example either C:\temp + * \ajcSandbox\workspace\ajcTest16957.tmp\simple.jar!pkg\BinaryAspect.class if the class file is in a jar file, or + * C:\temp\ajcSandbox\workspace\ajcTest16957.tmp!pkg\BinaryAspect.class if the class file is in a directory */ private File getBinaryFile() { if (binaryFile == null) { @@ -374,9 +337,8 @@ public abstract class ShadowMunger implements PartialOrder.PartialComparable, } /** - * Returns whether or not this shadow munger came from a binary aspect - - * keep a record of whether or not we've checked if we're binary otherwise - * we keep caluclating the same thing many times + * Returns whether or not this shadow munger came from a binary aspect - keep a record of whether or not we've checked if we're + * binary otherwise we keep caluclating the same thing many times */ protected boolean isBinary() { if (!checkedIsBinary) { diff --git a/weaver/src/org/aspectj/weaver/UnresolvedType.java b/weaver/src/org/aspectj/weaver/UnresolvedType.java index 0a9df7d92..64ce965ae 100644 --- a/weaver/src/org/aspectj/weaver/UnresolvedType.java +++ b/weaver/src/org/aspectj/weaver/UnresolvedType.java @@ -837,7 +837,7 @@ public class UnresolvedType implements Traceable, TypeVariableDeclaringElement { } int index = name.lastIndexOf('.'); if (index == -1) { - return null; + return ""; } else { return name.substring(0, index); }