]> source.dussan.org Git - aspectj.git/commitdiff
251277: making asmmanager non-singleton
authoraclement <aclement>
Mon, 20 Oct 2008 04:39:06 +0000 (04:39 +0000)
committeraclement <aclement>
Mon, 20 Oct 2008 04:39:06 +0000 (04:39 +0000)
asm/src/org/aspectj/asm/AsmManager.java
asm/src/org/aspectj/asm/IElementHandleProvider.java
asm/src/org/aspectj/asm/IHierarchy.java
asm/src/org/aspectj/asm/IProgramElement.java
asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java
asm/src/org/aspectj/asm/internal/FullPathHandleProvider.java [deleted file]
asm/src/org/aspectj/asm/internal/JDTLikeHandleProvider.java
asm/src/org/aspectj/asm/internal/ProgramElement.java

index eee12ab7e40ccef0266e2d01e73c143ac707a0fe..2d2f8285525f32a57e8a629a16538f066203f90e 100644 (file)
@@ -42,17 +42,35 @@ import org.aspectj.asm.internal.RelationshipMap;
 import org.aspectj.bridge.ISourceLocation;
 
 /**
- * The Abstract Structure Model (ASM) represents the containment hierarchy and crossccutting structure map for AspectJ programs. It
+ * The Abstract Structure Model (ASM) represents the containment hierarchy and crosscutting structure map for AspectJ programs. It
  * is used by IDE views such as the document outline, and by other tools such as ajdoc to show both AspectJ declarations and
  * crosscutting links, such as which advice affects which join point shadows.
  * 
  * @author Mik Kersten
+ * @author Andy Clement
  */
 public class AsmManager {
 
-       private static AsmManager instance = new AsmManager();
+       // For testing ONLY
+       public static boolean recordingLastActiveStructureModel = true;
+       public static AsmManager lastActiveStructureModel;
+       public static boolean forceSingletonBehaviour = false;
+
+       // SECRETAPI asc pull the secret options together into a system API you lazy fool
+       public static boolean attemptIncrementalModelRepairs = false;
+       // Dumping the model is expensive
+       public static boolean dumpModelPostBuild = false;
+       // For offline debugging, you can now ask for the AsmManager to
+       // dump the model - see the method setReporting()
+       private static boolean dumpModel = false;
+       private static boolean dumpRelationships = false;
+       private static boolean dumpDeltaProcessing = false;
+       private static IModelFilter modelFilter = null;
+       private static String dumpFilename = "";
+       private static boolean reporting = false;
+
+       private static boolean completingTypeBindings = false;
 
-       private IElementHandleProvider handleProvider;
        private final List structureListeners = new ArrayList();
 
        // The model is 'manipulated' by the AjBuildManager.setupModel() code which
@@ -64,24 +82,8 @@ public class AsmManager {
        // between projects.
        protected IHierarchy hierarchy;
        private IRelationshipMap mapper;
+       private IElementHandleProvider handleProvider;
 
-       private static boolean creatingModel = false;
-       public static boolean dumpModelPostBuild = false; // Dumping the model is
-       // expensive
-       // SECRETAPI asc pull the secret options together into a system API you lazy
-       // fool
-       public static boolean attemptIncrementalModelRepairs = false;
-
-       // For offline debugging, you can now ask for the AsmManager to
-       // dump the model - see the method setReporting()
-       private static boolean dumpModel = false;
-       private static boolean dumpRelationships = false;
-       private static boolean dumpDeltaProcessing = false;
-       private static IModelFilter modelFilter = null;
-       private static String dumpFilename = "";
-       private static boolean reporting = false;
-
-       private static boolean completingTypeBindings = false;
        private final CanonicalFilePathMap canonicalFilePathMap = new CanonicalFilePathMap();
        // Record the Set<File> for which the model has been modified during the
        // last incremental build
@@ -94,27 +96,29 @@ public class AsmManager {
        // setReporting("c:/model.nfo",true,true,true,true);
        // }
 
-       protected AsmManager() {
-               handleProvider = new JDTLikeHandleProvider();
-               createNewASM();
+       private AsmManager() {
        }
 
-       public void createNewASM() {
-               hierarchy = new AspectJElementHierarchy();
-               mapper = new RelationshipMap(hierarchy);
+       public static AsmManager createNewStructureModel() {
+               if (forceSingletonBehaviour && lastActiveStructureModel != null) {
+                       return lastActiveStructureModel;
+               }
+               AsmManager asm = new AsmManager();
+               asm.hierarchy = new AspectJElementHierarchy(asm);
+               asm.mapper = new RelationshipMap(asm.hierarchy);
+               asm.handleProvider = new JDTLikeHandleProvider(asm);
                // call initialize on the handleProvider when we create a new ASM
                // to give handleProviders the chance to reset any state
-               handleProvider.initialize();
-               resetDeltaProcessing();
+               asm.handleProvider.initialize();
+               asm.resetDeltaProcessing();
+               setLastActiveStructureModel(asm);
+               return asm;
        }
 
        public IHierarchy getHierarchy() {
                return hierarchy;
        }
 
-       public static AsmManager getDefault() {
-               return instance;
-       }
 
        public IRelationshipMap getRelationshipMap() {
                return mapper;
@@ -167,7 +171,7 @@ public class AsmManager {
                        return;
                for (Iterator it = children.iterator(); it.hasNext();) {
                        IProgramElement next = (IProgramElement) it.next();
-                       List rels = AsmManager.getDefault().getRelationshipMap().get(next);
+                       List rels = mapper.get(next);
                        if (next != null
                                        && ((next.getKind() == IProgramElement.Kind.CODE && showSubMember) || (next.getKind() != IProgramElement.Kind.CODE && showMemberAndType))
                                        && rels != null && rels.size() > 0) {
@@ -238,6 +242,7 @@ public class AsmManager {
                                FileInputStream in = new FileInputStream(filePath);
                                ObjectInputStream s = new ObjectInputStream(in);
                                hierarchy = (AspectJElementHierarchy) s.readObject();
+                               ((AspectJElementHierarchy) hierarchy).setAsmManager(this);
                                hierarchyReadOK = true;
                                mapper = (RelationshipMap) s.readObject();
                                ((RelationshipMap) mapper).setHierarchy(hierarchy);
@@ -419,7 +424,7 @@ public class AsmManager {
                        BufferedWriter bw = new BufferedWriter(fw);
                        if (dumpModel) {
                                bw.write("=== MODEL STATUS REPORT ========= " + reasonForReport + "\n");
-                               dumptree(bw, AsmManager.getDefault().getHierarchy().getRoot(), 0);
+                               dumptree(bw, hierarchy.getRoot(), 0);
 
                                bw.write("=== END OF MODEL REPORT =========\n");
                        }
@@ -428,7 +433,7 @@ public class AsmManager {
                                dumprels(bw);
                                bw.write("=== END OF RELATIONSHIPS REPORT ==\n");
                        }
-                       Properties p = ModelInfo.summarizeModel().getProperties();
+                       Properties p = summarizeModel().getProperties();
                        Enumeration pkeyenum = p.keys();
                        bw.write("=== Properties of the model and relationships map =====\n");
                        while (pkeyenum.hasMoreElements()) {
@@ -477,12 +482,11 @@ public class AsmManager {
        }
 
        public void dumprels(Writer w) throws IOException {
-               IRelationshipMap irm = AsmManager.getDefault().getRelationshipMap();
                int ctr = 1;
-               Set entries = irm.getEntries();
+               Set entries = mapper.getEntries();
                for (Iterator iter = entries.iterator(); iter.hasNext();) {
                        String hid = (String) iter.next();
-                       List rels = irm.get(hid);
+                       List rels = mapper.get(hid);
                        for (Iterator iterator = rels.iterator(); iterator.hasNext();) {
                                IRelationship ir = (IRelationship) iterator.next();
                                List targets = ir.getTargets();
@@ -500,12 +504,11 @@ public class AsmManager {
 
        private void dumprelsStderr(String key) {
                System.err.println("Relationships dump follows: " + key);
-               IRelationshipMap irm = AsmManager.getDefault().getRelationshipMap();
                int ctr = 1;
-               Set entries = irm.getEntries();
+               Set entries = mapper.getEntries();
                for (Iterator iter = entries.iterator(); iter.hasNext();) {
                        String hid = (String) iter.next();
-                       List rels = irm.get(hid);
+                       List rels = mapper.get(hid);
                        for (Iterator iterator = rels.iterator(); iterator.hasNext();) {
                                IRelationship ir = (IRelationship) iterator.next();
                                List targets = ir.getTargets();
@@ -527,15 +530,13 @@ public class AsmManager {
         */
        public boolean removeStructureModelForFiles(Writer fw, Collection files) throws IOException {
 
-               IHierarchy model = AsmManager.getDefault().getHierarchy();
-
                boolean modelModified = false;
 
                Set deletedNodes = new HashSet();
                for (Iterator iter = files.iterator(); iter.hasNext();) {
                        File fileForCompilation = (File) iter.next();
-                       String correctedPath = AsmManager.getDefault().getCanonicalFilePath(fileForCompilation);
-                       IProgramElement progElem = (IProgramElement) model.findInFileMap(correctedPath);
+                       String correctedPath = getCanonicalFilePath(fileForCompilation);
+                       IProgramElement progElem = (IProgramElement) hierarchy.findInFileMap(correctedPath);
                        if (progElem != null) {
                                // Found it, let's remove it
                                if (dumpDeltaProcessing) {
@@ -544,14 +545,15 @@ public class AsmManager {
                                removeNode(progElem);
                                lastBuildChanges.add(fileForCompilation);
                                deletedNodes.add(getCanonicalFilePath(progElem.getSourceLocation().getSourceFile()));
-                               if (!model.removeFromFileMap(correctedPath))
+                               if (!hierarchy.removeFromFileMap(correctedPath))
                                        throw new RuntimeException("Whilst repairing model, couldn't remove entry for file: " + correctedPath
                                                        + " from the filemap");
                                modelModified = true;
                        }
                }
-               if (modelModified)
-                       model.updateHandleMap(deletedNodes);
+               if (modelModified) {
+                       hierarchy.updateHandleMap(deletedNodes);
+               }
                return modelModified;
        }
 
@@ -565,7 +567,6 @@ public class AsmManager {
                // config.getFiles())
 
                // List files = config.getFiles();
-               IHierarchy model = AsmManager.getDefault().getHierarchy();
 
                boolean modelModified = false;
                // Files to delete are: those to be compiled + those that have been
@@ -576,8 +577,8 @@ public class AsmManager {
                Set deletedNodes = new HashSet();
                for (Iterator iter = filesToRemoveFromStructureModel.iterator(); iter.hasNext();) {
                        File fileForCompilation = (File) iter.next();
-                       String correctedPath = AsmManager.getDefault().getCanonicalFilePath(fileForCompilation);
-                       IProgramElement progElem = (IProgramElement) model.findInFileMap(correctedPath);
+                       String correctedPath = getCanonicalFilePath(fileForCompilation);
+                       IProgramElement progElem = (IProgramElement) hierarchy.findInFileMap(correctedPath);
                        if (progElem != null) {
                                // Found it, let's remove it
                                if (dumpDeltaProcessing) {
@@ -585,15 +586,15 @@ public class AsmManager {
                                }
                                removeNode(progElem);
                                deletedNodes.add(getCanonicalFilePath(progElem.getSourceLocation().getSourceFile()));
-                               if (!model.removeFromFileMap(correctedPath))
+                               if (!hierarchy.removeFromFileMap(correctedPath))
                                        throw new RuntimeException("Whilst repairing model, couldn't remove entry for file: " + correctedPath
                                                        + " from the filemap");
                                modelModified = true;
                        }
                }
                if (modelModified) {
-                       model.flushTypeMap();
-                       model.updateHandleMap(deletedNodes);
+                       hierarchy.flushTypeMap();
+                       hierarchy.updateHandleMap(deletedNodes);
                }
        }
 
@@ -867,7 +868,7 @@ public class AsmManager {
         */
        private void repairRelationships(Writer fw) {
                try {
-                       IHierarchy model = AsmManager.getDefault().getHierarchy();
+                       // IHierarchy model = AsmManager.getDefault().getHierarchy();
                        // TODO Speed this code up by making this assumption:
                        // the only piece of the handle that is interesting is the file
                        // name. We are working at file granularity, if the
@@ -877,7 +878,7 @@ public class AsmManager {
                                fw.write("Repairing relationships map:\n");
 
                        // Now sort out the relationships map
-                       IRelationshipMap irm = AsmManager.getDefault().getRelationshipMap();
+                       // IRelationshipMap irm = AsmManager.getDefault().getRelationshipMap();
                        Set sourcesToRemove = new HashSet();
                        Set nonExistingHandles = new HashSet(); // Cache of handles that we
                        // *know* are invalid
@@ -885,7 +886,7 @@ public class AsmManager {
                        int tgthandlecounter = 0;
 
                        // Iterate over the source handles in the relationships map
-                       Set keyset = irm.getEntries(); // These are source handles
+                       Set keyset = mapper.getEntries(); // These are source handles
                        for (Iterator keyiter = keyset.iterator(); keyiter.hasNext();) {
                                String hid = (String) keyiter.next();
                                srchandlecounter++;
@@ -895,7 +896,7 @@ public class AsmManager {
                                        sourcesToRemove.add(hid);
                                } else {
                                        // We better check if it actually exists
-                                       IProgramElement existingElement = model.getElement(hid);
+                                       IProgramElement existingElement = hierarchy.getElement(hid);
                                        if (dumpDeltaProcessing)
                                                fw.write("Looking for handle [" + hid + "] in model, found: " + existingElement + "\n");
 
@@ -906,7 +907,7 @@ public class AsmManager {
                                                nonExistingHandles.add(hid); // Speed up a bit you swine
                                        } else {
                                                // Ok, so the source is valid, what about the targets?
-                                               List relationships = irm.get(hid);
+                                               List relationships = mapper.get(hid);
                                                List relationshipsToRemove = new ArrayList();
                                                // Iterate through the relationships against this source
                                                // handle
@@ -927,7 +928,7 @@ public class AsmManager {
                                                                        targetsToRemove.add(targethid);
                                                                } else {
                                                                        // We better check
-                                                                       IProgramElement existingTarget = model.getElement(targethid);
+                                                                       IProgramElement existingTarget = hierarchy.getElement(targethid);
                                                                        if (existingTarget == null) {
                                                                                if (dumpDeltaProcessing)
                                                                                        fw.write("Target handle [" + targethid + "] for srchid[" + hid + "]rel["
@@ -989,10 +990,10 @@ public class AsmManager {
                                                                // relationships !!
                                                                for (int i = 0; i < relationshipsToRemove.size(); i++) {
                                                                        IRelationship irel = (IRelationship) relationshipsToRemove.get(i);
-                                                                       verifyAssumption(irm.remove(hid, irel), "Failed to remove relationship " + irel.getName()
+                                                                       verifyAssumption(mapper.remove(hid, irel), "Failed to remove relationship " + irel.getName()
                                                                                        + " for shid " + hid);
                                                                }
-                                                               List rels = irm.get(hid);
+                                                               List rels = mapper.get(hid);
                                                                if (rels == null || rels.size() == 0)
                                                                        sourcesToRemove.add(hid);
                                                        }
@@ -1003,8 +1004,8 @@ public class AsmManager {
                        // Remove sources that have no valid relationships any more
                        for (Iterator srciter = sourcesToRemove.iterator(); srciter.hasNext();) {
                                String hid = (String) srciter.next();
-                               irm.removeAll(hid);
-                               IProgramElement ipe = model.getElement(hid);
+                               mapper.removeAll(hid);
+                               IProgramElement ipe = hierarchy.getElement(hid);
                                if (ipe != null) {
                                        // If the relationship was hanging off a 'code' node, delete
                                        // it.
@@ -1113,7 +1114,7 @@ public class AsmManager {
        /**
         * A ModelInfo object captures basic information about the structure model. It is used for testing and producing debug info.
         */
-       public static class ModelInfo {
+       public class ModelInfo {
                private final Hashtable nodeTypeCount = new Hashtable();
                private final Properties extraProperties = new Properties();
 
@@ -1179,26 +1180,26 @@ public class AsmManager {
                        extraProperties.setProperty(string, string2);
                }
 
-               public static ModelInfo summarizeModel() {
-                       return new ModelInfo(AsmManager.getDefault().getHierarchy(), AsmManager.getDefault().getRelationshipMap());
-               }
        }
 
-       /**
-        * Set to indicate whether we are currently building a structure model, should be set up front.
-        */
-       public static void setCreatingModel(boolean b) {
-               creatingModel = b;
+       public ModelInfo summarizeModel() {
+               return new ModelInfo(getHierarchy(), getRelationshipMap());
        }
 
        /**
-        * returns true if we are currently generating a structure model, enables guarding of expensive operations on an empty/null
-        * model.
+        * Set to indicate whether we are currently building a structure model, should be set up front.
         */
-       public static boolean isCreatingModel() {
-               return creatingModel;
-       }
-
+       // public static void setCreatingModel(boolean b) {
+       // creatingModel = b;
+       // }
+       //
+       // /**
+       // * returns true if we are currently generating a structure model, enables guarding of expensive operations on an empty/null
+       // * model.
+       // */
+       // public static boolean isCreatingModel() {
+       // return creatingModel;
+       // }
        public static void setCompletingTypeBindings(boolean b) {
                completingTypeBindings = b;
        }
@@ -1207,13 +1208,13 @@ public class AsmManager {
                return completingTypeBindings;
        }
 
-       public void setRelationshipMap(IRelationshipMap irm) {
-               mapper = irm;
-       }
-
-       public void setHierarchy(IHierarchy ih) {
-               hierarchy = ih;
-       }
+       // public void setRelationshipMap(IRelationshipMap irm) {
+       // mapper = irm;
+       // }
+       //
+       // public void setHierarchy(IHierarchy ih) {
+       // hierarchy = ih;
+       // }
 
        public void resetDeltaProcessing() {
                lastBuildChanges.clear();
@@ -1239,4 +1240,10 @@ public class AsmManager {
                aspectsWeavingInLastBuild.add(f);
        }
 
+       public static void setLastActiveStructureModel(AsmManager structureModel) {
+               if (recordingLastActiveStructureModel) {
+                       lastActiveStructureModel = structureModel;
+               }
+       }
+
 }
index 79cd6bfabea7deca7446e6b2ebafe02142b3876d..c071f033701a64c943b881f4aa98cccc08703034 100644 (file)
@@ -17,61 +17,49 @@ import java.io.File;
 import org.aspectj.bridge.ISourceLocation;
 
 /**
- * Adapter used to uniquely identify program element handles.  Can be
- * implemented and overridden in @see{AsmManager} in order to provide
- * IDE-specific mechanisms of identifying elements.  For example, AJDT
- * uses workspace-relative paths that are understood by its JavaCore 
- * class.  
+ * Adapter used to uniquely identify program element handles. Can be implemented and overridden in @see{AsmManager} in order to
+ * provide IDE-specific mechanisms of identifying elements. For example, AJDT uses workspace-relative paths that are understood by
+ * its JavaCore class.
  * 
  * @author Mik Kersten
  */
 public interface IElementHandleProvider {
 
-    /**
-     * @return  a String uniquely identifying this element
-     */
-    public String createHandleIdentifier(ISourceLocation location);
+       /**
+        * @return a String uniquely identifying this element
+        */
+       public String createHandleIdentifier(ISourceLocation location);
 
-    /**
-     * @return  a String uniquely identifying this element
-     */
-    public String createHandleIdentifier(File sourceFile, int line,int column,int offset);
+       /**
+        * @return a String uniquely identifying this element
+        */
+       public String createHandleIdentifier(File sourceFile, int line, int column, int offset);
 
-    /**
-     * @return  a String uniquely identifying this element
-     */
+       /**
+        * @return a String uniquely identifying this element
+        */
        public String createHandleIdentifier(IProgramElement ipe);
-    
-    /**
-     * NOTE: this is necessary for the current implementation to look up nodes, 
-     * but we may want to consider removing it.
-     * 
-     * @return a String corresponding to the  
-     */
-    public String getFileForHandle(String handle);
-    
-    /**
-     * NOTE: this is necessary for the current implementation to look up nodes, 
-     * but we may want to consider removing it.
-     * 
-     * @return the line number corresponding to this handel
-     */
-    public int getLineNumberForHandle(String handle);
-    
-    public int getOffSetForHandle(String handle);
-    
-    // See pr134471 
-    /**
-     * @return true if the handles produced by the provider 
-     * depend on ISourceLocations and false otherwise
-     */
-    public boolean dependsOnLocation();
-    
-    /**
-     * Initializes handle provider state.
-     * 
-     * The initializer is invoked when a new ASM is
-     * created on a full build.
-     */
-    public void initialize();
+
+       /**
+        * NOTE: this is necessary for the current implementation to look up nodes, but we may want to consider removing it.
+        * 
+        * @return a String corresponding to the
+        */
+       public String getFileForHandle(String handle);
+
+       /**
+        * NOTE: this is necessary for the current implementation to look up nodes, but we may want to consider removing it.
+        * 
+        * @return the line number corresponding to this handel
+        */
+       public int getLineNumberForHandle(String handle);
+
+       public int getOffSetForHandle(String handle);
+
+       /**
+        * Initializes handle provider state.
+        * 
+        * The initializer is invoked when a new ASM is created on a full build.
+        */
+       public void initialize();
 }
index d458da3389582f7f972636c7e7c1d792d53d0551..740c8f77270e670b51dfbbd0cb9ddb36a981455f 100644 (file)
@@ -12,7 +12,8 @@
 package org.aspectj.asm;
 
 import java.io.Serializable;
-import java.util.*;
+import java.util.HashMap;
+import java.util.Set;
 
 import org.aspectj.asm.internal.ProgramElement;
 import org.aspectj.bridge.ISourceLocation;
@@ -21,80 +22,80 @@ 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 static final IProgramElement NO_STRUCTURE = new ProgramElement(null, "<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 boolean removeFromFileMap(Object key);
+
        public void setFileMap(HashMap fileMap);
+
        public Object findInFileMap(Object key);
+
        public Set getFileMapEntrySet();
+
        public boolean isValid();
 
        /**
-        * @return      null if not found
+        * @return null if not found
         */
        public IProgramElement findElementForHandle(String handle);
 
-       /** 
+       /**
         * Returns the first match
         * 
         * @param parent
-        * @param kind          not null
+        * @param kind not null
         * @return null if not found
         */
-       public IProgramElement findElementForSignature(
-               IProgramElement parent,
-               IProgramElement.Kind kind,
-               String signature);
+       public IProgramElement findElementForSignature(IProgramElement parent, IProgramElement.Kind kind, String signature);
 
-       /** 
+       /**
         * Returns the first match
         * 
         * @param parent
-        * @param kind          not null
+        * @param kind not null
         * @return null if not found
         */
-       public IProgramElement findElementForLabel(
-               IProgramElement parent,
-               IProgramElement.Kind kind,
-               String label);
+       public IProgramElement findElementForLabel(IProgramElement parent, IProgramElement.Kind kind, String label);
 
        /**
-        * @param packageName   if null default package is searched
-        * @param className     can't be null
+        * @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
+        * @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 
+        * 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
+        * @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 IProgramElement findElementForOffSet(String sourceFilePath, int lineNumber, int offSet);
-       
+
        public String getConfigFile();
-       
+
        public void setConfigFile(String configFile);
 
        public void flushTypeMap();
index 65b527e06380163fee6edb3e25d48b01effbef8f..ebcf99002d4866b04c285aafc35905de8fdfa747 100644 (file)
@@ -195,6 +195,8 @@ public interface IProgramElement extends Serializable {
 
        public IProgramElement walk(HierarchyWalker walker);
 
+       public AsmManager getModel();
+
        /**
         * Uses "typesafe enum" pattern.
         */
index 5dbeacf5a8faf021b5a8d38a92a468dc050ca07b..08993867494b5e5a19b4aa97aee43c1b8ed4406d 100644 (file)
@@ -36,17 +36,26 @@ public class AspectJElementHierarchy implements IHierarchy {
 
        private static final long serialVersionUID = 6462734311117048620L;
 
+       private transient AsmManager asm;
        protected IProgramElement root = null;
        protected String configFile = null;
 
        private Map fileMap = null;
-       private Map handleMap = null;
+       private Map handleMap = new HashMap();
        private Map typeMap = null;
 
+       public AspectJElementHierarchy(AsmManager asm) {
+               this.asm = asm;
+       }
+
        public IProgramElement getElement(String handle) {
                return findElementForHandleOrCreate(handle, false);
        }
 
+       public void setAsmManager(AsmManager asm) { // used when deserializing
+               this.asm = asm;
+       }
+
        public IProgramElement getRoot() {
                return root;
        }
@@ -281,7 +290,7 @@ public class AspectJElementHierarchy implements IHierarchy {
                        if (!isValid() || sourceFile == null) {
                                return IHierarchy.NO_STRUCTURE;
                        } else {
-                               String correctedPath = AsmManager.getDefault().getCanonicalFilePath(new File(sourceFile));
+                               String correctedPath = asm.getCanonicalFilePath(new File(sourceFile));
                                // StructureNode node = (StructureNode)getFileMap().get(correctedPath);//findFileNode(filePath, model);
                                IProgramElement node = (IProgramElement) findInFileMap(correctedPath);// findFileNode(filePath, model);
                                if (node != null) {
@@ -300,8 +309,7 @@ public class AspectJElementHierarchy implements IHierarchy {
         */
        public IProgramElement findElementForSourceLine(ISourceLocation location) {
                try {
-                       return findElementForSourceLine(AsmManager.getDefault().getCanonicalFilePath(location.getSourceFile()), location
-                                       .getLine());
+                       return findElementForSourceLine(asm.getCanonicalFilePath(location.getSourceFile()), location.getLine());
                } catch (Exception e) {
                        return null;
                }
@@ -315,7 +323,7 @@ public class AspectJElementHierarchy implements IHierarchy {
         * @return a new structure node for the file if it was not found in the model
         */
        public IProgramElement findElementForSourceLine(String sourceFilePath, int lineNumber) {
-               String canonicalSFP = AsmManager.getDefault().getCanonicalFilePath(new File(sourceFilePath));
+               String canonicalSFP = asm.getCanonicalFilePath(new File(sourceFilePath));
                IProgramElement node = findNodeForSourceLineHelper(root, canonicalSFP, lineNumber, -1);
                if (node != null) {
                        return node;
@@ -325,7 +333,7 @@ public class AspectJElementHierarchy implements IHierarchy {
        }
 
        public IProgramElement findElementForOffSet(String sourceFilePath, int lineNumber, int offSet) {
-               String canonicalSFP = AsmManager.getDefault().getCanonicalFilePath(new File(sourceFilePath));
+               String canonicalSFP = asm.getCanonicalFilePath(new File(sourceFilePath));
                IProgramElement node = findNodeForSourceLineHelper(root, canonicalSFP, lineNumber, offSet);
                if (node != null) {
                        return node;
@@ -348,7 +356,7 @@ public class AspectJElementHierarchy implements IHierarchy {
                        lastSlash = i;
                }
                String fileName = sourceFilePath.substring(lastSlash + 1);
-               IProgramElement fileNode = new ProgramElement(fileName, IProgramElement.Kind.FILE_JAVA, new SourceLocation(new File(
+               IProgramElement fileNode = new ProgramElement(asm, fileName, IProgramElement.Kind.FILE_JAVA, new SourceLocation(new File(
                                sourceFilePath), 1, 1), 0, null, null);
                // fileNode.setSourceLocation();
                fileNode.addChild(NO_STRUCTURE);
@@ -530,12 +538,12 @@ public class AspectJElementHierarchy implements IHierarchy {
        }
 
        private String getFilename(String hid) {
-               return AsmManager.getDefault().getHandleProvider().getFileForHandle(hid);
+               return asm.getHandleProvider().getFileForHandle(hid);
        }
 
        private String getCanonicalFilePath(IProgramElement ipe) {
                if (ipe.getSourceLocation() != null) {
-                       return AsmManager.getDefault().getCanonicalFilePath(ipe.getSourceLocation().getSourceFile());
+                       return asm.getCanonicalFilePath(ipe.getSourceLocation().getSourceFile());
                }
                return "";
        }
diff --git a/asm/src/org/aspectj/asm/internal/FullPathHandleProvider.java b/asm/src/org/aspectj/asm/internal/FullPathHandleProvider.java
deleted file mode 100644 (file)
index 1626732..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/* *******************************************************************
- * Copyright (c) 2003 Contributors.
- * All rights reserved. 
- * This program and the accompanying materials are made available 
- * under the terms of the Eclipse Public License v1.0 
- * which accompanies this distribution and is available at 
- * http://www.eclipse.org/legal/epl-v10.html 
- *  
- * Contributors: 
- *     Mik Kersten     initial implementation 
- * ******************************************************************/
-
-package org.aspectj.asm.internal;
-
-import java.io.File;
-import java.util.StringTokenizer;
-
-import org.aspectj.asm.AsmManager;
-import org.aspectj.asm.IElementHandleProvider;
-import org.aspectj.asm.IProgramElement;
-import org.aspectj.bridge.ISourceLocation;
-
-/**
- * HandleProvider of the form '<full path to src file>|line|column|offset'
- * 
- * @author Mik Kersten
- */
-public class FullPathHandleProvider implements IElementHandleProvider {
-
-    static final String ID_DELIM = "|";
-    
-    public String createHandleIdentifier(ISourceLocation location) {
-        StringBuffer sb = new StringBuffer();
-        sb.append(AsmManager.getDefault()
-                            .getCanonicalFilePath(location.getSourceFile()));
-        sb.append(ID_DELIM);
-        sb.append(location.getLine());
-        sb.append(ID_DELIM);
-        sb.append(location.getColumn());
-        sb.append(ID_DELIM);
-        sb.append(location.getOffset());
-        return sb.toString();
-    }
-    
-    public String createHandleIdentifier(File sourceFile, int line,int column,int offset) {
-        StringBuffer sb = new StringBuffer();
-        sb.append(AsmManager.getDefault().getCanonicalFilePath(sourceFile));
-        sb.append(ID_DELIM);
-        sb.append(line);
-        sb.append(ID_DELIM);
-        sb.append(column);
-        sb.append(ID_DELIM);
-        sb.append(offset);
-        return sb.toString();       
-    }
-
-    public String getFileForHandle(String handle) {
-        StringTokenizer st = new StringTokenizer(handle, ID_DELIM);
-        String file = st.nextToken();
-        return file;
-    }
-
-    public int getLineNumberForHandle(String handle) {
-        StringTokenizer st = new StringTokenizer(handle, ID_DELIM);
-        st.nextToken(); // skip over the file
-        return new Integer(st.nextToken()).intValue();
-    }
-
-       public int getOffSetForHandle(String handle) {
-               StringTokenizer st = new StringTokenizer(handle, ID_DELIM);
-        st.nextToken(); // skip over the file
-        st.nextToken(); // skip over the line number
-        st.nextToken(); // skip over the column
-        return new Integer(st.nextToken()).intValue();
-       }
-
-       public String createHandleIdentifier(IProgramElement ipe) {
-               if (ipe == null) return null;
-               if (ipe.getHandleIdentifier(false) != null) {
-                       return ipe.getHandleIdentifier(false);
-               }
-               String handle = null;  
-               if (ipe.getSourceLocation() != null) {
-                       handle = createHandleIdentifier(ipe.getSourceLocation());
-               } else {
-                       handle = createHandleIdentifier(ISourceLocation.NO_FILE,-1,-1,-1);
-               }
-               ipe.setHandleIdentifier(handle);
-               return handle;
-       }
-
-       public boolean dependsOnLocation() {
-               // handles contain information from the source location therefore 
-               // return true;
-               return true;
-       }
-
-       public void initialize() {
-               // nothing to initialize...
-       }
-}
index 9a1e36a48932f13bed1e02db926d6ddefd4f3e64..662f40deb724c4be2c4d676b914888468b1fb2d2 100644 (file)
@@ -29,6 +29,8 @@ import org.aspectj.bridge.ISourceLocation;
  */
 public class JDTLikeHandleProvider implements IElementHandleProvider {
 
+       private final AsmManager asm;
+
        // Need to keep our own count of the number of initializers
        // because this information cannot be gained from the ipe.
        private int initializerCounter = 0;
@@ -39,6 +41,10 @@ public class JDTLikeHandleProvider implements IElementHandleProvider {
        private final String backslash = "\\";
        private final String emptyString = "";
 
+       public JDTLikeHandleProvider(AsmManager asm) {
+               this.asm = asm;
+       }
+
        public String createHandleIdentifier(IProgramElement ipe) {
 
                // AjBuildManager.setupModel --> top of the tree is either
@@ -50,7 +56,7 @@ public class JDTLikeHandleProvider implements IElementHandleProvider {
                        // therefore just return it
                        return ipe.getHandleIdentifier();
                } else if (ipe.getKind().equals(IProgramElement.Kind.FILE_LST)) {
-                       String configFile = AsmManager.getDefault().getHierarchy().getConfigFile();
+                       String configFile = asm.getHierarchy().getConfigFile();
                        int start = configFile.lastIndexOf(File.separator);
                        int end = configFile.lastIndexOf(".lst");
                        if (end != -1) {
@@ -242,9 +248,9 @@ public class JDTLikeHandleProvider implements IElementHandleProvider {
        }
 
        public String getFileForHandle(String handle) {
-               IProgramElement node = AsmManager.getDefault().getHierarchy().getElement(handle);
+               IProgramElement node = asm.getHierarchy().getElement(handle);
                if (node != null) {
-                       return AsmManager.getDefault().getCanonicalFilePath(node.getSourceLocation().getSourceFile());
+                       return asm.getCanonicalFilePath(node.getSourceLocation().getSourceFile());
                } else if (handle.charAt(0) == HandleProviderDelimiter.ASPECT_CU.getDelimiter()
                                || handle.charAt(0) == HandleProviderDelimiter.COMPILATIONUNIT.getDelimiter()) {
                        // it's something like *MyAspect.aj or {MyClass.java. In other words
@@ -256,7 +262,7 @@ public class JDTLikeHandleProvider implements IElementHandleProvider {
        }
 
        public int getLineNumberForHandle(String handle) {
-               IProgramElement node = AsmManager.getDefault().getHierarchy().getElement(handle);
+               IProgramElement node = asm.getHierarchy().getElement(handle);
                if (node != null) {
                        return node.getSourceLocation().getLine();
                } else if (handle.charAt(0) == HandleProviderDelimiter.ASPECT_CU.getDelimiter()
@@ -270,7 +276,7 @@ public class JDTLikeHandleProvider implements IElementHandleProvider {
        }
 
        public int getOffSetForHandle(String handle) {
-               IProgramElement node = AsmManager.getDefault().getHierarchy().getElement(handle);
+               IProgramElement node = asm.getHierarchy().getElement(handle);
                if (node != null) {
                        return node.getSourceLocation().getOffset();
                } else if (handle.charAt(0) == HandleProviderDelimiter.ASPECT_CU.getDelimiter()
@@ -284,7 +290,7 @@ public class JDTLikeHandleProvider implements IElementHandleProvider {
        }
 
        public String createHandleIdentifier(ISourceLocation location) {
-               IProgramElement node = AsmManager.getDefault().getHierarchy().findElementForSourceLine(location);
+               IProgramElement node = asm.getHierarchy().findElementForSourceLine(location);
                if (node != null) {
                        return createHandleIdentifier(node);
                }
@@ -292,8 +298,7 @@ public class JDTLikeHandleProvider implements IElementHandleProvider {
        }
 
        public String createHandleIdentifier(File sourceFile, int line, int column, int offset) {
-               IProgramElement node = AsmManager.getDefault().getHierarchy().findElementForOffSet(sourceFile.getAbsolutePath(), line,
-                               offset);
+               IProgramElement node = asm.getHierarchy().findElementForOffSet(sourceFile.getAbsolutePath(), line, offset);
                if (node != null) {
                        return createHandleIdentifier(node);
                }
index 335bfdd63ecf86ea307c895f737284638d48eb36..98b318580216b60cf5161edc49b9f351538733d0 100644 (file)
@@ -31,6 +31,7 @@ import org.aspectj.bridge.ISourceLocation;
  */
 public class ProgramElement implements IProgramElement {
 
+       public transient AsmManager asm; // which structure model is this node part of
        private static final long serialVersionUID = 171673495267384449L;
        public static boolean shortITDNames = true;
 
@@ -60,21 +61,30 @@ public class ProgramElement implements IProgramElement {
 
        // --- ctors
 
+       public AsmManager getModel() {
+               return asm;
+       }
+
        /** Used during de-externalization */
        public ProgramElement() {
+               int stop = 1;
        }
 
        /** Use to create program element nodes that do not correspond to source locations */
-       public ProgramElement(String name, Kind kind, List children) {
+       public ProgramElement(AsmManager asm, String name, Kind kind, List children) {
+               this.asm = asm;
+               if (asm == null && !name.equals("<build to view structure>")) {
+                       throw new RuntimeException();
+               }
                this.name = name;
                this.kind = kind;
                if (children != null)
                        setChildren(children);
        }
 
-       public ProgramElement(String name, IProgramElement.Kind kind, ISourceLocation sourceLocation, int modifiers, String comment,
-                       List children) {
-               this(name, kind, children);
+       public ProgramElement(AsmManager asm, String name, IProgramElement.Kind kind, ISourceLocation sourceLocation, int modifiers,
+                       String comment, List children) {
+               this(asm, name, kind, children);
                this.sourceLocation = sourceLocation;
                setFormalComment(comment);
                // if (comment!=null && comment.length()>0) formalComment = comment;
@@ -525,7 +535,11 @@ public class ProgramElement implements IProgramElement {
 
        public String getHandleIdentifier(boolean create) {
                if (null == handle && create) {
-                       handle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(this);
+                       if (asm == null && name.equals("<build to view structure>")) {
+                               handle = "<build to view structure>";
+                       } else {
+                               handle = asm.getHandleProvider().createHandleIdentifier(this);
+                       }
                }
                return handle;
        }