From b5d8b449c79cbedc82e03381cc459ae8c8ae9718 Mon Sep 17 00:00:00 2001 From: mkersten Date: Thu, 14 Aug 2003 09:07:44 +0000 Subject: [PATCH] Updated org.aspectj.asm relationship model to string-handle-based API in order to support adding and removing relationships at any point in the compilation cycle, and to support external tools building relationships (e.g. JDT's incremental containment hierarchy builder). Also made inter-type declaration relationships show up in the model. --- .../tools/ajbrowser/BrowserManager.java | 5 +- .../aspectj/ajde/ui/StructureModelUtil.java | 7 +- .../ajde/ui/StructureSearchManager.java | 5 +- .../aspectj/ajde/ui/StructureViewManager.java | 17 +-- .../ajde/ui/StructureViewNodeFactory.java | 44 +++--- .../ui/internal/TreeStructureViewBuilder.java | 9 +- .../aspectj/ajde/ui/swing/AjdeUIManager.java | 7 + .../swing/SimpleStructureViewToolPanel.java | 26 ++-- .../ajde/ui/swing/StructureTreeManager.java | 2 +- .../ajde/ui/swing/SwingTreeViewNode.java | 2 +- .../examples/coverage/ModelCoverage.java | 8 +- .../org/aspectj/ajde/AjdeTestCase.java | 1 + .../org/aspectj/ajde/AsmDeclarationsTest.java | 116 ++++++++------- .../aspectj/ajde/AsmRelationshipsTest.java | 35 +++-- .../org/aspectj/ajde/NullIdeManager.java | 9 +- .../ajde/StructureModelRegressionTest.java | 10 +- .../org/aspectj/ajde/StructureModelTest.java | 25 ++-- .../ajde/ui/StructureViewManagerTest.java | 12 +- asm/src/org/aspectj/asm/AsmManager.java | 52 ++++--- asm/src/org/aspectj/asm/HierarchyWalker.java | 14 +- asm/src/org/aspectj/asm/IHierarchy.java | 92 ++++++++++++ ...lListener.java => IHierarchyListener.java} | 11 +- asm/src/org/aspectj/asm/IProgramElement.java | 71 +++++++-- asm/src/org/aspectj/asm/IRelationship.java | 10 +- ...nshipMapper.java => IRelationshipMap.java} | 32 ++++- .../AspectJElementHierarchy.java} | 114 ++++++++++----- .../aspectj/asm/internal/ProgramElement.java | 96 +++++++++++-- .../aspectj/asm/internal/Relationship.java | 16 ++- .../aspectj/asm/internal/RelationshipMap.java | 114 +++++++++++++++ .../asm/internal/RelationshipMapper.java | 90 ------------ docs/developer/asm.doc | Bin 138240 -> 140288 bytes .../compiler/lookup/AjLookupEnvironment.java | 5 + .../AsmInterTypeRelationshipProvider.java | 67 +++++++++ .../internal/core/builder/AjBuildManager.java | 11 +- ...ormatter.java => AsmElementFormatter.java} | 135 +++++++++++------- .../core/builder/AsmHierarchyBuilder.java | 19 ++- .../builder/EmacsStructureModelManager.java | 4 +- .../core/builder/AjBuildManagerTest.java | 2 +- ...ava => AsmAdviceRelationshipProvider.java} | 116 ++++++++------- weaver/src/org/aspectj/weaver/Checker.java | 2 +- weaver/src/org/aspectj/weaver/Shadow.java | 2 +- weaver/src/org/aspectj/weaver/World.java | 26 ++-- 42 files changed, 929 insertions(+), 512 deletions(-) create mode 100644 asm/src/org/aspectj/asm/IHierarchy.java rename asm/src/org/aspectj/asm/{IStructureModelListener.java => IHierarchyListener.java} (66%) rename asm/src/org/aspectj/asm/{IRelationshipMapper.java => IRelationshipMap.java} (53%) rename asm/src/org/aspectj/asm/{AspectJModel.java => internal/AspectJElementHierarchy.java} (68%) create mode 100644 asm/src/org/aspectj/asm/internal/RelationshipMap.java delete mode 100644 asm/src/org/aspectj/asm/internal/RelationshipMapper.java create mode 100644 org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java rename org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/{AsmNodeFormatter.java => AsmElementFormatter.java} (66%) rename weaver/src/org/aspectj/weaver/{AsmAdapter.java => AsmAdviceRelationshipProvider.java} (51%) diff --git a/ajbrowser/src/org/aspectj/tools/ajbrowser/BrowserManager.java b/ajbrowser/src/org/aspectj/tools/ajbrowser/BrowserManager.java index 6f7523f7a..826ca9299 100644 --- a/ajbrowser/src/org/aspectj/tools/ajbrowser/BrowserManager.java +++ b/ajbrowser/src/org/aspectj/tools/ajbrowser/BrowserManager.java @@ -24,6 +24,7 @@ import org.aspectj.ajde.ui.*; import org.aspectj.ajde.ui.internal.UserPreferencesStore; import org.aspectj.ajde.ui.swing.*; import org.aspectj.asm.*; +import org.aspectj.asm.internal.*; /** * IDE manager for standalone AJDE application. @@ -46,8 +47,8 @@ public class BrowserManager { private static TopFrame topFrame = null; - public final IStructureModelListener VIEW_LISTENER = new IStructureModelListener() { - public void containmentHierarchyUpdated(AspectJModel model) { + public final IHierarchyListener VIEW_LISTENER = new IHierarchyListener() { + public void elementsUpdated(IHierarchy 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/StructureModelUtil.java b/ajde/src/org/aspectj/ajde/ui/StructureModelUtil.java index 578c04e0c..0923caa79 100644 --- a/ajde/src/org/aspectj/ajde/ui/StructureModelUtil.java +++ b/ajde/src/org/aspectj/ajde/ui/StructureModelUtil.java @@ -18,6 +18,7 @@ import java.util.*; import org.aspectj.ajde.Ajde; import org.aspectj.asm.*; +import org.aspectj.asm.internal.*; /** * Prototype functionality for package view clients. @@ -114,9 +115,9 @@ public class StructureModelUtil { public static List getPackagesInModel() { List packages = new ArrayList(); - AspectJModel model = - Ajde.getDefault().getStructureModelManager().getModel(); - if (model.equals(AspectJModel.NO_STRUCTURE)) { + IHierarchy model = + Ajde.getDefault().getStructureModelManager().getHierarchy(); + if (model.equals(IHierarchy.NO_STRUCTURE)) { return null; } else { return getPackagesHelper( diff --git a/ajde/src/org/aspectj/ajde/ui/StructureSearchManager.java b/ajde/src/org/aspectj/ajde/ui/StructureSearchManager.java index c1f77c243..835ccc5be 100644 --- a/ajde/src/org/aspectj/ajde/ui/StructureSearchManager.java +++ b/ajde/src/org/aspectj/ajde/ui/StructureSearchManager.java @@ -18,6 +18,7 @@ import java.util.*; import org.aspectj.ajde.Ajde; import org.aspectj.asm.*; +import org.aspectj.asm.internal.*; /** * @author Mik Kersten @@ -34,8 +35,8 @@ public class StructureSearchManager { IProgramElement.Kind kind) { List matches = new ArrayList(); - AspectJModel model = Ajde.getDefault().getStructureModelManager().getModel(); - if (model.equals(AspectJModel.NO_STRUCTURE)) { + IHierarchy model = Ajde.getDefault().getStructureModelManager().getHierarchy(); + if (model.equals(IHierarchy.NO_STRUCTURE)) { return null; } else { return findMatchesHelper((IProgramElement)model.getRoot(), pattern, kind, matches); diff --git a/ajde/src/org/aspectj/ajde/ui/StructureViewManager.java b/ajde/src/org/aspectj/ajde/ui/StructureViewManager.java index 7eb9dfa5f..b2fe1224f 100644 --- a/ajde/src/org/aspectj/ajde/ui/StructureViewManager.java +++ b/ajde/src/org/aspectj/ajde/ui/StructureViewManager.java @@ -19,6 +19,7 @@ import java.util.*; import org.aspectj.ajde.Ajde; import org.aspectj.ajde.ui.internal.*; import org.aspectj.asm.*; +import org.aspectj.asm.internal.*; /** * @author Mik Kersten @@ -35,8 +36,8 @@ public class StructureViewManager { private static final StructureViewProperties DEFAULT_VIEW_PROPERTIES; private static final List AVAILABLE_RELATIONS; - public final IStructureModelListener VIEW_LISTENER = new IStructureModelListener() { - public void containmentHierarchyUpdated(AspectJModel model) { + public final IHierarchyListener VIEW_LISTENER = new IHierarchyListener() { + public void elementsUpdated(IHierarchy model) { Ajde.getDefault().logEvent("updating structure views: " + structureViews); // // if (defaultFileView != null) { @@ -44,7 +45,7 @@ public class StructureViewManager { // } for (Iterator it = structureViews.iterator(); it.hasNext(); ) { - treeViewBuilder.buildView((StructureView)it.next(), (AspectJModel)model); + treeViewBuilder.buildView((StructureView)it.next(), (AspectJElementHierarchy)model); } } }; @@ -84,7 +85,7 @@ public class StructureViewManager { * @param newFilePath the canonicalized path to the new file */ public void fireNavigationAction(String newFilePath, int lineNumber) { - IProgramElement currNode = Ajde.getDefault().getStructureModelManager().getModel().findNodeForSourceLine( + IProgramElement currNode = Ajde.getDefault().getStructureModelManager().getHierarchy().findElementForSourceLine( newFilePath, lineNumber); @@ -116,7 +117,7 @@ public class StructureViewManager { */ private void navigationAction(IProgramElement node, boolean recordHistory) { if (node == null - || node == AspectJModel.NO_STRUCTURE) { + || node == IHierarchy.NO_STRUCTURE) { Ajde.getDefault().getIdeUIAdapter().displayStatusInformation("Source not available for node: " + node.getName()); return; } @@ -127,7 +128,7 @@ public class StructureViewManager { if (defaultFileView.getSourceFile() != null && !defaultFileView.getSourceFile().equals(newFilePath)) { defaultFileView.setSourceFile(newFilePath); - treeViewBuilder.buildView(defaultFileView, AsmManager.getDefault().getModel()); + treeViewBuilder.buildView(defaultFileView, AsmManager.getDefault().getHierarchy()); } } @@ -161,7 +162,7 @@ public class StructureViewManager { public void refreshView(StructureView view) { IStructureViewNode activeNode = view.getActiveNode(); - treeViewBuilder.buildView(view, Ajde.getDefault().getStructureModelManager().getModel()); + treeViewBuilder.buildView(view, Ajde.getDefault().getStructureModelManager().getHierarchy()); view.setActiveNode(activeNode); } @@ -195,7 +196,7 @@ public class StructureViewManager { if (properties == null) properties = DEFAULT_VIEW_PROPERTIES; FileStructureView view = new FileStructureView(properties); view.setSourceFile(sourceFilePath); - treeViewBuilder.buildView(view, AsmManager.getDefault().getModel()); + treeViewBuilder.buildView(view, AsmManager.getDefault().getHierarchy()); structureViews.add(view); return view; } diff --git a/ajde/src/org/aspectj/ajde/ui/StructureViewNodeFactory.java b/ajde/src/org/aspectj/ajde/ui/StructureViewNodeFactory.java index 2339614ab..828d419ef 100644 --- a/ajde/src/org/aspectj/ajde/ui/StructureViewNodeFactory.java +++ b/ajde/src/org/aspectj/ajde/ui/StructureViewNodeFactory.java @@ -36,25 +36,31 @@ public abstract class StructureViewNodeFactory { public IStructureViewNode createNode(IProgramElement node, List children) { AbstractIcon icon = iconRegistry.getStructureIcon(node.getKind(), node.getAccessibility()); - IStructureViewNode svNode = createDeclaration(node, icon, children); - List relationships = AsmManager.getDefault().getMapper().get(node); - for (Iterator it = relationships.iterator(); it.hasNext(); ) { - IRelationship rel = (IRelationship)it.next(); - if (rel != null && rel.getTargets().size() > 0) { - IStructureViewNode relNode = createRelationship( - rel, - iconRegistry.getIcon(rel.getKind()) - ); - svNode.add(relNode, 0); - - for (Iterator it2 = rel.getTargets().iterator(); it2.hasNext(); ) { - IProgramElement link = (IProgramElement)it2.next(); - IStructureViewNode linkNode = createLink( - link, - iconRegistry.getStructureIcon(link.getKind(), link.getAccessibility()) - ); - relNode.add(linkNode); - + IStructureViewNode svNode = createDeclaration(node, icon, children); + String nodeHandle = node.getHandleIdentifier(); + if (nodeHandle != null) { + List relationships = AsmManager.getDefault().getRelationshipMap().get(nodeHandle); + if (relationships != null) { + for (Iterator it = relationships.iterator(); it.hasNext(); ) { + IRelationship rel = (IRelationship)it.next(); + if (rel != null && rel.getTargets().size() > 0) { + IStructureViewNode relNode = createRelationship( + rel, + iconRegistry.getIcon(rel.getKind()) + ); + svNode.add(relNode, 0); + for (Iterator it2 = rel.getTargets().iterator(); it2.hasNext(); ) { + String handle = (String)it2.next(); + IProgramElement link = AsmManager.getDefault().getHierarchy().findElementForHandle(handle); + if (link != null) { + IStructureViewNode linkNode = createLink( + link, + iconRegistry.getStructureIcon(link.getKind(), link.getAccessibility()) + ); + relNode.add(linkNode); + } + } + } } } } diff --git a/ajde/src/org/aspectj/ajde/ui/internal/TreeStructureViewBuilder.java b/ajde/src/org/aspectj/ajde/ui/internal/TreeStructureViewBuilder.java index 239628176..ecf8ed5ae 100644 --- a/ajde/src/org/aspectj/ajde/ui/internal/TreeStructureViewBuilder.java +++ b/ajde/src/org/aspectj/ajde/ui/internal/TreeStructureViewBuilder.java @@ -18,6 +18,7 @@ import java.util.*; import org.aspectj.ajde.ui.*; import org.aspectj.asm.*; +import org.aspectj.asm.internal.*; import org.aspectj.asm.internal.ProgramElement; /** @@ -34,17 +35,17 @@ public class TreeStructureViewBuilder { /** * @todo get rid of instanceof tests */ - public void buildView(StructureView view, AspectJModel model) { + public void buildView(StructureView view, IHierarchy model) { StructureViewProperties properties = view.getViewProperties(); IProgramElement modelRoot = null; boolean noStructure = false; if (isFileView(view)) { FileStructureView fileView = (FileStructureView)view; if (fileView.getSourceFile() == null) { - modelRoot = AspectJModel.NO_STRUCTURE; + modelRoot = IHierarchy.NO_STRUCTURE; noStructure = true; } else { - modelRoot = model.findRootNodeForSourceFile(fileView.getSourceFile()); + modelRoot = model.findElementForSourceFile(fileView.getSourceFile()); } } else { modelRoot = model.getRoot(); @@ -197,7 +198,7 @@ public class TreeStructureViewBuilder { } } - private IStructureViewNode buildCustomTree(GlobalStructureView view, AspectJModel model) { + private IStructureViewNode buildCustomTree(GlobalStructureView view, IHierarchy model) { IProgramElement rootNode = model.getRoot(); IStructureViewNode treeNode = nodeFactory.createNode(rootNode); diff --git a/ajde/src/org/aspectj/ajde/ui/swing/AjdeUIManager.java b/ajde/src/org/aspectj/ajde/ui/swing/AjdeUIManager.java index bd1f9d76b..583ce0539 100644 --- a/ajde/src/org/aspectj/ajde/ui/swing/AjdeUIManager.java +++ b/ajde/src/org/aspectj/ajde/ui/swing/AjdeUIManager.java @@ -42,6 +42,7 @@ public class AjdeUIManager { private IdeUIAdapter ideUIAdapter = null; private TreeViewBuildConfigEditor buildConfigEditor = null; private IconRegistry iconRegistry; + private boolean initialized = false; private OptionsFrame optionsFrame = null; private Frame rootFrame = null; @@ -116,11 +117,13 @@ public class AjdeUIManager { viewManager = new BrowserViewManager(); optionsFrame = new OptionsFrame(iconRegistry); + //Ajde.getDefault().getStructureViewManager().refreshView( // Ajde.getDefault().getStructureViewManager().getDefaultFileStructureView() //); //viewManager.updateView(); + initialized = true; } catch (Throwable t) { Ajde.getDefault().getErrorHandler().handleError("AJDE failed to initialize.", t); } @@ -190,6 +193,10 @@ public class AjdeUIManager { public IconRegistry getIconRegistry() { return iconRegistry; } + public boolean isInitialized() { + return initialized; + } + } //public abstract class AjdeAction { diff --git a/ajde/src/org/aspectj/ajde/ui/swing/SimpleStructureViewToolPanel.java b/ajde/src/org/aspectj/ajde/ui/swing/SimpleStructureViewToolPanel.java index 66c3a0e0a..f5b3fb555 100644 --- a/ajde/src/org/aspectj/ajde/ui/swing/SimpleStructureViewToolPanel.java +++ b/ajde/src/org/aspectj/ajde/ui/swing/SimpleStructureViewToolPanel.java @@ -14,27 +14,17 @@ package org.aspectj.ajde.ui.swing; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.SystemColor; +import java.awt.*; import java.awt.event.ActionEvent; import java.io.File; import java.util.ArrayList; -import javax.swing.BorderFactory; -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.border.BevelBorder; -import javax.swing.border.Border; +import javax.swing.*; +import javax.swing.border.*; import org.aspectj.ajde.Ajde; -import org.aspectj.ajde.ui.StructureView; -import org.aspectj.ajde.ui.StructureViewProperties; -import org.aspectj.asm.IProgramElement; -import org.aspectj.asm.AspectJModel; -import org.aspectj.asm.IStructureModelListener; +import org.aspectj.ajde.ui.*; +import org.aspectj.asm.*; public class SimpleStructureViewToolPanel extends JPanel { @@ -60,10 +50,10 @@ public class SimpleStructureViewToolPanel extends JPanel { BorderLayout borderLayout3 = new BorderLayout(); BorderLayout borderLayout4 = new BorderLayout(); - public final IStructureModelListener MODEL_LISTENER = new IStructureModelListener() { - public void containmentHierarchyUpdated(AspectJModel model) { + public final IHierarchyListener MODEL_LISTENER = new IHierarchyListener() { + public void elementsUpdated(IHierarchy model) { String path = Ajde.getDefault().getConfigurationManager().getActiveConfigFile(); - String fileName = ""; + String fileName = ""; if (path != null) fileName = new File(path).getName(); updateCurrConfigLabel(fileName); } diff --git a/ajde/src/org/aspectj/ajde/ui/swing/StructureTreeManager.java b/ajde/src/org/aspectj/ajde/ui/swing/StructureTreeManager.java index efb786b7f..9a32c26e5 100644 --- a/ajde/src/org/aspectj/ajde/ui/swing/StructureTreeManager.java +++ b/ajde/src/org/aspectj/ajde/ui/swing/StructureTreeManager.java @@ -35,7 +35,7 @@ class StructureTreeManager { private TreeSelectionListener treeListener = null; private final StructureTreeModel NO_STRUCTURE_MODEL - = new StructureTreeModel(new SwingTreeViewNode(AspectJModel.NO_STRUCTURE, new AbstractIcon(null), new ArrayList())); + = new StructureTreeModel(new SwingTreeViewNode(IHierarchy.NO_STRUCTURE, new AbstractIcon(null), new ArrayList())); /** * @todo should probably avoid that MouseListener cast diff --git a/ajde/src/org/aspectj/ajde/ui/swing/SwingTreeViewNode.java b/ajde/src/org/aspectj/ajde/ui/swing/SwingTreeViewNode.java index dbd0c7aad..b7cbe7403 100644 --- a/ajde/src/org/aspectj/ajde/ui/swing/SwingTreeViewNode.java +++ b/ajde/src/org/aspectj/ajde/ui/swing/SwingTreeViewNode.java @@ -108,7 +108,7 @@ public class SwingTreeViewNode extends DefaultMutableTreeNode implements IStruct if (kind == IStructureViewNode.Kind.RELATIONSHIP) { return relationshipName; } else { - return programElement.getName(); + return programElement.toLabelString(); } } diff --git a/ajde/testdata/examples/coverage/ModelCoverage.java b/ajde/testdata/examples/coverage/ModelCoverage.java index cb7b8391b..075bddc3b 100644 --- a/ajde/testdata/examples/coverage/ModelCoverage.java +++ b/ajde/testdata/examples/coverage/ModelCoverage.java @@ -10,9 +10,13 @@ class Point { public Point() { } - public int getX() { return x; } + public int getX() { + return x; + } - public void setX(int x) { this.x = x; } + public void setX(int x) { + this.x = x; + } public int changeX(int x) { this.x = x; diff --git a/ajde/testsrc/org/aspectj/ajde/AjdeTestCase.java b/ajde/testsrc/org/aspectj/ajde/AjdeTestCase.java index c280b68dc..7f3e2a481 100644 --- a/ajde/testsrc/org/aspectj/ajde/AjdeTestCase.java +++ b/ajde/testsrc/org/aspectj/ajde/AjdeTestCase.java @@ -52,6 +52,7 @@ public class AjdeTestCase extends TestCase { currTestDataPath = TEST_DATA_PATH + File.separatorChar + testDataPath; ideManager.init(currTestDataPath); super.setUp(); + assertTrue(NullIdeManager.getIdeManager().isInitialized()); Ajde.getDefault().getBuildManager().addListener(testerBuildListener); } diff --git a/ajde/testsrc/org/aspectj/ajde/AsmDeclarationsTest.java b/ajde/testsrc/org/aspectj/ajde/AsmDeclarationsTest.java index 8b815224b..9d7bdf79c 100644 --- a/ajde/testsrc/org/aspectj/ajde/AsmDeclarationsTest.java +++ b/ajde/testsrc/org/aspectj/ajde/AsmDeclarationsTest.java @@ -12,7 +12,7 @@ package org.aspectj.ajde; import java.util.Iterator; -import org.aspectj.ajdt.internal.core.builder.AsmNodeFormatter; +import org.aspectj.ajdt.internal.core.builder.AsmElementFormatter; import org.aspectj.asm.*; import org.aspectj.asm.IProgramElement.Kind; @@ -20,9 +20,9 @@ import org.aspectj.asm.IProgramElement.Kind; // TODO: add tests for java kinds public class AsmDeclarationsTest extends AjdeTestCase { - private AspectJModel model = null; + private IHierarchy model = null; private static final String CONFIG_FILE_PATH = "../examples/coverage/coverage.lst"; - private static final int DEC_MESSAGE_LENGTH = AsmNodeFormatter.MAX_MESSAGE_LENGTH; + private static final int DEC_MESSAGE_LENGTH = AsmElementFormatter.MAX_MESSAGE_LENGTH; public AsmDeclarationsTest(String name) { super(name); @@ -31,101 +31,97 @@ public class AsmDeclarationsTest extends AjdeTestCase { public void testRoot() { IProgramElement root = (IProgramElement)model.getRoot(); assertNotNull(root); - assertEquals(root.getName(), "coverage.lst"); + assertEquals(root.toLabelString(), "coverage.lst"); } public void testFileInPackageAndDefaultPackage() { IProgramElement root = model.getRoot(); - assertEquals(root.getName(), "coverage.lst"); + assertEquals(root.toLabelString(), "coverage.lst"); IProgramElement pkg = (IProgramElement)root.getChildren().get(1); - assertEquals(pkg.getName(), "pkg"); - assertEquals(((IProgramElement)pkg.getChildren().get(0)).getName(), "InPackage.java"); - assertEquals(((IProgramElement)root.getChildren().get(0)).getName(), "ModelCoverage.java"); + assertEquals(pkg.toLabelString(), "pkg"); + assertEquals(((IProgramElement)pkg.getChildren().get(0)).toLabelString(), "InPackage.java"); + assertEquals(((IProgramElement)root.getChildren().get(0)).toLabelString(), "ModelCoverage.java"); } public void testDeclares() { IProgramElement node = (IProgramElement)model.getRoot(); assertNotNull(node); - IProgramElement aspect = AsmManager.getDefault().getModel().findNodeForType(null, "DeclareCoverage"); + IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "DeclareCoverage"); assertNotNull(aspect); - String decErrMessage = "declare error: \"Illegal construct..\""; - IProgramElement decErrNode = model.findNode(aspect, IProgramElement.Kind.DECLARE_ERROR, decErrMessage); + String label = "declare error: \"Illegal construct..\""; + IProgramElement decErrNode = model.findElementForSignature(aspect, IProgramElement.Kind.DECLARE_ERROR, "declare error"); assertNotNull(decErrNode); - assertEquals(decErrNode.getName(), decErrMessage); + assertEquals(decErrNode.toLabelString(), label); String decWarnMessage = "declare warning: \"Illegal construct..\""; - IProgramElement decWarnNode = model.findNode(aspect, IProgramElement.Kind.DECLARE_WARNING, decWarnMessage); + IProgramElement decWarnNode = model.findElementForSignature(aspect, IProgramElement.Kind.DECLARE_WARNING, "declare warning"); assertNotNull(decWarnNode); - assertEquals(decWarnNode.getName(), decWarnMessage); + assertEquals(decWarnNode.toLabelString(), decWarnMessage); String decParentsMessage = "declare parents: Point"; - IProgramElement decParentsNode = model.findNode(aspect, IProgramElement.Kind.DECLARE_PARENTS, decParentsMessage); + IProgramElement decParentsNode = model.findElementForSignature(aspect, IProgramElement.Kind.DECLARE_PARENTS, "declare parents"); assertNotNull(decParentsNode); - assertEquals(decParentsNode.getName(), decParentsMessage); - - String decParentsPtnMessage = "declare parents: Point+"; - IProgramElement decParentsPtnNode = model.findNode(aspect, IProgramElement.Kind.DECLARE_PARENTS, decParentsPtnMessage); - assertNotNull(decParentsPtnNode); - assertEquals(decParentsPtnNode.getName(), decParentsPtnMessage); - - String decParentsTPMessage = "declare parents: "; - IProgramElement decParentsTPNode = model.findNode(aspect, IProgramElement.Kind.DECLARE_PARENTS, decParentsTPMessage); - assertNotNull(decParentsTPNode); - assertEquals(decParentsTPNode.getName(), decParentsTPMessage); + assertEquals(decParentsNode.toLabelString(), decParentsMessage); + // check the next two relative to this one + int declareIndex = decParentsNode.getParent().getChildren().indexOf(decParentsNode); + String decParentsPtnMessage = "declare parents: Point+"; + assertEquals(((IProgramElement)aspect.getChildren().get(declareIndex+1)).toLabelString(), decParentsPtnMessage); + String decParentsTPMessage = "declare parents: "; + assertEquals(((IProgramElement)aspect.getChildren().get(declareIndex+2)).toLabelString(), decParentsTPMessage); String decSoftMessage = "declare soft: SizeException"; - IProgramElement decSoftNode = model.findNode(aspect, IProgramElement.Kind.DECLARE_SOFT, decSoftMessage); + IProgramElement decSoftNode = model.findElementForSignature(aspect, IProgramElement.Kind.DECLARE_SOFT, "declare soft"); assertNotNull(decSoftNode); - assertEquals(decSoftNode.getName(), decSoftMessage); + assertEquals(decSoftNode.toLabelString(), decSoftMessage); String decPrecMessage = "declare precedence: AdviceCoverage, InterTypeDecCoverage, "; - IProgramElement decPrecNode = model.findNode(aspect, IProgramElement.Kind.DECLARE_PRECEDENCE, decPrecMessage); + IProgramElement decPrecNode = model.findElementForSignature(aspect, IProgramElement.Kind.DECLARE_PRECEDENCE, "declare precedence"); assertNotNull(decPrecNode); - assertEquals(decPrecNode.getName(), decPrecMessage); + assertEquals(decPrecNode.toLabelString(), decPrecMessage); } public void testInterTypeMemberDeclares() { IProgramElement node = (IProgramElement)model.getRoot(); assertNotNull(node); - IProgramElement aspect = AsmManager.getDefault().getModel().findNodeForType(null, "InterTypeDecCoverage"); + IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "InterTypeDecCoverage"); assertNotNull(aspect); String fieldMsg = "Point.xxx"; - IProgramElement fieldNode = model.findNode(aspect, IProgramElement.Kind.INTER_TYPE_FIELD, fieldMsg); + IProgramElement fieldNode = model.findElementForLabel(aspect, IProgramElement.Kind.INTER_TYPE_FIELD, fieldMsg); assertNotNull(fieldNode); - assertEquals(fieldNode.getName(), fieldMsg); + assertEquals(fieldNode.toLabelString(), fieldMsg); String methodMsg = "Point.check(int, Line)"; - IProgramElement methodNode = model.findNode(aspect, IProgramElement.Kind.INTER_TYPE_METHOD, methodMsg); + IProgramElement methodNode = model.findElementForLabel(aspect, IProgramElement.Kind.INTER_TYPE_METHOD, methodMsg); assertNotNull(methodNode); - assertEquals(methodNode.getName(), methodMsg); + assertEquals(methodNode.toLabelString(), methodMsg); // TODO: enable // String constructorMsg = "Point.new(int, int, int)"; // ProgramElementNode constructorNode = model.findNode(aspect, ProgramElementNode.Kind.INTER_TYPE_CONSTRUCTOR, constructorMsg); // assertNotNull(constructorNode); -// assertEquals(constructorNode.getName(), constructorMsg); +// assertEquals(constructorNode.toLabelString(), constructorMsg); } public void testPointcuts() { IProgramElement node = (IProgramElement)model.getRoot(); assertNotNull(node); - IProgramElement aspect = AsmManager.getDefault().getModel().findNodeForType(null, "AdviceNamingCoverage"); + IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "AdviceNamingCoverage"); assertNotNull(aspect); String ptct = "named()"; - IProgramElement ptctNode = model.findNode(aspect, IProgramElement.Kind.POINTCUT, ptct); + IProgramElement ptctNode = model.findElementForSignature(aspect, IProgramElement.Kind.POINTCUT, ptct); assertNotNull(ptctNode); - assertEquals(ptctNode.getName(), ptct); + assertEquals(ptctNode.toLabelString(), ptct); String params = "namedWithArgs(int, int)"; - IProgramElement paramsNode = model.findNode(aspect, IProgramElement.Kind.POINTCUT, params); + IProgramElement paramsNode = model.findElementForSignature(aspect, IProgramElement.Kind.POINTCUT, params); assertNotNull(paramsNode); - assertEquals(paramsNode.getName(), params); + assertEquals(paramsNode.toLabelString(), params); } @@ -134,62 +130,62 @@ public class AsmDeclarationsTest extends AjdeTestCase { IProgramElement node = (IProgramElement)model.getRoot(); assertNotNull(node); - IProgramElement aspect = AsmManager.getDefault().getModel().findNodeForType(null, "AbstractAspect"); + IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "AbstractAspect"); assertNotNull(aspect); String abst = "abPtct()"; - IProgramElement abstNode = model.findNode(aspect, IProgramElement.Kind.POINTCUT, abst); + IProgramElement abstNode = model.findElementForSignature(aspect, IProgramElement.Kind.POINTCUT, abst); assertNotNull(abstNode); - assertEquals(abstNode.getName(), abst); + assertEquals(abstNode.toLabelString(), abst); } public void testAdvice() { IProgramElement node = (IProgramElement)model.getRoot(); assertNotNull(node); - IProgramElement aspect = AsmManager.getDefault().getModel().findNodeForType(null, "AdviceNamingCoverage"); + IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "AdviceNamingCoverage"); assertNotNull(aspect); String anon = "before(): "; - IProgramElement anonNode = model.findNode(aspect, IProgramElement.Kind.ADVICE, anon); + IProgramElement anonNode = model.findElementForLabel(aspect, IProgramElement.Kind.ADVICE, anon); assertNotNull(anonNode); - assertEquals(anonNode.getName(), anon); + assertEquals(anonNode.toLabelString(), anon); String named = "before(): named.."; - IProgramElement namedNode = model.findNode(aspect, IProgramElement.Kind.ADVICE, named); + IProgramElement namedNode = model.findElementForLabel(aspect, IProgramElement.Kind.ADVICE, named); assertNotNull(namedNode); - assertEquals(namedNode.getName(), named); + assertEquals(namedNode.toLabelString(), named); String namedWithOneArg = "around(int): namedWithOneArg.."; - IProgramElement namedWithOneArgNode = model.findNode(aspect, IProgramElement.Kind.ADVICE, namedWithOneArg); + IProgramElement namedWithOneArgNode = model.findElementForLabel(aspect, IProgramElement.Kind.ADVICE, namedWithOneArg); assertNotNull(namedWithOneArgNode); - assertEquals(namedWithOneArgNode.getName(), namedWithOneArg); + assertEquals(namedWithOneArgNode.toLabelString(), namedWithOneArg); String afterReturning = "afterReturning(int, int): namedWithArgs.."; - IProgramElement afterReturningNode = model.findNode(aspect, IProgramElement.Kind.ADVICE, afterReturning); + IProgramElement afterReturningNode = model.findElementForLabel(aspect, IProgramElement.Kind.ADVICE, afterReturning); assertNotNull(afterReturningNode); - assertEquals(afterReturningNode.getName(), afterReturning); + assertEquals(afterReturningNode.toLabelString(), afterReturning); String around = "around(int): namedWithOneArg.."; - IProgramElement aroundNode = model.findNode(aspect, IProgramElement.Kind.ADVICE, around); + IProgramElement aroundNode = model.findElementForLabel(aspect, IProgramElement.Kind.ADVICE, around); assertNotNull(aroundNode); - assertEquals(aroundNode.getName(), around); + assertEquals(aroundNode.toLabelString(), around); String compAnon = "before(int): .."; - IProgramElement compAnonNode = model.findNode(aspect, IProgramElement.Kind.ADVICE, compAnon); + IProgramElement compAnonNode = model.findElementForLabel(aspect, IProgramElement.Kind.ADVICE, compAnon); assertNotNull(compAnonNode); - assertEquals(compAnonNode.getName(), compAnon); + assertEquals(compAnonNode.toLabelString(), compAnon); String compNamed = "before(int): named().."; - IProgramElement compNamedNode = model.findNode(aspect, IProgramElement.Kind.ADVICE, compNamed); + IProgramElement compNamedNode = model.findElementForLabel(aspect, IProgramElement.Kind.ADVICE, compNamed); assertNotNull(compNamedNode); - assertEquals(compNamedNode.getName(), compNamed); + assertEquals(compNamedNode.toLabelString(), compNamed); } protected void setUp() throws Exception { super.setUp("examples"); assertTrue("build success", doSynchronousBuild(CONFIG_FILE_PATH)); - model = AsmManager.getDefault().getModel(); + model = AsmManager.getDefault().getHierarchy(); } protected void tearDown() throws Exception { diff --git a/ajde/testsrc/org/aspectj/ajde/AsmRelationshipsTest.java b/ajde/testsrc/org/aspectj/ajde/AsmRelationshipsTest.java index f2a005670..db82a96cf 100644 --- a/ajde/testsrc/org/aspectj/ajde/AsmRelationshipsTest.java +++ b/ajde/testsrc/org/aspectj/ajde/AsmRelationshipsTest.java @@ -26,9 +26,11 @@ public class AsmRelationshipsTest extends AjdeTestCase { super(name); } -// public void testInterTypeDeclarations() { -// checkMapping("InterTypeDecCoverage", "Point", "Point.xxx:", "xxx", "declared on", "aspect declarations"); -// } + 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"); + + } public void testAdvice() { checkMapping("AdvisesRelationshipCoverage", "Point", "before(): methodExecutionP..", "setX(int)", "advises", "advised by"); @@ -37,31 +39,34 @@ public class AsmRelationshipsTest extends AjdeTestCase { } private void checkUniDirectionalMapping(String fromType, String toType, String from, String to, String relName) { - IProgramElement aspect = AsmManager.getDefault().getModel().findNodeForType(null, fromType); + IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, fromType); assertNotNull(aspect); String beforeExec = from; - IProgramElement beforeExecNode = manager.getModel().findNode(aspect, IProgramElement.Kind.ADVICE, beforeExec); + IProgramElement beforeExecNode = manager.getHierarchy().findElementForLabel(aspect, IProgramElement.Kind.ADVICE, beforeExec); assertNotNull(beforeExecNode); - IRelationship rel = manager.getMapper().get(beforeExecNode, IRelationship.Kind.ADVICE, relName); - assertEquals(((IProgramElement)rel.getTargets().get(0)).getName(), to); + IRelationship rel = manager.getRelationshipMap().get(beforeExecNode, IRelationship.Kind.ADVICE, relName); + String handle = (String)rel.getTargets().get(0); + assertEquals(manager.getHierarchy().findElementForHandle(handle).toLabelString(), to); } private void checkMapping(String fromType, String toType, String from, String to, String forwardRelName, String backRelName) { - IProgramElement aspect = AsmManager.getDefault().getModel().findNodeForType(null, fromType); + IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, fromType); assertNotNull(aspect); String beforeExec = from; - IProgramElement beforeExecNode = manager.getModel().findNode(aspect, IProgramElement.Kind.ADVICE, beforeExec); + IProgramElement beforeExecNode = manager.getHierarchy().findElementForLabel(aspect, IProgramElement.Kind.ADVICE, beforeExec); assertNotNull(beforeExecNode); - IRelationship rel = manager.getMapper().get(beforeExecNode, IRelationship.Kind.ADVICE, forwardRelName); - assertEquals(((IProgramElement)rel.getTargets().get(0)).getName(), to); + IRelationship rel = manager.getRelationshipMap().get(beforeExecNode, IRelationship.Kind.ADVICE, forwardRelName); + String handle = (String)rel.getTargets().get(0); + assertEquals(manager.getHierarchy().findElementForHandle(handle).toString(), to); - IProgramElement clazz = AsmManager.getDefault().getModel().findNodeForType(null, toType); + IProgramElement clazz = AsmManager.getDefault().getHierarchy().findElementForType(null, toType); assertNotNull(clazz); String set = to; - IProgramElement setNode = manager.getModel().findNode(clazz, IProgramElement.Kind.METHOD, set); + IProgramElement setNode = manager.getHierarchy().findElementForLabel(clazz, IProgramElement.Kind.METHOD, set); assertNotNull(setNode); - IRelationship rel2 = manager.getMapper().get(setNode, IRelationship.Kind.ADVICE, backRelName); - assertEquals(((IProgramElement)rel2.getTargets().get(0)).getName(), from); + IRelationship rel2 = manager.getRelationshipMap().get(setNode, IRelationship.Kind.ADVICE, backRelName); + String handle2 = (String)rel2.getTargets().get(0); + assertEquals(manager.getHierarchy().findElementForHandle(handle2).toString(), from); } protected void setUp() throws Exception { diff --git a/ajde/testsrc/org/aspectj/ajde/NullIdeManager.java b/ajde/testsrc/org/aspectj/ajde/NullIdeManager.java index 504907666..c535cff2c 100644 --- a/ajde/testsrc/org/aspectj/ajde/NullIdeManager.java +++ b/ajde/testsrc/org/aspectj/ajde/NullIdeManager.java @@ -33,6 +33,7 @@ public class NullIdeManager { private static NullIdeManager ideManager = null; private NullIdeTaskListManager taskListManager = null; private NullIdeProperties projectProperties = null; + private boolean initialized = false; public static NullIdeManager getIdeManager() { if ( null == ideManager ) { @@ -49,7 +50,6 @@ public class NullIdeManager { EditorAdapter ajdeEditor = new NullIdeEditorAdapter(); IdeUIAdapter uiAdapter = new NullIdeUIAdapter(); JFrame nullFrame = new JFrame(); - //configurationManager.setConfigFiles(getConfigFilesList(configFiles)); AjdeUIManager.getDefault().init( ajdeEditor, @@ -62,8 +62,9 @@ public class NullIdeManager { new NullIdeProgressMonitor(), new NullIdeErrorHandler(), true); - //Ajde.getDefault().enableLogging( System.out ); + initialized = true; } catch (Throwable t) { + initialized = false; t.printStackTrace(); Ajde.getDefault().getErrorHandler().handleError( "Null IDE failed to initialize.", @@ -83,4 +84,8 @@ public class NullIdeManager { projectProperties = properties; } + public boolean isInitialized() { + return initialized && AjdeUIManager.getDefault().isInitialized(); + } + } diff --git a/ajde/testsrc/org/aspectj/ajde/StructureModelRegressionTest.java b/ajde/testsrc/org/aspectj/ajde/StructureModelRegressionTest.java index cae44a403..70ffc8f30 100644 --- a/ajde/testsrc/org/aspectj/ajde/StructureModelRegressionTest.java +++ b/ajde/testsrc/org/aspectj/ajde/StructureModelRegressionTest.java @@ -45,11 +45,11 @@ public class StructureModelRegressionTest extends AjdeTestCase { public boolean verifyAgainstSavedModel(String lstFile) { File modelFile = new File(genStructureModelExternFilePath(lstFile)); - AspectJModel model = getModelForFile(lstFile); + IHierarchy model = getModelForFile(lstFile); if (modelFile.exists()) { Ajde.getDefault().getStructureModelManager().readStructureModel(lstFile); - AspectJModel savedModel = Ajde.getDefault().getStructureModelManager().getModel(); + IHierarchy savedModel = Ajde.getDefault().getStructureModelManager().getHierarchy(); // AMC This test will not pass as written until IProgramElement defines // equals. The equals loic is commented out in the IProgramElement // class - adding it back in could have unforeseen system-wide @@ -89,7 +89,7 @@ public class StructureModelRegressionTest extends AjdeTestCase { return equal; } - private AspectJModel getModelForFile(String lstFile) { + private IHierarchy getModelForFile(String lstFile) { Ajde.getDefault().getConfigurationManager().setActiveConfigFile(lstFile); Ajde.getDefault().getBuildManager().build(); // was buildStructure... while(!testerBuildListener.getBuildFinished()) { @@ -97,7 +97,7 @@ public class StructureModelRegressionTest extends AjdeTestCase { Thread.sleep(300); } catch (InterruptedException ie) { } } - return Ajde.getDefault().getStructureModelManager().getModel(); + return Ajde.getDefault().getStructureModelManager().getHierarchy(); } protected void setUp() throws Exception { @@ -106,7 +106,7 @@ public class StructureModelRegressionTest extends AjdeTestCase { } public void testModelExists() { - assertTrue(Ajde.getDefault().getStructureModelManager().getModel() != null); + assertTrue(Ajde.getDefault().getStructureModelManager().getHierarchy() != null); } protected void tearDown() throws Exception { diff --git a/ajde/testsrc/org/aspectj/ajde/StructureModelTest.java b/ajde/testsrc/org/aspectj/ajde/StructureModelTest.java index 674895e41..4332cf7d5 100644 --- a/ajde/testsrc/org/aspectj/ajde/StructureModelTest.java +++ b/ajde/testsrc/org/aspectj/ajde/StructureModelTest.java @@ -77,8 +77,8 @@ public class StructureModelTest extends AjdeTestCase { public void testRootForSourceFile() throws IOException { File testFile = openFile("figures-coverage/figures/Figure.java"); - IProgramElement node = Ajde.getDefault().getStructureModelManager().getModel().findRootNodeForSourceFile( - testFile.getCanonicalPath()); + IProgramElement node = Ajde.getDefault().getStructureModelManager().getHierarchy().findElementForSourceFile( + testFile.getAbsolutePath()); assertTrue("find result", node != null) ; IProgramElement pNode = (IProgramElement)node; String child = ((IProgramElement)pNode.getChildren().get(0)).getName(); @@ -87,23 +87,18 @@ public class StructureModelTest extends AjdeTestCase { public void testPointcutName() throws IOException { File testFile = openFile("figures-coverage/figures/Main.java"); - IProgramElement node = Ajde.getDefault().getStructureModelManager().getModel().findRootNodeForSourceFile( - testFile.getCanonicalPath()); + IProgramElement node = Ajde.getDefault().getStructureModelManager().getHierarchy().findElementForSourceFile( + testFile.getAbsolutePath()); assertTrue("find result", node != null) ; IProgramElement pNode = (IProgramElement)((IProgramElement)node).getChildren().get(1); IProgramElement pointcut = (IProgramElement)pNode.getChildren().get(0); assertTrue("kind", pointcut.getKind().equals(IProgramElement.Kind.POINTCUT)); - assertTrue("found node: " + pointcut.getName(), pointcut.getName().equals("testptct()")); - } - - public void testDeclare() { - - + assertTrue("found node: " + pointcut.getName(), pointcut.toLabelString().equals("testptct()")); } public void testFileNodeFind() throws IOException { File testFile = openFile("figures-coverage/figures/Main.java"); - IProgramElement node = Ajde.getDefault().getStructureModelManager().getModel().findNodeForSourceLine( + IProgramElement node = Ajde.getDefault().getStructureModelManager().getHierarchy().findElementForSourceLine( testFile.getCanonicalPath(), 1); assertTrue("find result", node != null) ; assertEquals("find result has children", 2, node.getChildren().size()) ; @@ -115,11 +110,11 @@ public class StructureModelTest extends AjdeTestCase { * @todo add negative test to make sure things that aren't runnable aren't annotated */ public void testMainClassNodeInfo() throws IOException { - AspectJModel model = Ajde.getDefault().getStructureModelManager().getModel(); + IHierarchy model = Ajde.getDefault().getStructureModelManager().getHierarchy(); assertTrue("model exists", model != null); assertTrue("root exists", model.getRoot() != null); File testFile = openFile("figures-coverage/figures/Main.java"); - IProgramElement node = model.findNodeForSourceLine(testFile.getCanonicalPath(), 11); + IProgramElement node = model.findElementForSourceLine(testFile.getCanonicalPath(), 11); assertTrue("find result", node != null); IProgramElement pNode = (IProgramElement)((IProgramElement)node).getParent(); if (null == pNode) { @@ -132,7 +127,7 @@ public class StructureModelTest extends AjdeTestCase { * Integrity could be checked somewhere in the API. */ public void testModelIntegrity() { - IProgramElement modelRoot = Ajde.getDefault().getStructureModelManager().getModel().getRoot(); + IProgramElement modelRoot = Ajde.getDefault().getStructureModelManager().getHierarchy().getRoot(); assertTrue("root exists", modelRoot != null); try { @@ -162,7 +157,7 @@ public class StructureModelTest extends AjdeTestCase { } } }; - Ajde.getDefault().getStructureModelManager().getModel().getRoot().walk(walker); + Ajde.getDefault().getStructureModelManager().getHierarchy().getRoot().walk(walker); } protected void setUp() throws Exception { diff --git a/ajde/testsrc/org/aspectj/ajde/ui/StructureViewManagerTest.java b/ajde/testsrc/org/aspectj/ajde/ui/StructureViewManagerTest.java index 99ff905f4..7977cc663 100644 --- a/ajde/testsrc/org/aspectj/ajde/ui/StructureViewManagerTest.java +++ b/ajde/testsrc/org/aspectj/ajde/ui/StructureViewManagerTest.java @@ -50,7 +50,7 @@ public class StructureViewManagerTest extends AjdeTestCase { } public void testModelExists() { - assertTrue(Ajde.getDefault().getStructureModelManager().getModel() != null); + assertTrue(Ajde.getDefault().getStructureModelManager().getHierarchy() != null); } public void testNotificationAfterConfigFileChange() { @@ -66,7 +66,7 @@ public class StructureViewManagerTest extends AjdeTestCase { assertTrue( "no structure", currentView.getRootNode().getStructureNode().getChildren().get(0) - == AspectJModel.NO_STRUCTURE + == IHierarchy.NO_STRUCTURE ); } @@ -83,17 +83,17 @@ public class StructureViewManagerTest extends AjdeTestCase { assertTrue("notified", renderer.getHasBeenNotified()); // AMC should this be currentView, or should we recreate the root... do the latter //IProgramElement n = currentView.getRootNode().getIProgramElement(); - IProgramElement n = Ajde.getDefault().getStructureModelManager().getModel().getRoot(); + IProgramElement n = Ajde.getDefault().getStructureModelManager().getHierarchy().getRoot(); assertTrue( "no structure", //currentView.getRootNode().getIProgramElement().getChildren().get(0) - n == AspectJModel.NO_STRUCTURE + n == IHierarchy.NO_STRUCTURE ); } public void testModelIntegrity() { doSynchronousBuild(CONFIG_FILE_PATH); - IProgramElement modelRoot = Ajde.getDefault().getStructureModelManager().getModel().getRoot(); + IProgramElement modelRoot = Ajde.getDefault().getStructureModelManager().getHierarchy().getRoot(); assertTrue("root exists", modelRoot != null); try { @@ -125,7 +125,7 @@ public class StructureViewManagerTest extends AjdeTestCase { assertTrue( "no structure", currentView.getRootNode().getStructureNode() - == AspectJModel.NO_STRUCTURE + == IHierarchy.NO_STRUCTURE ); } diff --git a/asm/src/org/aspectj/asm/AsmManager.java b/asm/src/org/aspectj/asm/AsmManager.java index b090abfcf..3fcb353e0 100644 --- a/asm/src/org/aspectj/asm/AsmManager.java +++ b/asm/src/org/aspectj/asm/AsmManager.java @@ -1,6 +1,5 @@ /* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). + * Copyright (c) 2003 Contributors. * All rights reserved. * This program and the accompanying materials are made available * under the terms of the Common Public License v1.0 @@ -8,7 +7,7 @@ * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: - * Xerox/PARC initial implementation + * Mik Kersten initial implementation * ******************************************************************/ @@ -29,24 +28,32 @@ public class AsmManager { */ private static AsmManager INSTANCE = new AsmManager(); private boolean shouldSaveModel = true; - protected AspectJModel model = new AspectJModel(); + protected IHierarchy hierarchy; private List structureListeners = new ArrayList(); - private IRelationshipMapper mapper; + private IRelationshipMap mapper; protected AsmManager() { + hierarchy = new AspectJElementHierarchy(); List relationships = new ArrayList(); -// relationships.add(ADVICE); - mapper = new RelationshipMapper(); + mapper = new RelationshipMap(hierarchy); } - public AspectJModel getModel() { - return model; + public IHierarchy getHierarchy() { + return hierarchy; + } + + public static AsmManager getDefault() { + return INSTANCE; + } + + public IRelationshipMap getRelationshipMap() { + return mapper; } public void fireModelUpdated() { notifyListeners(); - if (model.getConfigFile() != null) { - writeStructureModel(model.getConfigFile()); + if (hierarchy.getConfigFile() != null) { + writeStructureModel(hierarchy.getConfigFile()); } } @@ -105,17 +112,17 @@ public class AsmManager { // } // } - public void addListener(IStructureModelListener listener) { + public void addListener(IHierarchyListener listener) { structureListeners.add(listener); } - public void removeStructureListener(IStructureModelListener listener) { + public void removeStructureListener(IHierarchyListener listener) { structureListeners.remove(listener); } private void notifyListeners() { for (Iterator it = structureListeners.iterator(); it.hasNext(); ) { - ((IStructureModelListener)it.next()).containmentHierarchyUpdated(model); + ((IHierarchyListener)it.next()).elementsUpdated(hierarchy); } } @@ -126,7 +133,7 @@ public class AsmManager { try { String filePath = genExternFilePath(configFilePath); ObjectOutputStream s = new ObjectOutputStream(new FileOutputStream(filePath)); - s.writeObject(model); + s.writeObject(hierarchy); s.flush(); } catch (Exception e) { // ignore @@ -140,16 +147,16 @@ public class AsmManager { public void readStructureModel(String configFilePath) { try { if (configFilePath == null) { - model.setRoot(AspectJModel.NO_STRUCTURE); + hierarchy.setRoot(IHierarchy.NO_STRUCTURE); } else { String filePath = genExternFilePath(configFilePath); FileInputStream in = new FileInputStream(filePath); ObjectInputStream s = new ObjectInputStream(in); - model = (AspectJModel)s.readObject(); + hierarchy = (AspectJElementHierarchy)s.readObject(); } } catch (Exception e) { //System.err.println("AJDE Message: could not read structure model: " + e); - model.setRoot(AspectJModel.NO_STRUCTURE); + hierarchy.setRoot(IHierarchy.NO_STRUCTURE); } finally { notifyListeners(); } @@ -162,14 +169,5 @@ public class AsmManager { public void setShouldSaveModel(boolean shouldSaveModel) { this.shouldSaveModel = shouldSaveModel; } - - public static AsmManager getDefault() { - return INSTANCE; - } - - public IRelationshipMapper getMapper() { - return mapper; - } - } diff --git a/asm/src/org/aspectj/asm/HierarchyWalker.java b/asm/src/org/aspectj/asm/HierarchyWalker.java index cac375482..2e2c08df3 100644 --- a/asm/src/org/aspectj/asm/HierarchyWalker.java +++ b/asm/src/org/aspectj/asm/HierarchyWalker.java @@ -1,6 +1,5 @@ /* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). + * Copyright (c) 2003 Contributors. * All rights reserved. * This program and the accompanying materials are made available * under the terms of the Common Public License v1.0 @@ -8,25 +7,28 @@ * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: - * Xerox/PARC initial implementation + * Mik Kersten initial implementation * ******************************************************************/ package org.aspectj.asm; +import org.aspectj.asm.internal.*; +import org.aspectj.asm.internal.*; + /** * @author Mik Kersten */ public abstract class HierarchyWalker { - private AspectJModel model; + private IHierarchy hierarchy; public HierarchyWalker() { super(); } - public HierarchyWalker(AspectJModel model) { - this.model = model; + public HierarchyWalker(IHierarchy hierarchy) { + this.hierarchy = hierarchy; } protected void preProcess(IProgramElement node) { } diff --git a/asm/src/org/aspectj/asm/IHierarchy.java b/asm/src/org/aspectj/asm/IHierarchy.java new file mode 100644 index 000000000..34816ee12 --- /dev/null +++ b/asm/src/org/aspectj/asm/IHierarchy.java @@ -0,0 +1,92 @@ +/* ******************************************************************* + * 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.*; + +import org.aspectj.asm.internal.ProgramElement; +import org.aspectj.bridge.ISourceLocation; + +/** + * @author Mik Kersten + */ +public interface IHierarchy extends Serializable { + public static final IProgramElement NO_STRUCTURE = + new ProgramElement( + "", + IProgramElement.Kind.ERROR, + null); + + public IProgramElement getElement(String handle); + public IProgramElement getRoot(); + public void setRoot(IProgramElement root); + public void addToFileMap(Object key, Object value); + public void setFileMap(HashMap fileMap); + public Object findInFileMap(Object key); + public Set getFileMapEntrySet(); + public boolean isValid(); + + /** + * @return null if not found + */ + public IProgramElement findElementForHandle(String handle); + + /** + * Returns the first match + * + * @param parent + * @param kind not null + * @return null if not found + */ + public IProgramElement findElementForSignature( + IProgramElement parent, + IProgramElement.Kind kind, + String signature); + + /** + * Returns the first match + * + * @param parent + * @param kind not null + * @return null if not found + */ + public IProgramElement findElementForLabel( + IProgramElement parent, + IProgramElement.Kind kind, + String label); + + /** + * @param packageName if null default package is searched + * @param className can't be null + */ + public IProgramElement findElementForType(String packageName, String typeName); + + /** + * @param sourceFilePath modified to '/' delimited path for consistency + * @return a new structure node for the file if it was not found in the model + */ + public IProgramElement findElementForSourceFile(String sourceFile); + + /** + * TODO: discriminate columns + */ + public IProgramElement findElementForSourceLine(ISourceLocation location); + + /** + * Never returns null + * + * @param sourceFilePath canonicalized path for consistency + * @param lineNumber if 0 or 1 the corresponding file node will be returned + * @return a new structure node for the file if it was not found in the model + */ + public IProgramElement findElementForSourceLine(String sourceFilePath, int lineNumber); + + public String getConfigFile(); + + public void setConfigFile(String configFile); +} \ No newline at end of file diff --git a/asm/src/org/aspectj/asm/IStructureModelListener.java b/asm/src/org/aspectj/asm/IHierarchyListener.java similarity index 66% rename from asm/src/org/aspectj/asm/IStructureModelListener.java rename to asm/src/org/aspectj/asm/IHierarchyListener.java index 6e2879ee1..96381934f 100644 --- a/asm/src/org/aspectj/asm/IStructureModelListener.java +++ b/asm/src/org/aspectj/asm/IHierarchyListener.java @@ -1,6 +1,5 @@ /* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). + * Copyright (c) 2003 Contributors. * All rights reserved. * This program and the accompanying materials are made available * under the terms of the Common Public License v1.0 @@ -8,7 +7,7 @@ * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: - * Xerox/PARC initial implementation + * Mik Kersten initial implementation * ******************************************************************/ @@ -16,12 +15,14 @@ package org.aspectj.asm; import java.util.EventListener; +import org.aspectj.asm.internal.*; + /** * Compiler listeners get notified of structure model update events. * * @author Mik Kersten */ -public interface IStructureModelListener extends EventListener { +public interface IHierarchyListener extends EventListener { - public void containmentHierarchyUpdated(AspectJModel rootNode); + public void elementsUpdated(IHierarchy rootNode); } diff --git a/asm/src/org/aspectj/asm/IProgramElement.java b/asm/src/org/aspectj/asm/IProgramElement.java index ced44fa7e..42a83d2b3 100644 --- a/asm/src/org/aspectj/asm/IProgramElement.java +++ b/asm/src/org/aspectj/asm/IProgramElement.java @@ -1,11 +1,13 @@ /* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). + * Copyright (c) 2003 Contributors. * All rights reserved. * 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 + * + * Contributors: + * Mik Kersten initial implementation * ******************************************************************/ package org.aspectj.asm; @@ -22,6 +24,8 @@ import org.aspectj.bridge.*; */ public interface IProgramElement extends Serializable { + public static final String ID_DELIM = "|"; + public List/*IProgramElement*/ getChildren(); public void setChildren(List children); @@ -32,6 +36,9 @@ public interface IProgramElement extends Serializable { public String getName(); public void setName(String name); + + public String getDetails(); + public void setDetails(String details); public IProgramElement.Kind getKind(); public void setKind(Kind kind); @@ -47,8 +54,7 @@ public interface IProgramElement extends Serializable { public void setReturnType(String returnType); public String getReturnType(); - public String getFullSignature(); - public void setFullSignature(String string); + public String toSignatureString(); public void setRunnable(boolean value); public boolean isRunnable(); @@ -66,8 +72,25 @@ public interface IProgramElement extends Serializable { public void setSourceLocation(ISourceLocation sourceLocation); public String toString(); + + /** + * Includes name, parameter types (if any) and details (if any). + */ + public String toLabelString(); + + public List getParameterTypes(); + public void setParameterTypes(List list); + + public List getParameterNames(); + public void setParameterNames(List list); - // public String getHandle() TODO: check IJavaElement + /** + * The format of the string handle is not specified, but is stable across + * compilation sessions. + * + * @return a string representtaion of this element + */ + public String getHandleIdentifier(); /** * @return a string representation of this node and all of its children (recursive) @@ -160,6 +183,7 @@ public interface IProgramElement extends Serializable { public static final Kind INTER_TYPE_FIELD = new Kind("inter-type field"); public static final Kind INTER_TYPE_METHOD = new Kind("inter-type method"); public static final Kind INTER_TYPE_CONSTRUCTOR = new Kind("inter-type constructor"); + public static final Kind INTER_TYPE_PARENT = new Kind("inter-type parent"); public static final Kind CONSTRUCTOR = new Kind("constructor"); public static final Kind METHOD = new Kind("method"); public static final Kind FIELD = new Kind("field"); @@ -170,14 +194,39 @@ public interface IProgramElement extends Serializable { public static final Kind DECLARE_ERROR = new Kind("declare error"); public static final Kind DECLARE_SOFT = new Kind("declare soft"); public static final Kind DECLARE_PRECEDENCE= new Kind("declare precedence"); - public static final Kind CODE = new Kind("decBodyElement"); + public static final Kind CODE = new Kind("code"); public static final Kind ERROR = new Kind("error"); - public static final Kind[] ALL = { PROJECT, PACKAGE, FILE, FILE_JAVA, - FILE_ASPECTJ, FILE_LST, CLASS, INTERFACE, ASPECT, - INITIALIZER, INTER_TYPE_FIELD, INTER_TYPE_METHOD, INTER_TYPE_CONSTRUCTOR, - CONSTRUCTOR, METHOD, FIELD, POINTCUT, ADVICE, DECLARE_PARENTS, - DECLARE_WARNING, DECLARE_ERROR, DECLARE_SOFT, CODE, ERROR }; + + + public static final Kind[] ALL = + { + PROJECT, + PACKAGE, + FILE, + FILE_JAVA, + FILE_ASPECTJ, + FILE_LST, + CLASS, + INTERFACE, + ASPECT, + INITIALIZER, + INTER_TYPE_FIELD, + INTER_TYPE_METHOD, + INTER_TYPE_CONSTRUCTOR, + INTER_TYPE_PARENT, + CONSTRUCTOR, + METHOD, + FIELD, + POINTCUT, + ADVICE, + DECLARE_PARENTS, + DECLARE_WARNING, + DECLARE_ERROR, + DECLARE_SOFT, + DECLARE_PRECEDENCE, + CODE, + ERROR }; public static Kind getKindForString(String kindString) { for (int i = 0; i < ALL.length; i++) { diff --git a/asm/src/org/aspectj/asm/IRelationship.java b/asm/src/org/aspectj/asm/IRelationship.java index b6377e832..9edb5c0e6 100644 --- a/asm/src/org/aspectj/asm/IRelationship.java +++ b/asm/src/org/aspectj/asm/IRelationship.java @@ -1,6 +1,5 @@ /* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). + * Copyright (c) 2003 Contributors. * All rights reserved. * This program and the accompanying materials are made available * under the terms of the Common Public License v1.0 @@ -8,7 +7,7 @@ * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: - * Xerox/PARC initial implementation + * Mik Kersten initial implementation * ******************************************************************/ @@ -24,9 +23,9 @@ public interface IRelationship extends Serializable { public String getName(); - public List getTargets(); + public List/*String*/ getTargets(); - public IProgramElement getSource(); + public String getSourceHandle(); public Kind getKind(); @@ -37,6 +36,7 @@ public interface IRelationship extends Serializable { public static final Kind ADVICE = new Kind("advice"); public static final Kind DECLARE = new Kind("declare"); + public static final Kind DECLARE_INTER_TYPE = new Kind("inter-type declaration"); public static final Kind[] ALL = { ADVICE, DECLARE }; private final String name; diff --git a/asm/src/org/aspectj/asm/IRelationshipMapper.java b/asm/src/org/aspectj/asm/IRelationshipMap.java similarity index 53% rename from asm/src/org/aspectj/asm/IRelationshipMapper.java rename to asm/src/org/aspectj/asm/IRelationshipMap.java index 747347222..b5a12e534 100644 --- a/asm/src/org/aspectj/asm/IRelationshipMapper.java +++ b/asm/src/org/aspectj/asm/IRelationshipMap.java @@ -18,18 +18,29 @@ import java.util.List; import org.aspectj.asm.IRelationship.Kind; /** - * Maps from a program element to a list of relationships between that element + * Maps from a program element handles 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. * + * The elemetns can be stored and looked up as IProgramElement(s), in which cases the + * element corresponding to the handle is looked up in the containment hierarchy. + * + * put/get methods taking IProgramElement as a parameter are for convenience only. + * They work identically to calling their counterparts with IProgramElement.getIdentifierHandle() + * * @author Mik Kersten */ -public interface IRelationshipMapper extends Serializable { +public interface IRelationshipMap extends Serializable { /** * @return an empty list if the element is not found. */ - public List get(IProgramElement source); + public List/*IRelationship*/ get(IProgramElement source); + + /** + * @return an empty list if the element is not found. + */ + public List/*IRelationship*/ get(String handle); /** * Return a relationship matching the kind and name for the given element. @@ -37,12 +48,21 @@ public interface IRelationshipMapper extends Serializable { * @return null if the relationship is not found. */ public IRelationship get(IProgramElement source, IRelationship.Kind kind, String relationshipName); - - - public List/*IRelationship*/ get(String handle); + + /** + * Return a relationship matching the kind and name for the given element. + * Creates the relationship if not found. + * + * @return null if the relationship is not found. + */ + public IRelationship get(String source, IRelationship.Kind kind, String relationshipName); public void put(IProgramElement source, IRelationship relationship); + public void put(String handle, IRelationship relationship); + + public void remove(String handle, IRelationship relationship); + public void removeAll(String source); } diff --git a/asm/src/org/aspectj/asm/AspectJModel.java b/asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java similarity index 68% rename from asm/src/org/aspectj/asm/AspectJModel.java rename to asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java index e8c723edc..6a523da11 100644 --- a/asm/src/org/aspectj/asm/AspectJModel.java +++ b/asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java @@ -1,6 +1,5 @@ /* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). + * Copyright (c) 2003 Contributors. * All rights reserved. * This program and the accompanying materials are made available * under the terms of the Common Public License v1.0 @@ -8,30 +7,29 @@ * http://www.eclipse.org/legal/cpl-v10.html * * Contributors: - * Xerox/PARC initial implementation + * Mik Kersten initial implementation * ******************************************************************/ -package org.aspectj.asm; +package org.aspectj.asm.internal; import java.io.*; import java.util.*; -import org.aspectj.asm.internal.ProgramElement; +import org.aspectj.asm.*; +import org.aspectj.asm.IProgramElement.Kind; import org.aspectj.bridge.*; /** * @author Mik Kersten */ -public class AspectJModel implements Serializable { +public class AspectJElementHierarchy implements IHierarchy { protected IProgramElement root = null; protected String configFile = null; private Map fileMap = null; - public static final IProgramElement NO_STRUCTURE = new ProgramElement("", IProgramElement.Kind.ERROR, null); - public IProgramElement getElement(String handle) { throw new RuntimeException("unimplemented"); } @@ -64,43 +62,49 @@ public class AspectJModel implements Serializable { public boolean isValid() { return root != null && fileMap != null; } - - + /** * Returns the first match * * @param parent * @param kind not null - * @param decErrLabel * @return null if not found */ - public IProgramElement findNode(IProgramElement parent, IProgramElement.Kind kind, String name) { + public IProgramElement findElementForSignature(IProgramElement parent, IProgramElement.Kind kind, String signature) { for (Iterator it = parent.getChildren().iterator(); it.hasNext(); ) { IProgramElement node = (IProgramElement)it.next(); - if (node.getKind().equals(kind) - && name.equals(node.getName())) { + if (node.getKind() == kind && signature.equals(node.toSignatureString())) { return node; } else { - IProgramElement childSearch = findNode(node, kind, name); + IProgramElement childSearch = findElementForSignature(node, kind, signature); if (childSearch != null) return childSearch; } } return null; } - - /** - * - * @param signatureKey PackageName.TypeName.Signature.SourceLine.SourceColumn - */ - public IProgramElement findNodeForSignatureKey(String signatureKey) { - throw new RuntimeException("unimplemented"); - } - + + public IProgramElement findElementForLabel( + IProgramElement parent, + IProgramElement.Kind kind, + String label) { + + for (Iterator it = parent.getChildren().iterator(); it.hasNext(); ) { + IProgramElement node = (IProgramElement)it.next(); + if (node.getKind() == kind && label.equals(node.toLabelString())) { + return node; + } else { + IProgramElement childSearch = findElementForSignature(node, kind, label); + if (childSearch != null) return childSearch; + } + } + return null; + } + /** * @param packageName if null default package is searched * @param className can't be null */ - public IProgramElement findNodeForType(String packageName, String typeName) { + public IProgramElement findElementForType(String packageName, String typeName) { IProgramElement packageNode = null; if (packageName == null) { packageNode = root; @@ -153,10 +157,10 @@ public class AspectJModel implements Serializable { * @param sourceFilePath modified to '/' delimited path for consistency * @return a new structure node for the file if it was not found in the model */ - public IProgramElement findRootNodeForSourceFile(String sourceFile) { + public IProgramElement findElementForSourceFile(String sourceFile) { try { if (!isValid() || sourceFile == null) { - return AspectJModel.NO_STRUCTURE; + return IHierarchy.NO_STRUCTURE; } else { String correctedPath = new File(sourceFile).getCanonicalPath();//.replace('\\', '/'); //StructureNode node = (StructureNode)getFileMap().get(correctedPath);//findFileNode(filePath, model); @@ -168,15 +172,19 @@ public class AspectJModel implements Serializable { } } } catch (Exception e) { - return AspectJModel.NO_STRUCTURE; + return IHierarchy.NO_STRUCTURE; } } /** * TODO: discriminate columns */ - public IProgramElement findNodeForSourceLine(ISourceLocation location) { - return findNodeForSourceLine(location.getSourceFile().getAbsolutePath(), location.getLine()); + public IProgramElement findElementForSourceLine(ISourceLocation location) { + try { + return findElementForSourceLine(location.getSourceFile().getCanonicalPath(), location.getLine()); + } catch (Exception e) { + return null; + } } /** @@ -186,7 +194,7 @@ public class AspectJModel implements Serializable { * @param lineNumber if 0 or 1 the corresponding file node will be returned * @return a new structure node for the file if it was not found in the model */ - public IProgramElement findNodeForSourceLine(String sourceFilePath, int lineNumber) { + public IProgramElement findElementForSourceLine(String sourceFilePath, int lineNumber) { IProgramElement node = findNodeForSourceLineHelper(root, sourceFilePath, lineNumber); if (node != null) { return node; @@ -229,8 +237,7 @@ public class AspectJModel implements Serializable { // System.err.println("====\n1: " + // sourceFilePath + "\n2: " + // node.getSourceLocation().getSourceFile().getCanonicalPath().equals(sourceFilePath) -// ); - +// ); return node != null && node.getSourceLocation() != null && node.getSourceLocation().getSourceFile().getCanonicalPath().equals(sourceFilePath) @@ -238,8 +245,7 @@ public class AspectJModel implements Serializable { && node.getSourceLocation().getEndLine() >= lineNumber) || (lineNumber <= 1 - && node instanceof IProgramElement - && ((IProgramElement)node).getKind().isSourceFileKind()) + && node.getKind().isSourceFileKind()) ); } catch (IOException ioe) { return false; @@ -261,5 +267,43 @@ public class AspectJModel implements Serializable { public void setConfigFile(String configFile) { this.configFile = configFile; } + + // TODO: optimize this lookup + public IProgramElement findElementForHandle(String handle) { + StringTokenizer st = new StringTokenizer(handle, IProgramElement.ID_DELIM); + String file = st.nextToken(); + int line = new Integer(st.nextToken()).intValue(); + int col = new Integer(st.nextToken()).intValue(); + // TODO: use column number when available + return findElementForSourceLine(file, line); + +// IProgramElement parent = findElementForType(packageName, typeName); +// if (parent == null) return null; +// if (kind == IProgramElement.Kind.CLASS || +// kind == IProgramElement.Kind.ASPECT) { +// return parent; +// } else { +// return findElementForSignature(parent, kind, name); +// } + } +// +// private IProgramElement findElementForBytecodeInfo( +// IProgramElement node, +// String parentName, +// String name, +// String signature) { +// for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) { +// IProgramElement curr = (IProgramElement)it.next(); +// if (parentName.equals(curr.getParent().getBytecodeName()) +// && name.equals(curr.getBytecodeName()) +// && signature.equals(curr.getBytecodeSignature())) { +// return node; +// } else { +// IProgramElement childSearch = findElementForBytecodeInfo(curr, parentName, name, signature); +// if (childSearch != null) return childSearch; +// } +// } +// return null; +// } } diff --git a/asm/src/org/aspectj/asm/internal/ProgramElement.java b/asm/src/org/aspectj/asm/internal/ProgramElement.java index 9b2e3fdb0..ff509689d 100644 --- a/asm/src/org/aspectj/asm/internal/ProgramElement.java +++ b/asm/src/org/aspectj/asm/internal/ProgramElement.java @@ -1,16 +1,19 @@ /* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). + * Copyright (c) 2003 Contributors. * All rights reserved. * 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 + * + * Contributors: + * Mik Kersten initial implementation * ******************************************************************/ package org.aspectj.asm.internal; +import java.io.IOException; import java.util.*; import org.aspectj.asm.*; @@ -46,6 +49,11 @@ public class ProgramElement implements IProgramElement { private String bytecodeSignature; private String fullSignature; private String returnType; + + private List parameterNames = null; + private List parameterTypes = null; + + private String details = null; /** * Used during de-externalization. @@ -203,7 +211,7 @@ public class ProgramElement implements IProgramElement { } public String toString() { - return getName(); + return toLabelString(); } private static List genModifiers(int modifiers) { @@ -258,13 +266,13 @@ public class ProgramElement implements IProgramElement { this.bytecodeSignature = bytecodeSignature; } - public String getFullSignature() { - return fullSignature; - } - - public void setFullSignature(String string) { - fullSignature = string; - } +// public String getFullSignature() { +// return fullSignature; +// } +// +// public void setFullSignature(String string) { +// fullSignature = string; +// } public void setKind(Kind kind) { this.kind = kind; @@ -359,12 +367,70 @@ public class ProgramElement implements IProgramElement { this.modifiers = genModifiers(i); } - public String getSignatureKey() { - return packageName + '/' - + name + ':' - + sourceLocation.getLine() + ':' - + sourceLocation.getColumn(); + public String toSignatureString() { + StringBuffer sb = new StringBuffer(); + sb.append(name); + + if (parameterTypes != null ) { + sb.append('('); + for (Iterator it = parameterTypes.iterator(); it.hasNext(); ) { + sb.append((String)it.next()); + if (it.hasNext()) sb.append(", "); + } + sb.append(')'); + } + + return sb.toString(); } + public String toLabelString() { + String label = toSignatureString(); + if (details != null) { + label += ": " + details; + } + return label; + } + + public String getHandleIdentifier() { + try { + StringBuffer sb = new StringBuffer(); + if (sourceLocation == null) { + return null; + } else { + sb.append(sourceLocation.getSourceFile().getCanonicalPath()); + sb.append(ID_DELIM); + sb.append(sourceLocation.getLine()); + sb.append(ID_DELIM); + sb.append(sourceLocation.getColumn()); + return sb.toString(); + } + } catch (IOException ioe) { + return null; + } + } + + public List getParameterNames() { + return parameterNames; + } + + public List getParameterTypes() { + return parameterTypes; + } + + public void setParameterNames(List list) { + parameterNames = list; + } + + public void setParameterTypes(List list) { + parameterTypes = list; + } + + public String getDetails() { + return details; + } + + public void setDetails(String string) { + details = string; + } } diff --git a/asm/src/org/aspectj/asm/internal/Relationship.java b/asm/src/org/aspectj/asm/internal/Relationship.java index ef6d98683..cb9b97b60 100644 --- a/asm/src/org/aspectj/asm/internal/Relationship.java +++ b/asm/src/org/aspectj/asm/internal/Relationship.java @@ -1,11 +1,13 @@ /* ******************************************************************* - * Copyright (c) 1999-2001 Xerox Corporation, - * 2002 Palo Alto Research Center, Incorporated (PARC). + * Copyright (c) 2003 Contributors. * All rights reserved. * 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 + * + * Contributors: + * Mik Kersten initial implementation * ******************************************************************/ @@ -25,18 +27,18 @@ public class Relationship implements IRelationship { private String name; private Kind kind; - private IProgramElement source; + private String sourceHandle; private List targets; public Relationship( String name, Kind kind, - IProgramElement source, + String sourceHandle, List targets) { this.name = name; this.kind = kind; - this.source = source; + this.sourceHandle = sourceHandle; this.targets = targets; } @@ -52,8 +54,8 @@ public class Relationship implements IRelationship { return name; } - public IProgramElement getSource() { - return source; + public String getSourceHandle() { + return sourceHandle; } public List getTargets() { diff --git a/asm/src/org/aspectj/asm/internal/RelationshipMap.java b/asm/src/org/aspectj/asm/internal/RelationshipMap.java new file mode 100644 index 000000000..cd7e776c6 --- /dev/null +++ b/asm/src/org/aspectj/asm/internal/RelationshipMap.java @@ -0,0 +1,114 @@ +/* ******************************************************************* + * Copyright (c) 2003 Contributors. + * All rights reserved. + * 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 + * + * Contributors: + * Mik Kersten initial implementation + * ******************************************************************/ + +package org.aspectj.asm.internal; + +import java.util.*; + +import org.aspectj.asm.*; + +/** + * TODO: add a remove, and a clear all + * + * @author Mik Kersten + * + */ +public class RelationshipMap extends HashMap implements IRelationshipMap { + + private IHierarchy hierarchy; + + public RelationshipMap(IHierarchy hierarchy) { + this.hierarchy = hierarchy; + } + + public List get(String handle) { + List relationships = (List)super.get(handle); + if (relationships == null) { + return null; + } else { + return relationships; + } + } + + public List get(IProgramElement source) { + return get(source.getHandleIdentifier()); + } + + public IRelationship get(String source, IRelationship.Kind kind, String relationshipName) { + List relationships = get(source); + if (relationships == null) { + relationships = new ArrayList(); + IRelationship rel = new Relationship(relationshipName, kind, source, new ArrayList()); + relationships.add(rel); + super.put(source, relationships); + return rel; + } else { + for (Iterator it = relationships.iterator(); it.hasNext(); ) { + IRelationship curr = (IRelationship)it.next(); + if (curr.getKind() == kind && curr.getName().equals(relationshipName)) { + return curr; + } + } + } + return null; + } + + public IRelationship get(IProgramElement source, IRelationship.Kind kind, String relationshipName) { + return get(source.getHandleIdentifier(), kind, relationshipName); + } + + public void remove(String source, IRelationship relationship) { + List list = (List)super.get(source); + if (list != null) { + 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.remove(relationship); + } + } + + public void removeAll(String source) { + List list = (List)super.remove(source); + } + + public void put(String source, IRelationship relationship) { + System.err.println(">> for: " + source + ", put::" + 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.getKind() == relationship.getKind()) { + curr.getTargets().addAll(relationship.getTargets()); + matched = true; + } + } + if (matched) list.add(relationship); + } + } + + public void put(IProgramElement source, IRelationship relationship) { + put(source.getHandleIdentifier(), relationship); + } + +} diff --git a/asm/src/org/aspectj/asm/internal/RelationshipMapper.java b/asm/src/org/aspectj/asm/internal/RelationshipMapper.java deleted file mode 100644 index c3d1a5f4c..000000000 --- a/asm/src/org/aspectj/asm/internal/RelationshipMapper.java +++ /dev/null @@ -1,90 +0,0 @@ -/* ******************************************************************* - * Copyright (c) 2003 Contributors. - * All rights reserved. - * 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 - * - * Contributors: - * Mik Kersten initial implementation - * ******************************************************************/ - -package org.aspectj.asm.internal; - -import java.util.*; - -import org.aspectj.asm.*; - -/** - * @author Mik Kersten - */ -public class RelationshipMapper extends HashMap implements IRelationshipMapper { - - public List get(IProgramElement source) { - List relationships = (List)super.get(source); - if (relationships == null) { - return Collections.EMPTY_LIST; - } else { - return relationships; - } - } - - /** - * @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) { - 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 - - 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; - } - } - -} diff --git a/docs/developer/asm.doc b/docs/developer/asm.doc index 693bf5f06ad748db1cb48cabe9a27fbcc8d00dbc..f027bbec3438b8de2f2ea5a6d6941494b29d5d31 100644 GIT binary patch delta 7560 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 delta 6432 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 k2x&{BUsd>Kq> " + shadow.getThisVar() + " to " + shadow.getTargetVar()); } - public static void nodeMunger(AspectJModel model, Shadow shadow, ShadowMunger munger) { + public static void nodeMunger(IHierarchy model, Shadow shadow, ShadowMunger munger) { if (munger instanceof Advice) { - Advice a = (Advice)munger; - if (a.getKind().isPerEntry() || a.getKind().isCflow()) { + Advice advice = (Advice)munger; + if (advice.getKind().isPerEntry() || advice.getKind().isCflow()) { // TODO: might want to show these in the future return; } - IRelationshipMapper mapper = AsmManager.getDefault().getMapper(); - - IProgramElement targetNode = getNode(model, shadow); - IProgramElement adviceNode = getNode(model, a); + 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 (adviceNode != null && targetNode != null) { - IRelationship foreward = mapper.get(adviceNode, IRelationship.Kind.ADVICE, ADVISES); - if (foreward == null) { - foreward = new Relationship( - ADVISES, - IRelationship.Kind.ADVICE, - adviceNode, - new ArrayList() - ); - mapper.put(adviceNode, foreward); - } - foreward.getTargets().add(targetNode); - - IRelationship back = mapper.get(targetNode, IRelationship.Kind.ADVICE, ADVISED_BY); - if (back == null) { - back = new Relationship( - ADVISED_BY, - IRelationship.Kind.ADVICE, - targetNode, - new ArrayList() - ); - mapper.put(targetNode, back); + if (targetNode != null) { + String targetHandle = targetNode.getHandleIdentifier(); + + 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); + } } - back.getTargets().add(adviceNode); + } catch (IOException e) { + e.printStackTrace(); } } } - private static IProgramElement getNode(AspectJModel model, Advice a) { - //ResolvedTypeX inAspect = a.getConcreteAspect(); - Member member = a.getSignature(); - if (a.getSignature() == null) return null; - return lookupMember(model, member); - } - - private static IProgramElement getNode(AspectJModel model, Shadow shadow) { + private static IProgramElement getNode(IHierarchy model, Shadow shadow) { Member enclosingMember = shadow.getEnclosingCodeSignature(); IProgramElement enclosingNode = lookupMember(model, enclosingMember); @@ -91,16 +79,14 @@ public class AsmAdapter { Member shadowSig = shadow.getSignature(); if (!shadowSig.equals(enclosingMember)) { - IProgramElement bodyNode = findOrCreateBodyNode(enclosingNode, shadowSig, shadow); + IProgramElement bodyNode = findOrCreateCodeNode(enclosingNode, shadowSig, shadow); return bodyNode; } else { return enclosingNode; } } - - private static IProgramElement findOrCreateBodyNode( - IProgramElement enclosingNode, - Member shadowSig, Shadow shadow) + + private static IProgramElement findOrCreateCodeNode(IProgramElement enclosingNode, Member shadowSig, Shadow shadow) { for (Iterator it = enclosingNode.getChildren().iterator(); it.hasNext(); ) { IProgramElement node = (IProgramElement)it.next(); @@ -116,24 +102,22 @@ public class AsmAdapter { IProgramElement peNode = new ProgramElement( shadow.toString(), IProgramElement.Kind.CODE, -//XXX why not use shadow file? new SourceLocation(sl.getSourceFile(), sl.getLine()), - new SourceLocation(enclosingNode.getSourceLocation().getSourceFile(), sl.getLine()), -// enclosingNode.getSourceLocation(), + //XXX why not use shadow file? new SourceLocation(sl.getSourceFile(), sl.getLine()), + new SourceLocation(enclosingNode.getSourceLocation().getSourceFile(), sl.getLine()), 0, "", new ArrayList()); - - //System.err.println(peNode.getSourceLocation()); + peNode.setBytecodeName(shadowSig.getName()); peNode.setBytecodeSignature(shadowSig.getSignature()); enclosingNode.addChild(peNode); return peNode; } - public static IProgramElement lookupMember(AspectJModel model, Member member) { + private static IProgramElement lookupMember(IHierarchy model, Member member) { TypeX declaringType = member.getDeclaringType(); IProgramElement classNode = - model.findNodeForType(declaringType.getPackageName(), declaringType.getClassName()); + model.findElementForType(declaringType.getPackageName(), declaringType.getClassName()); return findMemberInClass(classNode, member); } @@ -154,4 +138,32 @@ public class AsmAdapter { // if we can't find the member, we'll just put it in the class return classNode; } + +// private static IProgramElement.Kind genShadowKind(Shadow shadow) { +// IProgramElement.Kind shadowKind; +// if (shadow.getKind() == Shadow.MethodCall +// || shadow.getKind() == Shadow.ConstructorCall +// || shadow.getKind() == Shadow.FieldGet +// || shadow.getKind() == Shadow.FieldSet +// || shadow.getKind() == Shadow.ExceptionHandler) { +// return IProgramElement.Kind.CODE; +// +// } else if (shadow.getKind() == Shadow.MethodExecution) { +// return IProgramElement.Kind.METHOD; +// +// } else if (shadow.getKind() == Shadow.ConstructorExecution) { +// return IProgramElement.Kind.CONSTRUCTOR; +// +// } else if (shadow.getKind() == Shadow.PreInitialization +// || shadow.getKind() == Shadow.Initialization) { +// return IProgramElement.Kind.CLASS; +// +// } else if (shadow.getKind() == Shadow.AdviceExecution) { +// return IProgramElement.Kind.ADVICE; +// +// } else { +// return IProgramElement.Kind.ERROR; +// } +// } + } diff --git a/weaver/src/org/aspectj/weaver/Checker.java b/weaver/src/org/aspectj/weaver/Checker.java index 83c9f40b9..a17bba0bb 100644 --- a/weaver/src/org/aspectj/weaver/Checker.java +++ b/weaver/src/org/aspectj/weaver/Checker.java @@ -55,7 +55,7 @@ public class Checker extends ShadowMunger { shadow.getSourceLocation()); world.getMessageHandler().handleMessage(message); - AsmAdapter.checkerMunger(world.getModel(), shadow); + AsmAdviceRelationshipProvider.checkerMunger(world.getModel(), shadow); } return false; } diff --git a/weaver/src/org/aspectj/weaver/Shadow.java b/weaver/src/org/aspectj/weaver/Shadow.java index a6ec5529a..a8a1ebd94 100644 --- a/weaver/src/org/aspectj/weaver/Shadow.java +++ b/weaver/src/org/aspectj/weaver/Shadow.java @@ -341,7 +341,7 @@ public abstract class Shadow { munger.implementOn(this); if (world.getModel() != null) { //System.err.println("munger: " + munger + " on " + this); - AsmAdapter.nodeMunger(world.getModel(), this, munger); + AsmAdviceRelationshipProvider.nodeMunger(world.getModel(), this, munger); } } } diff --git a/weaver/src/org/aspectj/weaver/World.java b/weaver/src/org/aspectj/weaver/World.java index 9f2285e23..804332090 100644 --- a/weaver/src/org/aspectj/weaver/World.java +++ b/weaver/src/org/aspectj/weaver/World.java @@ -13,21 +13,13 @@ package org.aspectj.weaver; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.aspectj.asm.AspectJModel; -import org.aspectj.bridge.IMessageHandler; -import org.aspectj.bridge.ISourceLocation; -import org.aspectj.bridge.Message; -import org.aspectj.bridge.MessageUtil; +import java.util.*; + +import org.aspectj.asm.IHierarchy; +import org.aspectj.asm.internal.AspectJElementHierarchy; +import org.aspectj.bridge.*; import org.aspectj.bridge.IMessage.Kind; -import org.aspectj.weaver.ResolvedTypeX.Name; -import org.aspectj.weaver.patterns.DeclarePrecedence; -import org.aspectj.weaver.patterns.Pointcut; +import org.aspectj.weaver.patterns.*; public abstract class World { protected IMessageHandler messageHandler = IMessageHandler.SYSTEM_ERR; @@ -36,7 +28,7 @@ public abstract class World { protected CrosscuttingMembersSet crosscuttingMembersSet = new CrosscuttingMembersSet(this); - protected AspectJModel model = null; + protected IHierarchy model = null; protected Lint lint = new Lint(this); @@ -340,11 +332,11 @@ public abstract class World { return crosscuttingMembersSet; } - public AspectJModel getModel() { + public IHierarchy getModel() { return model; } - public void setModel(AspectJModel model) { + public void setModel(IHierarchy model) { this.model = model; } -- 2.39.5