summaryrefslogtreecommitdiffstats
path: root/weaver
diff options
context:
space:
mode:
authormkersten <mkersten>2003-08-14 09:07:44 +0000
committermkersten <mkersten>2003-08-14 09:07:44 +0000
commitb5d8b449c79cbedc82e03381cc459ae8c8ae9718 (patch)
tree839c55908b7814d7fab40208b1c2afaa5fb84483 /weaver
parentbffcd4c30591bce89ba938325159374e1ea1ea96 (diff)
downloadaspectj-b5d8b449c79cbedc82e03381cc459ae8c8ae9718.tar.gz
aspectj-b5d8b449c79cbedc82e03381cc459ae8c8ae9718.zip
Updated org.aspectj.asm relationship model to string-handle-based API in order to support adding and removing relationships at any point in the compilation cycle, and to support external tools building relationships (e.g. JDT's incremental containment hierarchy builder). Also made inter-type declaration relationships show up in the model.
Diffstat (limited to 'weaver')
-rw-r--r--weaver/src/org/aspectj/weaver/AsmAdviceRelationshipProvider.java (renamed from weaver/src/org/aspectj/weaver/AsmAdapter.java)116
-rw-r--r--weaver/src/org/aspectj/weaver/Checker.java2
-rw-r--r--weaver/src/org/aspectj/weaver/Shadow.java2
-rw-r--r--weaver/src/org/aspectj/weaver/World.java26
4 files changed, 75 insertions, 71 deletions
diff --git a/weaver/src/org/aspectj/weaver/AsmAdapter.java b/weaver/src/org/aspectj/weaver/AsmAdviceRelationshipProvider.java
index 5c121b169..577957069 100644
--- a/weaver/src/org/aspectj/weaver/AsmAdapter.java
+++ b/weaver/src/org/aspectj/weaver/AsmAdviceRelationshipProvider.java
@@ -13,71 +13,59 @@
package org.aspectj.weaver;
+import java.io.IOException;
import java.util.*;
import org.aspectj.asm.*;
import org.aspectj.asm.internal.*;
import org.aspectj.bridge.*;
-public class AsmAdapter {
+public class AsmAdviceRelationshipProvider {
public static final String ADVISES = "advises";
public static final String ADVISED_BY = "advised by";
public static final String DECLARES_ON = "declares on";
public static final String DECLAREDY_BY = "declared by";
- public static void checkerMunger(AspectJModel model, Shadow shadow) {
+ public static void checkerMunger(IHierarchy model, Shadow shadow) {
// System.err.println("> " + shadow.getThisVar() + " to " + shadow.getTargetVar());
}
- public static void nodeMunger(AspectJModel model, Shadow shadow, ShadowMunger munger) {
+ public static void nodeMunger(IHierarchy model, Shadow shadow, ShadowMunger munger) {
if (munger instanceof Advice) {
- Advice a = (Advice)munger;
- if (a.getKind().isPerEntry() || a.getKind().isCflow()) {
+ Advice advice = (Advice)munger;
+ if (advice.getKind().isPerEntry() || advice.getKind().isCflow()) {
// TODO: might want to show these in the future
return;
}
- IRelationshipMapper mapper = AsmManager.getDefault().getMapper();
-
- IProgramElement targetNode = getNode(model, shadow);
- IProgramElement adviceNode = getNode(model, a);
+ IRelationshipMap mapper = AsmManager.getDefault().getRelationshipMap();
+ IProgramElement targetNode = getNode(AsmManager.getDefault().getHierarchy(), shadow);
+ try {
+ if (advice.getSourceLocation() != null && targetNode != null) {
+ String adviceHandle =
+ advice.getSourceLocation().getSourceFile().getCanonicalPath()
+ + IProgramElement.ID_DELIM + advice.getSourceLocation().getLine()
+ + IProgramElement.ID_DELIM + advice.getSourceLocation().getColumn();
+
+
- if (adviceNode != null && targetNode != null) {
- IRelationship foreward = mapper.get(adviceNode, IRelationship.Kind.ADVICE, ADVISES);
- if (foreward == null) {
- foreward = new Relationship(
- ADVISES,
- IRelationship.Kind.ADVICE,
- adviceNode,
- new ArrayList()
- );
- mapper.put(adviceNode, foreward);
- }
- foreward.getTargets().add(targetNode);
-
- IRelationship back = mapper.get(targetNode, IRelationship.Kind.ADVICE, ADVISED_BY);
- if (back == null) {
- back = new Relationship(
- ADVISED_BY,
- IRelationship.Kind.ADVICE,
- targetNode,
- new ArrayList()
- );
- mapper.put(targetNode, back);
+ if (targetNode != null) {
+ String targetHandle = targetNode.getHandleIdentifier();
+
+ IRelationship foreward = mapper.get(adviceHandle, IRelationship.Kind.ADVICE, ADVISES);
+ if (foreward != null) foreward.getTargets().add(targetHandle);
+
+ IRelationship back = mapper.get(targetHandle, IRelationship.Kind.ADVICE, ADVISED_BY);
+ if (back != null) back.getTargets().add(adviceHandle);
+ }
}
- back.getTargets().add(adviceNode);
+ } catch (IOException e) {
+ e.printStackTrace();
}
}
}
- private static IProgramElement getNode(AspectJModel model, Advice a) {
- //ResolvedTypeX inAspect = a.getConcreteAspect();
- Member member = a.getSignature();
- if (a.getSignature() == null) return null;
- return lookupMember(model, member);
- }
-
- private static IProgramElement getNode(AspectJModel model, Shadow shadow) {
+ private static IProgramElement getNode(IHierarchy model, Shadow shadow) {
Member enclosingMember = shadow.getEnclosingCodeSignature();
IProgramElement enclosingNode = lookupMember(model, enclosingMember);
@@ -91,16 +79,14 @@ public class AsmAdapter {
Member shadowSig = shadow.getSignature();
if (!shadowSig.equals(enclosingMember)) {
- IProgramElement bodyNode = findOrCreateBodyNode(enclosingNode, shadowSig, shadow);
+ IProgramElement bodyNode = findOrCreateCodeNode(enclosingNode, shadowSig, shadow);
return bodyNode;
} else {
return enclosingNode;
}
}
-
- private static IProgramElement findOrCreateBodyNode(
- IProgramElement enclosingNode,
- Member shadowSig, Shadow shadow)
+
+ private static IProgramElement findOrCreateCodeNode(IProgramElement enclosingNode, Member shadowSig, Shadow shadow)
{
for (Iterator it = enclosingNode.getChildren().iterator(); it.hasNext(); ) {
IProgramElement node = (IProgramElement)it.next();
@@ -116,24 +102,22 @@ public class AsmAdapter {
IProgramElement peNode = new ProgramElement(
shadow.toString(),
IProgramElement.Kind.CODE,
-//XXX why not use shadow file? new SourceLocation(sl.getSourceFile(), sl.getLine()),
- new SourceLocation(enclosingNode.getSourceLocation().getSourceFile(), sl.getLine()),
-// enclosingNode.getSourceLocation(),
+ //XXX why not use shadow file? new SourceLocation(sl.getSourceFile(), sl.getLine()),
+ new SourceLocation(enclosingNode.getSourceLocation().getSourceFile(), sl.getLine()),
0,
"",
new ArrayList());
-
- //System.err.println(peNode.getSourceLocation());
+
peNode.setBytecodeName(shadowSig.getName());
peNode.setBytecodeSignature(shadowSig.getSignature());
enclosingNode.addChild(peNode);
return peNode;
}
- public static IProgramElement lookupMember(AspectJModel model, Member member) {
+ private static IProgramElement lookupMember(IHierarchy model, Member member) {
TypeX declaringType = member.getDeclaringType();
IProgramElement classNode =
- model.findNodeForType(declaringType.getPackageName(), declaringType.getClassName());
+ model.findElementForType(declaringType.getPackageName(), declaringType.getClassName());
return findMemberInClass(classNode, member);
}
@@ -154,4 +138,32 @@ public class AsmAdapter {
// if we can't find the member, we'll just put it in the class
return classNode;
}
+
+// private static IProgramElement.Kind genShadowKind(Shadow shadow) {
+// IProgramElement.Kind shadowKind;
+// if (shadow.getKind() == Shadow.MethodCall
+// || shadow.getKind() == Shadow.ConstructorCall
+// || shadow.getKind() == Shadow.FieldGet
+// || shadow.getKind() == Shadow.FieldSet
+// || shadow.getKind() == Shadow.ExceptionHandler) {
+// return IProgramElement.Kind.CODE;
+//
+// } else if (shadow.getKind() == Shadow.MethodExecution) {
+// return IProgramElement.Kind.METHOD;
+//
+// } else if (shadow.getKind() == Shadow.ConstructorExecution) {
+// return IProgramElement.Kind.CONSTRUCTOR;
+//
+// } else if (shadow.getKind() == Shadow.PreInitialization
+// || shadow.getKind() == Shadow.Initialization) {
+// return IProgramElement.Kind.CLASS;
+//
+// } else if (shadow.getKind() == Shadow.AdviceExecution) {
+// return IProgramElement.Kind.ADVICE;
+//
+// } else {
+// return IProgramElement.Kind.ERROR;
+// }
+// }
+
}
diff --git a/weaver/src/org/aspectj/weaver/Checker.java b/weaver/src/org/aspectj/weaver/Checker.java
index 83c9f40b9..a17bba0bb 100644
--- a/weaver/src/org/aspectj/weaver/Checker.java
+++ b/weaver/src/org/aspectj/weaver/Checker.java
@@ -55,7 +55,7 @@ public class Checker extends ShadowMunger {
shadow.getSourceLocation());
world.getMessageHandler().handleMessage(message);
- AsmAdapter.checkerMunger(world.getModel(), shadow);
+ AsmAdviceRelationshipProvider.checkerMunger(world.getModel(), shadow);
}
return false;
}
diff --git a/weaver/src/org/aspectj/weaver/Shadow.java b/weaver/src/org/aspectj/weaver/Shadow.java
index a6ec5529a..a8a1ebd94 100644
--- a/weaver/src/org/aspectj/weaver/Shadow.java
+++ b/weaver/src/org/aspectj/weaver/Shadow.java
@@ -341,7 +341,7 @@ public abstract class Shadow {
munger.implementOn(this);
if (world.getModel() != null) {
//System.err.println("munger: " + munger + " on " + this);
- AsmAdapter.nodeMunger(world.getModel(), this, munger);
+ AsmAdviceRelationshipProvider.nodeMunger(world.getModel(), this, munger);
}
}
}
diff --git a/weaver/src/org/aspectj/weaver/World.java b/weaver/src/org/aspectj/weaver/World.java
index 9f2285e23..804332090 100644
--- a/weaver/src/org/aspectj/weaver/World.java
+++ b/weaver/src/org/aspectj/weaver/World.java
@@ -13,21 +13,13 @@
package org.aspectj.weaver;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.aspectj.asm.AspectJModel;
-import org.aspectj.bridge.IMessageHandler;
-import org.aspectj.bridge.ISourceLocation;
-import org.aspectj.bridge.Message;
-import org.aspectj.bridge.MessageUtil;
+import java.util.*;
+
+import org.aspectj.asm.IHierarchy;
+import org.aspectj.asm.internal.AspectJElementHierarchy;
+import org.aspectj.bridge.*;
import org.aspectj.bridge.IMessage.Kind;
-import org.aspectj.weaver.ResolvedTypeX.Name;
-import org.aspectj.weaver.patterns.DeclarePrecedence;
-import org.aspectj.weaver.patterns.Pointcut;
+import org.aspectj.weaver.patterns.*;
public abstract class World {
protected IMessageHandler messageHandler = IMessageHandler.SYSTEM_ERR;
@@ -36,7 +28,7 @@ public abstract class World {
protected CrosscuttingMembersSet crosscuttingMembersSet = new CrosscuttingMembersSet(this);
- protected AspectJModel model = null;
+ protected IHierarchy model = null;
protected Lint lint = new Lint(this);
@@ -340,11 +332,11 @@ public abstract class World {
return crosscuttingMembersSet;
}
- public AspectJModel getModel() {
+ public IHierarchy getModel() {
return model;
}
- public void setModel(AspectJModel model) {
+ public void setModel(IHierarchy model) {
this.model = model;
}