]> source.dussan.org Git - aspectj.git/commitdiff
Minor improvements to structure model generation, clean up of test suite output,...
authormkersten <mkersten>
Tue, 12 Aug 2003 10:23:30 +0000 (10:23 +0000)
committermkersten <mkersten>
Tue, 12 Aug 2003 10:23:30 +0000 (10:23 +0000)
ajbrowser/src/org/aspectj/tools/ajbrowser/BrowserManager.java
asm/src/org/aspectj/asm/AsmManager.java [new file with mode: 0644]
asm/src/org/aspectj/asm/IProgramElement.java
asm/src/org/aspectj/asm/IRelationshipMapper.java
asm/src/org/aspectj/asm/StructureModel.java
asm/src/org/aspectj/asm/StructureModelManager.java [deleted file]
asm/src/org/aspectj/asm/internal/ProgramElement.java
asm/src/org/aspectj/asm/internal/RelationshipMapper.java
docs/developer/asm.doc

index 6ed175fed7d9bb15c5bb5fac67153a21707cbfdf..c11db439966600ed1348c0cdcf85f6867c7ba76f 100644 (file)
@@ -102,7 +102,7 @@ public class BrowserManager {
                
                        AjdeUIManager.getDefault().getOptionsFrame().addOptionsPanel(new BrowserOptionsPanel());
                
-                       StructureModelManager.getDefault().addListener(VIEW_LISTENER);  
+                       AsmManager.getDefault().addListener(VIEW_LISTENER);     
                
                        //String lastOpenFilePath = browserProjectProperties.getLastOpenSourceFilePath();
                        //editorManager.showSourceLine(lastOpenFilePath, 1, false);     
diff --git a/asm/src/org/aspectj/asm/AsmManager.java b/asm/src/org/aspectj/asm/AsmManager.java
new file mode 100644 (file)
index 0000000..dda0ab0
--- /dev/null
@@ -0,0 +1,175 @@
+/* *******************************************************************
+ * 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.*;
+
+/**
+ * @author Mik Kersten
+ */
+public class AsmManager {
+       
+       /**
+        * @deprecated  use getDefault() method instead
+        */  
+       private static AsmManager INSTANCE = new AsmManager();
+       private boolean shouldSaveModel = true;
+    protected StructureModel model = new StructureModel();
+    private List structureListeners = new ArrayList();
+       private IRelationshipMapper mapper;
+
+    protected AsmManager() {
+       List relationships = new ArrayList();
+//     relationships.add(ADVICE);
+               mapper = new RelationshipMapper();
+    }
+
+    public StructureModel getModel() {
+        return model;  
+       }
+
+       public void fireModelUpdated() {
+               notifyListeners();      
+               if (model.getConfigFile() != null) {
+                       writeStructureModel(model.getConfigFile());
+               }
+       }
+
+    /**
+     * Constructs map each time it's called.
+     */
+    public HashMap getInlineAnnotations(
+       String sourceFile, 
+       boolean showSubMember, 
+       boolean showMemberAndType) { 
+        
+        throw new RuntimeException("unimplemented");
+        
+//        if (!model.isValid()) return null;
+//             
+//        HashMap annotations = new HashMap();
+//        IProgramElement node = model.findRootNodeForSourceFile(sourceFile);
+//        if (node == StructureModel.NO_STRUCTURE) {
+//            return null;
+//        } else {
+//            IProgramElement fileNode = (IProgramElement)node;
+//            ArrayList peNodes = new ArrayList();
+//            getAllStructureChildren(fileNode, peNodes, showSubMember, showMemberAndType);
+//            for (Iterator it = peNodes.iterator(); it.hasNext(); ) {
+//                IProgramElement peNode = (IProgramElement)it.next();
+//                List entries = new ArrayList();
+//                entries.add(peNode);
+//                ISourceLocation sourceLoc = peNode.getSourceLocation();
+//                if (null != sourceLoc) {
+//                    Integer hash = new Integer(sourceLoc.getLine());
+//                    List existingEntry = (List)annotations.get(hash);
+//                    if (existingEntry != null) {
+//                        entries.addAll(existingEntry);
+//                    }
+//                    annotations.put(hash, entries);
+//                }
+//            }
+//            return annotations;
+//        }
+    }
+
+//    private void getAllStructureChildren(IProgramElement node, List result, boolean showSubMember, boolean showMemberAndType) {
+//        List children = node.getChildren();
+//        for (Iterator it = children.iterator(); it.hasNext(); ) {
+//                     IProgramElement next = (IProgramElement)it.next();
+//            if (next instanceof IProgramElement) {
+//                IProgramElement pNode = (IProgramElement)next;
+//                if (pNode != null
+//                     && ((pNode.isCode() && showSubMember) || (!pNode.isCode() && showMemberAndType))
+//                     && pNode.getRelations() != null 
+//                     && pNode.getRelations().size() > 0) {
+//                    result.add(next);
+//                }
+//                getAllStructureChildren((IProgramElement)next, result, showSubMember, showMemberAndType);
+//            }
+//        }
+//    }
+
+    public void addListener(IStructureModelListener listener) {
+        structureListeners.add(listener);
+    }
+
+    public void removeStructureListener(IStructureModelListener listener) {
+        structureListeners.remove(listener);
+    }
+
+    private void notifyListeners() {
+        for (Iterator it = structureListeners.iterator(); it.hasNext(); ) {
+            ((IStructureModelListener)it.next()).containmentHierarchyUpdated(model);
+        }
+    }
+
+       /**
+        * Fails silently.
+        */
+    public void writeStructureModel(String configFilePath) {
+        try {
+            String filePath = genExternFilePath(configFilePath);
+            ObjectOutputStream s = new ObjectOutputStream(new FileOutputStream(filePath));
+            s.writeObject(model);
+            s.flush();
+        } catch (Exception e) {
+            // ignore
+        }
+    }
+  
+       /**
+        * @todo        add proper handling of bad paths/suffixes/etc
+        * @param       configFilePath          path to an ".lst" file
+        */
+    public void readStructureModel(String configFilePath) {
+        try {
+            if (configFilePath == null) {
+               model.setRoot(StructureModel.NO_STRUCTURE);
+            } else {
+                   String filePath = genExternFilePath(configFilePath);
+                   FileInputStream in = new FileInputStream(filePath);
+                   ObjectInputStream s = new ObjectInputStream(in);
+                   model = (StructureModel)s.readObject();
+            }
+        } catch (Exception e) {
+               //System.err.println("AJDE Message: could not read structure model: " + e);
+            model.setRoot(StructureModel.NO_STRUCTURE);
+        } finally {
+               notifyListeners();      
+        }
+    }
+
+    private String genExternFilePath(String configFilePath) {
+        return configFilePath.substring(0, configFilePath.lastIndexOf(".lst")) + ".ajsym";
+    }
+    
+       public void setShouldSaveModel(boolean shouldSaveModel) {
+               this.shouldSaveModel = shouldSaveModel;
+       }
+
+       public static AsmManager getDefault() {
+               return INSTANCE;
+       }
+       
+       public IRelationshipMapper getMapper() {
+               return mapper;
+       }
+
+}
+
index 8cde2586264a1bd8ac87befa5c54c6361ae35d3e..ced44fa7e6c80aeb314071ec863b297b230a8bc7 100644 (file)
@@ -23,46 +23,63 @@ import org.aspectj.bridge.*;
 public interface IProgramElement extends Serializable {
        
        public List/*IProgramElement*/ getChildren();
+
+       public void setChildren(List children); 
        public void addChild(IProgramElement child);
-       public Kind getKind();
+
+       public IProgramElement getParent();
+       public void setParent(IProgramElement parent);
+
+       public String getName();
+       public void setName(String name);
+       
+       public IProgramElement.Kind getKind();
+       public void setKind(Kind kind);
+               
        public List getModifiers();
+       public void setModifiers(int i);
+
        public Accessibility getAccessibility();
-       public String getDeclaringType();
+
+       public String getDeclaringType();  // TODO: remove (Emacs uses it)
        public String getPackageName();
-       public String getSignature();
-       public String getName();
-       public boolean isCode();
-       public boolean isMemberKind();
+
+       public void setReturnType(String returnType);
+       public String getReturnType();
+       
+       public String getFullSignature();
+       public void setFullSignature(String string);
+       
        public void setRunnable(boolean value);
        public boolean isRunnable();
+       
        public boolean isImplementor();
        public void setImplementor(boolean value);
+       
        public boolean isOverrider();
        public void setOverrider(boolean value);
-       public List getRelations();
-       public void setRelations(List relations);
-       public String getFormalComment();
+
+       public IMessage getMessage();
+       public void setMessage(IMessage message);
+
+       public ISourceLocation getSourceLocation();
+       public void setSourceLocation(ISourceLocation sourceLocation);
+       
        public String toString();
+       
+       // public String getHandle() TODO: check IJavaElement
+       
+       /**
+        * @return      a string representation of this node and all of its children (recursive)
+        */
+       public String toLongString();
+       
        public String getBytecodeName();
        public String getBytecodeSignature();
        public void setBytecodeName(String bytecodeName);
        public void setBytecodeSignature(String bytecodeSignature);
-       public String getFullSignature();
-       public void setFullSignature(String string);
-       public void setKind(Kind kind);
-       public void setReturnType(String returnType);
-       public String getReturnType();
-       public ISourceLocation getSourceLocation();
-       public void setSourceLocation(ISourceLocation sourceLocation);
-       public IMessage getMessage();
-       public void setMessage(IMessage message);
-       public IProgramElement getParent();
-       public void setParent(IProgramElement parent);
+
        public IProgramElement walk(HierarchyWalker walker);
-       public void setName(String name);
-       public void setChildren(List children);
-       public void setModifiers(int i);
-//     public String getSignatureKey();
        
        /**
         * Uses "typesafe enum" pattern.
index d27aec8d346c9fcd227026710d544d9bd123445f..ab8fffd34439449eb7aa229b08a0b7d94afb7365 100644 (file)
@@ -21,17 +21,15 @@ import org.aspectj.asm.IRelationship.Kind;
  * @author Mik Kersten
  */
 public interface IRelationshipMapper extends Serializable {
-
-//     public List getRelationshipsForElement(String source, IRelationship relationship);
-//     
-//     public void putRelationshipForElement(String source, IRelationship relationship, List targets);
-//
-//     public void putRelationshipForElement(String source, IRelationship kind, String target);
  
+       // TODO: return a list
        public IRelationship get(IProgramElement source);
-
-//     public void putRelationshipForElement(IProgramElement source, IRelationship relationship, List targets);
-
+       
+       // TODO: return a list 
+       public IRelationship get(String handle);
+       
        public void put(IProgramElement source, IRelationship relationship);
+       
+       
  
 }
index 60f48edcb9af3781ec6785cbebe1b31515abd2bc..36318a2e5c9763582856b9bb5b43aafbb2ad4f95 100644 (file)
@@ -18,7 +18,7 @@ import java.io.*;
 import java.util.*;
 
 import org.aspectj.asm.internal.ProgramElement;
-import org.aspectj.bridge.SourceLocation;
+import org.aspectj.bridge.*;
 
 /**
  * @author Mik Kersten
@@ -32,6 +32,10 @@ public class StructureModel implements Serializable {
     
     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;
     }
@@ -40,21 +44,18 @@ public class StructureModel implements Serializable {
         this.root = root;
     }
 
-       private Map getFileMap() {
-        return fileMap;
-    }
-
        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 void setFileMap(HashMap fileMap) {
-        this.fileMap = fileMap;
-    }
 
        public Set getFileMapEntrySet() {
                return fileMap.entrySet();
@@ -64,6 +65,7 @@ public class StructureModel implements Serializable {
         return root != null && fileMap != null;
     }
 
+
        /** 
         * Returns the first match
         * 
@@ -86,8 +88,12 @@ public class StructureModel implements Serializable {
                return null;
        }
 
+       /**
+        * 
+        * @param signatureKey  PackageName.TypeName.Signature.SourceLine.SourceColumn
+        */
        public IProgramElement findNodeForSignatureKey(String signatureKey) {
-               return null;    
+               throw new RuntimeException("unimplemented");
        }       
 
        /**
@@ -166,6 +172,13 @@ public class StructureModel implements Serializable {
                }
     }
 
+       /**
+        * TODO: discriminate columns
+        */
+       public IProgramElement findNodeForSourceLine(ISourceLocation location) {
+               return findNodeForSourceLine(location.getSourceFile().getAbsolutePath(), location.getLine());
+       }
+
        /**
         * Never returns null 
         * 
@@ -174,8 +187,7 @@ public class StructureModel implements Serializable {
         * @return              a new structure node for the file if it was not found in the model
         */
        public IProgramElement findNodeForSourceLine(String sourceFilePath, int lineNumber) {
-               String correctedPath = sourceFilePath;//.replace('\\', '/');
-               IProgramElement node = findNodeForSourceLineHelper(root, correctedPath, lineNumber);
+               IProgramElement node = findNodeForSourceLineHelper(root, sourceFilePath, lineNumber);
                if (node != null) {
                        return node;    
                } else {
@@ -224,7 +236,7 @@ public class StructureModel implements Serializable {
                                && node.getSourceLocation().getSourceFile().getCanonicalPath().equals(sourceFilePath)
                                && ((node.getSourceLocation().getLine() <= lineNumber
                                        && node.getSourceLocation().getEndLine() >= lineNumber)
-                                   ||
+                                       ||
                                        (lineNumber <= 1
                                         && node instanceof IProgramElement 
                                         && ((IProgramElement)node).getKind().isSourceFileKind())       
@@ -249,6 +261,5 @@ public class StructureModel implements Serializable {
        public void setConfigFile(String configFile) {
                this.configFile = configFile;
        }
-
 }
 
diff --git a/asm/src/org/aspectj/asm/StructureModelManager.java b/asm/src/org/aspectj/asm/StructureModelManager.java
deleted file mode 100644 (file)
index 1e966bb..0000000
+++ /dev/null
@@ -1,176 +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.*;
-
-/**
- * @author Mik Kersten
- */
-public class StructureModelManager {
-       
-       /**
-        * @deprecated  use getDefault() method instead
-        */ 
-       public static StructureModelManager INSTANCE = new StructureModelManager();
-       private boolean shouldSaveModel = true;
-    protected StructureModel model = new StructureModel();
-    private List structureListeners = new ArrayList();
-
-       private IRelationshipMapper mapper;
-//     public static final IRelationship ADVICE = new Relationship("advises", "advised by", IRelationship.Kind.ADVICE);
-
-    protected StructureModelManager() {
-       List relationships = new ArrayList();
-//     relationships.add(ADVICE);
-               mapper = new RelationshipMapper();
-    }
-
-    public StructureModel getModel() {
-        return model;  
-       }
-
-       public void fireModelUpdated() {
-               notifyListeners();      
-               if (model.getConfigFile() != null) {
-                       writeStructureModel(model.getConfigFile());
-               }
-       }
-
-    /**
-     * Constructs map each time it's called.
-     */
-    public HashMap getInlineAnnotations(
-       String sourceFile, 
-       boolean showSubMember, 
-       boolean showMemberAndType) { 
-        
-        throw new RuntimeException("unimplemented");
-        
-//        if (!model.isValid()) return null;
-//             
-//        HashMap annotations = new HashMap();
-//        IProgramElement node = model.findRootNodeForSourceFile(sourceFile);
-//        if (node == StructureModel.NO_STRUCTURE) {
-//            return null;
-//        } else {
-//            IProgramElement fileNode = (IProgramElement)node;
-//            ArrayList peNodes = new ArrayList();
-//            getAllStructureChildren(fileNode, peNodes, showSubMember, showMemberAndType);
-//            for (Iterator it = peNodes.iterator(); it.hasNext(); ) {
-//                IProgramElement peNode = (IProgramElement)it.next();
-//                List entries = new ArrayList();
-//                entries.add(peNode);
-//                ISourceLocation sourceLoc = peNode.getSourceLocation();
-//                if (null != sourceLoc) {
-//                    Integer hash = new Integer(sourceLoc.getLine());
-//                    List existingEntry = (List)annotations.get(hash);
-//                    if (existingEntry != null) {
-//                        entries.addAll(existingEntry);
-//                    }
-//                    annotations.put(hash, entries);
-//                }
-//            }
-//            return annotations;
-//        }
-    }
-
-//    private void getAllStructureChildren(IProgramElement node, List result, boolean showSubMember, boolean showMemberAndType) {
-//        List children = node.getChildren();
-//        for (Iterator it = children.iterator(); it.hasNext(); ) {
-//                     IProgramElement next = (IProgramElement)it.next();
-//            if (next instanceof IProgramElement) {
-//                IProgramElement pNode = (IProgramElement)next;
-//                if (pNode != null
-//                     && ((pNode.isCode() && showSubMember) || (!pNode.isCode() && showMemberAndType))
-//                     && pNode.getRelations() != null 
-//                     && pNode.getRelations().size() > 0) {
-//                    result.add(next);
-//                }
-//                getAllStructureChildren((IProgramElement)next, result, showSubMember, showMemberAndType);
-//            }
-//        }
-//    }
-
-    public void addListener(IStructureModelListener listener) {
-        structureListeners.add(listener);
-    }
-
-    public void removeStructureListener(IStructureModelListener listener) {
-        structureListeners.remove(listener);
-    }
-
-    private void notifyListeners() {
-        for (Iterator it = structureListeners.iterator(); it.hasNext(); ) {
-            ((IStructureModelListener)it.next()).containmentHierarchyUpdated(model);
-        }
-    }
-
-       /**
-        * Fails silently.
-        */
-    public void writeStructureModel(String configFilePath) {
-        try {
-            String filePath = genExternFilePath(configFilePath);
-            ObjectOutputStream s = new ObjectOutputStream(new FileOutputStream(filePath));
-            s.writeObject(model);
-            s.flush();
-        } catch (Exception e) {
-            // ignore
-        }
-    }
-  
-       /**
-        * @todo        add proper handling of bad paths/suffixes/etc
-        * @param       configFilePath          path to an ".lst" file
-        */
-    public void readStructureModel(String configFilePath) {
-        try {
-            if (configFilePath == null) {
-               model.setRoot(StructureModel.NO_STRUCTURE);
-            } else {
-                   String filePath = genExternFilePath(configFilePath);
-                   FileInputStream in = new FileInputStream(filePath);
-                   ObjectInputStream s = new ObjectInputStream(in);
-                   model = (StructureModel)s.readObject();
-            }
-        } catch (Exception e) {
-               //System.err.println("AJDE Message: could not read structure model: " + e);
-            model.setRoot(StructureModel.NO_STRUCTURE);
-        } finally {
-               notifyListeners();      
-        }
-    }
-
-    private String genExternFilePath(String configFilePath) {
-        return configFilePath.substring(0, configFilePath.lastIndexOf(".lst")) + ".ajsym";
-    }
-    
-       public void setShouldSaveModel(boolean shouldSaveModel) {
-               this.shouldSaveModel = shouldSaveModel;
-       }
-
-       public static StructureModelManager getDefault() {
-               return INSTANCE;
-       }
-       public IRelationshipMapper getMapper() {
-               return mapper;
-       }
-
-}
-
index 9562169cd716d9954498997452929e6c244e097a..9b2e3fdb0d02656bcd8fe2841d0ed90ec5e38e02 100644 (file)
@@ -121,7 +121,7 @@ public class ProgramElement implements IProgramElement {
        }
 
        public String getPackageName() {
-               if (kind == Kind.PACKAGE) return getSignature();
+               if (kind == Kind.PACKAGE) return getName();
                if (getParent() == null || !(getParent() instanceof IProgramElement)) {
                        return "";
                }
@@ -132,10 +132,6 @@ public class ProgramElement implements IProgramElement {
                return kind;
        }
 
-       public String getSignature() {
-               return name;
-       }
-
        public boolean isCode() {
                return kind.equals(Kind.CODE);
        }
index 706a5603b2077a6c05771d9d7a2984038a4f8e54..e794b76e017474e1e113cecb86849105c517eb99 100644 (file)
@@ -25,12 +25,15 @@ public class RelationshipMapper extends HashMap implements IRelationshipMapper {
                return (IRelationship)super.get(source);
        }
 
-       /**
-        * Creates the relationship if not present.
-        */
+       public IRelationship get(String handle) {
+               throw new RuntimeException("unimplemented");
+       }
+
        public void put(IProgramElement source, IRelationship relationship) {
                super.put(source, relationship);
        }
+       
+       // TODO: add a remove, and a clear all
 
        private static class RelationshipTable {
                private IRelationship relationship;
@@ -49,4 +52,5 @@ public class RelationshipMapper extends HashMap implements IRelationshipMapper {
                        return relationship;
                }
        }
+
 }
index 608f8dca5229ee847f8fe76309b1f3df6e08c3b8..693bf5f06ad748db1cb48cabe9a27fbcc8d00dbc 100644 (file)
Binary files a/docs/developer/asm.doc and b/docs/developer/asm.doc differ