]> source.dussan.org Git - aspectj.git/commitdiff
Improved declare relationships. Implemented batch-build relationship clearing policy.
authormkersten <mkersten>
Thu, 14 Aug 2003 17:18:34 +0000 (17:18 +0000)
committermkersten <mkersten>
Thu, 14 Aug 2003 17:18:34 +0000 (17:18 +0000)
ajde/src/org/aspectj/ajde/Ajde.java
ajde/testdata/examples/coverage/ModelCoverage.java
ajde/testsrc/org/aspectj/ajde/AsmRelationshipsTest.java
asm/src/org/aspectj/asm/IProgramElement.java
asm/src/org/aspectj/asm/IRelationshipMap.java
asm/src/org/aspectj/asm/internal/AspectJElementHierarchy.java
asm/src/org/aspectj/asm/internal/ProgramElement.java
asm/src/org/aspectj/asm/internal/RelationshipMap.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java
weaver/src/org/aspectj/weaver/AsmAdviceRelationshipProvider.java

index 032ad6e59da0972b42bf3fde54ab5bc201964873..687f8bbbddd880850d5b87d3d5b9f208724b4c47 100644 (file)
@@ -294,6 +294,9 @@ public class Ajde {
         * Writes the default configuration file if it has been selected for compilation
         */
        public void compileStarted(String buildConfig) { 
+               // TODO: implement incremental policy
+               AsmManager.getDefault().getRelationshipMap().clear();
+               
                String configFilePath = projectProperties.getDefaultBuildConfigFile();
                if (buildConfig.equals(configFilePath)) {
                        configurationManager.writePaths(configFilePath, projectProperties.getProjectSourceFiles());     
index 075bddc3b978284150d607cb985b8876bda72346..bb977e36c2ca2de112f631b52d4e4b3c77e198db 100644 (file)
@@ -55,7 +55,7 @@ aspect AdvisesRelationshipCoverage {
        pointcut getP(): get(int *.*);
        before(): getP() { }
 
-       pointcut setP(): set(int *.*);
+       pointcut setP(): set(int *.*) && !set(int *.xxx);
        before(): setP() { }
 
        pointcut initializationP(): initialization(Point.new(..));
index db82a96cf9c284858a43005c34f6309622dcdd39..85df30d08817e1a2572c9f4e6e84634da2161fe2 100644 (file)
 
 package org.aspectj.ajde;
 
-import java.util.List;
+import java.util.Iterator;
 
 import org.aspectj.asm.*;
-import org.aspectj.asm.internal.ProgramElement;
 
 // TODO: check for return types
 public class AsmRelationshipsTest extends AjdeTestCase {
@@ -27,29 +26,40 @@ public class AsmRelationshipsTest extends AjdeTestCase {
        }
   
        public void testInterTypeDeclarations() {               
-//             checkMapping("InterTypeDecCoverage", "Point", "Point.xxx", "xxx", "declared on", "aspect declarations");        
-//             checkMapping("InterTypeDecCoverage", "Point", "Point.check(int, Line)", "Point", "declared on", "aspect declarations"); 
-
+               checkInterTypeMapping("InterTypeDecCoverage", "Point", "Point.xxx", "Point", 
+                       "declared on", "aspect declarations", IProgramElement.Kind.INTER_TYPE_FIELD);   
+               checkInterTypeMapping("InterTypeDecCoverage", "Point", "Point.check(int, Line)", 
+                       "Point", "declared on", "aspect declarations", IProgramElement.Kind.INTER_TYPE_METHOD); 
        }
 
        public void testAdvice() {      
-               checkMapping("AdvisesRelationshipCoverage", "Point", "before(): methodExecutionP..", "setX(int)", "advises", "advised by");
-               checkUniDirectionalMapping("AdvisesRelationshipCoverage", "Point", "before(): getP..", "field-get(int Point.x)", "advises");
-               checkUniDirectionalMapping("AdvisesRelationshipCoverage", "Point", "before(): setP..", "field-set(int Point.xxx)", "advises");  
+               checkMapping("AdvisesRelationshipCoverage", "Point", "before(): methodExecutionP..", 
+                       "setX(int)", "advises", "advised by");
+               checkUniDirectionalMapping("AdvisesRelationshipCoverage", "Point", "before(): getP..", 
+                       "field-get(int Point.x)", "advises");
+               checkUniDirectionalMapping("AdvisesRelationshipCoverage", "Point", "before(): setP..", 
+                       "field-set(int Point.x)", "advises");   
        }
 
-       private void checkUniDirectionalMapping(String fromType, String toType, String from, String to, String relName) {
+       private void checkUniDirectionalMapping(String fromType, String toType, String from, 
+               String to, String relName) {
+               
                IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, fromType);
                assertNotNull(aspect);          
                String beforeExec = from;
                IProgramElement beforeExecNode = manager.getHierarchy().findElementForLabel(aspect, IProgramElement.Kind.ADVICE, beforeExec);
                assertNotNull(beforeExecNode);
                IRelationship rel = manager.getRelationshipMap().get(beforeExecNode, IRelationship.Kind.ADVICE, relName);
-               String handle = (String)rel.getTargets().get(0);
-               assertEquals(manager.getHierarchy().findElementForHandle(handle).toLabelString(), to);
+               for (Iterator it = rel.getTargets().iterator(); it.hasNext(); ) {
+                       String currHandle = (String)it.next();
+                       if (manager.getHierarchy().findElementForHandle(currHandle).toLabelString().equals(to)) return;
+               }
+               fail(); // didn't find it
        }
 
-       private void checkMapping(String fromType, String toType, String from, String to, String forwardRelName, String backRelName) {
+       private void checkMapping(String fromType, String toType, String from, String to, 
+               String forwardRelName, String backRelName) {
+               
                IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, fromType);
                assertNotNull(aspect);          
                String beforeExec = from;
@@ -69,6 +79,30 @@ public class AsmRelationshipsTest extends AjdeTestCase {
                assertEquals(manager.getHierarchy().findElementForHandle(handle2).toString(), from);
        }
 
+       private void checkInterTypeMapping(String fromType, String toType, String from, 
+               String to, String forwardRelName, String backRelName, IProgramElement.Kind declareKind) {
+               
+               IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, fromType);
+               assertNotNull(aspect);          
+               String beforeExec = from;
+               IProgramElement fromNode = manager.getHierarchy().findElementForLabel(aspect, declareKind, beforeExec);
+               assertNotNull(fromNode);
+               IRelationship rel = manager.getRelationshipMap().get(fromNode, IRelationship.Kind.DECLARE_INTER_TYPE, forwardRelName);
+               String handle = (String)rel.getTargets().get(0);
+               assertEquals(manager.getHierarchy().findElementForHandle(handle).toString(), to);  
+
+               IProgramElement clazz = AsmManager.getDefault().getHierarchy().findElementForType(null, toType);
+               assertNotNull(clazz);
+               String set = to;
+               IRelationship rel2 = manager.getRelationshipMap().get(clazz, IRelationship.Kind.DECLARE_INTER_TYPE, backRelName);
+               String handle2 = (String)rel2.getTargets().get(0);
+               for (Iterator it = rel2.getTargets().iterator(); it.hasNext(); ) {
+                       String currHandle = (String)it.next();
+                       if (manager.getHierarchy().findElementForHandle(currHandle).toLabelString().equals(from)) return;
+               }
+               fail(); // didn't find it
+       }
        protected void setUp() throws Exception {
                super.setUp("examples");
                assertTrue("build success", doSynchronousBuild(CONFIG_FILE_PATH));      
index 42a83d2b37f371bd1b3df67f0b1732c686c5979a..0c1b0595c75397d5b923650bd7cb36d3300b8c00 100644 (file)
@@ -24,8 +24,6 @@ import org.aspectj.bridge.*;
  */
 public interface IProgramElement extends Serializable {
        
-       public static final String ID_DELIM = "|";
-       
        public List/*IProgramElement*/ getChildren();
 
        public void setChildren(List children); 
index b5a12e534db0f18e18fb4a5b8fb5e8097796f986..f487ce661e58ad358c6f348452ecbb2438ff8a74 100644 (file)
@@ -64,5 +64,10 @@ public interface IRelationshipMap extends Serializable {
        public void remove(String handle, IRelationship relationship);
        
        public void removeAll(String source);
+       
+       /**
+        * Clear all of the relationships in the map.
+        */
+       public void clear();
  
 }
index 6a523da11d9b3f5bad55a41f6daa8f2cd279481f..e8d2f99028b1c3b3b71f1bee98ee2f1ade1259c5 100644 (file)
@@ -270,7 +270,7 @@ public class AspectJElementHierarchy implements IHierarchy {
        
        // TODO: optimize this lookup
        public IProgramElement findElementForHandle(String handle) {
-               StringTokenizer st = new StringTokenizer(handle, IProgramElement.ID_DELIM);
+               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();
index ff509689da333ec05cc030773d8ef48ee25f3e3a..830b323bdaccb74bc33cd7866cab7647b38ea07a 100644 (file)
 
 package org.aspectj.asm.internal;
 
-import java.io.IOException;
+import java.io.*;
 import java.util.*;
 
 import org.aspectj.asm.*;
 import org.aspectj.bridge.*;
-import org.aspectj.bridge.IMessage.Kind;
 
 
 /**
@@ -26,6 +25,8 @@ import org.aspectj.bridge.IMessage.Kind;
  */
 public class ProgramElement implements IProgramElement {
                
+       static final String ID_DELIM = "|";
+               
        protected IProgramElement parent = null;
        protected String name = "";
        // children.listIterator() should support remove() operation
@@ -391,6 +392,22 @@ public class ProgramElement implements IProgramElement {
                return label;
        }
 
+       // TODO: determine if using canonical path incurrs performance overhead
+       public static String createHandleIdentifier(File sourceFile, int line,int column) {
+               try {
+                       StringBuffer sb = new StringBuffer();
+                       sb.append(sourceFile.getCanonicalPath());
+                       sb.append(ID_DELIM);
+                       sb.append(line);
+                       sb.append(ID_DELIM);
+                       sb.append(column);
+                       return sb.toString();           
+               } catch (IOException ioe) {
+                       ioe.printStackTrace();
+                       return null;
+               }
+       }
+
        public String getHandleIdentifier() {
                try {
                        StringBuffer sb = new StringBuffer();
index cd7e776c6d2fd19f659d459f227194a3f5b5303d..86f9606f1e8a4fcd1699bb78f74f4e498fd4f144 100644 (file)
@@ -111,4 +111,8 @@ public class RelationshipMap extends HashMap implements IRelationshipMap {
                put(source.getHandleIdentifier(), relationship);
        }
 
+       public void clear() {
+               super.clear();
+       }
+
 }
index 329e5b57e468cdd1b19741921fe59d38be1e4a83..46a155204d881e3ad413fa77e5d523d0d66c1873 100644 (file)
  
 package org.aspectj.ajdt.internal.compiler.lookup;
 
-import java.util.*;
+import java.io.IOException;
 
 import org.aspectj.asm.*;
-import org.aspectj.asm.internal.Relationship;
+import org.aspectj.asm.internal.ProgramElement;
 import org.aspectj.weaver.*;
 
 /**
@@ -23,7 +23,7 @@ import org.aspectj.weaver.*;
  */
 public class AsmInterTypeRelationshipProvider {
 
-       public static final String INTER_TYPE_DECLARES = "declares on";
+       public static final String INTER_TYPE_DECLARES = "declared on";
        public static final String INTER_TYPE_DECLARED_BY = "aspect declarations";
 
        public static void addRelationship(
@@ -43,25 +43,25 @@ public class AsmInterTypeRelationshipProvider {
        
                if (munger.getSourceLocation() != null
                        && munger.getSourceLocation() != null) {
-                       String sourceHandle = 
-                               munger.getSourceLocation().getSourceFile().getAbsolutePath() + IProgramElement.ID_DELIM
-                               + munger.getSourceLocation().getLine() + IProgramElement.ID_DELIM
-                               + munger.getSourceLocation().getColumn();
+                       String sourceHandle = ProgramElement.createHandleIdentifier(
+                               munger.getSourceLocation().getSourceFile(),
+                               munger.getSourceLocation().getLine(),
+                               munger.getSourceLocation().getColumn());
                                
-                       String targetHandle = 
-                               onType.getSourceLocation().getSourceFile().getAbsolutePath() + IProgramElement.ID_DELIM
-                               + onType.getSourceLocation().getLine() + IProgramElement.ID_DELIM
-                               + onType.getSourceLocation().getColumn();
-       
+                       String targetHandle = ProgramElement.createHandleIdentifier(
+                               onType.getSourceLocation().getSourceFile(),
+                               onType.getSourceLocation().getLine(),
+                               onType.getSourceLocation().getColumn());
+                               
+//                             System.err.println(">> putting: " + sourceHandle + ", to " + targetHandle);
                        IRelationshipMap mapper = AsmManager.getDefault().getRelationshipMap();
                        if (sourceHandle != null && targetHandle != null) {
-                               IRelationship foreward = mapper.get(sourceHandle, IRelationship.Kind.ADVICE, INTER_TYPE_DECLARES);
+                               IRelationship foreward = mapper.get(sourceHandle, IRelationship.Kind.DECLARE_INTER_TYPE, INTER_TYPE_DECLARES);
                                foreward.getTargets().add(targetHandle);
                                
-                               IRelationship back = mapper.get(targetHandle, IRelationship.Kind.ADVICE, INTER_TYPE_DECLARED_BY);
-                               back.getTargets().add(sourceHandle);
+                               IRelationship back = mapper.get(targetHandle, IRelationship.Kind.DECLARE_INTER_TYPE, INTER_TYPE_DECLARED_BY);
+                               back.getTargets().add(sourceHandle);  
                        }
                }
        }
-
 }
index 57795706999581e87b4c95f4c2120594c7916435..59f65ed8db9f9c0b9e36771a9ac5ba9760f6ed4b 100644 (file)
 
 package org.aspectj.weaver;
 
-import java.io.IOException;
 import java.util.*;
 
 import org.aspectj.asm.*;
-import org.aspectj.asm.internal.*;
+import org.aspectj.asm.internal.ProgramElement;
 import org.aspectj.bridge.*;
 
 public class AsmAdviceRelationshipProvider {
@@ -40,28 +39,23 @@ public class AsmAdviceRelationshipProvider {
                        }
                        IRelationshipMap mapper = AsmManager.getDefault().getRelationshipMap();
                        IProgramElement targetNode = getNode(AsmManager.getDefault().getHierarchy(), shadow);
-                       try {
-                               if (advice.getSourceLocation() != null && targetNode != null) {
-                                       String adviceHandle =
-                                               advice.getSourceLocation().getSourceFile().getCanonicalPath()
-                                               + IProgramElement.ID_DELIM + advice.getSourceLocation().getLine()
-                                               + IProgramElement.ID_DELIM + advice.getSourceLocation().getColumn();
-                                       
-                                                                       
-                       
-                                       if (targetNode != null) {
-                                               String targetHandle = targetNode.getHandleIdentifier(); 
+                       if (advice.getSourceLocation() != null && targetNode != null) {
+                               String adviceHandle = ProgramElement.createHandleIdentifier(
+                                       advice.getSourceLocation().getSourceFile(),
+                                       advice.getSourceLocation().getLine(),
+                                       advice.getSourceLocation().getColumn());
+               
+                               if (targetNode != null) {
+                                       String targetHandle = targetNode.getHandleIdentifier(); 
+                               
+                                       IRelationship foreward = mapper.get(adviceHandle, IRelationship.Kind.ADVICE, ADVISES);
+                                       if (foreward != null) foreward.getTargets().add(targetHandle);
                                        
-                                               IRelationship foreward = mapper.get(adviceHandle, IRelationship.Kind.ADVICE, ADVISES);
-                                               if (foreward != null) foreward.getTargets().add(targetHandle);
-                                               
-                                               IRelationship back = mapper.get(targetHandle, IRelationship.Kind.ADVICE, ADVISED_BY);
-                                               if (back != null) back.getTargets().add(adviceHandle);
-                                       }
+                                       IRelationship back = mapper.get(targetHandle, IRelationship.Kind.ADVICE, ADVISED_BY);
+                                       if (back != null) back.getTargets().add(adviceHandle);
                                }
-                       } catch (IOException e) {
-                               e.printStackTrace();
                        }
+
                }
        }