]> source.dussan.org Git - aspectj.git/commitdiff
Updated org.aspectj.asm relationship model to string-handle-based API in order to...
authormkersten <mkersten>
Thu, 14 Aug 2003 09:07:44 +0000 (09:07 +0000)
committermkersten <mkersten>
Thu, 14 Aug 2003 09:07:44 +0000 (09:07 +0000)
47 files changed:
ajbrowser/src/org/aspectj/tools/ajbrowser/BrowserManager.java
ajde/src/org/aspectj/ajde/ui/StructureModelUtil.java
ajde/src/org/aspectj/ajde/ui/StructureSearchManager.java
ajde/src/org/aspectj/ajde/ui/StructureViewManager.java
ajde/src/org/aspectj/ajde/ui/StructureViewNodeFactory.java
ajde/src/org/aspectj/ajde/ui/internal/TreeStructureViewBuilder.java
ajde/src/org/aspectj/ajde/ui/swing/AjdeUIManager.java
ajde/src/org/aspectj/ajde/ui/swing/SimpleStructureViewToolPanel.java
ajde/src/org/aspectj/ajde/ui/swing/StructureTreeManager.java
ajde/src/org/aspectj/ajde/ui/swing/SwingTreeViewNode.java
ajde/testdata/examples/coverage/ModelCoverage.java
ajde/testsrc/org/aspectj/ajde/AjdeTestCase.java
ajde/testsrc/org/aspectj/ajde/AsmDeclarationsTest.java
ajde/testsrc/org/aspectj/ajde/AsmRelationshipsTest.java
ajde/testsrc/org/aspectj/ajde/NullIdeManager.java
ajde/testsrc/org/aspectj/ajde/StructureModelRegressionTest.java
ajde/testsrc/org/aspectj/ajde/StructureModelTest.java
ajde/testsrc/org/aspectj/ajde/ui/StructureViewManagerTest.java
asm/src/org/aspectj/asm/AsmManager.java
asm/src/org/aspectj/asm/AspectJModel.java [deleted file]
asm/src/org/aspectj/asm/HierarchyWalker.java
asm/src/org/aspectj/asm/IHierarchy.java [new file with mode: 0644]
asm/src/org/aspectj/asm/IHierarchyListener.java [new file with mode: 0644]
asm/src/org/aspectj/asm/IProgramElement.java
asm/src/org/aspectj/asm/IRelationship.java
asm/src/org/aspectj/asm/IRelationshipMap.java [new file with mode: 0644]
asm/src/org/aspectj/asm/IRelationshipMapper.java [deleted file]
asm/src/org/aspectj/asm/IStructureModelListener.java [deleted file]
asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java [new file with mode: 0644]
asm/src/org/aspectj/asm/internal/ProgramElement.java
asm/src/org/aspectj/asm/internal/Relationship.java
asm/src/org/aspectj/asm/internal/RelationshipMap.java [new file with mode: 0644]
asm/src/org/aspectj/asm/internal/RelationshipMapper.java [deleted file]
docs/developer/asm.doc
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AjLookupEnvironment.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java [new file with mode: 0644]
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmElementFormatter.java [new file with mode: 0644]
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmNodeFormatter.java [deleted file]
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/EmacsStructureModelManager.java
org.aspectj.ajdt.core/testsrc/org/aspectj/ajdt/internal/core/builder/AjBuildManagerTest.java
weaver/src/org/aspectj/weaver/AsmAdapter.java [deleted file]
weaver/src/org/aspectj/weaver/AsmAdviceRelationshipProvider.java [new file with mode: 0644]
weaver/src/org/aspectj/weaver/Checker.java
weaver/src/org/aspectj/weaver/Shadow.java
weaver/src/org/aspectj/weaver/World.java

index 6f7523f7a70effa5aa996eea5a1d88ede3c687c6..826ca92991cc293a19c5c3c12a6382f3e229bf73 100644 (file)
@@ -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());
index 578c04e0c8f9f870d25d4997d26aca861bc80f13..0923caa795887b31b8ac58c8f7e20e2abb4a64da 100644 (file)
@@ -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(
index c1f77c2431acd760a07d26c7a4ec95ede46c62e8..835ccc5be6a665a4060271f77628c3fc6240fb86 100644 (file)
@@ -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);
index 7eb9dfa5fdc2b093a63ab8ac1c7752e392afc084..b2fe1224ff8cb8a38e88821ce0fd167932d3ccac 100644 (file)
@@ -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; 
        }
index 2339614abdacda8571cfc9fd3d7082693e8fb781..828d419efcf1008a11c220f59a5af1e38f9d48e1 100644 (file)
@@ -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);
+                                                       }
+                                               }
+                                       }
                                }
                        }
                }
index 239628176f283f647676a76d6b5af4bdce802786..ecf8ed5ae811266db952f83b778a01eeb1e36a57 100644 (file)
@@ -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);
 
index bd1f9d76b87fc044133f1fa8ac71524f07c79899..583ce0539aaf2bdd206e8036cf71dd19aad7a55d 100644 (file)
@@ -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 {
index 66c3a0e0abc07f0949c2b649c79214bb8aa4d7eb..f5b3fb555436b9cf19b4d1628084c235a6f59436 100644 (file)
 
 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);
         }
index efb786b7f14ac13676b78042883e9a279d88e473..9a32c26e5e6605da12278742b15c4ac3a867e864 100644 (file)
@@ -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
index dbd0c7aadb7717ae36d688a8237afe212f3bdaa3..b7cbe7403eda7a37e99bf83d92d3653781c59d78 100644 (file)
@@ -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();
                }
        }
 
index cb7b8391bab741b4626498a2617376be3b64de5b..075bddc3b978284150d607cb985b8876bda72346 100644 (file)
@@ -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;
index c280b68dc5163b02b9d40d277fd8913edecd6398..7f3e2a4815edb456760039a4bf7ef03f6c8dd30a 100644 (file)
@@ -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);
        }
     
index 8b815224b889331fb1b6ae039647dc7636c50317..9d7bdf79c3fbd7c9f7313edb242764d55c8b8be8 100644 (file)
@@ -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 {
index f2a005670bed74db36e9330ce82acd95caa49514..db82a96cf9c284858a43005c34f6309622dcdd39 100644 (file)
@@ -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 {
index 5049076662e3e5229139fb6b15a1b92c3dc8c514..c535cff2c21f5d9d05a3588c1fa02c68d85b10ba 100644 (file)
@@ -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();
+       }
+
 }
index cae44a4030f522d66fca81bced41db0c17814716..70ffc8f303c7587c02f574c958b0455920f0026c 100644 (file)
@@ -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 {
index 674895e41f7ef14374e2bc78397ac1a8809f642c..4332cf7d59aa7afa2eaf32aedce5078dc5446b6e 100644 (file)
@@ -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 {
index 99ff905f4f4171a3896df978df56e206466109fe..7977cc6632305fb95b172a43ab03ced396c7ce87 100644 (file)
@@ -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
                );
        }
   
index b090abfcfe0931b1cf90cc4c9c288466a43ebc5e..3fcb353e07367abd6c0bf9ee7ef2876aaf33e64a 100644 (file)
@@ -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/AspectJModel.java b/asm/src/org/aspectj/asm/AspectJModel.java
deleted file mode 100644 (file)
index e8c723e..0000000
+++ /dev/null
@@ -1,265 +0,0 @@
-/* *******************************************************************
- * Copyright (c) 1999-2001 Xerox Corporation, 
- *               2002 Palo Alto Research Center, Incorporated (PARC).
- * 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: 
- *     Xerox/PARC     initial implementation 
- * ******************************************************************/
-
-
-package org.aspectj.asm;
-
-import java.io.*;
-import java.util.*;
-
-import org.aspectj.asm.internal.ProgramElement;
-import org.aspectj.bridge.*;
-
-/**
- * @author Mik Kersten
- */
-public class AspectJModel implements Serializable {
-       
-    protected  IProgramElement root = null;
-    protected String configFile = null;
-
-    private Map fileMap = null;
-    
-    public static final IProgramElement NO_STRUCTURE = new ProgramElement("<build to view structure>", IProgramElement.Kind.ERROR, null);
-
-       public IProgramElement getElement(String handle) {
-               throw new RuntimeException("unimplemented");
-       }
-
-    public IProgramElement getRoot() {
-        return root;
-    }
-
-    public void setRoot(IProgramElement root) {
-        this.root = root;
-    }
-
-       public void addToFileMap( Object key, Object value ){
-               fileMap.put( key, value );
-       }
-
-       public void setFileMap(HashMap fileMap) {
-                 this.fileMap = fileMap;
-         }
-
-       public Object findInFileMap( Object key ) {
-               return fileMap.get(key);
-       }
-
-
-       public Set getFileMapEntrySet() {
-               return fileMap.entrySet();
-       }
-       
-       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) {
-               for (Iterator it = parent.getChildren().iterator(); it.hasNext(); ) {
-                       IProgramElement node = (IProgramElement)it.next();
-                       if (node.getKind().equals(kind) 
-                               && name.equals(node.getName())) {
-                               return node;
-                       } else {
-                               IProgramElement childSearch = findNode(node, kind, name);
-                               if (childSearch != null) return childSearch;
-                       }
-               }
-               return null;
-       }
-
-       /**
-        * 
-        * @param signatureKey  PackageName.TypeName.Signature.SourceLine.SourceColumn
-        */
-       public IProgramElement findNodeForSignatureKey(String signatureKey) {
-               throw new RuntimeException("unimplemented");
-       }       
-
-       /**
-        * @param packageName   if null default package is searched
-        * @param className     can't be null
-        */ 
-       public IProgramElement findNodeForType(String packageName, String typeName) {
-               IProgramElement packageNode = null;
-               if (packageName == null) {
-                       packageNode = root;
-               } else {
-                       for (Iterator it = root.getChildren().iterator(); it.hasNext(); ) {
-                               IProgramElement node = (IProgramElement)it.next();
-                               if (packageName.equals(node.getName())) {
-                                       packageNode = node;
-                               } 
-                       }
-                       if (packageNode == null) return null;
-               }
-               
-               // this searches each file for a class
-               for (Iterator it = packageNode.getChildren().iterator(); it.hasNext(); ) {
-                       IProgramElement fileNode = (IProgramElement)it.next();
-                       IProgramElement ret = findClassInNodes(fileNode.getChildren(), typeName);
-                       if (ret != null) return ret;
-               }
-               
-               return null;
-       }
-       
-       private IProgramElement findClassInNodes(Collection nodes, String name) {
-               String baseName;
-               String innerName;
-               int dollar = name.indexOf('$');
-               if (dollar == -1) {
-                       baseName = name;
-                       innerName = null;
-               } else {
-                       baseName = name.substring(0, dollar);
-                       innerName = name.substring(dollar+1);
-               }
-               
-               for (Iterator j = nodes.iterator(); j.hasNext(); ) {
-                       IProgramElement classNode = (IProgramElement)j.next();
-                       if (baseName.equals(classNode.getName())) {
-                               if (innerName == null) return classNode;
-                               else return findClassInNodes(classNode.getChildren(), innerName);
-                       } else if (name.equals(classNode.getName())) {
-                               return classNode;
-                       }
-               }
-               return null;
-       }
-
-
-       /**
-        * @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) {
-               try {
-               if (!isValid() || sourceFile == null) {   
-                   return AspectJModel.NO_STRUCTURE;
-               } else {
-                   String correctedPath = new File(sourceFile).getCanonicalPath();//.replace('\\', '/');
-                   //StructureNode node = (StructureNode)getFileMap().get(correctedPath);//findFileNode(filePath, model);
-                               IProgramElement node = (IProgramElement)findInFileMap(correctedPath);//findFileNode(filePath, model);
-                   if (node != null) {
-                       return node;
-                   } else {
-                       return createFileStructureNode(correctedPath);
-                   }
-               }
-               } catch (Exception e) {
-                       return AspectJModel.NO_STRUCTURE;
-               }
-    }
-
-       /**
-        * TODO: discriminate columns
-        */
-       public IProgramElement findNodeForSourceLine(ISourceLocation location) {
-               return findNodeForSourceLine(location.getSourceFile().getAbsolutePath(), location.getLine());
-       }
-
-       /**
-        * 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 findNodeForSourceLine(String sourceFilePath, int lineNumber) {
-               IProgramElement node = findNodeForSourceLineHelper(root, sourceFilePath, lineNumber);
-               if (node != null) {
-                       return node;    
-               } else {
-                       return createFileStructureNode(sourceFilePath);
-               }
-       }
-
-       private IProgramElement createFileStructureNode(String sourceFilePath) {
-               String fileName = new File(sourceFilePath).getName();
-               IProgramElement fileNode = new ProgramElement(fileName, IProgramElement.Kind.FILE_JAVA, null);
-               fileNode.setSourceLocation(new SourceLocation(new File(sourceFilePath), 1, 1));
-               fileNode.addChild(NO_STRUCTURE);
-               return fileNode;
-       }
-
-
-       private IProgramElement findNodeForSourceLineHelper(IProgramElement node, String sourceFilePath, int lineNumber) {
-               if (matches(node, sourceFilePath, lineNumber) 
-                       && !hasMoreSpecificChild(node, sourceFilePath, lineNumber)) {
-                       return node;    
-               } 
-               
-               if (node != null && node.getChildren() != null) {
-                       for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
-                               IProgramElement foundNode = findNodeForSourceLineHelper(
-                                       (IProgramElement)it.next(), 
-                                       sourceFilePath, 
-                                       lineNumber);            
-                               if (foundNode != null) return foundNode;
-                       }
-               }
-               
-               return null;            
-       }
-
-       private boolean matches(IProgramElement node, String sourceFilePath, int lineNumber) {
-               try {                   
-//                     if (node != null && node.getSourceLocation() != null)
-//                             System.err.println("====\n1: " + 
-//                                     sourceFilePath + "\n2: " +
-//                                     node.getSourceLocation().getSourceFile().getCanonicalPath().equals(sourceFilePath)
-//                             );      
-                       
-                       return node != null 
-                               && node.getSourceLocation() != null
-                               && node.getSourceLocation().getSourceFile().getCanonicalPath().equals(sourceFilePath)
-                               && ((node.getSourceLocation().getLine() <= lineNumber
-                                       && node.getSourceLocation().getEndLine() >= lineNumber)
-                                       ||
-                                       (lineNumber <= 1
-                                        && node instanceof IProgramElement 
-                                        && ((IProgramElement)node).getKind().isSourceFileKind())       
-                               );
-               } catch (IOException ioe) { 
-                       return false;
-               } 
-       }
-       
-       private boolean hasMoreSpecificChild(IProgramElement node, String sourceFilePath, int lineNumber) {
-               for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
-                       IProgramElement child = (IProgramElement)it.next();
-                       if (matches(child, sourceFilePath, lineNumber)) return true;
-               }
-               return false;
-       }
-
-       public String getConfigFile() {
-               return configFile;
-       }
-
-       public void setConfigFile(String configFile) {
-               this.configFile = configFile;
-       }
-}
-
index cac375482f45457ecc85070de772680fd4fdb38d..2e2c08df36887cf57feb47a4200fbecd6b6a058c 100644 (file)
@@ -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 (file)
index 0000000..34816ee
--- /dev/null
@@ -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/IHierarchyListener.java b/asm/src/org/aspectj/asm/IHierarchyListener.java
new file mode 100644 (file)
index 0000000..9638193
--- /dev/null
@@ -0,0 +1,28 @@
+/* *******************************************************************
+ * 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;
+
+import java.util.EventListener;
+
+import org.aspectj.asm.internal.*;
+
+/**
+ * Compiler listeners get notified of structure model update events.
+ *
+ * @author Mik Kersten
+ */
+public interface IHierarchyListener extends EventListener {
+
+    public void elementsUpdated(IHierarchy rootNode);
+}
index ced44fa7e6c80aeb314071ec863b297b230a8bc7..42a83d2b37f371bd1b3df67f0b1732c686c5979a 100644 (file)
@@ -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++) {
index b6377e83250c8cca6381c5abd0e2b6807292004f..9edb5c0e6cd96379e23e4a87303ff8f9e284ba94 100644 (file)
@@ -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/IRelationshipMap.java b/asm/src/org/aspectj/asm/IRelationshipMap.java
new file mode 100644 (file)
index 0000000..b5a12e5
--- /dev/null
@@ -0,0 +1,68 @@
+/* *******************************************************************
+ * 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;
+
+import java.io.Serializable;
+import java.util.List;
+
+import org.aspectj.asm.IRelationship.Kind;
+
+/**
+ * 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 IRelationshipMap extends Serializable {
+       /**
+        * @return      an empty list if the element is not found.
+        */
+       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.
+        * 
+        * @return      null if the relationship is not found.
+        */
+       public IRelationship get(IProgramElement source, IRelationship.Kind kind, String relationshipName);
+
+       /**
+        * 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/IRelationshipMapper.java b/asm/src/org/aspectj/asm/IRelationshipMapper.java
deleted file mode 100644 (file)
index 7473472..0000000
+++ /dev/null
@@ -1,48 +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;
-
-import java.io.Serializable;
-import java.util.List;
-
-import org.aspectj.asm.IRelationship.Kind;
-
-/**
- * Maps from a program element to a list of relationships between that element
- * and othe program elements.  Each element in the list or relationships is
- * uniquely identified by a kind and a relationship name.
- * 
- * @author Mik Kersten
- */
-public interface IRelationshipMapper extends Serializable {
-       /**
-        * @return      an empty list if the element is not found.
-        */
-       public List get(IProgramElement source);
-
-       /**
-        * Return a relationship matching the kind and name for the given element.
-        * 
-        * @return      null if the relationship is not found.
-        */
-       public IRelationship get(IProgramElement source, IRelationship.Kind kind, String relationshipName);
-       
-       
-       public List/*IRelationship*/ get(String handle);
-       
-       public void put(IProgramElement source, IRelationship relationship);
-
-       
-}
diff --git a/asm/src/org/aspectj/asm/IStructureModelListener.java b/asm/src/org/aspectj/asm/IStructureModelListener.java
deleted file mode 100644 (file)
index 6e2879e..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-/* *******************************************************************
- * Copyright (c) 1999-2001 Xerox Corporation, 
- *               2002 Palo Alto Research Center, Incorporated (PARC).
- * 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: 
- *     Xerox/PARC     initial implementation 
- * ******************************************************************/
-
-
-package org.aspectj.asm;
-
-import java.util.EventListener;
-
-/**
- * Compiler listeners get notified of structure model update events.
- *
- * @author Mik Kersten
- */
-public interface IStructureModelListener extends EventListener {
-
-    public void containmentHierarchyUpdated(AspectJModel rootNode);
-}
diff --git a/asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java b/asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java
new file mode 100644 (file)
index 0000000..6a523da
--- /dev/null
@@ -0,0 +1,309 @@
+/* *******************************************************************
+ * 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.*;
+import java.util.*;
+
+import org.aspectj.asm.*;
+import org.aspectj.asm.IProgramElement.Kind;
+import org.aspectj.bridge.*;
+
+/**
+ * @author Mik Kersten
+ */
+public class AspectJElementHierarchy implements IHierarchy {
+       
+    protected  IProgramElement root = null;
+    protected String configFile = null;
+
+    private Map fileMap = null;
+    
+       public IProgramElement getElement(String handle) {
+               throw new RuntimeException("unimplemented");
+       }
+
+    public IProgramElement getRoot() {
+        return root;
+    }
+
+    public void setRoot(IProgramElement root) {
+        this.root = root;
+    }
+
+       public void addToFileMap( Object key, Object value ){
+               fileMap.put( key, value );
+       }
+
+       public void setFileMap(HashMap fileMap) {
+                 this.fileMap = fileMap;
+         }
+
+       public Object findInFileMap( Object key ) {
+               return fileMap.get(key);
+       }
+
+
+       public Set getFileMapEntrySet() {
+               return fileMap.entrySet();
+       }
+       
+       public boolean isValid() {
+        return root != null && fileMap != null;
+    }
+       /** 
+        * 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) {
+               for (Iterator it = parent.getChildren().iterator(); it.hasNext(); ) {
+                       IProgramElement node = (IProgramElement)it.next();
+                       if (node.getKind() == kind && signature.equals(node.toSignatureString())) {
+                               return node;
+                       } else {
+                               IProgramElement childSearch = findElementForSignature(node, kind, signature);
+                               if (childSearch != null) return childSearch;
+                       }
+               }
+               return null;
+       }
+       
+       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 findElementForType(String packageName, String typeName) {
+               IProgramElement packageNode = null;
+               if (packageName == null) {
+                       packageNode = root;
+               } else {
+                       for (Iterator it = root.getChildren().iterator(); it.hasNext(); ) {
+                               IProgramElement node = (IProgramElement)it.next();
+                               if (packageName.equals(node.getName())) {
+                                       packageNode = node;
+                               } 
+                       }
+                       if (packageNode == null) return null;
+               }
+               
+               // this searches each file for a class
+               for (Iterator it = packageNode.getChildren().iterator(); it.hasNext(); ) {
+                       IProgramElement fileNode = (IProgramElement)it.next();
+                       IProgramElement ret = findClassInNodes(fileNode.getChildren(), typeName);
+                       if (ret != null) return ret;
+               }
+               
+               return null;
+       }
+       
+       private IProgramElement findClassInNodes(Collection nodes, String name) {
+               String baseName;
+               String innerName;
+               int dollar = name.indexOf('$');
+               if (dollar == -1) {
+                       baseName = name;
+                       innerName = null;
+               } else {
+                       baseName = name.substring(0, dollar);
+                       innerName = name.substring(dollar+1);
+               }
+               
+               for (Iterator j = nodes.iterator(); j.hasNext(); ) {
+                       IProgramElement classNode = (IProgramElement)j.next();
+                       if (baseName.equals(classNode.getName())) {
+                               if (innerName == null) return classNode;
+                               else return findClassInNodes(classNode.getChildren(), innerName);
+                       } else if (name.equals(classNode.getName())) {
+                               return classNode;
+                       }
+               }
+               return null;
+       }
+
+
+       /**
+        * @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) {
+               try {
+               if (!isValid() || sourceFile == null) {   
+                   return IHierarchy.NO_STRUCTURE;
+               } else {
+                   String correctedPath = new File(sourceFile).getCanonicalPath();//.replace('\\', '/');
+                   //StructureNode node = (StructureNode)getFileMap().get(correctedPath);//findFileNode(filePath, model);
+                               IProgramElement node = (IProgramElement)findInFileMap(correctedPath);//findFileNode(filePath, model);
+                   if (node != null) {
+                       return node;
+                   } else {
+                       return createFileStructureNode(correctedPath);
+                   }
+               }
+               } catch (Exception e) {
+                       return IHierarchy.NO_STRUCTURE;
+               }
+    }
+
+       /**
+        * TODO: discriminate columns
+        */
+       public IProgramElement findElementForSourceLine(ISourceLocation location) {
+               try {
+                       return findElementForSourceLine(location.getSourceFile().getCanonicalPath(), location.getLine());
+               } catch (Exception e) {
+                       return null;
+               }
+       }
+
+       /**
+        * 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) {
+               IProgramElement node = findNodeForSourceLineHelper(root, sourceFilePath, lineNumber);
+               if (node != null) {
+                       return node;    
+               } else {
+                       return createFileStructureNode(sourceFilePath);
+               }
+       }
+
+       private IProgramElement createFileStructureNode(String sourceFilePath) {
+               String fileName = new File(sourceFilePath).getName();
+               IProgramElement fileNode = new ProgramElement(fileName, IProgramElement.Kind.FILE_JAVA, null);
+               fileNode.setSourceLocation(new SourceLocation(new File(sourceFilePath), 1, 1));
+               fileNode.addChild(NO_STRUCTURE);
+               return fileNode;
+       }
+
+
+       private IProgramElement findNodeForSourceLineHelper(IProgramElement node, String sourceFilePath, int lineNumber) {
+               if (matches(node, sourceFilePath, lineNumber) 
+                       && !hasMoreSpecificChild(node, sourceFilePath, lineNumber)) {
+                       return node;    
+               } 
+               
+               if (node != null && node.getChildren() != null) {
+                       for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
+                               IProgramElement foundNode = findNodeForSourceLineHelper(
+                                       (IProgramElement)it.next(), 
+                                       sourceFilePath, 
+                                       lineNumber);            
+                               if (foundNode != null) return foundNode;
+                       }
+               }
+               
+               return null;            
+       }
+
+       private boolean matches(IProgramElement node, String sourceFilePath, int lineNumber) {
+               try {                   
+//                     if (node != null && node.getSourceLocation() != null)
+//                             System.err.println("====\n1: " + 
+//                                     sourceFilePath + "\n2: " +
+//                                     node.getSourceLocation().getSourceFile().getCanonicalPath().equals(sourceFilePath)
+//                             );                              
+                       return node != null 
+                               && node.getSourceLocation() != null
+                               && node.getSourceLocation().getSourceFile().getCanonicalPath().equals(sourceFilePath)
+                               && ((node.getSourceLocation().getLine() <= lineNumber
+                                       && node.getSourceLocation().getEndLine() >= lineNumber)
+                                       ||
+                                       (lineNumber <= 1
+                                        && node.getKind().isSourceFileKind())
+                               );
+               } catch (IOException ioe) { 
+                       return false;
+               } 
+       }
+       
+       private boolean hasMoreSpecificChild(IProgramElement node, String sourceFilePath, int lineNumber) {
+               for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
+                       IProgramElement child = (IProgramElement)it.next();
+                       if (matches(child, sourceFilePath, lineNumber)) return true;
+               }
+               return false;
+       }
+
+       public String getConfigFile() {
+               return configFile;
+       }
+
+       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;
+//     }
+}
+
index 9b2e3fdb0d02656bcd8fe2841d0ed90ec5e38e02..ff509689da333ec05cc030773d8ef48ee25f3e3a 100644 (file)
@@ -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;
+       }
 }
 
index ef6d98683d5585cb7a1da2c0f07d4ddab0c160b5..cb9b97b60f47c5d4d82279df29c9697f4f1c6847 100644 (file)
@@ -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 (file)
index 0000000..cd7e776
--- /dev/null
@@ -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 (file)
index c3d1a5f..0000000
+++ /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;
-               }
-       }
-
-}
index 693bf5f06ad748db1cb48cabe9a27fbcc8d00dbc..f027bbec3438b8de2f2ea5a6d6941494b29d5d31 100644 (file)
Binary files a/docs/developer/asm.doc and b/docs/developer/asm.doc differ
index 8bbf228a887e30c93b6c3b384b12f81fbed21d15..171aeb722d743dcc0c9e84b07d2af5a93d64e043 100644 (file)
@@ -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 (file)
index 0000000..329e5b5
--- /dev/null
@@ -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);
+                       }
+               }
+       }
+
+}
index 8cb60f48fa64bbaefba5fc930f44323ca15e15d9..bada76650cc6d2fa0e7bfe540869ef037254668d 100644 (file)
@@ -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/AsmElementFormatter.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmElementFormatter.java
new file mode 100644 (file)
index 0000000..114bf74
--- /dev/null
@@ -0,0 +1,268 @@
+/* *******************************************************************
+ * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
+ * 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 
+ *  
+ * ******************************************************************/
+
+package org.aspectj.ajdt.internal.core.builder;
+
+import java.util.*;
+
+import org.aspectj.ajdt.internal.compiler.ast.*;
+import org.aspectj.asm.IProgramElement;
+import org.aspectj.weaver.*;
+import org.aspectj.weaver.patterns.*;
+import org.eclipse.jdt.internal.compiler.ast.*;
+
+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_UNKNONWN = "<unknown declare>";
+       public static final String POINTCUT_ABSTRACT = "<abstract pointcut>";
+       public static final String POINTCUT_ANONYMOUS = "<anonymous pointcut>";
+       public static final int MAX_MESSAGE_LENGTH = 18;
+       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);
+
+                       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();
+                                       details += rp.name + "..";
+                               } else if (ad.pointcutDesignator.getPointcut() instanceof AndPointcut) {
+                                       AndPointcut ap = (AndPointcut)ad.pointcutDesignator.getPointcut();
+                                       if (ap.getLeft() instanceof ReferencePointcut) {
+                                               details += ap.getLeft().toString() + "..";      
+                                       } else {
+                                               details += POINTCUT_ANONYMOUS + "..";
+                                       }
+                               } else if (ad.pointcutDesignator.getPointcut() instanceof OrPointcut) {
+                                       OrPointcut op = (OrPointcut)ad.pointcutDesignator.getPointcut();
+                                       if (op.getLeft() instanceof ReferencePointcut) {
+                                               details += op.getLeft().toString() + "..";      
+                                       } else {
+                                               details += POINTCUT_ANONYMOUS + "..";
+                                       }
+                               } else {
+                                       details += POINTCUT_ANONYMOUS;
+                               }
+                       } else {
+                               details += POINTCUT_ABSTRACT;
+                       } 
+                       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);
+                       node.setName(translatePointcutName(new String(methodDeclaration.selector)));
+                       setParameters(methodDeclaration, node);
+                       
+               } else if (methodDeclaration instanceof DeclareDeclaration) { 
+                       DeclareDeclaration declare = (DeclareDeclaration)methodDeclaration;
+                       String name = DEC_LABEL + " ";
+                       if (declare.declare instanceof DeclareErrorOrWarning) {
+                               DeclareErrorOrWarning deow = (DeclareErrorOrWarning)declare.declare;
+                               
+                               if (deow.isError()) {
+                                       node.setKind( IProgramElement.Kind.DECLARE_ERROR);
+                                       name += DECLARE_ERROR;
+                               } else {
+                                       node.setKind( IProgramElement.Kind.DECLARE_WARNING);
+                                       name += DECLARE_WARNING;
+                               }
+                               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(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(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(name + DECLARE_PRECEDENCE);
+                               node.setDetails(genPrecedenceListLabel(ds.getPatterns()));
+                               
+                               
+                       } else {
+                               node.setKind(IProgramElement.Kind.ERROR);
+                               node.setName(DECLARE_UNKNONWN);
+                       }
+                       
+               } else if (methodDeclaration instanceof InterTypeDeclaration) {
+                       InterTypeDeclaration itd = (InterTypeDeclaration)methodDeclaration;
+                       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;
+                       } else if (methodDeclaration instanceof InterTypeConstructorDeclaration) {
+                               node.setKind(IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR);
+                               InterTypeConstructorDeclaration itcd = (InterTypeConstructorDeclaration)methodDeclaration;                              
+                       } else {
+                               node.setKind(IProgramElement.Kind.ERROR);
+                       }
+                       node.setName(name);
+                       node.setReturnType(itd.returnType.toString());
+                       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);
+                       node.setName(label); 
+                       setParameters(methodDeclaration, node);
+               }
+       }
+
+
+       private String genPrecedenceListLabel(TypePatternList list) {
+               String tpList = "";
+               for (int i = 0; i < list.size(); i++) {
+                       tpList += genTypePatternLabel(list.get(i));
+                       if (i < list.size()-1) tpList += ", ";
+               } 
+               return tpList;
+       }
+  
+//     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;
+               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();
+                       if (acceptArgument(argName, argType)) { 
+                               names.add(argName);
+                               types.add(argType);
+                       }   
+               }
+       }
+
+       // 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;
+               TypeX typeX = tp.getExactType();
+               
+               if (typeX != ResolvedTypeX.MISSING) {
+                       label = typeX.getName();
+                       if (tp.isIncludeSubtypes()) label += "+";
+               } else {
+                       label = TYPE_PATTERN_LITERAL;
+               }
+               return label;
+               
+       }
+
+       public String genDeclareMessage(String message) {
+               int length = message.length();
+               if (length < MAX_MESSAGE_LENGTH) {
+                       return message;
+               } else {
+                       return message.substring(0, MAX_MESSAGE_LENGTH-1) + "..";
+               }
+       }
+       
+//     // TODO: 
+//     private String translateAdviceName(String label) {
+//             if (label.indexOf("before") != -1) return "before";
+//             if (label.indexOf("returning") != -1) return "after returning";
+//             if (label.indexOf("after") != -1) return "after";
+//             if (label.indexOf("around") != -1) return "around";
+//             else return "<advice>";
+//     }
+       
+//     // !!! move or replace
+//     private String translateDeclareName(String name) {
+//             int colonIndex = name.indexOf(":");
+//             if (colonIndex != -1) {
+//                     return name.substring(0, colonIndex);
+//             } else { 
+//                     return name;
+//             }
+//     }
+
+       // !!! move or replace
+//     private String translateInterTypeDecName(String name) {
+//             int index = name.lastIndexOf('$');
+//             if (index != -1) {
+//                     return name.substring(index+1);
+//             } else { 
+//                     return name;
+//             }
+//     }
+
+       // !!! move or replace
+       private String translatePointcutName(String name) {
+               int index = name.indexOf("$$")+2;
+               int endIndex = name.lastIndexOf('$');
+               if (index != -1 && endIndex != -1) {
+                       return name.substring(index, endIndex);
+               } else { 
+                       return name;
+               }
+       }
+
+
+}
index c159919d51200bd817d5516fa773bcb1c9ebdd78..d044ab0fbe2eb1352b32d22ac2f97b3fb3537ec6 100644 (file)
@@ -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/AsmNodeFormatter.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmNodeFormatter.java
deleted file mode 100644 (file)
index e202574..0000000
+++ /dev/null
@@ -1,237 +0,0 @@
-/* *******************************************************************
- * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
- * 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 
- *  
- * ******************************************************************/
-
-package org.aspectj.ajdt.internal.core.builder;
-
-import java.util.Iterator;
-
-import org.aspectj.ajdt.internal.compiler.ast.*;
-import org.aspectj.asm.IProgramElement;
-import org.aspectj.weaver.*;
-import org.aspectj.weaver.patterns.*;
-import org.eclipse.jdt.internal.compiler.ast.*;
-
-public class AsmNodeFormatter {
-
-       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>";
-       public static final int MAX_MESSAGE_LENGTH = 18;
-       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) + "): ";
-
-                       if (ad.kind == AdviceKind.Around) {
-                               node.setReturnType(ad.returnTypeToString(0));
-                       }
-       
-                       if (ad.pointcutDesignator != null) {    
-                               if (ad.pointcutDesignator.getPointcut() instanceof ReferencePointcut) {
-                                       ReferencePointcut rp = (ReferencePointcut)ad.pointcutDesignator.getPointcut();
-                                       label += rp.name + "..";
-                               } else if (ad.pointcutDesignator.getPointcut() instanceof AndPointcut) {
-                                       AndPointcut ap = (AndPointcut)ad.pointcutDesignator.getPointcut();
-                                       if (ap.getLeft() instanceof ReferencePointcut) {
-                                               label += ap.getLeft().toString() + "..";        
-                                       } else {
-                                               label += POINTCUT_ANONYMOUS + "..";
-                                       }
-                               } else if (ad.pointcutDesignator.getPointcut() instanceof OrPointcut) {
-                                       OrPointcut op = (OrPointcut)ad.pointcutDesignator.getPointcut();
-                                       if (op.getLeft() instanceof ReferencePointcut) {
-                                               label += op.getLeft().toString() + "..";        
-                                       } else {
-                                               label += POINTCUT_ANONYMOUS + "..";
-                                       }
-                               } else {
-                                       label += POINTCUT_ANONYMOUS;
-                               }
-                       } else {
-                               label += POINTCUT_ABSTRACT;
-                       } 
-                       node.setName(label);
-
-               } 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); 
-                       
-               } else if (methodDeclaration instanceof DeclareDeclaration) { 
-                       DeclareDeclaration declare = (DeclareDeclaration)methodDeclaration;
-                       String label = DEC_LABEL + " ";
-                       if (declare.declare instanceof DeclareErrorOrWarning) {
-                               DeclareErrorOrWarning deow = (DeclareErrorOrWarning)declare.declare;
-                               
-                               if (deow.isError()) {
-                                       node.setKind( IProgramElement.Kind.DECLARE_ERROR);
-                                       label += DECLARE_ERROR;
-                               } else {
-                                       node.setKind( IProgramElement.Kind.DECLARE_WARNING);
-                                       label += DECLARE_WARNING;
-                               }
-                               node.setName(label + "\"" + 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()));     
-                               
-                       } 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()));
-                       } 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()));
-                       } else {
-                               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()); 
-                       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) + ")";
-                       } 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.setReturnType(itd.returnType.toString());
-                       
-               } 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); 
-               }
-       }
-
-
-       private String genPrecedenceListLabel(TypePatternList list) {
-               String tpList = "";
-               for (int i = 0; i < list.size(); i++) {
-                       tpList += genTypePatternLabel(list.get(i));
-                       if (i < list.size()-1) tpList += ", ";
-               } 
-               return tpList;
-       }
-  
-       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();
-//                     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 + ", ";
-                       }  
-               }
-               int lastSepIndex = args.lastIndexOf(',');
-               if (lastSepIndex != -1 && args.endsWith(", ")) args = args.substring(0, lastSepIndex);
-               return args;
-       }
-
-       public String genTypePatternLabel(TypePattern tp) {
-               final String TYPE_PATTERN_LITERAL = "<type pattern>";
-               String label;
-               TypeX typeX = tp.getExactType();
-               
-               if (typeX != ResolvedTypeX.MISSING) {
-                       label = typeX.getName();
-                       if (tp.isIncludeSubtypes()) label += "+";
-               } else {
-                       label = TYPE_PATTERN_LITERAL;
-               }
-               return label;
-               
-       }
-
-       public String genDeclareMessage(String message) {
-               int length = message.length();
-               if (length < MAX_MESSAGE_LENGTH) {
-                       return message;
-               } else {
-                       return message.substring(0, MAX_MESSAGE_LENGTH-1) + "..";
-               }
-       }
-       
-//     // TODO: 
-//     private String translateAdviceName(String label) {
-//             if (label.indexOf("before") != -1) return "before";
-//             if (label.indexOf("returning") != -1) return "after returning";
-//             if (label.indexOf("after") != -1) return "after";
-//             if (label.indexOf("around") != -1) return "around";
-//             else return "<advice>";
-//     }
-       
-//     // !!! move or replace
-//     private String translateDeclareName(String name) {
-//             int colonIndex = name.indexOf(":");
-//             if (colonIndex != -1) {
-//                     return name.substring(0, colonIndex);
-//             } else { 
-//                     return name;
-//             }
-//     }
-
-       // !!! move or replace
-//     private String translateInterTypeDecName(String name) {
-//             int index = name.lastIndexOf('$');
-//             if (index != -1) {
-//                     return name.substring(index+1);
-//             } else { 
-//                     return name;
-//             }
-//     }
-
-       // !!! move or replace
-       private String translatePointcutName(String name) {
-               int index = name.indexOf("$$")+2;
-               int endIndex = name.lastIndexOf('$');
-               if (index != -1 && endIndex != -1) {
-                       return name.substring(index, endIndex);
-               } else { 
-                       return name;
-               }
-       }
-
-
-}
index 93e1bd5fed8cc9027750da58cdf4501df4a74278..4188adeb4c188b8969c5a798e2f375f21ef22499 100644 (file)
@@ -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);
index 76e3671e09f1d9123ef51d1445442e0f010e4591..dc783f0c8f28c7e1757a78db4f38b0c689cc8634 100644 (file)
@@ -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/AsmAdapter.java
deleted file mode 100644 (file)
index 5c121b1..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-/* *******************************************************************
- * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
- * 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: 
- *     PARC     initial implementation 
- * ******************************************************************/
-
-
-package org.aspectj.weaver;
-
-import java.util.*;
-
-import org.aspectj.asm.*;
-import org.aspectj.asm.internal.*;
-import org.aspectj.bridge.*;
-
-public class AsmAdapter {
-       
-       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) {
-//             System.err.println("> " + shadow.getThisVar() + " to " + shadow.getTargetVar());
-       }
-       
-       public static void nodeMunger(AspectJModel model, Shadow shadow, ShadowMunger munger) {
-               if (munger instanceof Advice) {
-                       Advice a = (Advice)munger;
-                       if (a.getKind().isPerEntry() || a.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);  
-                       
-                       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);
-                               }
-                               back.getTargets().add(adviceNode);
-                       }
-               }
-       }
-
-       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) {
-               Member enclosingMember = shadow.getEnclosingCodeSignature();
-               
-               IProgramElement enclosingNode = lookupMember(model, enclosingMember);
-               if (enclosingNode == null) {
-                       Lint.Kind err = shadow.getIWorld().getLint().shadowNotInStructure;
-                       if (err.isEnabled()) {
-                               err.signal(shadow.toString(), shadow.getSourceLocation());
-                       }
-                       return null;
-               }
-               
-               Member shadowSig = shadow.getSignature();
-               if (!shadowSig.equals(enclosingMember)) {
-                       IProgramElement bodyNode = findOrCreateBodyNode(enclosingNode, shadowSig, shadow);
-                       return bodyNode;
-               } else {
-                       return enclosingNode;
-               }
-       }
-
-       private static IProgramElement findOrCreateBodyNode(
-               IProgramElement enclosingNode,
-               Member shadowSig, Shadow shadow)
-       {
-               for (Iterator it = enclosingNode.getChildren().iterator(); it.hasNext(); ) {
-                       IProgramElement node = (IProgramElement)it.next();
-                       if (shadowSig.getName().equals(node.getBytecodeName()) &&
-                               shadowSig.getSignature().equals(node.getBytecodeSignature()))
-                       {
-                               return node;
-                       }
-               }
-               
-               ISourceLocation sl = shadow.getSourceLocation();
-               
-               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(),
-                       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) {
-               TypeX declaringType = member.getDeclaringType();
-               IProgramElement classNode =
-                       model.findNodeForType(declaringType.getPackageName(), declaringType.getClassName());
-               return findMemberInClass(classNode, member);
-       }
-
-       private static IProgramElement findMemberInClass(
-               IProgramElement classNode,
-               Member member)
-       {
-               if (classNode == null) return null; // XXX remove this check
-               for (Iterator it = classNode.getChildren().iterator(); it.hasNext(); ) {
-                       IProgramElement node = (IProgramElement)it.next();
-                       //System.err.println("checking: " + member.getName() + " with " + node.getBytecodeName() + ", " + node.getBytecodeSignature());
-                       if (member.getName().equals(node.getBytecodeName()) &&
-                               member.getSignature().equals(node.getBytecodeSignature()))
-                       {
-                               return node;
-                       }
-               }
-               // if we can't find the member, we'll just put it in the class
-               return classNode;
-       }
-}
diff --git a/weaver/src/org/aspectj/weaver/AsmAdviceRelationshipProvider.java b/weaver/src/org/aspectj/weaver/AsmAdviceRelationshipProvider.java
new file mode 100644 (file)
index 0000000..5779570
--- /dev/null
@@ -0,0 +1,169 @@
+/* *******************************************************************
+ * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
+ * 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: 
+ *     PARC     initial implementation 
+ * ******************************************************************/
+
+
+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 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(IHierarchy model, Shadow shadow) {
+//             System.err.println("> " + shadow.getThisVar() + " to " + shadow.getTargetVar());
+       }
+       
+       public static void nodeMunger(IHierarchy model, Shadow shadow, ShadowMunger munger) {
+               if (munger instanceof Advice) {
+                       Advice advice = (Advice)munger;
+                       if (advice.getKind().isPerEntry() || advice.getKind().isCflow()) {
+                               // TODO: might want to show these in the future
+                               return;
+                       }
+                       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 (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);
+                                       }
+                               }
+                       } catch (IOException e) {
+                               e.printStackTrace();
+                       }
+               }
+       }
+
+       private static IProgramElement getNode(IHierarchy model, Shadow shadow) {
+               Member enclosingMember = shadow.getEnclosingCodeSignature();
+               
+               IProgramElement enclosingNode = lookupMember(model, enclosingMember);
+               if (enclosingNode == null) {
+                       Lint.Kind err = shadow.getIWorld().getLint().shadowNotInStructure;
+                       if (err.isEnabled()) {
+                               err.signal(shadow.toString(), shadow.getSourceLocation());
+                       }
+                       return null;
+               }
+               
+               Member shadowSig = shadow.getSignature();
+               if (!shadowSig.equals(enclosingMember)) {
+                       IProgramElement bodyNode = findOrCreateCodeNode(enclosingNode, shadowSig, shadow);
+                       return bodyNode;
+               } else {
+                       return enclosingNode;
+               }
+       }
+       
+       private static IProgramElement findOrCreateCodeNode(IProgramElement enclosingNode, Member shadowSig, Shadow shadow)
+       {
+               for (Iterator it = enclosingNode.getChildren().iterator(); it.hasNext(); ) {
+                       IProgramElement node = (IProgramElement)it.next();
+                       if (shadowSig.getName().equals(node.getBytecodeName()) &&
+                               shadowSig.getSignature().equals(node.getBytecodeSignature()))
+                       {
+                               return node;
+                       }
+               }
+               
+               ISourceLocation sl = shadow.getSourceLocation();
+               
+               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()),
+                       0,
+                       "",
+                       new ArrayList());
+                               
+               peNode.setBytecodeName(shadowSig.getName());
+               peNode.setBytecodeSignature(shadowSig.getSignature());
+               enclosingNode.addChild(peNode);
+               return peNode;
+       }
+       
+       private static IProgramElement lookupMember(IHierarchy model, Member member) {
+               TypeX declaringType = member.getDeclaringType();
+               IProgramElement classNode =
+                       model.findElementForType(declaringType.getPackageName(), declaringType.getClassName());
+               return findMemberInClass(classNode, member);
+       }
+
+       private static IProgramElement findMemberInClass(
+               IProgramElement classNode,
+               Member member)
+       {
+               if (classNode == null) return null; // XXX remove this check
+               for (Iterator it = classNode.getChildren().iterator(); it.hasNext(); ) {
+                       IProgramElement node = (IProgramElement)it.next();
+                       //System.err.println("checking: " + member.getName() + " with " + node.getBytecodeName() + ", " + node.getBytecodeSignature());
+                       if (member.getName().equals(node.getBytecodeName()) &&
+                               member.getSignature().equals(node.getBytecodeSignature()))
+                       {
+                               return node;
+                       }
+               }
+               // 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;
+//             }
+//     }
+
+}
index 83c9f40b9c026cca01a7f098af6d1b6cb0dc41c2..a17bba0bbae6384b122f7cb96dfe514fcb606e52 100644 (file)
@@ -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;
        }
index a6ec5529a58ece134423fa6a73207c739585aaf6..a8a1ebd94f6f2caeafc61220dcbb05ba1de5dae8 100644 (file)
@@ -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);
                        }
                }
        }
index 9f2285e230bb189b227dc6cf9d893e3a1031a079..8043320906a54a938667a979aea3ecba929f2b1b 100644 (file)
 
 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;
        }