summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormkersten <mkersten>2003-08-14 17:18:34 +0000
committermkersten <mkersten>2003-08-14 17:18:34 +0000
commit56d4d719ba6e1ff20efe3f1003aa8eec8d5b88a2 (patch)
tree98aed82a88fcdef2d0aaf660ce44f9ec8bb8896d
parentb5d8b449c79cbedc82e03381cc459ae8c8ae9718 (diff)
downloadaspectj-56d4d719ba6e1ff20efe3f1003aa8eec8d5b88a2.tar.gz
aspectj-56d4d719ba6e1ff20efe3f1003aa8eec8d5b88a2.zip
Improved declare relationships. Implemented batch-build relationship clearing policy.
-rw-r--r--ajde/src/org/aspectj/ajde/Ajde.java3
-rw-r--r--ajde/testdata/examples/coverage/ModelCoverage.java2
-rw-r--r--ajde/testsrc/org/aspectj/ajde/AsmRelationshipsTest.java58
-rw-r--r--asm/src/org/aspectj/asm/IProgramElement.java2
-rw-r--r--asm/src/org/aspectj/asm/IRelationshipMap.java5
-rw-r--r--asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java2
-rw-r--r--asm/src/org/aspectj/asm/internal/ProgramElement.java21
-rw-r--r--asm/src/org/aspectj/asm/internal/RelationshipMap.java4
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java32
-rw-r--r--weaver/src/org/aspectj/weaver/AsmAdviceRelationshipProvider.java36
10 files changed, 110 insertions, 55 deletions
diff --git a/ajde/src/org/aspectj/ajde/Ajde.java b/ajde/src/org/aspectj/ajde/Ajde.java
index 032ad6e59..687f8bbbd 100644
--- a/ajde/src/org/aspectj/ajde/Ajde.java
+++ b/ajde/src/org/aspectj/ajde/Ajde.java
@@ -294,6 +294,9 @@ public class Ajde {
* Writes the default configuration file if it has been selected for compilation
*/
public void compileStarted(String buildConfig) {
+ // TODO: implement incremental policy
+ AsmManager.getDefault().getRelationshipMap().clear();
+
String configFilePath = projectProperties.getDefaultBuildConfigFile();
if (buildConfig.equals(configFilePath)) {
configurationManager.writePaths(configFilePath, projectProperties.getProjectSourceFiles());
diff --git a/ajde/testdata/examples/coverage/ModelCoverage.java b/ajde/testdata/examples/coverage/ModelCoverage.java
index 075bddc3b..bb977e36c 100644
--- a/ajde/testdata/examples/coverage/ModelCoverage.java
+++ b/ajde/testdata/examples/coverage/ModelCoverage.java
@@ -55,7 +55,7 @@ aspect AdvisesRelationshipCoverage {
pointcut getP(): get(int *.*);
before(): getP() { }
- pointcut setP(): set(int *.*);
+ pointcut setP(): set(int *.*) && !set(int *.xxx);
before(): setP() { }
pointcut initializationP(): initialization(Point.new(..));
diff --git a/ajde/testsrc/org/aspectj/ajde/AsmRelationshipsTest.java b/ajde/testsrc/org/aspectj/ajde/AsmRelationshipsTest.java
index db82a96cf..85df30d08 100644
--- a/ajde/testsrc/org/aspectj/ajde/AsmRelationshipsTest.java
+++ b/ajde/testsrc/org/aspectj/ajde/AsmRelationshipsTest.java
@@ -11,10 +11,9 @@
package org.aspectj.ajde;
-import java.util.List;
+import java.util.Iterator;
import org.aspectj.asm.*;
-import org.aspectj.asm.internal.ProgramElement;
// TODO: check for return types
public class AsmRelationshipsTest extends AjdeTestCase {
@@ -27,29 +26,40 @@ public class AsmRelationshipsTest extends AjdeTestCase {
}
public void testInterTypeDeclarations() {
-// checkMapping("InterTypeDecCoverage", "Point", "Point.xxx", "xxx", "declared on", "aspect declarations");
-// checkMapping("InterTypeDecCoverage", "Point", "Point.check(int, Line)", "Point", "declared on", "aspect declarations");
-
+ checkInterTypeMapping("InterTypeDecCoverage", "Point", "Point.xxx", "Point",
+ "declared on", "aspect declarations", IProgramElement.Kind.INTER_TYPE_FIELD);
+ checkInterTypeMapping("InterTypeDecCoverage", "Point", "Point.check(int, Line)",
+ "Point", "declared on", "aspect declarations", IProgramElement.Kind.INTER_TYPE_METHOD);
}
public void testAdvice() {
- checkMapping("AdvisesRelationshipCoverage", "Point", "before(): methodExecutionP..", "setX(int)", "advises", "advised by");
- checkUniDirectionalMapping("AdvisesRelationshipCoverage", "Point", "before(): getP..", "field-get(int Point.x)", "advises");
- checkUniDirectionalMapping("AdvisesRelationshipCoverage", "Point", "before(): setP..", "field-set(int Point.xxx)", "advises");
+ checkMapping("AdvisesRelationshipCoverage", "Point", "before(): methodExecutionP..",
+ "setX(int)", "advises", "advised by");
+ checkUniDirectionalMapping("AdvisesRelationshipCoverage", "Point", "before(): getP..",
+ "field-get(int Point.x)", "advises");
+ checkUniDirectionalMapping("AdvisesRelationshipCoverage", "Point", "before(): setP..",
+ "field-set(int Point.x)", "advises");
}
- private void checkUniDirectionalMapping(String fromType, String toType, String from, String to, String relName) {
+ private void checkUniDirectionalMapping(String fromType, String toType, String from,
+ String to, String relName) {
+
IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, fromType);
assertNotNull(aspect);
String beforeExec = from;
IProgramElement beforeExecNode = manager.getHierarchy().findElementForLabel(aspect, IProgramElement.Kind.ADVICE, beforeExec);
assertNotNull(beforeExecNode);
IRelationship rel = manager.getRelationshipMap().get(beforeExecNode, IRelationship.Kind.ADVICE, relName);
- String handle = (String)rel.getTargets().get(0);
- assertEquals(manager.getHierarchy().findElementForHandle(handle).toLabelString(), to);
+ for (Iterator it = rel.getTargets().iterator(); it.hasNext(); ) {
+ String currHandle = (String)it.next();
+ if (manager.getHierarchy().findElementForHandle(currHandle).toLabelString().equals(to)) return;
+ }
+ fail(); // didn't find it
}
- private void checkMapping(String fromType, String toType, String from, String to, String forwardRelName, String backRelName) {
+ private void checkMapping(String fromType, String toType, String from, String to,
+ String forwardRelName, String backRelName) {
+
IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, fromType);
assertNotNull(aspect);
String beforeExec = from;
@@ -69,6 +79,30 @@ public class AsmRelationshipsTest extends AjdeTestCase {
assertEquals(manager.getHierarchy().findElementForHandle(handle2).toString(), from);
}
+ private void checkInterTypeMapping(String fromType, String toType, String from,
+ String to, String forwardRelName, String backRelName, IProgramElement.Kind declareKind) {
+
+ IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, fromType);
+ assertNotNull(aspect);
+ String beforeExec = from;
+ IProgramElement fromNode = manager.getHierarchy().findElementForLabel(aspect, declareKind, beforeExec);
+ assertNotNull(fromNode);
+ IRelationship rel = manager.getRelationshipMap().get(fromNode, IRelationship.Kind.DECLARE_INTER_TYPE, forwardRelName);
+ String handle = (String)rel.getTargets().get(0);
+ assertEquals(manager.getHierarchy().findElementForHandle(handle).toString(), to);
+
+ IProgramElement clazz = AsmManager.getDefault().getHierarchy().findElementForType(null, toType);
+ assertNotNull(clazz);
+ String set = to;
+ IRelationship rel2 = manager.getRelationshipMap().get(clazz, IRelationship.Kind.DECLARE_INTER_TYPE, backRelName);
+ String handle2 = (String)rel2.getTargets().get(0);
+ for (Iterator it = rel2.getTargets().iterator(); it.hasNext(); ) {
+ String currHandle = (String)it.next();
+ if (manager.getHierarchy().findElementForHandle(currHandle).toLabelString().equals(from)) return;
+ }
+ fail(); // didn't find it
+ }
+
protected void setUp() throws Exception {
super.setUp("examples");
assertTrue("build success", doSynchronousBuild(CONFIG_FILE_PATH));
diff --git a/asm/src/org/aspectj/asm/IProgramElement.java b/asm/src/org/aspectj/asm/IProgramElement.java
index 42a83d2b3..0c1b0595c 100644
--- a/asm/src/org/aspectj/asm/IProgramElement.java
+++ b/asm/src/org/aspectj/asm/IProgramElement.java
@@ -24,8 +24,6 @@ import org.aspectj.bridge.*;
*/
public interface IProgramElement extends Serializable {
- public static final String ID_DELIM = "|";
-
public List/*IProgramElement*/ getChildren();
public void setChildren(List children);
diff --git a/asm/src/org/aspectj/asm/IRelationshipMap.java b/asm/src/org/aspectj/asm/IRelationshipMap.java
index b5a12e534..f487ce661 100644
--- a/asm/src/org/aspectj/asm/IRelationshipMap.java
+++ b/asm/src/org/aspectj/asm/IRelationshipMap.java
@@ -64,5 +64,10 @@ public interface IRelationshipMap extends Serializable {
public void remove(String handle, IRelationship relationship);
public void removeAll(String source);
+
+ /**
+ * Clear all of the relationships in the map.
+ */
+ public void clear();
}
diff --git a/asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java b/asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java
index 6a523da11..e8d2f9902 100644
--- a/asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java
+++ b/asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java
@@ -270,7 +270,7 @@ public class AspectJElementHierarchy implements IHierarchy {
// TODO: optimize this lookup
public IProgramElement findElementForHandle(String handle) {
- StringTokenizer st = new StringTokenizer(handle, IProgramElement.ID_DELIM);
+ StringTokenizer st = new StringTokenizer(handle, ProgramElement.ID_DELIM);
String file = st.nextToken();
int line = new Integer(st.nextToken()).intValue();
int col = new Integer(st.nextToken()).intValue();
diff --git a/asm/src/org/aspectj/asm/internal/ProgramElement.java b/asm/src/org/aspectj/asm/internal/ProgramElement.java
index ff509689d..830b323bd 100644
--- a/asm/src/org/aspectj/asm/internal/ProgramElement.java
+++ b/asm/src/org/aspectj/asm/internal/ProgramElement.java
@@ -13,12 +13,11 @@
package org.aspectj.asm.internal;
-import java.io.IOException;
+import java.io.*;
import java.util.*;
import org.aspectj.asm.*;
import org.aspectj.bridge.*;
-import org.aspectj.bridge.IMessage.Kind;
/**
@@ -26,6 +25,8 @@ import org.aspectj.bridge.IMessage.Kind;
*/
public class ProgramElement implements IProgramElement {
+ static final String ID_DELIM = "|";
+
protected IProgramElement parent = null;
protected String name = "";
// children.listIterator() should support remove() operation
@@ -391,6 +392,22 @@ public class ProgramElement implements IProgramElement {
return label;
}
+ // TODO: determine if using canonical path incurrs performance overhead
+ public static String createHandleIdentifier(File sourceFile, int line,int column) {
+ try {
+ StringBuffer sb = new StringBuffer();
+ sb.append(sourceFile.getCanonicalPath());
+ sb.append(ID_DELIM);
+ sb.append(line);
+ sb.append(ID_DELIM);
+ sb.append(column);
+ return sb.toString();
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ return null;
+ }
+ }
+
public String getHandleIdentifier() {
try {
StringBuffer sb = new StringBuffer();
diff --git a/asm/src/org/aspectj/asm/internal/RelationshipMap.java b/asm/src/org/aspectj/asm/internal/RelationshipMap.java
index cd7e776c6..86f9606f1 100644
--- a/asm/src/org/aspectj/asm/internal/RelationshipMap.java
+++ b/asm/src/org/aspectj/asm/internal/RelationshipMap.java
@@ -111,4 +111,8 @@ public class RelationshipMap extends HashMap implements IRelationshipMap {
put(source.getHandleIdentifier(), relationship);
}
+ public void clear() {
+ super.clear();
+ }
+
}
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java
index 329e5b57e..46a155204 100644
--- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java
+++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java
@@ -12,10 +12,10 @@
package org.aspectj.ajdt.internal.compiler.lookup;
-import java.util.*;
+import java.io.IOException;
import org.aspectj.asm.*;
-import org.aspectj.asm.internal.Relationship;
+import org.aspectj.asm.internal.ProgramElement;
import org.aspectj.weaver.*;
/**
@@ -23,7 +23,7 @@ import org.aspectj.weaver.*;
*/
public class AsmInterTypeRelationshipProvider {
- public static final String INTER_TYPE_DECLARES = "declares on";
+ public static final String INTER_TYPE_DECLARES = "declared on";
public static final String INTER_TYPE_DECLARED_BY = "aspect declarations";
public static void addRelationship(
@@ -43,25 +43,25 @@ public class AsmInterTypeRelationshipProvider {
if (munger.getSourceLocation() != null
&& munger.getSourceLocation() != null) {
- String sourceHandle =
- munger.getSourceLocation().getSourceFile().getAbsolutePath() + IProgramElement.ID_DELIM
- + munger.getSourceLocation().getLine() + IProgramElement.ID_DELIM
- + munger.getSourceLocation().getColumn();
+ String sourceHandle = ProgramElement.createHandleIdentifier(
+ munger.getSourceLocation().getSourceFile(),
+ munger.getSourceLocation().getLine(),
+ munger.getSourceLocation().getColumn());
- String targetHandle =
- onType.getSourceLocation().getSourceFile().getAbsolutePath() + IProgramElement.ID_DELIM
- + onType.getSourceLocation().getLine() + IProgramElement.ID_DELIM
- + onType.getSourceLocation().getColumn();
-
+ String targetHandle = ProgramElement.createHandleIdentifier(
+ onType.getSourceLocation().getSourceFile(),
+ onType.getSourceLocation().getLine(),
+ onType.getSourceLocation().getColumn());
+
+// System.err.println(">> putting: " + sourceHandle + ", to " + targetHandle);
IRelationshipMap mapper = AsmManager.getDefault().getRelationshipMap();
if (sourceHandle != null && targetHandle != null) {
- IRelationship foreward = mapper.get(sourceHandle, IRelationship.Kind.ADVICE, INTER_TYPE_DECLARES);
+ IRelationship foreward = mapper.get(sourceHandle, IRelationship.Kind.DECLARE_INTER_TYPE, INTER_TYPE_DECLARES);
foreward.getTargets().add(targetHandle);
- IRelationship back = mapper.get(targetHandle, IRelationship.Kind.ADVICE, INTER_TYPE_DECLARED_BY);
- back.getTargets().add(sourceHandle);
+ IRelationship back = mapper.get(targetHandle, IRelationship.Kind.DECLARE_INTER_TYPE, INTER_TYPE_DECLARED_BY);
+ back.getTargets().add(sourceHandle);
}
}
}
-
}
diff --git a/weaver/src/org/aspectj/weaver/AsmAdviceRelationshipProvider.java b/weaver/src/org/aspectj/weaver/AsmAdviceRelationshipProvider.java
index 577957069..59f65ed8d 100644
--- a/weaver/src/org/aspectj/weaver/AsmAdviceRelationshipProvider.java
+++ b/weaver/src/org/aspectj/weaver/AsmAdviceRelationshipProvider.java
@@ -13,11 +13,10 @@
package org.aspectj.weaver;
-import java.io.IOException;
import java.util.*;
import org.aspectj.asm.*;
-import org.aspectj.asm.internal.*;
+import org.aspectj.asm.internal.ProgramElement;
import org.aspectj.bridge.*;
public class AsmAdviceRelationshipProvider {
@@ -40,28 +39,23 @@ public class AsmAdviceRelationshipProvider {
}
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 (targetNode != null) {
- String targetHandle = targetNode.getHandleIdentifier();
+ if (advice.getSourceLocation() != null && targetNode != null) {
+ String adviceHandle = ProgramElement.createHandleIdentifier(
+ advice.getSourceLocation().getSourceFile(),
+ advice.getSourceLocation().getLine(),
+ advice.getSourceLocation().getColumn());
+
+ if (targetNode != null) {
+ String targetHandle = targetNode.getHandleIdentifier();
+
+ IRelationship foreward = mapper.get(adviceHandle, IRelationship.Kind.ADVICE, ADVISES);
+ if (foreward != null) foreward.getTargets().add(targetHandle);
- 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);
- }
+ IRelationship back = mapper.get(targetHandle, IRelationship.Kind.ADVICE, ADVISED_BY);
+ if (back != null) back.getTargets().add(adviceHandle);
}
- } catch (IOException e) {
- e.printStackTrace();
}
+
}
}