aboutsummaryrefslogtreecommitdiffstats
path: root/asm
diff options
context:
space:
mode:
authormkersten <mkersten>2003-08-08 14:59:46 +0000
committermkersten <mkersten>2003-08-08 14:59:46 +0000
commitf7944d2c68e8561e12498c006729c6c341b657f7 (patch)
tree205af60b87fa308248a3d01694a9685a53260fe8 /asm
parent555d9cd8fec8a2c0bc3daac63123a9bea941a912 (diff)
downloadaspectj-f7944d2c68e8561e12498c006729c6c341b657f7.tar.gz
aspectj-f7944d2c68e8561e12498c006729c6c341b657f7.zip
First pass at new relationship API support.
Diffstat (limited to 'asm')
-rw-r--r--asm/src/org/aspectj/asm/IProgramElement.java1
-rw-r--r--asm/src/org/aspectj/asm/IRelationship.java18
-rw-r--r--asm/src/org/aspectj/asm/IRelationshipMapper.java31
-rw-r--r--asm/src/org/aspectj/asm/IStructureModelListener.java2
-rw-r--r--asm/src/org/aspectj/asm/StructureModel.java6
-rw-r--r--asm/src/org/aspectj/asm/StructureModelManager.java20
-rw-r--r--asm/src/org/aspectj/asm/internal/ProgramElement.java12
-rw-r--r--asm/src/org/aspectj/asm/internal/Relationship.java30
-rw-r--r--asm/src/org/aspectj/asm/internal/RelationshipMapper.java100
9 files changed, 177 insertions, 43 deletions
diff --git a/asm/src/org/aspectj/asm/IProgramElement.java b/asm/src/org/aspectj/asm/IProgramElement.java
index 17f16aa87..8cde25862 100644
--- a/asm/src/org/aspectj/asm/IProgramElement.java
+++ b/asm/src/org/aspectj/asm/IProgramElement.java
@@ -62,6 +62,7 @@ public interface IProgramElement extends Serializable {
public void setName(String name);
public void setChildren(List children);
public void setModifiers(int i);
+// public String getSignatureKey();
/**
* Uses "typesafe enum" pattern.
diff --git a/asm/src/org/aspectj/asm/IRelationship.java b/asm/src/org/aspectj/asm/IRelationship.java
index ab8d9bf09..efcc1b969 100644
--- a/asm/src/org/aspectj/asm/IRelationship.java
+++ b/asm/src/org/aspectj/asm/IRelationship.java
@@ -24,26 +24,24 @@ public interface IRelationship extends Serializable {
public String getName();
- public Kind getKind();
-
- public IProgramElement getSource();
+ public String getReverseName();
- public List/*IProgramElement*/ getTargets();
+ public Kind getKind();
/**
* Uses "typesafe enum" pattern.
*/
public static class Kind implements Serializable {
- public static final Kind ADVICE = new Kind("static");
- public static final Kind INHERITANCE = new Kind("final");
- public static final Kind REFERENCE = new Kind("abstract");
- public static final Kind DECLARE = new Kind("volatile");
- public static final Kind[] ALL = { ADVICE, INHERITANCE, REFERENCE, DECLARE };
+ public static final Kind ADVICE = new Kind("advice");
+// public static final Kind INHERITANCE = new Kind("inherits", "inherited by");
+// public static final Kind REFERENCE = new Kind("reference");
+ public static final Kind DECLARE = new Kind("declare");
+ public static final Kind[] ALL = { ADVICE, DECLARE };
private final String name;
private Kind(String name) {
- this.name = name;
+ this.name = name;
}
public String toString() {
diff --git a/asm/src/org/aspectj/asm/IRelationshipMapper.java b/asm/src/org/aspectj/asm/IRelationshipMapper.java
new file mode 100644
index 000000000..eaf6653de
--- /dev/null
+++ b/asm/src/org/aspectj/asm/IRelationshipMapper.java
@@ -0,0 +1,31 @@
+/* *******************************************************************
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ * ******************************************************************/
+
+package org.aspectj.asm;
+
+import java.io.Serializable;
+import java.util.List;
+
+import org.aspectj.asm.IRelationship.Kind;
+
+/**
+ * @author Mik Kersten
+ */
+public interface IRelationshipMapper extends Serializable {
+
+// public List getRelationshipsForElement(String source, IRelationship relationship);
+//
+// public void putRelationshipForElement(String source, IRelationship relationship, List targets);
+//
+// public void putRelationshipForElement(String source, IRelationship kind, String target);
+
+ public List getRelationshipsForElement(IProgramElement source, IRelationship relationship);
+
+ public void putRelationshipForElement(IProgramElement source, IRelationship relationship, List targets);
+
+ public void putRelationshipForElement(IProgramElement source, IRelationship kind, IProgramElement target);
+}
diff --git a/asm/src/org/aspectj/asm/IStructureModelListener.java b/asm/src/org/aspectj/asm/IStructureModelListener.java
index 9512045ac..9356b6f2d 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 modelUpdated(StructureModel rootNode);
+ public void containmentHierarchyUpdated(StructureModel rootNode);
}
diff --git a/asm/src/org/aspectj/asm/StructureModel.java b/asm/src/org/aspectj/asm/StructureModel.java
index 65b596d05..472509b1a 100644
--- a/asm/src/org/aspectj/asm/StructureModel.java
+++ b/asm/src/org/aspectj/asm/StructureModel.java
@@ -27,7 +27,9 @@ public class StructureModel implements Serializable {
protected IProgramElement root = null;
protected String configFile = null;
+
private Map fileMap = null;
+
public static final IProgramElement NO_STRUCTURE = new ProgramElement("<build to view structure>", IProgramElement.Kind.ERROR, null);
public IProgramElement getRoot() {
@@ -84,6 +86,10 @@ public class StructureModel implements Serializable {
return null;
}
+ public IProgramElement findNodeForSignatureKey(String signatureKey) {
+ return null;
+ }
+
/**
* @param packageName if null default package is searched
* @param className can't be null
diff --git a/asm/src/org/aspectj/asm/StructureModelManager.java b/asm/src/org/aspectj/asm/StructureModelManager.java
index c99b747ad..6130bfe59 100644
--- a/asm/src/org/aspectj/asm/StructureModelManager.java
+++ b/asm/src/org/aspectj/asm/StructureModelManager.java
@@ -14,10 +14,10 @@
package org.aspectj.asm;
-import java.util.*;
import java.io.*;
+import java.util.*;
-import org.aspectj.bridge.ISourceLocation;
+import org.aspectj.asm.internal.*;
/**
* @author Mik Kersten
@@ -31,13 +31,13 @@ public class StructureModelManager {
private boolean shouldSaveModel = true;
protected StructureModel model = new StructureModel();
private List structureListeners = new ArrayList();
- private List associations = new ArrayList();
+
+ private IRelationshipMapper mapper;
+ private static final IRelationship ADVICE = new Relationship("advises", "advised by", IRelationship.Kind.ADVICE);
+ private static final IRelationship[] ALL = { ADVICE };
protected StructureModelManager() {
-// associations.add(new AdviceAssociation());
-// associations.add(new IntroductionAssociation());
-// associations.add(new InheritanceAssociation());
-// associations.add(new ReferenceAssociation());
+ mapper = new RelationshipMapper(Arrays.asList(ALL));
}
public StructureModel getStructureModel() {
@@ -116,14 +116,10 @@ public class StructureModelManager {
private void notifyListeners() {
for (Iterator it = structureListeners.iterator(); it.hasNext(); ) {
- ((IStructureModelListener)it.next()).modelUpdated(model);
+ ((IStructureModelListener)it.next()).containmentHierarchyUpdated(model);
}
}
- public List getAssociations() {
- return associations;
- }
-
/**
* Fails silently.
*/
diff --git a/asm/src/org/aspectj/asm/internal/ProgramElement.java b/asm/src/org/aspectj/asm/internal/ProgramElement.java
index eec6389e2..9562169cd 100644
--- a/asm/src/org/aspectj/asm/internal/ProgramElement.java
+++ b/asm/src/org/aspectj/asm/internal/ProgramElement.java
@@ -358,13 +358,17 @@ public class ProgramElement implements IProgramElement {
walker.process(this);
return buffer.toString();
}
- /**
- *
- */
-
+
public void setModifiers(int i) {
this.modifiers = genModifiers(i);
}
+ public String getSignatureKey() {
+ return packageName + '/'
+ + name + ':'
+ + sourceLocation.getLine() + ':'
+ + sourceLocation.getColumn();
+ }
+
}
diff --git a/asm/src/org/aspectj/asm/internal/Relationship.java b/asm/src/org/aspectj/asm/internal/Relationship.java
index bb26501dc..be86fd473 100644
--- a/asm/src/org/aspectj/asm/internal/Relationship.java
+++ b/asm/src/org/aspectj/asm/internal/Relationship.java
@@ -23,31 +23,29 @@ import org.aspectj.asm.IRelationship.Kind;
*/
public class Relationship implements IRelationship {
- private String name = null;
- private IProgramElement source = null;
- private List/*IProgramElement*/ targets = null;
- private Kind kind = null;
+ private String name;
+ private String reverseName;
+ private Kind kind;
- public Relationship(String name, IProgramElement source, List targets, Kind kind) {
+ public Relationship(String name, String reverseName, Kind kind) {
this.name = name;
- this.source = source;
- this.targets = targets;
+ this.reverseName = reverseName;
this.kind = kind;
- }
+ }
public String getName() {
return null;
}
-
- public IProgramElement getSource() {
- return null;
- }
-
- public List getTargets() {
- return null;
- }
public Kind getKind() {
return null;
}
+
+ public String getReverseName() {
+ return reverseName;
+ }
+
+ public String toString() {
+ return name + '/' + reverseName;
+ }
}
diff --git a/asm/src/org/aspectj/asm/internal/RelationshipMapper.java b/asm/src/org/aspectj/asm/internal/RelationshipMapper.java
new file mode 100644
index 000000000..f4929563b
--- /dev/null
+++ b/asm/src/org/aspectj/asm/internal/RelationshipMapper.java
@@ -0,0 +1,100 @@
+/* *******************************************************************
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ * ******************************************************************/
+
+package org.aspectj.asm.internal;
+
+import java.util.*;
+
+import org.aspectj.asm.*;
+
+/**
+ * @author Mik Kersten
+ */
+public class RelationshipMapper extends HashMap implements IRelationshipMapper {
+
+ private Map/*IRelationship*/ relationships = new HashMap();
+
+ public RelationshipMapper(List availableRelationships) {
+ for (Iterator it = availableRelationships.iterator(); it.hasNext(); ) {
+ IRelationship r = (IRelationship)it.next();
+ relationships.put(r, new HashMap());
+ }
+ }
+
+ public List getRelationshipsForElement(IProgramElement source, IRelationship relationship) {
+ Map map = (Map)relationships.get(relationship);
+ return (List)map.get(source);
+ }
+
+ /**
+ * Creates the relationship if not present.
+ */
+ public void putRelationshipForElement(IProgramElement source, IRelationship relationship, List targets) {
+ Map map = (Map)relationships.get(relationship);
+ if (map == null) {
+ map = new HashMap();
+ relationships.put(relationship, map);
+ }
+ map.put(source, targets);
+ }
+
+ public void putRelationshipForElement(IProgramElement source, IRelationship relationship, IProgramElement target) {
+ Map map = (Map)relationships.get(relationship);
+ if (map == null) {
+ map = new HashMap();
+ relationships.put(relationship, map);
+ }
+ List targetList = (List)map.get(source);
+ if (targetList == null) {
+ targetList = new ArrayList();
+ map.put(source, targetList);
+ }
+ targetList.add(target);
+ }
+
+ private static class RelationshipTable {
+ private IRelationship relationship;
+ private Map map;
+
+ public RelationshipTable(IRelationship relationship) {
+ this.relationship = relationship;
+ map = new HashMap();
+ }
+
+ public Map getMap() {
+ return map;
+ }
+
+ public IRelationship getRelationship() {
+ return relationship;
+ }
+ }
+// public List getRelationshipsForElement(
+// IProgramElement source,
+// IRelationship relationship) {
+//
+// String signatureKey = (List)getRelationshipsForElement(source.getSignatureKey(), relationship);
+//
+// }
+//
+// public void putRelationshipForElement(
+// IProgramElement source,
+// IRelationship kind,
+// IProgramElement target) {
+//
+// }
+//
+// public void putRelationshipForElement(
+// IProgramElement source,
+// IRelationship relationship,
+// List targets) {
+//
+// }
+
+
+
+}