]> source.dussan.org Git - aspectj.git/commitdiff
bug#82171 Created sepereate handle provider to enable ASM use of IDE-specific handle...
authormkersten <mkersten>
Thu, 14 Apr 2005 16:44:01 +0000 (16:44 +0000)
committermkersten <mkersten>
Thu, 14 Apr 2005 16:44:01 +0000 (16:44 +0000)
asm/src/org/aspectj/asm/AsmManager.java
asm/src/org/aspectj/asm/IElementHandleProvider.java [new file with mode: 0644]
asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java
asm/src/org/aspectj/asm/internal/FullPathHandleProvider.java [new file with mode: 0644]
asm/src/org/aspectj/asm/internal/ProgramElement.java
docs/sandbox/api-clients/org/aspectj/samples/AsmRelationshipMapExtensionTest.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmHierarchyBuilder.java
weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java
weaver/src/org/aspectj/weaver/ShadowMunger.java

index 3f3a900aa24efcd3bfb53a73823453a6b389543c..623638b79a991efc5fa18121174c59527a26de01 100644 (file)
@@ -34,6 +34,7 @@ public class AsmManager {
         * @deprecated  use getDefault() method instead
         */  
        private static AsmManager INSTANCE = new AsmManager();
+    private IElementHandleProvider handleProvider;
        private boolean shouldSaveModel = true;
     protected IHierarchy hierarchy;
     private List structureListeners = new ArrayList();
@@ -44,8 +45,6 @@ public class AsmManager {
        public static boolean dumpModelPostBuild = false; // Dumping the model is expensive
        public static boolean attemptIncrementalModelRepairs = false;
 //     for debugging ...       
-       
-
 
     // For offline debugging, you can now ask for the AsmManager to
     // dump the model - see the method setReporting()
@@ -63,6 +62,7 @@ public class AsmManager {
        hierarchy = new AspectJElementHierarchy();
 //     List relationships = new ArrayList();
                mapper = new RelationshipMap(hierarchy);
+        handleProvider = new FullPathHandleProvider(); 
     }
 
     public IHierarchy getHierarchy() {
@@ -159,6 +159,14 @@ public class AsmManager {
         }
     }
 
+    public IElementHandleProvider getHandleProvider() {
+        return handleProvider;
+    }
+    
+    public void setHandleProvider(IElementHandleProvider handleProvider) {
+        this.handleProvider = handleProvider;
+    }
+    
        /**
         * Fails silently.
         */
@@ -789,6 +797,7 @@ public class AsmManager {
                }
        }
 
+
     /**
      * Set to indicate whether we are currently building a structure model, should
      * be set up front.
diff --git a/asm/src/org/aspectj/asm/IElementHandleProvider.java b/asm/src/org/aspectj/asm/IElementHandleProvider.java
new file mode 100644 (file)
index 0000000..97902ab
--- /dev/null
@@ -0,0 +1,56 @@
+/* *******************************************************************
+ * Copyright (c) 2003 Contributors.
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Common Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://www.eclipse.org/legal/cpl-v10.html 
+ *  
+ * Contributors: 
+ *     Mik Kersten     initial implementation 
+ * ******************************************************************/
+
+package org.aspectj.asm;
+
+import java.io.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.  
+ * 
+ * @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(File sourceFile, int line,int column,int offset);
+
+    /**
+     * 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);
+    
+}
index 26bf3f4b0d49d0884e595476e3aac6079d2d9d3b..cc95646cfc77f1344953d68ad4caabd238eef9a6 100644 (file)
@@ -36,11 +36,13 @@ public class AspectJElementHierarchy implements IHierarchy {
                IProgramElement cachedEntry = (IProgramElement)handleMap.get(handle);
                if (cachedEntry!=null) return cachedEntry;
                
-               StringTokenizer st = new StringTokenizer(handle, ProgramElement.ID_DELIM);
-               String file = st.nextToken();
-               int line = new Integer(st.nextToken()).intValue();
-               // int col = new Integer(st.nextToken()).intValue(); TODO: use column number when available
-               String canonicalSFP = AsmManager.getDefault().getCanonicalFilePath(new File(file));
+//             StringTokenizer st = new StringTokenizer(handle, ProgramElement.ID_DELIM);
+//        int line = new Integer(st.nextToken()).intValue();
+        // int col = new Integer(st.nextToken()).intValue(); TODO: use column number when available
+        String file = AsmManager.getDefault().getHandleProvider().getFileForHandle(handle); // st.nextToken();
+        int line = AsmManager.getDefault().getHandleProvider().getLineNumberForHandle(handle); // st.nextToken();
+        
+        String canonicalSFP = AsmManager.getDefault().getCanonicalFilePath(new File(file));
                IProgramElement ret = findNodeForSourceLineHelper(root,canonicalSFP, line);
                if (ret!=null) {
                        handleMap.put(handle,ret);
@@ -318,11 +320,14 @@ public class AspectJElementHierarchy implements IHierarchy {
                IProgramElement ret = (IProgramElement) handleMap.get(handle);
                if (ret != null) return ret;
                
-               StringTokenizer st = new StringTokenizer(handle, ProgramElement.ID_DELIM);
-               String file = st.nextToken();
-               int line = new Integer(st.nextToken()).intValue();
+//             StringTokenizer st = new StringTokenizer(handle, ProgramElement.ID_DELIM);
+//             String file = st.nextToken();
+//             int line = new Integer(st.nextToken()).intValue();
 //             int col = new Integer(st.nextToken()).intValue();
                // TODO: use column number when available
+        String file = AsmManager.getDefault().getHandleProvider().getFileForHandle(handle); // st.nextToken();
+        int line = AsmManager.getDefault().getHandleProvider().getLineNumberForHandle(handle); // st.nextToken();
+        
                ret = findElementForSourceLine(file, line);
                if (ret != null) { 
                        cache(handle,(ProgramElement)ret);
diff --git a/asm/src/org/aspectj/asm/internal/FullPathHandleProvider.java b/asm/src/org/aspectj/asm/internal/FullPathHandleProvider.java
new file mode 100644 (file)
index 0000000..0a32af2
--- /dev/null
@@ -0,0 +1,65 @@
+/* *******************************************************************
+ * Copyright (c) 2003 Contributors.
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Common Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://www.eclipse.org/legal/cpl-v10.html 
+ *  
+ * Contributors: 
+ *     Mik Kersten     initial implementation 
+ * ******************************************************************/
+
+package org.aspectj.asm.internal;
+
+import java.io.File;
+import java.util.StringTokenizer;
+
+import org.aspectj.asm.AsmManager;
+import org.aspectj.asm.IElementHandleProvider;
+import org.aspectj.bridge.ISourceLocation;
+
+/**
+ * @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();
+    }
+}
index 6bfe851151276c3cf353caeb879e163ac649fff9..a34a5ffa86fd1acfe7c97093a804e3520efb5ea8 100644 (file)
@@ -31,8 +31,6 @@ import org.aspectj.bridge.ISourceLocation;
  */
 public class ProgramElement implements IProgramElement {
                
-       static final String ID_DELIM = "|";
-               
        protected IProgramElement parent = null;
        protected String name = "";
        // children.listIterator() should support remove() operation
@@ -447,40 +445,16 @@ public class ProgramElement implements IProgramElement {
                return label;
        }
 
-       public static 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();           
-       }
-
        private String handle = null;
        public String getHandleIdentifier() {
            if (null == handle) {
                        if (sourceLocation != null) {
-                           return genHandleIdentifier(sourceLocation);
-                       }
+                return AsmManager.getDefault().getHandleProvider().createHandleIdentifier(sourceLocation);
+//                         return genHandleIdentifier(sourceLocation);
+                       } 
            }
            return handle;
        }
-
-       public static String genHandleIdentifier(ISourceLocation sourceLocation) {
-               StringBuffer sb = new StringBuffer();
-               sb.append(AsmManager.getDefault()
-                                                       .getCanonicalFilePath(sourceLocation.getSourceFile()));
-               sb.append(ID_DELIM);
-               sb.append(sourceLocation.getLine());
-               sb.append(ID_DELIM);
-               sb.append(sourceLocation.getColumn());
-               sb.append(ID_DELIM);
-               sb.append(sourceLocation.getOffset());
-               return sb.toString();
-       }
        
        public List getParameterNames() {
                return parameterNames;
index 5ffeaa85f721a0eb85606c0cc9e09d5e60f34510..f11b5bc8258040e8770c5fd286d1207f22a82c88 100644 (file)
@@ -59,11 +59,11 @@ class DeclareInfoProvider extends AsmRelationshipProvider {
         for (Iterator it = newParents.iterator(); it.hasNext();) {
             ResolvedTypeX superType = (ResolvedTypeX) it.next();
             
-               String sourceHandle = ProgramElement.createHandleIdentifier(
+               String sourceHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(
                     decp.getSourceFile(),decp.getLine(),decp.getColumn(), decp.getOffset());
                IProgramElement ipe = AsmManager.getDefault().getHierarchy().findElementForHandle(sourceHandle);
   
-               String superHandle = ProgramElement.createHandleIdentifier(
+               String superHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(
                        superType.getSourceLocation().getSourceFile(),
                        superType.getSourceLocation().getLine(),
                        superType.getSourceLocation().getColumn(),
index 523fea5a6e095f990efeded4343ff443aca27e45..ab2ce9f080d831d11dbe667c8d684e2f3c0cd3e2 100644 (file)
@@ -47,13 +47,13 @@ public class AsmInterTypeRelationshipProvider {
        
                if (munger.getSourceLocation() != null
                        && munger.getSourceLocation() != null) {
-                       String sourceHandle = ProgramElement.createHandleIdentifier(
+                       String sourceHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(
                                munger.getSourceLocation().getSourceFile(),
                                munger.getSourceLocation().getLine(),
                                munger.getSourceLocation().getColumn(),
                                munger.getSourceLocation().getOffset());
                                
-                       String targetHandle = ProgramElement.createHandleIdentifier(
+                       String targetHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(
                                onType.getSourceLocation().getSourceFile(),
                                onType.getSourceLocation().getLine(),
                                onType.getSourceLocation().getColumn(),
index b0587d3f9a37e6837fa13b210e348f32ac15b8d7..460de15f477097d15b552c9f514fbc9413b78b83 100644 (file)
@@ -369,9 +369,9 @@ public class AsmHierarchyBuilder extends ASTVisitor {
             ResolvedMember member = getPointcutDeclaration(rp, declaration);
             if (member != null) {
                 IRelationship foreward = AsmManager.getDefault().getRelationshipMap().get(peNode.getHandleIdentifier(), IRelationship.Kind.USES_POINTCUT, "uses pointcut", false, true);
-                foreward.addTarget(ProgramElement.genHandleIdentifier(member.getSourceLocation()));            
+                foreward.addTarget(AsmManager.getDefault().getHandleProvider().createHandleIdentifier(member.getSourceLocation()));            
                 
-                IRelationship back = AsmManager.getDefault().getRelationshipMap().get(ProgramElement.genHandleIdentifier(member.getSourceLocation()), IRelationship.Kind.USES_POINTCUT, "pointcut used by", false, true);
+                IRelationship back = AsmManager.getDefault().getRelationshipMap().get(AsmManager.getDefault().getHandleProvider().createHandleIdentifier(member.getSourceLocation()), IRelationship.Kind.USES_POINTCUT, "pointcut used by", false, true);
                 back.addTarget(peNode.getHandleIdentifier());             
             } 
         }        
index 15b58dcb2da1bbac04229e3c9cee6386115d1158..7a1bbba438ca0d79140e610e73a9c2c716d7a495 100644 (file)
@@ -55,13 +55,13 @@ public class AsmRelationshipProvider {
                // Ensure a node for the target exists
                IProgramElement targetNode = getNode(AsmManager.getDefault().getHierarchy(), shadow);
 
-               String sourceHandle = ProgramElement.createHandleIdentifier(
+               String sourceHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(
                        checker.getSourceLocation().getSourceFile(),
                        checker.getSourceLocation().getLine(),
                        checker.getSourceLocation().getColumn(),
                        checker.getSourceLocation().getOffset());
                        
-               String targetHandle = ProgramElement.createHandleIdentifier(
+               String targetHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(
                        shadow.getSourceLocation().getSourceFile(),
                        shadow.getSourceLocation().getLine(),
                        shadow.getSourceLocation().getColumn(),
@@ -90,13 +90,13 @@ public class AsmRelationshipProvider {
          if (!AsmManager.isCreatingModel()) return;
                String sourceHandle = "";
                if (munger.getSourceLocation()!=null) {
-                       sourceHandle = ProgramElement.createHandleIdentifier(
+                       sourceHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(
                                                                                munger.getSourceLocation().getSourceFile(),
                                                                                munger.getSourceLocation().getLine(),
                                                                                munger.getSourceLocation().getColumn(),
                                                                                munger.getSourceLocation().getOffset());
                } else {
-                       sourceHandle = ProgramElement.createHandleIdentifier(
+                       sourceHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(
                                                        originatingAspect.getSourceLocation().getSourceFile(),
                                                        originatingAspect.getSourceLocation().getLine(),
                                                        originatingAspect.getSourceLocation().getColumn(),
@@ -104,7 +104,7 @@ public class AsmRelationshipProvider {
                }
                if (originatingAspect.getSourceLocation() != null) {
                                
-                       String targetHandle = ProgramElement.createHandleIdentifier(
+                       String targetHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(
                                onType.getSourceLocation().getSourceFile(),
                                onType.getSourceLocation().getLine(),
                                onType.getSourceLocation().getColumn(),
@@ -126,12 +126,12 @@ public class AsmRelationshipProvider {
        public void addDeclareParentsRelationship(ISourceLocation decp,ResolvedTypeX targetType, List newParents) {
            if (!AsmManager.isCreatingModel()) return;
 
-               String sourceHandle = ProgramElement.createHandleIdentifier(decp.getSourceFile(),decp.getLine(),decp.getColumn(),decp.getOffset());
+               String sourceHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(decp.getSourceFile(),decp.getLine(),decp.getColumn(),decp.getOffset());
                
                IProgramElement ipe = AsmManager.getDefault().getHierarchy().findElementForHandle(sourceHandle);
                
        
-               String targetHandle = ProgramElement.createHandleIdentifier(
+               String targetHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(
                                targetType.getSourceLocation().getSourceFile(),
                                targetType.getSourceLocation().getLine(),
                                targetType.getSourceLocation().getColumn(),
@@ -154,11 +154,11 @@ public class AsmRelationshipProvider {
         */
        public void addDeclareAnnotationRelationship(ISourceLocation declareAnnotationLocation,ISourceLocation annotatedLocation) {
            if (!AsmManager.isCreatingModel()) return;
-               String sourceHandle = ProgramElement.createHandleIdentifier(declareAnnotationLocation.getSourceFile(),declareAnnotationLocation.getLine(),
+               String sourceHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(declareAnnotationLocation.getSourceFile(),declareAnnotationLocation.getLine(),
                                                                                                                                        declareAnnotationLocation.getColumn(),declareAnnotationLocation.getOffset());
                IProgramElement declareAnnotationPE = AsmManager.getDefault().getHierarchy().findElementForHandle(sourceHandle);
                
-               String targetHandle = ProgramElement.createHandleIdentifier(
+               String targetHandle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(
                                annotatedLocation.getSourceFile(),
                                annotatedLocation.getLine(),
                                annotatedLocation.getColumn(),
@@ -384,7 +384,7 @@ public class AsmRelationshipProvider {
          
          try {
            String sourceHandle = 
-             ProgramElement.createHandleIdentifier(sourceLocation.getSourceFile(),sourceLocation.getLine(),
+            AsmManager.getDefault().getHandleProvider().createHandleIdentifier(sourceLocation.getSourceFile(),sourceLocation.getLine(),
                        sourceLocation.getColumn(),sourceLocation.getOffset());
                                
            String targetHandle = methodElem.getHandleIdentifier();
@@ -425,7 +425,7 @@ public class AsmRelationshipProvider {
         if (fieldElem== null) return;
 
                String sourceHandle = 
-                 ProgramElement.createHandleIdentifier(sourceLocation.getSourceFile(),sourceLocation.getLine(),
+            AsmManager.getDefault().getHandleProvider().createHandleIdentifier(sourceLocation.getSourceFile(),sourceLocation.getLine(),
                        sourceLocation.getColumn(),sourceLocation.getOffset());
                        
                String targetHandle = fieldElem.getHandleIdentifier();
index 9924d2e7fb0c13b6a744c11c9b8c121cee971e02..9425cd6fdf622675cc633e7c9a8f239e4ff1f4ed 100644 (file)
@@ -15,6 +15,7 @@ package org.aspectj.weaver;
 
 import java.util.Collection;
 
+import org.aspectj.asm.AsmManager;
 import org.aspectj.asm.internal.ProgramElement;
 import org.aspectj.bridge.ISourceLocation;
 import org.aspectj.util.PartialOrder;
@@ -87,7 +88,7 @@ public abstract class ShadowMunger implements PartialOrder.PartialComparable, IH
                if (null == handle) {
                        ISourceLocation sl = getSourceLocation();
                        if (sl != null) {
-                               handle = ProgramElement.createHandleIdentifier(
+                               handle = AsmManager.getDefault().getHandleProvider().createHandleIdentifier(
                                            sl.getSourceFile(),
                                            sl.getLine(),
                                            sl.getColumn(),