]> source.dussan.org Git - aspectj.git/commitdiff
Added support for multiple relationships for a single program element. Renamed model...
authormkersten <mkersten>
Wed, 13 Aug 2003 20:51:10 +0000 (20:51 +0000)
committermkersten <mkersten>
Wed, 13 Aug 2003 20:51:10 +0000 (20:51 +0000)
25 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/SimpleStructureViewToolPanel.java
ajde/src/org/aspectj/ajde/ui/swing/StructureTreeManager.java
ajde/testsrc/org/aspectj/ajde/AsmDeclarationsTest.java
ajde/testsrc/org/aspectj/ajde/AsmRelationshipsTest.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 [new file with mode: 0644]
asm/src/org/aspectj/asm/HierarchyWalker.java
asm/src/org/aspectj/asm/IRelationship.java
asm/src/org/aspectj/asm/IRelationshipMapper.java
asm/src/org/aspectj/asm/IStructureModelListener.java
asm/src/org/aspectj/asm/StructureModel.java [deleted file]
asm/src/org/aspectj/asm/internal/RelationshipMapper.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java
weaver/src/org/aspectj/weaver/AsmAdapter.java
weaver/src/org/aspectj/weaver/World.java

index c11db439966600ed1348c0cdcf85f6867c7ba76f..6f7523f7a70effa5aa996eea5a1d88ede3c687c6 100644 (file)
@@ -47,7 +47,7 @@ public class BrowserManager {
     private static TopFrame topFrame = null;
     
        public final IStructureModelListener VIEW_LISTENER = new IStructureModelListener() {
-               public void containmentHierarchyUpdated(StructureModel model) {         
+               public void containmentHierarchyUpdated(AspectJModel model) {           
                        FileStructureView fsv = Ajde.getDefault().getStructureViewManager().getDefaultFileView();
                        if (fsv != null) {
                                fsv.setSourceFile(BrowserManager.getDefault().getEditorManager().getCurrFile());
index ec0b44a9eb9a24a079b8bc88f5fb1c751236f6fd..578c04e0c8f9f870d25d4997d26aca861bc80f13 100644 (file)
@@ -114,9 +114,9 @@ public class StructureModelUtil {
 
        public static List getPackagesInModel() {
                List packages = new ArrayList();
-               StructureModel model =
+               AspectJModel model =
                        Ajde.getDefault().getStructureModelManager().getModel();
-               if (model.equals(StructureModel.NO_STRUCTURE)) {
+               if (model.equals(AspectJModel.NO_STRUCTURE)) {
                        return null;
                } else {
                        return getPackagesHelper(
index f98f5147e366ccee1e0d563774a990945732e315..c1f77c2431acd760a07d26c7a4ec95ede46c62e8 100644 (file)
@@ -34,8 +34,8 @@ public class StructureSearchManager {
                IProgramElement.Kind kind) {
                
                List matches = new ArrayList();
-               StructureModel model = Ajde.getDefault().getStructureModelManager().getModel();
-               if (model.equals(StructureModel.NO_STRUCTURE)) {
+               AspectJModel model = Ajde.getDefault().getStructureModelManager().getModel();
+               if (model.equals(AspectJModel.NO_STRUCTURE)) {
                        return null;
                } else {
                        return findMatchesHelper((IProgramElement)model.getRoot(), pattern, kind, matches);
index 7170001ba77dbccb173fb5cf1a34ee8a1e6590f2..7eb9dfa5fdc2b093a63ab8ac1c7752e392afc084 100644 (file)
@@ -36,7 +36,7 @@ public class StructureViewManager {
     private static final List AVAILABLE_RELATIONS;
        
     public final IStructureModelListener VIEW_LISTENER = new IStructureModelListener() {
-        public void containmentHierarchyUpdated(StructureModel model) {                
+        public void containmentHierarchyUpdated(AspectJModel model) {          
                Ajde.getDefault().logEvent("updating structure views: " + structureViews);
 //             
 //             if (defaultFileView != null) {
@@ -44,7 +44,7 @@ public class StructureViewManager {
 //             }
                
                for (Iterator it = structureViews.iterator(); it.hasNext(); ) {
-                       treeViewBuilder.buildView((StructureView)it.next(), (StructureModel)model);
+                       treeViewBuilder.buildView((StructureView)it.next(), (AspectJModel)model);
                }
         }
     }; 
@@ -116,7 +116,7 @@ public class StructureViewManager {
         */ 
        private void navigationAction(IProgramElement node, boolean recordHistory) { 
                if (node == null 
-                       || node == StructureModel.NO_STRUCTURE) {
+                       || node == AspectJModel.NO_STRUCTURE) {
                        Ajde.getDefault().getIdeUIAdapter().displayStatusInformation("Source not available for node: " + node.getName());
                        return;         
                }
index 2cb82282732791a516378c2aacd356951b18b187..2339614abdacda8571cfc9fd3d7082693e8fb781 100644 (file)
@@ -37,22 +37,25 @@ public abstract class StructureViewNodeFactory {
                AbstractIcon icon = iconRegistry.getStructureIcon(node.getKind(), node.getAccessibility());
 
                IStructureViewNode svNode = createDeclaration(node, icon, children);            
-               IRelationship rel = AsmManager.getDefault().getMapper().get(node);
-               if (rel != null && rel.getTargets().size() > 0) {
-                       IStructureViewNode relNode = createRelationship(
-                               rel, 
-                               iconRegistry.getIcon(rel.getKind())
-                       );
-                       svNode.add(relNode, 0);
-                       
-                       for (Iterator it = rel.getTargets().iterator(); it.hasNext(); ) {
-                               IProgramElement link = (IProgramElement)it.next();
-                               IStructureViewNode linkNode = createLink(
-                                       link,   
-                                       iconRegistry.getStructureIcon(link.getKind(), link.getAccessibility())  
-                               );      
-                               relNode.add(linkNode);
-                                       
+               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);
+                                               
+                               }
                        }
                }
                return svNode;
index cdbd5a11d5c19a5188d715d17f4bbc4aea8f1574..239628176f283f647676a76d6b5af4bdce802786 100644 (file)
@@ -34,14 +34,14 @@ public class TreeStructureViewBuilder {
        /**
         * @todo        get rid of instanceof tests
         */
-       public void buildView(StructureView view, StructureModel model) {
+       public void buildView(StructureView view, AspectJModel model) {
                StructureViewProperties properties = view.getViewProperties();
                IProgramElement modelRoot = null;
                boolean noStructure = false;
                if (isFileView(view)) {
                        FileStructureView fileView = (FileStructureView)view;
                        if (fileView.getSourceFile() == null) { 
-                               modelRoot = StructureModel.NO_STRUCTURE;
+                               modelRoot = AspectJModel.NO_STRUCTURE;
                                noStructure = true;
                        } else {
                                modelRoot = model.findRootNodeForSourceFile(fileView.getSourceFile());
@@ -197,7 +197,7 @@ public class TreeStructureViewBuilder {
                }
        }
 
-    private IStructureViewNode buildCustomTree(GlobalStructureView view, StructureModel model) {
+    private IStructureViewNode buildCustomTree(GlobalStructureView view, AspectJModel model) {
         IProgramElement rootNode = model.getRoot();
         IStructureViewNode treeNode = nodeFactory.createNode(rootNode);
 
index dc9b5cd76548d5b4cacf2ab88549cda50c1b9f1f..66c3a0e0abc07f0949c2b649c79214bb8aa4d7eb 100644 (file)
@@ -33,7 +33,7 @@ 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.StructureModel;
+import org.aspectj.asm.AspectJModel;
 import org.aspectj.asm.IStructureModelListener;
 
 public class SimpleStructureViewToolPanel extends JPanel {
@@ -61,7 +61,7 @@ public class SimpleStructureViewToolPanel extends JPanel {
     BorderLayout borderLayout4 = new BorderLayout();
 
     public final IStructureModelListener MODEL_LISTENER = new IStructureModelListener() {
-        public void containmentHierarchyUpdated(StructureModel model) {
+        public void containmentHierarchyUpdated(AspectJModel model) {
                        String path = Ajde.getDefault().getConfigurationManager().getActiveConfigFile();
                        String fileName = "<no active config>";
                        if (path != null) fileName = new File(path).getName();
index 29871bf8d571dcc14ce287b2ed38ca5de2c55aa4..efb786b7f14ac13676b78042883e9a279d88e473 100644 (file)
@@ -35,7 +35,7 @@ class StructureTreeManager {
     private TreeSelectionListener treeListener = null;
 
     private final StructureTreeModel NO_STRUCTURE_MODEL
-        = new StructureTreeModel(new SwingTreeViewNode(StructureModel.NO_STRUCTURE, new AbstractIcon(null), new ArrayList()));
+        = new StructureTreeModel(new SwingTreeViewNode(AspectJModel.NO_STRUCTURE, new AbstractIcon(null), new ArrayList()));
         
     /**
      * @todo   should probably avoid that MouseListener cast
index b0d854238a0ec7ab0f430d16cb31c0d4e4946ee7..8b815224b889331fb1b6ae039647dc7636c50317 100644 (file)
@@ -20,7 +20,7 @@ import org.aspectj.asm.IProgramElement.Kind;
 // TODO: add tests for java kinds
 public class AsmDeclarationsTest extends AjdeTestCase {
 
-       private StructureModel model = null;
+       private AspectJModel model = null;
        private static final String CONFIG_FILE_PATH = "../examples/coverage/coverage.lst";
        private static final int DEC_MESSAGE_LENGTH = AsmNodeFormatter.MAX_MESSAGE_LENGTH;
 
index 3714da143884b7a8f319ca54595e48a7fe993dc8..f2a005670bed74db36e9330ce82acd95caa49514 100644 (file)
@@ -16,7 +16,6 @@ import java.util.List;
 import org.aspectj.asm.*;
 import org.aspectj.asm.internal.ProgramElement;
 
-
 // TODO: check for return types
 public class AsmRelationshipsTest extends AjdeTestCase {
   
@@ -28,32 +27,32 @@ public class AsmRelationshipsTest extends AjdeTestCase {
        }
   
 //     public void testInterTypeDeclarations() {               
-//             checkMapping("InterTypeDecCoverage", "Point", "Point.xxx:", "xxx");     
+//             checkMapping("InterTypeDecCoverage", "Point", "Point.xxx:", "xxx", "declared on", "aspect declarations");       
 //     }
 
        public void testAdvice() {      
-               checkMapping("AdvisesRelationshipCoverage", "Point", "before(): methodExecutionP..", "setX(int)");
-               checkUniDirectionalMapping("AdvisesRelationshipCoverage", "Point", "before(): getP..", "field-get(int Point.x)");
-               checkUniDirectionalMapping("AdvisesRelationshipCoverage", "Point", "before(): setP..", "field-set(int Point.xxx)");     
+               checkMapping("AdvisesRelationshipCoverage", "Point", "before(): methodExecutionP..", "setX(int)", "advises", "advised by");
+               checkUniDirectionalMapping("AdvisesRelationshipCoverage", "Point", "before(): getP..", "field-get(int Point.x)", "advises");
+               checkUniDirectionalMapping("AdvisesRelationshipCoverage", "Point", "before(): setP..", "field-set(int Point.xxx)", "advises");  
        }
 
-       private void checkUniDirectionalMapping(String fromType, String toType, String from, String to) {
+       private void checkUniDirectionalMapping(String fromType, String toType, String from, String to, String relName) {
                IProgramElement aspect = AsmManager.getDefault().getModel().findNodeForType(null, fromType);
                assertNotNull(aspect);          
                String beforeExec = from;
                IProgramElement beforeExecNode = manager.getModel().findNode(aspect, IProgramElement.Kind.ADVICE, beforeExec);
                assertNotNull(beforeExecNode);
-               IRelationship rel = manager.getMapper().get(beforeExecNode);
+               IRelationship rel = manager.getMapper().get(beforeExecNode, IRelationship.Kind.ADVICE, relName);
                assertEquals(((IProgramElement)rel.getTargets().get(0)).getName(), to);
        }
 
-       private void checkMapping(String fromType, String toType, String from, String to) {
+       private void checkMapping(String fromType, String toType, String from, String to, String forwardRelName, String backRelName) {
                IProgramElement aspect = AsmManager.getDefault().getModel().findNodeForType(null, fromType);
                assertNotNull(aspect);          
                String beforeExec = from;
                IProgramElement beforeExecNode = manager.getModel().findNode(aspect, IProgramElement.Kind.ADVICE, beforeExec);
                assertNotNull(beforeExecNode);
-               IRelationship rel = manager.getMapper().get(beforeExecNode);
+               IRelationship rel = manager.getMapper().get(beforeExecNode, IRelationship.Kind.ADVICE, forwardRelName);
                assertEquals(((IProgramElement)rel.getTargets().get(0)).getName(), to);
 
                IProgramElement clazz = AsmManager.getDefault().getModel().findNodeForType(null, toType);
@@ -61,7 +60,7 @@ public class AsmRelationshipsTest extends AjdeTestCase {
                String set = to;
                IProgramElement setNode = manager.getModel().findNode(clazz, IProgramElement.Kind.METHOD, set);
                assertNotNull(setNode);
-               IRelationship rel2 = manager.getMapper().get(setNode);
+               IRelationship rel2 = manager.getMapper().get(setNode, IRelationship.Kind.ADVICE, backRelName);
                assertEquals(((IProgramElement)rel2.getTargets().get(0)).getName(), from);
        }
 
index d7c1038aab2c1cd5e2c644d68aff318770b3acda..cae44a4030f522d66fca81bced41db0c17814716 100644 (file)
@@ -45,11 +45,11 @@ public class StructureModelRegressionTest extends AjdeTestCase {
 
        public boolean verifyAgainstSavedModel(String lstFile) {
                File modelFile = new File(genStructureModelExternFilePath(lstFile));
-               StructureModel model = getModelForFile(lstFile);
+               AspectJModel model = getModelForFile(lstFile);
                
                if (modelFile.exists()) {
                        Ajde.getDefault().getStructureModelManager().readStructureModel(lstFile);
-                       StructureModel savedModel = Ajde.getDefault().getStructureModelManager().getModel();
+                       AspectJModel savedModel = Ajde.getDefault().getStructureModelManager().getModel();
                        // 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 StructureModel getModelForFile(String lstFile) {
+       private AspectJModel getModelForFile(String lstFile) {
                Ajde.getDefault().getConfigurationManager().setActiveConfigFile(lstFile);
                Ajde.getDefault().getBuildManager().build(); // was buildStructure...
                while(!testerBuildListener.getBuildFinished()) {
index ba451fcfaaa8aedd192c38d4fc0ede4b26f7a843..674895e41f7ef14374e2bc78397ac1a8809f642c 100644 (file)
@@ -115,7 +115,7 @@ 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 {
-        StructureModel model = Ajde.getDefault().getStructureModelManager().getModel();
+        AspectJModel model = Ajde.getDefault().getStructureModelManager().getModel();
         assertTrue("model exists", model != null);
                assertTrue("root exists", model.getRoot() != null);
                File testFile = openFile("figures-coverage/figures/Main.java");
index dad5bf24073a0947dd88251b91864cd23df776d2..99ff905f4f4171a3896df978df56e206466109fe 100644 (file)
@@ -66,7 +66,7 @@ public class StructureViewManagerTest extends AjdeTestCase {
                assertTrue(
                        "no structure", 
                        currentView.getRootNode().getStructureNode().getChildren().get(0) 
-                       == StructureModel.NO_STRUCTURE
+                       == AspectJModel.NO_STRUCTURE
                );                      
        }
 
@@ -87,7 +87,7 @@ public class StructureViewManagerTest extends AjdeTestCase {
                assertTrue(
                        "no structure", 
                        //currentView.getRootNode().getIProgramElement().getChildren().get(0) 
-                       n == StructureModel.NO_STRUCTURE
+                       n == AspectJModel.NO_STRUCTURE
                );      
        }
 
@@ -125,7 +125,7 @@ public class StructureViewManagerTest extends AjdeTestCase {
                assertTrue(
                        "no structure", 
                        currentView.getRootNode().getStructureNode() 
-                       == StructureModel.NO_STRUCTURE
+                       == AspectJModel.NO_STRUCTURE
                );
        }
   
index dda0ab096cc5ebd406b6b95ea9e1e37820013014..b090abfcfe0931b1cf90cc4c9c288466a43ebc5e 100644 (file)
@@ -29,7 +29,7 @@ public class AsmManager {
         */  
        private static AsmManager INSTANCE = new AsmManager();
        private boolean shouldSaveModel = true;
-    protected StructureModel model = new StructureModel();
+    protected AspectJModel model = new AspectJModel();
     private List structureListeners = new ArrayList();
        private IRelationshipMapper mapper;
 
@@ -39,7 +39,7 @@ public class AsmManager {
                mapper = new RelationshipMapper();
     }
 
-    public StructureModel getModel() {
+    public AspectJModel getModel() {
         return model;  
        }
 
@@ -140,16 +140,16 @@ public class AsmManager {
     public void readStructureModel(String configFilePath) {
         try {
             if (configFilePath == null) {
-               model.setRoot(StructureModel.NO_STRUCTURE);
+               model.setRoot(AspectJModel.NO_STRUCTURE);
             } else {
                    String filePath = genExternFilePath(configFilePath);
                    FileInputStream in = new FileInputStream(filePath);
                    ObjectInputStream s = new ObjectInputStream(in);
-                   model = (StructureModel)s.readObject();
+                   model = (AspectJModel)s.readObject();
             }
         } catch (Exception e) {
                //System.err.println("AJDE Message: could not read structure model: " + e);
-            model.setRoot(StructureModel.NO_STRUCTURE);
+            model.setRoot(AspectJModel.NO_STRUCTURE);
         } finally {
                notifyListeners();      
         }
diff --git a/asm/src/org/aspectj/asm/AspectJModel.java b/asm/src/org/aspectj/asm/AspectJModel.java
new file mode 100644 (file)
index 0000000..e8c723e
--- /dev/null
@@ -0,0 +1,265 @@
+/* *******************************************************************
+ * 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 b1d9e6100bd0d0437060e03c7fedf5f260096b9b..cac375482f45457ecc85070de772680fd4fdb38d 100644 (file)
@@ -17,15 +17,15 @@ package org.aspectj.asm;
 /**
  * @author Mik Kersten
  */
-public class HierarchyWalker {
+public abstract class HierarchyWalker {
 
-       private StructureModel model;
+       private AspectJModel model;
 
        public HierarchyWalker() {
                super();
        }
        
-       public HierarchyWalker(StructureModel model) {
+       public HierarchyWalker(AspectJModel model) {
                this.model = model;
     }
 
index 892f50006a1b073b8cb6d3f8adf4264ef2021814..b6377e83250c8cca6381c5abd0e2b6807292004f 100644 (file)
@@ -29,7 +29,7 @@ public interface IRelationship extends Serializable {
        public IProgramElement getSource();
        
        public Kind getKind();
-       
+               
        /**
         * Uses "typesafe enum" pattern.
         */
index ab8fffd34439449eb7aa229b08a0b7d94afb7365..747347222f16aeefaddabfb0fe770a2eeefe5653 100644 (file)
@@ -18,18 +18,31 @@ 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 {
  
-       // TODO: return a list
-       public IRelationship get(IProgramElement source);
+       /**
+        * @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);
        
-       // TODO: return a list 
-       public IRelationship get(String handle);
        
-       public void put(IProgramElement source, IRelationship relationship);
+       public List/*IRelationship*/ get(String handle);
        
+       public void put(IProgramElement source, IRelationship relationship);
+
        
  
 }
index 9356b6f2d29f0ce93f380ec968d2537dfd662da0..6e2879ee11ccd3d1a5520507234ab434a681b357 100644 (file)
@@ -23,5 +23,5 @@ import java.util.EventListener;
  */
 public interface IStructureModelListener extends EventListener {
 
-    public void containmentHierarchyUpdated(StructureModel rootNode);
+    public void containmentHierarchyUpdated(AspectJModel rootNode);
 }
diff --git a/asm/src/org/aspectj/asm/StructureModel.java b/asm/src/org/aspectj/asm/StructureModel.java
deleted file mode 100644 (file)
index 36318a2..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 StructureModel implements Serializable {
-       
-    protected  IProgramElement root = null;
-    protected String configFile = null;
-
-    private Map fileMap = null;
-    
-    public static final IProgramElement NO_STRUCTURE = new ProgramElement("<build to view structure>", IProgramElement.Kind.ERROR, null);
-
-       public IProgramElement 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 StructureModel.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 StructureModel.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 e794b76e017474e1e113cecb86849105c517eb99..c3d1a5f4c15011ee73ba4ace5cefa9a4c5781287 100644 (file)
@@ -21,16 +21,50 @@ import org.aspectj.asm.*;
  */
 public class RelationshipMapper extends HashMap implements IRelationshipMapper {
        
-       public IRelationship get(IProgramElement source) {
-               return (IRelationship)super.get(source);
+       public List get(IProgramElement source) {
+               List relationships = (List)super.get(source);
+               if (relationships == null) {
+                       return Collections.EMPTY_LIST;
+               } else {
+                       return relationships;
+               }
        }
 
-       public IRelationship get(String handle) {
+       /**
+        * @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) {
-               super.put(source, 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
index 37f50061c76a639eba8dc4b59cb3ff384bd74faa..8cb60f48fa64bbaefba5fc930f44323ca15e15d9 100644 (file)
@@ -42,7 +42,7 @@ public class AjBuildManager {
        private int compiledCount;
        private int sourceFileCount;
        
-       private StructureModel structureModel;
+       private AspectJModel structureModel;
        public AjBuildConfig buildConfig;
        
        AjState state = new AjState(this);
@@ -167,7 +167,7 @@ public class AjBuildManager {
      
     private void setupModel() {
         String rootLabel = "<root>";
-        StructureModel model = AsmManager.getDefault().getModel();
+        AspectJModel model = AsmManager.getDefault().getModel();
         IProgramElement.Kind kind = IProgramElement.Kind.FILE_JAVA;
         if (buildConfig.getConfigFile() != null) {
             rootLabel = buildConfig.getConfigFile().getName();
@@ -523,14 +523,14 @@ public class AjBuildManager {
        }
 
 
-       public void setStructureModel(StructureModel structureModel) {
+       public void setStructureModel(AspectJModel structureModel) {
                this.structureModel = structureModel;
        }
 
        /**
         * Returns null if there is no structure model
         */
-       public StructureModel getStructureModel() {
+       public AspectJModel getStructureModel() {
                return structureModel;
        }
     
index b7fd8d1be536488579bce58b2d0c9e229f8baaec..c159919d51200bd817d5516fa773bcb1c9ebdd78 100644 (file)
@@ -32,7 +32,7 @@ public class AsmHierarchyBuilder extends AbstractSyntaxTreeVisitorAdapter {
        
     public static void build(    
         CompilationUnitDeclaration unit,
-        StructureModel structureModel) {
+        AspectJModel structureModel) {
         LangUtil.throwIaxIfNull(unit, "unit");
         new AsmHierarchyBuilder(unit.compilationResult()).internalBuild(unit, structureModel);
     }
@@ -53,7 +53,7 @@ public class AsmHierarchyBuilder extends AbstractSyntaxTreeVisitorAdapter {
      */
     private void internalBuild(
         CompilationUnitDeclaration unit, 
-        StructureModel structureModel) {
+        AspectJModel structureModel) {
         LangUtil.throwIaxIfNull(structureModel, "structureModel");        
         if (!currCompilationResult.equals(unit.compilationResult())) {
             throw new IllegalArgumentException("invalid unit: " + unit);
@@ -116,7 +116,7 @@ public class AsmHierarchyBuilder extends AbstractSyntaxTreeVisitorAdapter {
         */
        private IProgramElement genAddToNode(
                CompilationUnitDeclaration unit,
-               StructureModel structureModel) {
+               AspectJModel structureModel) {
                final IProgramElement addToNode;
                {
                    ImportReference currentPackage = unit.currentPackage;
index 2c4188db6ab5963661b7b6e2ea255eb961a2c810..5c121b1692421c90b8b67e0c4119c4a441069314 100644 (file)
@@ -26,11 +26,11 @@ public class AsmAdapter {
        public static final String DECLARES_ON = "declares on";
        public static final String DECLAREDY_BY = "declared by";
 
-       public static void checkerMunger(StructureModel model, Shadow shadow) {
+       public static void checkerMunger(AspectJModel model, Shadow shadow) {
 //             System.err.println("> " + shadow.getThisVar() + " to " + shadow.getTargetVar());
        }
        
-       public static void nodeMunger(StructureModel model, Shadow shadow, ShadowMunger munger) {
+       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()) {
@@ -43,7 +43,7 @@ public class AsmAdapter {
                        IProgramElement adviceNode = getNode(model, a);  
                        
                        if (adviceNode != null && targetNode != null) {
-                               IRelationship foreward = mapper.get(adviceNode);
+                               IRelationship foreward = mapper.get(adviceNode, IRelationship.Kind.ADVICE, ADVISES);
                                if (foreward == null) {
                                        foreward = new Relationship(
                                                ADVISES,
@@ -55,7 +55,7 @@ public class AsmAdapter {
                                }
                                foreward.getTargets().add(targetNode);
 
-                               IRelationship back = mapper.get(targetNode);
+                               IRelationship back = mapper.get(targetNode, IRelationship.Kind.ADVICE, ADVISED_BY);
                                if (back == null) {
                                        back = new Relationship(
                                                ADVISED_BY,
@@ -70,14 +70,14 @@ public class AsmAdapter {
                }
        }
 
-       private static IProgramElement getNode(StructureModel model, Advice a) {
+       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(StructureModel model, Shadow shadow) {
+       private static IProgramElement getNode(AspectJModel model, Shadow shadow) {
                Member enclosingMember = shadow.getEnclosingCodeSignature();
                
                IProgramElement enclosingNode = lookupMember(model, enclosingMember);
@@ -130,7 +130,7 @@ public class AsmAdapter {
                return peNode;
        }
        
-       public static IProgramElement lookupMember(StructureModel model, Member member) {
+       public static IProgramElement lookupMember(AspectJModel model, Member member) {
                TypeX declaringType = member.getDeclaringType();
                IProgramElement classNode =
                        model.findNodeForType(declaringType.getPackageName(), declaringType.getClassName());
index 792201dd03c355997e798e5a433ce9934549c0b5..9f2285e230bb189b227dc6cf9d893e3a1031a079 100644 (file)
@@ -19,7 +19,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import org.aspectj.asm.StructureModel;
+import org.aspectj.asm.AspectJModel;
 import org.aspectj.bridge.IMessageHandler;
 import org.aspectj.bridge.ISourceLocation;
 import org.aspectj.bridge.Message;
@@ -36,7 +36,7 @@ public abstract class World {
     
     protected CrosscuttingMembersSet crosscuttingMembersSet = new CrosscuttingMembersSet(this);
     
-    protected StructureModel model = null;
+    protected AspectJModel model = null;
     
     protected Lint lint = new Lint(this);
     
@@ -340,11 +340,11 @@ public abstract class World {
                return crosscuttingMembersSet;
        }
 
-       public StructureModel getModel() {
+       public AspectJModel getModel() {
                return model;
        }
 
-       public void setModel(StructureModel model) {
+       public void setModel(AspectJModel model) {
                this.model = model;
        }