aboutsummaryrefslogtreecommitdiffstats
path: root/asm/src
diff options
context:
space:
mode:
authormkersten <mkersten>2003-08-13 20:51:10 +0000
committermkersten <mkersten>2003-08-13 20:51:10 +0000
commitbffcd4c30591bce89ba938325159374e1ea1ea96 (patch)
tree29f2247cf0806c7e5ea7e419c33d86b6a3738b38 /asm/src
parent11d7649fc3219af5a71d3bf0b9fe004c075c2b4f (diff)
downloadaspectj-bffcd4c30591bce89ba938325159374e1ea1ea96.tar.gz
aspectj-bffcd4c30591bce89ba938325159374e1ea1ea96.zip
Added support for multiple relationships for a single program element. Renamed model container class.
Diffstat (limited to 'asm/src')
-rw-r--r--asm/src/org/aspectj/asm/AsmManager.java10
-rw-r--r--asm/src/org/aspectj/asm/AspectJModel.java (renamed from asm/src/org/aspectj/asm/StructureModel.java)6
-rw-r--r--asm/src/org/aspectj/asm/HierarchyWalker.java6
-rw-r--r--asm/src/org/aspectj/asm/IRelationship.java2
-rw-r--r--asm/src/org/aspectj/asm/IRelationshipMapper.java23
-rw-r--r--asm/src/org/aspectj/asm/IStructureModelListener.java2
-rw-r--r--asm/src/org/aspectj/asm/internal/RelationshipMapper.java42
7 files changed, 69 insertions, 22 deletions
diff --git a/asm/src/org/aspectj/asm/AsmManager.java b/asm/src/org/aspectj/asm/AsmManager.java
index dda0ab096..b090abfcf 100644
--- a/asm/src/org/aspectj/asm/AsmManager.java
+++ b/asm/src/org/aspectj/asm/AsmManager.java
@@ -29,7 +29,7 @@ public class AsmManager {
*/
private static AsmManager INSTANCE = new AsmManager();
private boolean shouldSaveModel = true;
- protected StructureModel model = new StructureModel();
+ protected AspectJModel model = new AspectJModel();
private List structureListeners = new ArrayList();
private IRelationshipMapper mapper;
@@ -39,7 +39,7 @@ public class AsmManager {
mapper = new RelationshipMapper();
}
- public StructureModel getModel() {
+ public AspectJModel getModel() {
return model;
}
@@ -140,16 +140,16 @@ public class AsmManager {
public void readStructureModel(String configFilePath) {
try {
if (configFilePath == null) {
- model.setRoot(StructureModel.NO_STRUCTURE);
+ model.setRoot(AspectJModel.NO_STRUCTURE);
} else {
String filePath = genExternFilePath(configFilePath);
FileInputStream in = new FileInputStream(filePath);
ObjectInputStream s = new ObjectInputStream(in);
- model = (StructureModel)s.readObject();
+ model = (AspectJModel)s.readObject();
}
} catch (Exception e) {
//System.err.println("AJDE Message: could not read structure model: " + e);
- model.setRoot(StructureModel.NO_STRUCTURE);
+ model.setRoot(AspectJModel.NO_STRUCTURE);
} finally {
notifyListeners();
}
diff --git a/asm/src/org/aspectj/asm/StructureModel.java b/asm/src/org/aspectj/asm/AspectJModel.java
index 36318a2e5..e8c723edc 100644
--- a/asm/src/org/aspectj/asm/StructureModel.java
+++ b/asm/src/org/aspectj/asm/AspectJModel.java
@@ -23,7 +23,7 @@ import org.aspectj.bridge.*;
/**
* @author Mik Kersten
*/
-public class StructureModel implements Serializable {
+public class AspectJModel implements Serializable {
protected IProgramElement root = null;
protected String configFile = null;
@@ -156,7 +156,7 @@ public class StructureModel implements Serializable {
public IProgramElement findRootNodeForSourceFile(String sourceFile) {
try {
if (!isValid() || sourceFile == null) {
- return StructureModel.NO_STRUCTURE;
+ return AspectJModel.NO_STRUCTURE;
} else {
String correctedPath = new File(sourceFile).getCanonicalPath();//.replace('\\', '/');
//StructureNode node = (StructureNode)getFileMap().get(correctedPath);//findFileNode(filePath, model);
@@ -168,7 +168,7 @@ public class StructureModel implements Serializable {
}
}
} catch (Exception e) {
- return StructureModel.NO_STRUCTURE;
+ return AspectJModel.NO_STRUCTURE;
}
}
diff --git a/asm/src/org/aspectj/asm/HierarchyWalker.java b/asm/src/org/aspectj/asm/HierarchyWalker.java
index b1d9e6100..cac375482 100644
--- a/asm/src/org/aspectj/asm/HierarchyWalker.java
+++ b/asm/src/org/aspectj/asm/HierarchyWalker.java
@@ -17,15 +17,15 @@ package org.aspectj.asm;
/**
* @author Mik Kersten
*/
-public class HierarchyWalker {
+public abstract class HierarchyWalker {
- private StructureModel model;
+ private AspectJModel model;
public HierarchyWalker() {
super();
}
- public HierarchyWalker(StructureModel model) {
+ public HierarchyWalker(AspectJModel model) {
this.model = model;
}
diff --git a/asm/src/org/aspectj/asm/IRelationship.java b/asm/src/org/aspectj/asm/IRelationship.java
index 892f50006..b6377e832 100644
--- a/asm/src/org/aspectj/asm/IRelationship.java
+++ b/asm/src/org/aspectj/asm/IRelationship.java
@@ -29,7 +29,7 @@ public interface IRelationship extends Serializable {
public IProgramElement getSource();
public Kind getKind();
-
+
/**
* Uses "typesafe enum" pattern.
*/
diff --git a/asm/src/org/aspectj/asm/IRelationshipMapper.java b/asm/src/org/aspectj/asm/IRelationshipMapper.java
index ab8fffd34..747347222 100644
--- a/asm/src/org/aspectj/asm/IRelationshipMapper.java
+++ b/asm/src/org/aspectj/asm/IRelationshipMapper.java
@@ -18,18 +18,31 @@ import java.util.List;
import org.aspectj.asm.IRelationship.Kind;
/**
+ * Maps from a program element to a list of relationships between that element
+ * and othe program elements. Each element in the list or relationships is
+ * uniquely identified by a kind and a relationship name.
+ *
* @author Mik Kersten
*/
public interface IRelationshipMapper extends Serializable {
- // TODO: return a list
- public IRelationship get(IProgramElement source);
+ /**
+ * @return an empty list if the element is not found.
+ */
+ public List get(IProgramElement source);
+
+ /**
+ * Return a relationship matching the kind and name for the given element.
+ *
+ * @return null if the relationship is not found.
+ */
+ public IRelationship get(IProgramElement source, IRelationship.Kind kind, String relationshipName);
- // TODO: return a list
- public IRelationship get(String handle);
- public void put(IProgramElement source, IRelationship relationship);
+ public List/*IRelationship*/ get(String handle);
+ public void put(IProgramElement source, IRelationship relationship);
+
}
diff --git a/asm/src/org/aspectj/asm/IStructureModelListener.java b/asm/src/org/aspectj/asm/IStructureModelListener.java
index 9356b6f2d..6e2879ee1 100644
--- a/asm/src/org/aspectj/asm/IStructureModelListener.java
+++ b/asm/src/org/aspectj/asm/IStructureModelListener.java
@@ -23,5 +23,5 @@ import java.util.EventListener;
*/
public interface IStructureModelListener extends EventListener {
- public void containmentHierarchyUpdated(StructureModel rootNode);
+ public void containmentHierarchyUpdated(AspectJModel rootNode);
}
diff --git a/asm/src/org/aspectj/asm/internal/RelationshipMapper.java b/asm/src/org/aspectj/asm/internal/RelationshipMapper.java
index e794b76e0..c3d1a5f4c 100644
--- a/asm/src/org/aspectj/asm/internal/RelationshipMapper.java
+++ b/asm/src/org/aspectj/asm/internal/RelationshipMapper.java
@@ -21,16 +21,50 @@ import org.aspectj.asm.*;
*/
public class RelationshipMapper extends HashMap implements IRelationshipMapper {
- public IRelationship get(IProgramElement source) {
- return (IRelationship)super.get(source);
+ public List get(IProgramElement source) {
+ List relationships = (List)super.get(source);
+ if (relationships == null) {
+ return Collections.EMPTY_LIST;
+ } else {
+ return relationships;
+ }
}
- public IRelationship get(String handle) {
+ /**
+ * @return null if the relationship is not found.
+ */
+ public IRelationship get(IProgramElement source, IRelationship.Kind kind, String relationshipName) {
+ List relationships = get(source);
+ for (Iterator it = relationships.iterator(); it.hasNext(); ) {
+ IRelationship curr = (IRelationship)it.next();
+ if (curr.getKind() == kind && curr.getName() == relationshipName) {
+ return curr;
+ }
+ }
+ return null;
+ }
+
+ public List get(String handle) {
throw new RuntimeException("unimplemented");
}
public void put(IProgramElement source, IRelationship relationship) {
- super.put(source, relationship);
+ List list = (List)super.get(source);
+ if (list == null) {
+ list = new ArrayList();
+ list.add(relationship);
+ super.put(source, list);
+ } else {
+ boolean matched = false;
+ for (Iterator it = list.iterator(); it.hasNext(); ) {
+ IRelationship curr = (IRelationship)it.next();
+ if (curr.getName().equals(relationship.getName())) {
+ curr.getTargets().addAll(relationship.getTargets());
+ matched = true;
+ }
+ }
+ if (!matched) list.add(relationship);
+ }
}
// TODO: add a remove, and a clear all