* 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());
pointcut getP(): get(int *.*);
before(): getP() { }
- pointcut setP(): set(int *.*);
+ pointcut setP(): set(int *.*) && !set(int *.xxx);
before(): setP() { }
pointcut initializationP(): initialization(Point.new(..));
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 {
}
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;
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));
*/
public interface IProgramElement extends Serializable {
- public static final String ID_DELIM = "|";
-
public List/*IProgramElement*/ getChildren();
public void setChildren(List children);
public void remove(String handle, IRelationship relationship);
public void removeAll(String source);
+
+ /**
+ * Clear all of the relationships in the map.
+ */
+ public void clear();
}
// 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();
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;
/**
*/
public class ProgramElement implements IProgramElement {
+ static final String ID_DELIM = "|";
+
protected IProgramElement parent = null;
protected String name = "";
// children.listIterator() should support remove() operation
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();
put(source.getHandleIdentifier(), relationship);
}
+ public void clear() {
+ super.clear();
+ }
+
}
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.*;
/**
*/
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(
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);
}
}
}
-
}
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 {
}
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();
}
+
}
}