diff options
42 files changed, 929 insertions, 512 deletions
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 = "<no active config>"; + String fileName = "<no active config>"; 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: <type pattern>"; - 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: <type pattern>"; + 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, <type pattern>"; - 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(): <anonymous pointcut>"; - 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): <anonymous pointcut>.."; - 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( + "<build to view structure>", + 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 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 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 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("<build to view structure>", 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 Binary files differindex 693bf5f06..f027bbec3 100644 --- a/docs/developer/asm.doc +++ b/docs/developer/asm.doc diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AjLookupEnvironment.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AjLookupEnvironment.java index 8bbf228a8..171aeb722 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AjLookupEnvironment.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AjLookupEnvironment.java @@ -16,6 +16,9 @@ package org.aspectj.ajdt.internal.compiler.lookup; import java.util.*; import org.aspectj.ajdt.internal.compiler.ast.AspectDeclaration; +import org.aspectj.asm.*; +import org.aspectj.asm.IProgramElement; +import org.aspectj.asm.internal.Relationship; import org.aspectj.bridge.IMessage; import org.aspectj.weaver.*; import org.aspectj.weaver.patterns.*; @@ -211,6 +214,8 @@ public class AjLookupEnvironment extends LookupEnvironment { needOldStyleWarning = false; } onType.addInterTypeMunger(munger); + + AsmInterTypeRelationshipProvider.addRelationship(onType, munger); } } diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java new file mode 100644 index 000000000..329e5b57e --- /dev/null +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java @@ -0,0 +1,67 @@ +/* ******************************************************************* + * 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.ajdt.internal.compiler.lookup; + +import java.util.*; + +import org.aspectj.asm.*; +import org.aspectj.asm.internal.Relationship; +import org.aspectj.weaver.*; + +/** + * @author Mik Kersten + */ +public class AsmInterTypeRelationshipProvider { + + public static final String INTER_TYPE_DECLARES = "declares on"; + public static final String INTER_TYPE_DECLARED_BY = "aspect declarations"; + + public static void addRelationship( + ResolvedTypeX onType, + EclipseTypeMunger munger) { + + IProgramElement.Kind kind = IProgramElement.Kind.ERROR; + if (munger.getMunger().getKind() == ResolvedTypeMunger.Field) { + kind = IProgramElement.Kind.INTER_TYPE_FIELD; + } else if (munger.getMunger().getKind() == ResolvedTypeMunger.Constructor) { + kind = IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR; + } else if (munger.getMunger().getKind() == ResolvedTypeMunger.Method) { + kind = IProgramElement.Kind.INTER_TYPE_METHOD; + } else if (munger.getMunger().getKind() == ResolvedTypeMunger.Parent) { + kind = IProgramElement.Kind.INTER_TYPE_PARENT; + } + + if (munger.getSourceLocation() != null + && munger.getSourceLocation() != null) { + String sourceHandle = + munger.getSourceLocation().getSourceFile().getAbsolutePath() + IProgramElement.ID_DELIM + + munger.getSourceLocation().getLine() + IProgramElement.ID_DELIM + + munger.getSourceLocation().getColumn(); + + String targetHandle = + onType.getSourceLocation().getSourceFile().getAbsolutePath() + IProgramElement.ID_DELIM + + onType.getSourceLocation().getLine() + IProgramElement.ID_DELIM + + onType.getSourceLocation().getColumn(); + + IRelationshipMap mapper = AsmManager.getDefault().getRelationshipMap(); + if (sourceHandle != null && targetHandle != null) { + IRelationship foreward = mapper.get(sourceHandle, IRelationship.Kind.ADVICE, INTER_TYPE_DECLARES); + foreward.getTargets().add(targetHandle); + + IRelationship back = mapper.get(targetHandle, IRelationship.Kind.ADVICE, INTER_TYPE_DECLARED_BY); + back.getTargets().add(sourceHandle); + } + } + } + +} diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java index 8cb60f48f..bada76650 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java @@ -22,6 +22,7 @@ import org.aspectj.ajdt.internal.compiler.lookup.*; import org.aspectj.ajdt.internal.compiler.parser.AjParser; import org.aspectj.ajdt.internal.compiler.problem.AjProblemReporter; import org.aspectj.asm.*; +import org.aspectj.asm.internal.*; import org.aspectj.asm.internal.ProgramElement; import org.aspectj.bridge.*; import org.aspectj.weaver.World; @@ -42,7 +43,7 @@ public class AjBuildManager { private int compiledCount; private int sourceFileCount; - private AspectJModel structureModel; + private IHierarchy structureModel; public AjBuildConfig buildConfig; AjState state = new AjState(this); @@ -118,7 +119,7 @@ public class AjBuildManager { if (batch) { // System.err.println("XXXX batch: " + buildConfig.getFiles()); if (buildConfig.isEmacsSymMode() || buildConfig.isGenerateModelMode()) { - bcelWorld.setModel(AsmManager.getDefault().getModel()); + bcelWorld.setModel(AsmManager.getDefault().getHierarchy()); // in incremental build, only get updated model? } performCompilation(buildConfig.getFiles()); @@ -167,7 +168,7 @@ public class AjBuildManager { private void setupModel() { String rootLabel = "<root>"; - AspectJModel model = AsmManager.getDefault().getModel(); + IHierarchy model = AsmManager.getDefault().getHierarchy(); IProgramElement.Kind kind = IProgramElement.Kind.FILE_JAVA; if (buildConfig.getConfigFile() != null) { rootLabel = buildConfig.getConfigFile().getName(); @@ -523,14 +524,14 @@ public class AjBuildManager { } - public void setStructureModel(AspectJModel structureModel) { + public void setStructureModel(IHierarchy structureModel) { this.structureModel = structureModel; } /** * Returns null if there is no structure model */ - public AspectJModel getStructureModel() { + public IHierarchy getStructureModel() { return structureModel; } diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmNodeFormatter.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmElementFormatter.java index e2025743e..114bf7439 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmNodeFormatter.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmElementFormatter.java @@ -10,7 +10,7 @@ package org.aspectj.ajdt.internal.core.builder; -import java.util.Iterator; +import java.util.*; import org.aspectj.ajdt.internal.compiler.ast.*; import org.aspectj.asm.IProgramElement; @@ -18,13 +18,13 @@ import org.aspectj.weaver.*; import org.aspectj.weaver.patterns.*; import org.eclipse.jdt.internal.compiler.ast.*; -public class AsmNodeFormatter { +public class AsmElementFormatter { - public static final String DECLARE_PRECEDENCE = "precedence: "; - public static final String DECLARE_SOFT = "soft: "; - public static final String DECLARE_PARENTS = "parents: "; - public static final String DECLARE_WARNING = "warning: "; - public static final String DECLARE_ERROR = "error: "; + public static final String DECLARE_PRECEDENCE = "precedence"; + public static final String DECLARE_SOFT = "soft"; + public static final String DECLARE_PARENTS = "parents"; + public static final String DECLARE_WARNING = "warning"; + public static final String DECLARE_ERROR = "error"; public static final String DECLARE_UNKNONWN = "<unknown declare>"; public static final String POINTCUT_ABSTRACT = "<abstract pointcut>"; public static final String POINTCUT_ANONYMOUS = "<anonymous pointcut>"; @@ -32,110 +32,118 @@ public class AsmNodeFormatter { public static final String DEC_LABEL = "declare"; public void genLabelAndKind(MethodDeclaration methodDeclaration, IProgramElement node) { + if (methodDeclaration instanceof AdviceDeclaration) { AdviceDeclaration ad = (AdviceDeclaration)methodDeclaration; - node.setKind( IProgramElement.Kind.ADVICE); - String label = ""; - label += ad.kind.toString(); - label += "(" + genArguments(ad) + "): "; + node.setKind(IProgramElement.Kind.ADVICE); if (ad.kind == AdviceKind.Around) { node.setReturnType(ad.returnTypeToString(0)); } + String details = ""; if (ad.pointcutDesignator != null) { if (ad.pointcutDesignator.getPointcut() instanceof ReferencePointcut) { ReferencePointcut rp = (ReferencePointcut)ad.pointcutDesignator.getPointcut(); - label += rp.name + ".."; + details += rp.name + ".."; } else if (ad.pointcutDesignator.getPointcut() instanceof AndPointcut) { AndPointcut ap = (AndPointcut)ad.pointcutDesignator.getPointcut(); if (ap.getLeft() instanceof ReferencePointcut) { - label += ap.getLeft().toString() + ".."; + details += ap.getLeft().toString() + ".."; } else { - label += POINTCUT_ANONYMOUS + ".."; + details += POINTCUT_ANONYMOUS + ".."; } } else if (ad.pointcutDesignator.getPointcut() instanceof OrPointcut) { OrPointcut op = (OrPointcut)ad.pointcutDesignator.getPointcut(); if (op.getLeft() instanceof ReferencePointcut) { - label += op.getLeft().toString() + ".."; + details += op.getLeft().toString() + ".."; } else { - label += POINTCUT_ANONYMOUS + ".."; + details += POINTCUT_ANONYMOUS + ".."; } } else { - label += POINTCUT_ANONYMOUS; + details += POINTCUT_ANONYMOUS; } } else { - label += POINTCUT_ABSTRACT; + details += POINTCUT_ABSTRACT; } - node.setName(label); + node.setName(ad.kind.toString()); + node.setDetails(details); + setParameters(methodDeclaration, node); } else if (methodDeclaration instanceof PointcutDeclaration) { PointcutDeclaration pd = (PointcutDeclaration)methodDeclaration; - node.setKind( IProgramElement.Kind.POINTCUT); - String label = translatePointcutName(new String(methodDeclaration.selector)); - label += "(" + genArguments(pd) + ")"; - node.setName(label); + node.setKind(IProgramElement.Kind.POINTCUT); + node.setName(translatePointcutName(new String(methodDeclaration.selector))); + setParameters(methodDeclaration, node); } else if (methodDeclaration instanceof DeclareDeclaration) { DeclareDeclaration declare = (DeclareDeclaration)methodDeclaration; - String label = DEC_LABEL + " "; + String name = DEC_LABEL + " "; if (declare.declare instanceof DeclareErrorOrWarning) { DeclareErrorOrWarning deow = (DeclareErrorOrWarning)declare.declare; if (deow.isError()) { node.setKind( IProgramElement.Kind.DECLARE_ERROR); - label += DECLARE_ERROR; + name += DECLARE_ERROR; } else { node.setKind( IProgramElement.Kind.DECLARE_WARNING); - label += DECLARE_WARNING; + name += DECLARE_WARNING; } - node.setName(label + "\"" + genDeclareMessage(deow.getMessage()) + "\"") ; - + node.setName(name) ; + node.setDetails("\"" + genDeclareMessage(deow.getMessage()) + "\""); + } else if (declare.declare instanceof DeclareParents) { node.setKind( IProgramElement.Kind.DECLARE_PARENTS); DeclareParents dp = (DeclareParents)declare.declare; - node.setName(label + DECLARE_PARENTS + genTypePatternLabel(dp.getChild())); + node.setName(name + DECLARE_PARENTS); + node.setDetails(genTypePatternLabel(dp.getChild())); } else if (declare.declare instanceof DeclareSoft) { node.setKind( IProgramElement.Kind.DECLARE_SOFT); DeclareSoft ds = (DeclareSoft)declare.declare; - node.setName(label + DECLARE_SOFT + genTypePatternLabel(ds.getException())); + node.setName(name + DECLARE_SOFT); + node.setDetails(genTypePatternLabel(ds.getException())); + } else if (declare.declare instanceof DeclarePrecedence) { node.setKind( IProgramElement.Kind.DECLARE_PRECEDENCE); DeclarePrecedence ds = (DeclarePrecedence)declare.declare; - node.setName(label + DECLARE_PRECEDENCE + genPrecedenceListLabel(ds.getPatterns())); + node.setName(name + DECLARE_PRECEDENCE); + node.setDetails(genPrecedenceListLabel(ds.getPatterns())); + + } else { - node.setKind( IProgramElement.Kind.ERROR); + node.setKind(IProgramElement.Kind.ERROR); node.setName(DECLARE_UNKNONWN); } } else if (methodDeclaration instanceof InterTypeDeclaration) { InterTypeDeclaration itd = (InterTypeDeclaration)methodDeclaration; - String label = itd.onType.toString() + "." + new String(itd.getDeclaredSelector()); + String name = itd.onType.toString() + "." + new String(itd.getDeclaredSelector()); if (methodDeclaration instanceof InterTypeFieldDeclaration) { node.setKind(IProgramElement.Kind.INTER_TYPE_FIELD); } else if (methodDeclaration instanceof InterTypeMethodDeclaration) { node.setKind(IProgramElement.Kind.INTER_TYPE_METHOD); - InterTypeMethodDeclaration itmd = (InterTypeMethodDeclaration)methodDeclaration; - label += "(" + genArguments(itd) + ")"; + InterTypeMethodDeclaration itmd = (InterTypeMethodDeclaration)methodDeclaration; } else if (methodDeclaration instanceof InterTypeConstructorDeclaration) { node.setKind(IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR); InterTypeConstructorDeclaration itcd = (InterTypeConstructorDeclaration)methodDeclaration; } else { node.setKind(IProgramElement.Kind.ERROR); } - node.setName(label); + node.setName(name); node.setReturnType(itd.returnType.toString()); - - } else { + if (node.getKind() != IProgramElement.Kind.INTER_TYPE_FIELD) { + setParameters(methodDeclaration, node); + } + } else { if (methodDeclaration.isConstructor()) { node.setKind(IProgramElement.Kind.CONSTRUCTOR); } else { node.setKind(IProgramElement.Kind.METHOD); } String label = new String(methodDeclaration.selector); - label += "(" + genArguments(methodDeclaration) + ")"; node.setName(label); + setParameters(methodDeclaration, node); } } @@ -149,26 +157,49 @@ public class AsmNodeFormatter { return tpList; } - private String genArguments(MethodDeclaration md) { - String args = ""; +// private String genArguments(MethodDeclaration md) { +// String args = ""; +// Argument[] argArray = md.arguments; +// if (argArray == null) return args; +// for (int i = 0; i < argArray.length; i++) { +// String argName = new String(argArray[i].name); +// String argType = argArray[i].type.toString(); +// if (acceptArgument(argName, argType)) { +// args += argType + ", "; +// } +// } +// int lastSepIndex = args.lastIndexOf(','); +// if (lastSepIndex != -1 && args.endsWith(", ")) args = args.substring(0, lastSepIndex); +// return args; +// } + + private void setParameters(MethodDeclaration md, IProgramElement pe) { Argument[] argArray = md.arguments; - if (argArray == null) return args; + List names = new ArrayList(); + List types = new ArrayList(); + pe.setParameterNames(names); + pe.setParameterTypes(types); + + if (argArray == null) return; for (int i = 0; i < argArray.length; i++) { String argName = new String(argArray[i].name); String argType = argArray[i].type.toString(); -// TODO: fix this way of determing ajc-added arguments, make subtype of Argument with extra info - if (!argName.startsWith("ajc$this_") - && !argType.equals("org.aspectj.lang.JoinPoint.StaticPart") - && !argType.equals("org.aspectj.lang.JoinPoint") - && !argType.equals("org.aspectj.runtime.internal.AroundClosure")) { - args += argType + ", "; - } + if (acceptArgument(argName, argType)) { + names.add(argName); + types.add(argType); + } } - int lastSepIndex = args.lastIndexOf(','); - if (lastSepIndex != -1 && args.endsWith(", ")) args = args.substring(0, lastSepIndex); - return args; } + // TODO: fix this way of determing ajc-added arguments, make subtype of Argument with extra info + private boolean acceptArgument(String name, String type) { + return !name.startsWith("ajc$this_") + && !type.equals("org.aspectj.lang.JoinPoint.StaticPart") + && !type.equals("org.aspectj.lang.JoinPoint") + && !type.equals("org.aspectj.runtime.internal.AroundClosure"); + } + + public String genTypePatternLabel(TypePattern tp) { final String TYPE_PATTERN_LITERAL = "<type pattern>"; String label; diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java index c159919d5..d044ab0fb 100644 --- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java +++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java @@ -19,6 +19,7 @@ import java.util.*; import org.aspectj.ajdt.internal.compiler.ast.AspectDeclaration; import org.aspectj.ajdt.internal.compiler.lookup.EclipseFactory; import org.aspectj.asm.*; +import org.aspectj.asm.internal.*; import org.aspectj.asm.internal.ProgramElement; import org.aspectj.bridge.*; import org.aspectj.util.LangUtil; @@ -32,14 +33,14 @@ public class AsmHierarchyBuilder extends AbstractSyntaxTreeVisitorAdapter { public static void build( CompilationUnitDeclaration unit, - AspectJModel structureModel) { + IHierarchy structureModel) { LangUtil.throwIaxIfNull(unit, "unit"); new AsmHierarchyBuilder(unit.compilationResult()).internalBuild(unit, structureModel); } private final Stack stack; private final CompilationResult currCompilationResult; - private AsmNodeFormatter formatter = new AsmNodeFormatter(); + private AsmElementFormatter formatter = new AsmElementFormatter(); protected AsmHierarchyBuilder(CompilationResult result) { LangUtil.throwIaxIfNull(result, "result"); @@ -53,7 +54,7 @@ public class AsmHierarchyBuilder extends AbstractSyntaxTreeVisitorAdapter { */ private void internalBuild( CompilationUnitDeclaration unit, - AspectJModel structureModel) { + IHierarchy structureModel) { LangUtil.throwIaxIfNull(structureModel, "structureModel"); if (!currCompilationResult.equals(unit.compilationResult())) { throw new IllegalArgumentException("invalid unit: " + unit); @@ -112,11 +113,11 @@ public class AsmHierarchyBuilder extends AbstractSyntaxTreeVisitorAdapter { } /** - * Get/create teh node (package or root) to add to. + * Get/create the node (package or root) to add to. */ private IProgramElement genAddToNode( CompilationUnitDeclaration unit, - AspectJModel structureModel) { + IHierarchy structureModel) { final IProgramElement addToNode; { ImportReference currentPackage = unit.currentPackage; @@ -174,8 +175,6 @@ public class AsmHierarchyBuilder extends AbstractSyntaxTreeVisitorAdapter { typeDeclaration.modifiers, "", new ArrayList()); -// peNode.setFullSignature(typeDeclaration.()); - ((IProgramElement)stack.peek()).addChild(peNode); stack.push(peNode); return true; @@ -201,8 +200,6 @@ public class AsmHierarchyBuilder extends AbstractSyntaxTreeVisitorAdapter { "", new ArrayList()); - peNode.setFullSignature(memberTypeDeclaration.toString()); - ((IProgramElement)stack.peek()).addChild(peNode); stack.push(peNode); return true; @@ -265,7 +262,7 @@ public class AsmHierarchyBuilder extends AbstractSyntaxTreeVisitorAdapter { return (IProgramElement)stack.peek(); } - public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) { + public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) { IProgramElement peNode = new ProgramElement( "", IProgramElement.Kind.ERROR, @@ -280,7 +277,7 @@ public class AsmHierarchyBuilder extends AbstractSyntaxTreeVisitorAdapter { // TODO: add return type test if (peNode.getKind().equals(IProgramElement.Kind.METHOD)) { - if (peNode.getName().equals("main(String[])") + if (peNode.toLabelString().equals("main(String[])") && peNode.getModifiers().contains(IProgramElement.Modifiers.STATIC) && peNode.getAccessibility().equals(IProgramElement.Accessibility.PUBLIC)) { ((IProgramElement)stack.peek()).setRunnable(true); 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 93e1bd5fe..4188adeb4 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 @@ -32,11 +32,11 @@ public class EmacsStructureModelManager { } public void externalizeModel() { - if (!AsmManager.getDefault().getModel().isValid()) return; + if (!AsmManager.getDefault().getHierarchy().isValid()) return; try { //Set fileSet = StructureModelManager.INSTANCE.getStructureModel().getFileMap().entrySet(); - Set fileSet = AsmManager.getDefault().getModel().getFileMapEntrySet(); + Set fileSet = AsmManager.getDefault().getHierarchy().getFileMapEntrySet(); for (Iterator it = fileSet.iterator(); it.hasNext(); ) { IProgramElement peNode = (IProgramElement)((Map.Entry)it.next()).getValue(); dumpStructureToFile(peNode); diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/AjBuildManagerTest.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/AjBuildManagerTest.java index 76e3671e0..dc783f0c8 100644 --- a/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/AjBuildManagerTest.java +++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/AjBuildManagerTest.java @@ -73,7 +73,7 @@ public class AjBuildManagerTest extends TestCase { }, messageWriter); String err = parser.getOtherMessages(true); assertTrue(err, null == err); - manager.setStructureModel(AsmManager.getDefault().getModel()); + manager.setStructureModel(AsmManager.getDefault().getHierarchy()); MessageHandler handler = new MessageHandler(); manager.batchBuild(buildConfig, handler); assertCompileMessagesValid(handler); diff --git a/weaver/src/org/aspectj/weaver/AsmAdapter.java b/weaver/src/org/aspectj/weaver/AsmAdviceRelationshipProvider.java index 5c121b169..577957069 100644 --- a/weaver/src/org/aspectj/weaver/AsmAdapter.java +++ b/weaver/src/org/aspectj/weaver/AsmAdviceRelationshipProvider.java @@ -13,71 +13,59 @@ package org.aspectj.weaver; +import java.io.IOException; import java.util.*; import org.aspectj.asm.*; import org.aspectj.asm.internal.*; import org.aspectj.bridge.*; -public class AsmAdapter { +public class AsmAdviceRelationshipProvider { public static final String ADVISES = "advises"; public static final String ADVISED_BY = "advised by"; public static final String DECLARES_ON = "declares on"; public static final String DECLAREDY_BY = "declared by"; - public static void checkerMunger(AspectJModel model, Shadow shadow) { + public static void checkerMunger(IHierarchy model, Shadow shadow) { // System.err.println("> " + 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; } |