diff options
19 files changed, 259 insertions, 111 deletions
diff --git a/ajbrowser/src/org/aspectj/tools/ajbrowser/BrowserManager.java b/ajbrowser/src/org/aspectj/tools/ajbrowser/BrowserManager.java index d5ca9956f..6ed175fed 100644 --- a/ajbrowser/src/org/aspectj/tools/ajbrowser/BrowserManager.java +++ b/ajbrowser/src/org/aspectj/tools/ajbrowser/BrowserManager.java @@ -47,7 +47,7 @@ public class BrowserManager { private static TopFrame topFrame = null; public final IStructureModelListener VIEW_LISTENER = new IStructureModelListener() { - public void modelUpdated(StructureModel model) { + public void containmentHierarchyUpdated(StructureModel model) { FileStructureView fsv = Ajde.getDefault().getStructureViewManager().getDefaultFileView(); if (fsv != null) { fsv.setSourceFile(BrowserManager.getDefault().getEditorManager().getCurrFile()); diff --git a/ajde/src/org/aspectj/ajde/ui/AbstractIconRegistry.java b/ajde/src/org/aspectj/ajde/ui/AbstractIconRegistry.java index 6e4a32b41..edf519bc9 100644 --- a/ajde/src/org/aspectj/ajde/ui/AbstractIconRegistry.java +++ b/ajde/src/org/aspectj/ajde/ui/AbstractIconRegistry.java @@ -63,8 +63,8 @@ public abstract class AbstractIconRegistry { return RELATION_ADVICE_FORWARD; } else if (relationship == IRelationship.Kind.DECLARE) { return RELATION_ADVICE_FORWARD; - } else if (relationship == IRelationship.Kind.INHERITANCE) { - return RELATION_INHERITANCE_FORWARD; +// } else if (relationship == IRelationship.Kind.INHERITANCE) { +// return RELATION_INHERITANCE_FORWARD; } else { return RELATION_REFERENCE_FORWARD; } diff --git a/ajde/src/org/aspectj/ajde/ui/StructureModelUtil.java b/ajde/src/org/aspectj/ajde/ui/StructureModelUtil.java index 1b4a1a9d1..540449669 100644 --- a/ajde/src/org/aspectj/ajde/ui/StructureModelUtil.java +++ b/ajde/src/org/aspectj/ajde/ui/StructureModelUtil.java @@ -55,34 +55,34 @@ public class StructureModelUtil { for (Iterator it3 = relations.iterator(); it3.hasNext();) { IRelationship relationNode = (IRelationship) it3.next(); - if (relationNode.getKind().equals("Advice")) { - List children = relationNode.getTargets(); - - List aspects = new Vector(); - - for (Iterator it4 = children.iterator(); - it4.hasNext(); - ) { - Object object = it4.next(); - -// if (object instanceof LinkNode) { -// IProgramElement pNode = -// ((LinkNode) object).getProgramElementNode(); -// -// if (pNode.getProgramElementKind() -// == IProgramElement.Kind.ADVICE) { +// if (relationNode.getKind().equals("Advice")) { +// List children = relationNode.getTargets(); // -// IProgramElement theAspect = pNode.getParent(); +// List aspects = new Vector(); // -// aspects.add(theAspect); +// for (Iterator it4 = children.iterator(); +// it4.hasNext(); +// ) { +// Object object = it4.next(); // -// } -// } - } - if (!aspects.isEmpty()) { - aspectMap.put(key, aspects); - } - } +//// if (object instanceof LinkNode) { +//// IProgramElement pNode = +//// ((LinkNode) object).getProgramElementNode(); +//// +//// if (pNode.getProgramElementKind() +//// == IProgramElement.Kind.ADVICE) { +//// +//// IProgramElement theAspect = pNode.getParent(); +//// +//// aspects.add(theAspect); +//// +//// } +//// } +// } +// if (!aspects.isEmpty()) { +// aspectMap.put(key, aspects); +// } +// } } } diff --git a/ajde/src/org/aspectj/ajde/ui/StructureViewManager.java b/ajde/src/org/aspectj/ajde/ui/StructureViewManager.java index 880ddd5ae..5507db525 100644 --- a/ajde/src/org/aspectj/ajde/ui/StructureViewManager.java +++ b/ajde/src/org/aspectj/ajde/ui/StructureViewManager.java @@ -36,7 +36,7 @@ public class StructureViewManager { private static final List AVAILABLE_RELATIONS; public final IStructureModelListener VIEW_LISTENER = new IStructureModelListener() { - public void modelUpdated(StructureModel model) { + public void containmentHierarchyUpdated(StructureModel model) { Ajde.getDefault().logEvent("updating structure views: " + structureViews); // // if (defaultFileView != null) { @@ -218,9 +218,9 @@ public class StructureViewManager { static { AVAILABLE_RELATIONS = new ArrayList(); AVAILABLE_RELATIONS.add(IRelationship.Kind.ADVICE); - AVAILABLE_RELATIONS.add(IRelationship.Kind.INHERITANCE); - AVAILABLE_RELATIONS.add(IRelationship.Kind.DECLARE); - AVAILABLE_RELATIONS.add(IRelationship.Kind.REFERENCE); + AVAILABLE_RELATIONS.add(IRelationship.Kind.DECLARE); +// AVAILABLE_RELATIONS.add(IRelationship.Kind.INHERITANCE); +// AVAILABLE_RELATIONS.add(IRelationship.Kind.REFERENCE); DEFAULT_VIEW_PROPERTIES = new StructureViewProperties(); DEFAULT_VIEW_PROPERTIES.setRelations(AVAILABLE_RELATIONS); diff --git a/ajde/src/org/aspectj/ajde/ui/swing/PointcutWizard.java b/ajde/src/org/aspectj/ajde/ui/swing/PointcutWizard.java index bfd469a6d..33bcfc18e 100644 --- a/ajde/src/org/aspectj/ajde/ui/swing/PointcutWizard.java +++ b/ajde/src/org/aspectj/ajde/ui/swing/PointcutWizard.java @@ -69,8 +69,8 @@ class PointcutWizard extends JFrame { private Map getViewProperties() { Map views = new HashMap(); GlobalViewProperties INHERITANCE_VIEW = new GlobalViewProperties(StructureViewProperties.Hierarchy.INHERITANCE); - INHERITANCE_VIEW.addRelation(IRelationship.Kind.INHERITANCE); - views.put(INHERITANCE_VIEW.toString(), INHERITANCE_VIEW); +// INHERITANCE_VIEW.addRelation(IRelationship.Kind.INHERITANCE); +// views.put(INHERITANCE_VIEW.toString(), INHERITANCE_VIEW); return views; } diff --git a/ajde/src/org/aspectj/ajde/ui/swing/SimpleStructureViewToolPanel.java b/ajde/src/org/aspectj/ajde/ui/swing/SimpleStructureViewToolPanel.java index afdf6ba52..dc9b5cd76 100644 --- a/ajde/src/org/aspectj/ajde/ui/swing/SimpleStructureViewToolPanel.java +++ b/ajde/src/org/aspectj/ajde/ui/swing/SimpleStructureViewToolPanel.java @@ -61,7 +61,7 @@ public class SimpleStructureViewToolPanel extends JPanel { BorderLayout borderLayout4 = new BorderLayout(); public final IStructureModelListener MODEL_LISTENER = new IStructureModelListener() { - public void modelUpdated(StructureModel model) { + public void containmentHierarchyUpdated(StructureModel model) { String path = Ajde.getDefault().getConfigurationManager().getActiveConfigFile(); String fileName = "<no active config>"; if (path != null) fileName = new File(path).getName(); diff --git a/ajde/testdata/examples/coverage/ModelCoverage.java b/ajde/testdata/examples/coverage/ModelCoverage.java index 2ba60fbf0..8066ca751 100644 --- a/ajde/testdata/examples/coverage/ModelCoverage.java +++ b/ajde/testdata/examples/coverage/ModelCoverage.java @@ -2,7 +2,6 @@ import java.io.*; class Point { - int x; static int sx; @@ -36,7 +35,10 @@ class SubPoint extends Point { } class Line { } -aspect AdvisesRelationCoverage { +aspect AdvisesRelationshipCoverage { + pointcut executionP(): execution(void Point.setX(int)); + before(): executionP() { } + before(): execution(*..*.new(..)) { } before(): get(int *.*) { } before(): set(int *.*) { } diff --git a/ajde/testsrc/org/aspectj/ajde/AsmRelationshipsTest.java b/ajde/testsrc/org/aspectj/ajde/AsmRelationshipsTest.java index 6dd2a8ea7..dce7331e4 100644 --- a/ajde/testsrc/org/aspectj/ajde/AsmRelationshipsTest.java +++ b/ajde/testsrc/org/aspectj/ajde/AsmRelationshipsTest.java @@ -28,11 +28,23 @@ public class AsmRelationshipsTest extends AjdeTestCase { super(name); } - public void testPointcuts() { + public void testExecution() { IProgramElement node = (IProgramElement)model.getRoot(); assertNotNull(node); - - System.err.println("> root: " + node); + + IProgramElement aspect = StructureModelManager.getDefault().getStructureModel().findNodeForClass(null, "AdvisesRelationshipCoverage"); + assertNotNull(aspect); + + String beforeExec = "before(): executionP.."; + IProgramElement beforeExecNode = model.findNode(aspect, IProgramElement.Kind.ADVICE, beforeExec); + assertNotNull(beforeExecNode); + + + +// System.err.println("> root: " + node); + + +// assertEquals(ptctNode.getName(), ptct); // // IProgramElement aspect = StructureModelManager.getDefault().getStructureModel().findNodeForClass(null, "AdviceNamingCoverage"); @@ -40,10 +52,7 @@ public class AsmRelationshipsTest extends AjdeTestCase { // fail(); -// String ptct = "named()"; -// IProgramElement ptctNode = model.findNode(aspect, IProgramElement.Kind.POINTCUT, ptct); -// assertNotNull(ptctNode); -// assertEquals(ptctNode.getName(), ptct); + // // String params = "namedWithArgs(int, int)"; // IProgramElement paramsNode = model.findNode(aspect, IProgramElement.Kind.POINTCUT, params); 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) { +// +// } + + + +} diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EmacsStructureModelManager.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EmacsStructureModelManager.java index 74a394da4..2f11f5e8d 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EmacsStructureModelManager.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EmacsStructureModelManager.java @@ -107,19 +107,19 @@ public class EmacsStructureModelManager { } private void printDecls(IRelationship node) { - for (Iterator it = node.getTargets().iterator(); it.hasNext(); ) { - // this ignores relations on the compile unit - Object nodeObject = it.next(); - throw new RuntimeException("unimplemented"); -// if (nodeObject instanceof LinkNode) { -// LinkNode child = (LinkNode)nodeObject; -// if (//!child.getProgramElementNode().getKind().equals("stmnt") && -// !child.getProgramElementNode().getKind().equals("<undefined>")) { -// printDecl(child.getProgramElementNode(), false); +// for (Iterator it = node.getTargets().iterator(); it.hasNext(); ) { +// // this ignores relations on the compile unit +// Object nodeObject = it.next(); +// throw new RuntimeException("unimplemented"); +//// if (nodeObject instanceof LinkNode) { +//// LinkNode child = (LinkNode)nodeObject; +//// if (//!child.getProgramElementNode().getKind().equals("stmnt") && +//// !child.getProgramElementNode().getKind().equals("<undefined>")) { //// printDecl(child.getProgramElementNode(), false); -// } -// } - } +////// printDecl(child.getProgramElementNode(), false); +//// } +//// } +// } } /** diff --git a/weaver/src/org/aspectj/weaver/AsmAdaptor.java b/weaver/src/org/aspectj/weaver/AsmAdaptor.java index 8b557cf33..e448896a4 100644 --- a/weaver/src/org/aspectj/weaver/AsmAdaptor.java +++ b/weaver/src/org/aspectj/weaver/AsmAdaptor.java @@ -20,20 +20,29 @@ import org.aspectj.asm.internal.*; import org.aspectj.bridge.*; public class AsmAdaptor { - public static void noteMunger(StructureModel model, Shadow shadow, ShadowMunger munger) { + + public static void nodeMunger(StructureModel model, Shadow shadow, ShadowMunger munger) { if (munger instanceof Advice) { Advice a = (Advice)munger; - if (a.getKind().isPerEntry() || a.getKind().isCflow()) { +// if (a.getKind().isPerEntry() || a.getKind().isCflow()) { // ??? might want to show these in the future - return; - } +// return; +// } // System.out.println("--------------------------"); IProgramElement targetNode = getNode(model, shadow); IProgramElement adviceNode = getNode(model, a); + if (adviceNode != null && targetNode != null) { +// mapper.putRelationshipForElement( +// adviceNode, +// ADVICE, +// targetNode); + } + +// System.out.println("> target: " + targetNode + ", advice: " + adviceNode); // throw new RuntimeException("unimplemented"); - IRelationship relation = null; +// IRelationship relation = new Relationship(); // if (shadow.getKind().equals(Shadow.FieldGet) || shadow.getKind().equals(Shadow.FieldSet)) { // relation = AdviceAssociation.FIELD_ACCESS_RELATION; // } else if (shadow.getKind().equals(Shadow.Initialization) || shadow.getKind().equals(Shadow.StaticInitialization)) { @@ -55,9 +64,7 @@ public class AsmAdaptor { // System.err.println("> unmatched relation: " + shadow.getKind()); // relation = AdviceAssociation.METHOD_RELATION; // } -// -// System.out.println("> target: " + targetNode + ", advice: " + adviceNode); - createAppropriateLinks(targetNode, adviceNode, relation); +// createAppropriateLinks(targetNode, adviceNode, relation); } } @@ -189,8 +196,4 @@ public class AsmAdaptor { // if we can't find the member, we'll just put it in the class return classNode; } - - - - } |