summaryrefslogtreecommitdiffstats
path: root/weaver
diff options
context:
space:
mode:
authoraclement <aclement>2006-06-12 13:09:51 +0000
committeraclement <aclement>2006-06-12 13:09:51 +0000
commit4dcb8f3d88ed5e464bf31378d9c222fdf791ff4a (patch)
tree33e156385995a2fa2194b72a6ba29a7e73ba38f4 /weaver
parent75afb31e38f75e61de5c15058d3332f3dac0df15 (diff)
downloadaspectj-4dcb8f3d88ed5e464bf31378d9c222fdf791ff4a.tar.gz
aspectj-4dcb8f3d88ed5e464bf31378d9c222fdf791ff4a.zip
test and fix for 145963: faulting in aspects coming in as binary inputs
Diffstat (limited to 'weaver')
-rw-r--r--weaver/src/org/aspectj/weaver/Advice.java6
-rw-r--r--weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java6
-rw-r--r--weaver/src/org/aspectj/weaver/Checker.java16
-rw-r--r--weaver/src/org/aspectj/weaver/ShadowMunger.java126
-rw-r--r--weaver/src/org/aspectj/weaver/World.java5
5 files changed, 153 insertions, 6 deletions
diff --git a/weaver/src/org/aspectj/weaver/Advice.java b/weaver/src/org/aspectj/weaver/Advice.java
index 959ce3a18..737e0d087 100644
--- a/weaver/src/org/aspectj/weaver/Advice.java
+++ b/weaver/src/org/aspectj/weaver/Advice.java
@@ -428,5 +428,11 @@ public abstract class Advice extends ShadowMunger {
public ResolvedType getConcreteAspect() {
return concreteAspect;
}
+
+ public ResolvedType getResolvedDeclaringAspect() {
+ // The aspect which declares this piece of advice
+ // is 'concreteAspect' since 'declaringType' is null
+ return concreteAspect;
+ }
}
diff --git a/weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java b/weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java
index 68398df13..7ea351930 100644
--- a/weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java
+++ b/weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java
@@ -61,7 +61,11 @@ public class AsmRelationshipProvider {
checker.getSourceLocation().getLine(),
checker.getSourceLocation().getColumn(),
checker.getSourceLocation().getOffset());
-
+
+ if (World.createInjarHierarchy) {
+ checker.createHierarchy();
+ }
+
String targetHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(
shadow.getSourceLocation().getSourceFile(),
shadow.getSourceLocation().getLine(),
diff --git a/weaver/src/org/aspectj/weaver/Checker.java b/weaver/src/org/aspectj/weaver/Checker.java
index 6700b8b36..329716106 100644
--- a/weaver/src/org/aspectj/weaver/Checker.java
+++ b/weaver/src/org/aspectj/weaver/Checker.java
@@ -13,11 +13,17 @@
package org.aspectj.weaver;
-import java.util.*;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
import org.aspectj.asm.IRelationship;
-import org.aspectj.bridge.*;
-import org.aspectj.weaver.patterns.*;
+import org.aspectj.bridge.IMessage;
+import org.aspectj.bridge.ISourceLocation;
+import org.aspectj.bridge.Message;
+import org.aspectj.weaver.patterns.DeclareErrorOrWarning;
+import org.aspectj.weaver.patterns.PerClause;
+import org.aspectj.weaver.patterns.Pointcut;
public class Checker extends ShadowMunger {
@@ -127,4 +133,8 @@ public class Checker extends ShadowMunger {
return isError;
}
+ public ResolvedType getResolvedDeclaringAspect() {
+ // The aspect which declares this deow is the declaring type
+ return getDeclaringType();
+ }
}
diff --git a/weaver/src/org/aspectj/weaver/ShadowMunger.java b/weaver/src/org/aspectj/weaver/ShadowMunger.java
index 9646cfc20..6e045e83b 100644
--- a/weaver/src/org/aspectj/weaver/ShadowMunger.java
+++ b/weaver/src/org/aspectj/weaver/ShadowMunger.java
@@ -13,12 +13,19 @@
package org.aspectj.weaver;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
import java.util.Map;
import org.aspectj.asm.AsmManager;
+import org.aspectj.asm.IProgramElement;
+import org.aspectj.asm.internal.ProgramElement;
import org.aspectj.bridge.ISourceLocation;
import org.aspectj.util.PartialOrder;
+import org.aspectj.weaver.bcel.BcelAdvice;
+import org.aspectj.weaver.patterns.DeclareErrorOrWarning;
import org.aspectj.weaver.patterns.PerClause;
import org.aspectj.weaver.patterns.Pointcut;
@@ -91,11 +98,14 @@ public abstract class ShadowMunger implements PartialOrder.PartialComparable, IH
if (null == handle) {
ISourceLocation sl = getSourceLocation();
if (sl != null) {
+ if (World.createInjarHierarchy) {
+ createHierarchy();
+ }
handle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(
sl.getSourceFile(),
sl.getLine(),
sl.getColumn(),
- sl.getOffset());
+ sl.getOffset());
}
}
return handle;
@@ -141,4 +151,118 @@ public abstract class ShadowMunger implements PartialOrder.PartialComparable, IH
* @return true if munger has to check that its exceptions can be throwned based on the shadow
*/
public abstract boolean mustCheckExceptions();
+
+ /**
+ * Returns the ResolvedType corresponding to the aspect in which this
+ * shadowMunger is declared. This is different for deow's and advice.
+ */
+ public abstract ResolvedType getResolvedDeclaringAspect();
+
+ public void createHierarchy() {
+ IProgramElement sourceFileNode = AsmManager.getDefault().getHierarchy().findElementForSourceLine(getSourceLocation());
+ if (!sourceFileNode.getKind().equals(IProgramElement.Kind.FILE_JAVA)) {
+ return;
+ }
+ String name = sourceFileNode.getName();
+ sourceFileNode.setName(name + " (binary)");
+
+ ResolvedType aspect = getResolvedDeclaringAspect();
+
+ // 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(sourceFileNode);
+ } else {
+ root.addChild(sourceFileNode);
+ }
+
+ // remove the error child from the 'A.aj' node
+ if (sourceFileNode instanceof ProgramElement) {
+ IProgramElement errorNode = (IProgramElement) sourceFileNode.getChildren().get(0);
+ if (errorNode.getKind().equals(IProgramElement.Kind.ERROR)) {
+ ((ProgramElement)sourceFileNode).removeChild(errorNode);
+ }
+ }
+
+ // add and create empty import declaration ipe
+ sourceFileNode.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,
+ aspect.getSourceLocation(),
+ aspect.getModifiers(),
+ null,null);
+ sourceFileNode.addChild(aspectNode);
+
+ addChildNodes(aspectNode,aspect.getDeclaredPointcuts());
+
+ addChildNodes(aspectNode,aspect.getDeclaredAdvice());
+ addChildNodes(aspectNode,aspect.getDeclares());
+ }
+
+ private void addChildNodes(IProgramElement parent,ResolvedMember[] children) {
+ for (int i = 0; i < children.length; i++) {
+ ResolvedMember pcd = children[i];
+ if (pcd instanceof ResolvedPointcutDefinition) {
+ ResolvedPointcutDefinition rpcd = (ResolvedPointcutDefinition)pcd;
+ parent.addChild(new ProgramElement(
+ pcd.getName(),
+ IProgramElement.Kind.POINTCUT,
+ rpcd.getPointcut().getSourceLocation(),
+ pcd.getModifiers(),
+ null,
+ Collections.EMPTY_LIST));
+ }
+ }
+ }
+
+ private void addChildNodes(IProgramElement parent, Collection children) {
+ for (Iterator iter = children.iterator(); iter.hasNext();) {
+ Object element = (Object) iter.next();
+ if (element instanceof DeclareErrorOrWarning) {
+ DeclareErrorOrWarning decl = (DeclareErrorOrWarning)element;
+ IProgramElement deowNode = new ProgramElement(
+ decl.isError() ? "declare error" : "declare warning",
+ decl.isError() ? IProgramElement.Kind.DECLARE_ERROR : IProgramElement.Kind.DECLARE_WARNING,
+ getSourceLocation(),
+ this.getDeclaringType().getModifiers(),
+ null,null);
+ deowNode.setDetails("\"" + genDeclareMessage(decl.getMessage()) + "\"");
+ parent.addChild(deowNode);
+ } else if (element instanceof BcelAdvice) {
+ BcelAdvice advice = (BcelAdvice)element;
+ parent.addChild(new ProgramElement(
+ advice.kind.getName(),
+ IProgramElement.Kind.ADVICE,
+ getSourceLocation(),
+ advice.signature.getModifiers(),null,Collections.EMPTY_LIST));
+ }
+ }
+ }
+
+ // taken from AsmElementFormatter
+ private String genDeclareMessage(String message) {
+ int length = message.length();
+ if (length < 18) {
+ return message;
+ } else {
+ return message.substring(0, 17) + "..";
+ }
+ }
}
diff --git a/weaver/src/org/aspectj/weaver/World.java b/weaver/src/org/aspectj/weaver/World.java
index 5cb41d2b4..108fff263 100644
--- a/weaver/src/org/aspectj/weaver/World.java
+++ b/weaver/src/org/aspectj/weaver/World.java
@@ -59,7 +59,10 @@ public abstract class World implements Dump.INode {
// to be independent of location before we can do that.
/** Should we take into account source location when comparing mungers - which may trigger full builds */
public final static boolean compareLocations = true;
-
+
+ // see pr145963
+ /** Should we create the hierarchy for binary classes and aspects*/
+ public static boolean createInjarHierarchy = true;
/** Calculator for working out aspect precedence */
private AspectPrecedenceCalculator precedenceCalculator;