]> source.dussan.org Git - aspectj.git/commitdiff
Added spacewar project for testing.
authormkersten <mkersten>
Sat, 16 Aug 2003 03:14:36 +0000 (03:14 +0000)
committermkersten <mkersten>
Sat, 16 Aug 2003 03:14:36 +0000 (03:14 +0000)
ajde/testdata/examples/coverage/ModelCoverage.java
ajde/testsrc/org/aspectj/ajde/AsmDeclarationsTest.java
ajde/testsrc/org/aspectj/ajde/AsmRelationshipsTest.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/AsmInterTypeRelationshipProvider.java
weaver/src/org/aspectj/weaver/AsmAdviceRelationshipProvider.java [deleted file]
weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java [new file with mode: 0644]
weaver/src/org/aspectj/weaver/Shadow.java

index bb977e36c2ca2de112f631b52d4e4b3c77e198db..51fb54b89f176163087b14cdb8dcd34e7de562ab 100644 (file)
@@ -107,7 +107,7 @@ aspect DeclareCoverage {
     pointcut illegalNewFigElt(): call(Point.new(..)) && !withincode(* *.doIt(..));
 
     declare error: illegalNewFigElt(): "Illegal constructor call.";
-    declare warning: illegalNewFigElt(): "Illegal constructor call.";
+    declare warning: call(* Point.setX(..)): "Illegal call.";
 
     declare parents: Point extends java.io.Serializable;
     declare parents: Point+ implements java.util.Observable;
index 9d7bdf79c3fbd7c9f7313edb242764d55c8b8be8..028d8414023e5798ad3e1f5a9d8a51da81676ecb 100644 (file)
@@ -55,7 +55,7 @@ public class AsmDeclarationsTest extends AjdeTestCase {
                assertNotNull(decErrNode);
                assertEquals(decErrNode.toLabelString(), label);
                
-               String decWarnMessage = "declare warning: \"Illegal construct..\"";
+               String decWarnMessage = "declare warning: \"Illegal call.\"";
                IProgramElement decWarnNode = model.findElementForSignature(aspect, IProgramElement.Kind.DECLARE_WARNING, "declare warning");
                assertNotNull(decWarnNode);
                assertEquals(decWarnNode.toLabelString(), decWarnMessage);      
index 85df30d08817e1a2572c9f4e6e84634da2161fe2..f4b41a846e7d01df37cbabd47d019cfa47fb8e2c 100644 (file)
@@ -24,6 +24,11 @@ public class AsmRelationshipsTest extends AjdeTestCase {
        public AsmRelationshipsTest(String name) {
                super(name);
        }
+
+       public void testDeclareWarningAndError() {              
+               checkDeclareMapping("DeclareCoverage", "Point", "declare warning: \"Illegal call.\"", 
+                       "method-call(void Point.setX(int))", "matched by", "matches declare", IProgramElement.Kind.DECLARE_WARNING);            
+       }
   
        public void testInterTypeDeclarations() {               
                checkInterTypeMapping("InterTypeDecCoverage", "Point", "Point.xxx", "Point", 
@@ -41,6 +46,28 @@ public class AsmRelationshipsTest extends AjdeTestCase {
                        "field-set(int Point.x)", "advises");   
        }
 
+       private void checkDeclareMapping(String fromType, String toType, String from, String to, 
+               String forwardRelName, String backRelName, IProgramElement.Kind kind) {
+               
+               IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, fromType);
+               assertNotNull(aspect);          
+               String beforeExec = from;
+               IProgramElement beforeExecNode = manager.getHierarchy().findElementForLabel(aspect, kind, beforeExec);
+               assertNotNull(beforeExecNode);
+               IRelationship rel = manager.getRelationshipMap().get(beforeExecNode, IRelationship.Kind.DECLARE, 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;
+               IProgramElement setNode = manager.getHierarchy().findElementForLabel(clazz, IProgramElement.Kind.CODE, set);
+               assertNotNull(setNode);
+               IRelationship rel2 = manager.getRelationshipMap().get(setNode, IRelationship.Kind.DECLARE, backRelName);
+               String handle2 = (String)rel2.getTargets().get(0);
+               assertEquals(manager.getHierarchy().findElementForHandle(handle2).toString(), from);
+       }
+       
        private void checkUniDirectionalMapping(String fromType, String toType, String from, 
                String to, String relName) {
                
index 46a155204d881e3ad413fa77e5d523d0d66c1873..88a9e1953ea2f2d1775aa96cb9310f8b8f3bf702 100644 (file)
@@ -53,7 +53,6 @@ public class AsmInterTypeRelationshipProvider {
                                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.DECLARE_INTER_TYPE, INTER_TYPE_DECLARES);
diff --git a/weaver/src/org/aspectj/weaver/AsmAdviceRelationshipProvider.java b/weaver/src/org/aspectj/weaver/AsmAdviceRelationshipProvider.java
deleted file mode 100644 (file)
index 59f65ed..0000000
+++ /dev/null
@@ -1,163 +0,0 @@
-/* *******************************************************************
- * Copyright (c) 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: 
- *     PARC     initial implementation 
- * ******************************************************************/
-
-
-package org.aspectj.weaver;
-
-import java.util.*;
-
-import org.aspectj.asm.*;
-import org.aspectj.asm.internal.ProgramElement;
-import org.aspectj.bridge.*;
-
-public class AsmAdviceRelationshipProvider {
-       
-       public static final String ADVISES = "advises";
-       public static final String ADVISED_BY = "advised by";
-       public static final String DECLARES_ON = "declares on";
-       public static final String DECLAREDY_BY = "declared by";
-
-       public static void checkerMunger(IHierarchy model, Shadow shadow) {
-//             System.err.println("> " + shadow.getThisVar() + " to " + shadow.getTargetVar());
-       }
-       
-       public static void nodeMunger(IHierarchy model, Shadow shadow, ShadowMunger munger) {
-               if (munger instanceof Advice) {
-                       Advice advice = (Advice)munger;
-                       if (advice.getKind().isPerEntry() || advice.getKind().isCflow()) {
-                               // TODO: might want to show these in the future
-                               return;
-                       }
-                       IRelationshipMap mapper = AsmManager.getDefault().getRelationshipMap();
-                       IProgramElement targetNode = getNode(AsmManager.getDefault().getHierarchy(), shadow);
-                       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 back = mapper.get(targetHandle, IRelationship.Kind.ADVICE, ADVISED_BY);
-                                       if (back != null) back.getTargets().add(adviceHandle);
-                               }
-                       }
-
-               }
-       }
-
-       private static IProgramElement getNode(IHierarchy model, Shadow shadow) {
-               Member enclosingMember = shadow.getEnclosingCodeSignature();
-               
-               IProgramElement enclosingNode = lookupMember(model, enclosingMember);
-               if (enclosingNode == null) {
-                       Lint.Kind err = shadow.getIWorld().getLint().shadowNotInStructure;
-                       if (err.isEnabled()) {
-                               err.signal(shadow.toString(), shadow.getSourceLocation());
-                       }
-                       return null;
-               }
-               
-               Member shadowSig = shadow.getSignature();
-               if (!shadowSig.equals(enclosingMember)) {
-                       IProgramElement bodyNode = findOrCreateCodeNode(enclosingNode, shadowSig, shadow);
-                       return bodyNode;
-               } else {
-                       return enclosingNode;
-               }
-       }
-       
-       private static IProgramElement findOrCreateCodeNode(IProgramElement enclosingNode, Member shadowSig, Shadow shadow)
-       {
-               for (Iterator it = enclosingNode.getChildren().iterator(); it.hasNext(); ) {
-                       IProgramElement node = (IProgramElement)it.next();
-                       if (shadowSig.getName().equals(node.getBytecodeName()) &&
-                               shadowSig.getSignature().equals(node.getBytecodeSignature()))
-                       {
-                               return node;
-                       }
-               }
-               
-               ISourceLocation sl = shadow.getSourceLocation();
-               
-               IProgramElement peNode = new ProgramElement(
-                       shadow.toString(),
-                       IProgramElement.Kind.CODE,
-               //XXX why not use shadow file? new SourceLocation(sl.getSourceFile(), sl.getLine()),
-                       new SourceLocation(enclosingNode.getSourceLocation().getSourceFile(), sl.getLine()),
-                       0,
-                       "",
-                       new ArrayList());
-                               
-               peNode.setBytecodeName(shadowSig.getName());
-               peNode.setBytecodeSignature(shadowSig.getSignature());
-               enclosingNode.addChild(peNode);
-               return peNode;
-       }
-       
-       private static IProgramElement lookupMember(IHierarchy model, Member member) {
-               TypeX declaringType = member.getDeclaringType();
-               IProgramElement classNode =
-                       model.findElementForType(declaringType.getPackageName(), declaringType.getClassName());
-               return findMemberInClass(classNode, member);
-       }
-
-       private static IProgramElement findMemberInClass(
-               IProgramElement classNode,
-               Member member)
-       {
-               if (classNode == null) return null; // XXX remove this check
-               for (Iterator it = classNode.getChildren().iterator(); it.hasNext(); ) {
-                       IProgramElement node = (IProgramElement)it.next();
-                       //System.err.println("checking: " + member.getName() + " with " + node.getBytecodeName() + ", " + node.getBytecodeSignature());
-                       if (member.getName().equals(node.getBytecodeName()) &&
-                               member.getSignature().equals(node.getBytecodeSignature()))
-                       {
-                               return node;
-                       }
-               }
-               // if we can't find the member, we'll just put it in the class
-               return classNode;
-       }
-       
-//     private static IProgramElement.Kind genShadowKind(Shadow shadow) {
-//             IProgramElement.Kind shadowKind;
-//             if (shadow.getKind() == Shadow.MethodCall
-//                     || shadow.getKind() == Shadow.ConstructorCall
-//                     || shadow.getKind() == Shadow.FieldGet
-//                     || shadow.getKind() == Shadow.FieldSet
-//                     || shadow.getKind() == Shadow.ExceptionHandler) {
-//                     return IProgramElement.Kind.CODE;
-//                     
-//             } else if (shadow.getKind() == Shadow.MethodExecution) {
-//                     return IProgramElement.Kind.METHOD;
-//                     
-//             } else if (shadow.getKind() == Shadow.ConstructorExecution) {
-//                     return IProgramElement.Kind.CONSTRUCTOR;
-//                     
-//             } else if (shadow.getKind() == Shadow.PreInitialization
-//                     || shadow.getKind() == Shadow.Initialization) {
-//                     return IProgramElement.Kind.CLASS;
-//                     
-//             } else if (shadow.getKind() == Shadow.AdviceExecution) {
-//                     return IProgramElement.Kind.ADVICE;
-//                     
-//             } else {
-//                     return IProgramElement.Kind.ERROR;
-//             }
-//     }
-
-}
diff --git a/weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java b/weaver/src/org/aspectj/weaver/AsmRelationshipProvider.java
new file mode 100644 (file)
index 0000000..b6ce564
--- /dev/null
@@ -0,0 +1,186 @@
+/* *******************************************************************
+ * Copyright (c) 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: 
+ *     PARC     initial implementation 
+ * ******************************************************************/
+
+
+package org.aspectj.weaver;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import org.aspectj.asm.*;
+import org.aspectj.asm.internal.ProgramElement;
+import org.aspectj.bridge.ISourceLocation;
+import org.aspectj.bridge.SourceLocation;
+
+public class AsmRelationshipProvider {
+       
+       public static final String ADVISES = "advises";
+       public static final String ADVISED_BY = "advised by";
+       public static final String DECLARES_ON = "declares on";
+       public static final String DECLAREDY_BY = "declared by";
+       public static final String MATCHED_BY = "matched by";
+       public static final String MATCHES_DECLARE = "matches declare";
+
+       public static void checkerMunger(IHierarchy model, Shadow shadow, Checker checker) {
+               if (shadow.getSourceLocation() == null || checker == null) return;
+               
+               String sourceHandle = ProgramElement.createHandleIdentifier(
+                       checker.getSourceLocation().getSourceFile(),
+                       checker.getSourceLocation().getLine(),
+                       checker.getSourceLocation().getColumn());
+                       
+               String targetHandle = ProgramElement.createHandleIdentifier(
+                       shadow.getSourceLocation().getSourceFile(),
+                       shadow.getSourceLocation().getLine(),
+                       shadow.getSourceLocation().getColumn());
+
+               IRelationshipMap mapper = AsmManager.getDefault().getRelationshipMap();
+               if (sourceHandle != null && targetHandle != null) {
+                       IRelationship foreward = mapper.get(sourceHandle, IRelationship.Kind.DECLARE, MATCHED_BY);
+                       foreward.getTargets().add(targetHandle);
+                               
+                       IRelationship back = mapper.get(targetHandle, IRelationship.Kind.DECLARE, MATCHES_DECLARE);
+                       back.getTargets().add(sourceHandle);  
+               }
+       }
+       
+       public static void adviceMunger(IHierarchy model, Shadow shadow, ShadowMunger munger) {
+               if (munger instanceof Advice) {
+                       Advice advice = (Advice)munger;
+                       if (advice.getKind().isPerEntry() || advice.getKind().isCflow()) {
+                               // TODO: might want to show these in the future
+                               return;
+                       }
+                       IRelationshipMap mapper = AsmManager.getDefault().getRelationshipMap();
+                       IProgramElement targetNode = getNode(AsmManager.getDefault().getHierarchy(), shadow);
+                       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 back = mapper.get(targetHandle, IRelationship.Kind.ADVICE, ADVISED_BY);
+                                       if (back != null) back.getTargets().add(adviceHandle);
+                               }
+                       }
+
+               }
+       }
+
+       private static IProgramElement getNode(IHierarchy model, Shadow shadow) {
+               Member enclosingMember = shadow.getEnclosingCodeSignature();
+               
+               IProgramElement enclosingNode = lookupMember(model, enclosingMember);
+               if (enclosingNode == null) {
+                       Lint.Kind err = shadow.getIWorld().getLint().shadowNotInStructure;
+                       if (err.isEnabled()) {
+                               err.signal(shadow.toString(), shadow.getSourceLocation());
+                       }
+                       return null;
+               }
+               
+               Member shadowSig = shadow.getSignature();
+               if (!shadowSig.equals(enclosingMember)) {
+                       IProgramElement bodyNode = findOrCreateCodeNode(enclosingNode, shadowSig, shadow);
+                       return bodyNode;
+               } else {
+                       return enclosingNode;
+               }
+       }
+       
+       private static IProgramElement findOrCreateCodeNode(IProgramElement enclosingNode, Member shadowSig, Shadow shadow)
+       {
+               for (Iterator it = enclosingNode.getChildren().iterator(); it.hasNext(); ) {
+                       IProgramElement node = (IProgramElement)it.next();
+                       if (shadowSig.getName().equals(node.getBytecodeName()) &&
+                               shadowSig.getSignature().equals(node.getBytecodeSignature()))
+                       {
+                               return node;
+                       }
+               }
+               
+               ISourceLocation sl = shadow.getSourceLocation();
+               
+               IProgramElement peNode = new ProgramElement(
+                       shadow.toString(),
+                       IProgramElement.Kind.CODE,
+               //XXX why not use shadow file? new SourceLocation(sl.getSourceFile(), sl.getLine()),
+                       new SourceLocation(enclosingNode.getSourceLocation().getSourceFile(), sl.getLine()),
+                       0,
+                       "",
+                       new ArrayList());
+                               
+               peNode.setBytecodeName(shadowSig.getName());
+               peNode.setBytecodeSignature(shadowSig.getSignature());
+               enclosingNode.addChild(peNode);
+               return peNode;
+       }
+       
+       private static IProgramElement lookupMember(IHierarchy model, Member member) {
+               TypeX declaringType = member.getDeclaringType();
+               IProgramElement classNode =
+                       model.findElementForType(declaringType.getPackageName(), declaringType.getClassName());
+               return findMemberInClass(classNode, member);
+       }
+
+       private static IProgramElement findMemberInClass(
+               IProgramElement classNode,
+               Member member)
+       {
+               if (classNode == null) return null; // XXX remove this check
+               for (Iterator it = classNode.getChildren().iterator(); it.hasNext(); ) {
+                       IProgramElement node = (IProgramElement)it.next();
+                       //System.err.println("checking: " + member.getName() + " with " + node.getBytecodeName() + ", " + node.getBytecodeSignature());
+                       if (member.getName().equals(node.getBytecodeName()) &&
+                               member.getSignature().equals(node.getBytecodeSignature()))
+                       {
+                               return node;
+                       }
+               }
+               // if we can't find the member, we'll just put it in the class
+               return classNode;
+       }
+       
+//     private static IProgramElement.Kind genShadowKind(Shadow shadow) {
+//             IProgramElement.Kind shadowKind;
+//             if (shadow.getKind() == Shadow.MethodCall
+//                     || shadow.getKind() == Shadow.ConstructorCall
+//                     || shadow.getKind() == Shadow.FieldGet
+//                     || shadow.getKind() == Shadow.FieldSet
+//                     || shadow.getKind() == Shadow.ExceptionHandler) {
+//                     return IProgramElement.Kind.CODE;
+//                     
+//             } else if (shadow.getKind() == Shadow.MethodExecution) {
+//                     return IProgramElement.Kind.METHOD;
+//                     
+//             } else if (shadow.getKind() == Shadow.ConstructorExecution) {
+//                     return IProgramElement.Kind.CONSTRUCTOR;
+//                     
+//             } else if (shadow.getKind() == Shadow.PreInitialization
+//                     || shadow.getKind() == Shadow.Initialization) {
+//                     return IProgramElement.Kind.CLASS;
+//                     
+//             } else if (shadow.getKind() == Shadow.AdviceExecution) {
+//                     return IProgramElement.Kind.ADVICE;
+//                     
+//             } else {
+//                     return IProgramElement.Kind.ERROR;
+//             }
+//     }
+
+}
index a8a1ebd94f6f2caeafc61220dcbb05ba1de5dae8..029a16d692141572622b7574b7e91f03788d1bb0 100644 (file)
@@ -341,7 +341,7 @@ public abstract class Shadow {
                        munger.implementOn(this);
                        if (world.getModel() != null) {
                                //System.err.println("munger: " + munger + " on " + this);
-                               AsmAdviceRelationshipProvider.nodeMunger(world.getModel(), this, munger);
+                               AsmRelationshipProvider.adviceMunger(world.getModel(), this, munger);
                        }
                }
        }