]> source.dussan.org Git - aspectj.git/commitdiff
Improved generation of advice and pointcut names in the ASM.
authormkersten <mkersten>
Wed, 6 Aug 2003 12:26:34 +0000 (12:26 +0000)
committermkersten <mkersten>
Wed, 6 Aug 2003 12:26:34 +0000 (12:26 +0000)
ajde/testdata/examples/coverage/ModelCoverage.java
ajde/testdata/examples/coverage/coverage.ajsym
ajde/testsrc/org/aspectj/ajde/AsmDeclarationsTest.java
asm/src/org/aspectj/asm/ProgramElementNode.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AsmNodeFormatter.java

index 6fa3255d69e26300e0b160c1929b5d2c4e2295f5..6d09ba59dead4bb31630a82ac36247b3d673844d 100644 (file)
@@ -65,9 +65,14 @@ aspect AdviceNamingCoverage {
        int around(int i) throws SizeException: namedWithOneArg(i) { return proceed(i); }
        
        before(): named() { }   
+       before(int i): call(* *.mumble()) && named() && namedWithOneArg(i) { }  
+       before(int i): named() && call(* *.mumble()) && namedWithOneArg(i) { }  
        
        before(): call(* *.mumble()) { }
+}
   
+abstract aspect AbstractAspect {
+       abstract pointcut abPtct();     
 }
   
 aspect InterTypeDecCoverage {
index 324199378d5be89464da79b478ef2ac172e13df2..25bc2b07046ec3b7e3b7add2d385561b3a467fbf 100644 (file)
Binary files a/ajde/testdata/examples/coverage/coverage.ajsym and b/ajde/testdata/examples/coverage/coverage.ajsym differ
index 4f2a82bbe2dd73a3dc3efbdebe9fbf54b9b18e01..81f054f6b619c10fab0bc22f9d9743c525504c6d 100644 (file)
@@ -18,6 +18,7 @@ import org.aspectj.asm.*;
 import org.aspectj.asm.ProgramElementNode.Kind;
 
 
+// TODO: check for return types
 public class AsmDeclarationsTest extends AjdeTestCase {
 
        private StructureModel model = null;
@@ -35,12 +36,12 @@ public class AsmDeclarationsTest extends AjdeTestCase {
                ProgramElementNode aspect = StructureModelManager.getDefault().getStructureModel().findNodeForClass(null, "InterTypeDecCoverage");
                assertNotNull(aspect);
                
-               String decErrMessage = "declare error: Illegal construct..";
+               String decErrMessage = "declare error: \"Illegal construct..\"";
                ProgramElementNode decErrNode = model.findNode(aspect, ProgramElementNode.Kind.DECLARE_ERROR, decErrMessage);
                assertNotNull(decErrNode);
                assertEquals(decErrNode.getName(), decErrMessage);
                
-               String decWarnMessage = "declare warning: Illegal construct..";
+               String decWarnMessage = "declare warning: \"Illegal construct..\"";
                ProgramElementNode decWarnNode = model.findNode(aspect, ProgramElementNode.Kind.DECLARE_WARNING, decWarnMessage);
                assertNotNull(decWarnNode);
                assertEquals(decWarnNode.getName(), decWarnMessage);    
@@ -115,6 +116,19 @@ public class AsmDeclarationsTest extends AjdeTestCase {
 
        }
 
+       public void testAbstract() {
+               ProgramElementNode node = (ProgramElementNode)model.getRoot();
+               assertNotNull(node);
+       
+               ProgramElementNode aspect = StructureModelManager.getDefault().getStructureModel().findNodeForClass(null, "AbstractAspect");
+               assertNotNull(aspect);  
+               
+               String abst = "abPtct()";
+               ProgramElementNode abstNode = model.findNode(aspect, ProgramElementNode.Kind.POINTCUT, abst);
+               assertNotNull(abstNode);                
+               assertEquals(abstNode.getName(), abst);                 
+       }
+
        public void testAdvice() {
                ProgramElementNode node = (ProgramElementNode)model.getRoot();
                assertNotNull(node);
@@ -122,10 +136,40 @@ public class AsmDeclarationsTest extends AjdeTestCase {
                ProgramElementNode aspect = StructureModelManager.getDefault().getStructureModel().findNodeForClass(null, "AdviceNamingCoverage");
                assertNotNull(aspect);  
 
-//             String anon = "<anonymous pointcut>";
-//             ProgramElementNode anonNode = model.findNode(aspect, ProgramElementNode.Kind.POINTCUT, anon);
-//             assertNotNull(anonNode);                
-//             assertEquals(anonNode.getName(), anon);                 
+               String anon = "before(): <anonymous pointcut>";
+               ProgramElementNode anonNode = model.findNode(aspect, ProgramElementNode.Kind.ADVICE, anon);
+               assertNotNull(anonNode);                
+               assertEquals(anonNode.getName(), anon);                 
+
+               String named = "before(): named..";
+               ProgramElementNode namedNode = model.findNode(aspect, ProgramElementNode.Kind.ADVICE, named);
+               assertNotNull(namedNode);               
+               assertEquals(namedNode.getName(), named);               
+
+               String namedWithOneArg = "around(int): namedWithOneArg..";
+               ProgramElementNode namedWithOneArgNode = model.findNode(aspect, ProgramElementNode.Kind.ADVICE, namedWithOneArg);
+               assertNotNull(namedWithOneArgNode);             
+               assertEquals(namedWithOneArgNode.getName(), namedWithOneArg);           
+
+               String afterReturning = "afterReturning(int, int): namedWithArgs..";
+               ProgramElementNode afterReturningNode = model.findNode(aspect, ProgramElementNode.Kind.ADVICE, afterReturning);
+               assertNotNull(afterReturningNode);              
+               assertEquals(afterReturningNode.getName(), afterReturning);
+
+               String around = "around(int): namedWithOneArg..";
+               ProgramElementNode aroundNode = model.findNode(aspect, ProgramElementNode.Kind.ADVICE, around);
+               assertNotNull(aroundNode);              
+               assertEquals(aroundNode.getName(), around);
+
+               String compAnon = "before(int): <anonymous pointcut>..";
+               ProgramElementNode compAnonNode = model.findNode(aspect, ProgramElementNode.Kind.ADVICE, compAnon);
+               assertNotNull(compAnonNode);            
+               assertEquals(compAnonNode.getName(), compAnon);
+
+               String compNamed = "before(int): named()..";
+               ProgramElementNode compNamedNode = model.findNode(aspect, ProgramElementNode.Kind.ADVICE, compNamed);
+               assertNotNull(compNamedNode);           
+               assertEquals(compNamedNode.getName(), compNamed);
        }
 
        protected void setUp() throws Exception {
index 7cacd890e136198b8f832a36e3e26897ec21c9b9..37861a48f0f71c74f1ce0c1e46d104f9175ee498 100644 (file)
@@ -405,5 +405,9 @@ public class ProgramElementNode extends StructureNode {
                this.returnType = returnType;
        }
 
+       public String getReturnType() {
+               return returnType;
+       }
+
 }
 
index eef14d7fddb26b59d4f58c067091ab667203c26d..b7425d426f0c57cdc140e4db2580ab6e93832b3a 100644 (file)
@@ -20,14 +20,55 @@ import org.eclipse.jdt.internal.compiler.ast.*;
 
 public class AsmNodeFormatter {
 
+       public static final String DECLARE_PRECEDENCE = "precedence: ";
+       public static final String DECLARE_SOFT = "soft: ";
+       public static final String DECLARE_PARENTS = "parents: ";
+       public static final String DECLARE_WARNING = "warning: ";
+       public static final String DECLARE_ERROR = "error: ";
+       public static final String DECLARE_UNKNONWN = "<unknown declare>";
+       public static final String POINTCUT_ABSTRACT = "<abstract pointcut>";
+       public static final String POINTCUT_ANONYMOUS = "<anonymous pointcut>";
        public static final int MAX_MESSAGE_LENGTH = 18;
        public static final String DEC_LABEL = "declare";
 
        public void genLabelAndKind(MethodDeclaration methodDeclaration, ProgramElementNode node) {
                if (methodDeclaration instanceof AdviceDeclaration) { 
+                       AdviceDeclaration ad = (AdviceDeclaration)methodDeclaration;
                        node.setKind( ProgramElementNode.Kind.ADVICE);
-                       node.setName(translateAdviceName(new String(methodDeclaration.selector)));
-                       
+                       String label = "";
+                       label += ad.kind.toString();
+                       label += "(" + genArguments(ad) + "): ";
+
+                       if (ad.kind == AdviceKind.Around) {
+                               node.setReturnType(ad.returnTypeToString(0));
+                       }
+       
+                       if (ad.pointcutDesignator != null) {    
+                               if (ad.pointcutDesignator.getPointcut() instanceof ReferencePointcut) {
+                                       ReferencePointcut rp = (ReferencePointcut)ad.pointcutDesignator.getPointcut();
+                                       label += rp.name + "..";
+                               } else if (ad.pointcutDesignator.getPointcut() instanceof AndPointcut) {
+                                       AndPointcut ap = (AndPointcut)ad.pointcutDesignator.getPointcut();
+                                       if (ap.getLeft() instanceof ReferencePointcut) {
+                                               label += ap.getLeft().toString() + "..";        
+                                       } else {
+                                               label += POINTCUT_ANONYMOUS + "..";
+                                       }
+                               } else if (ad.pointcutDesignator.getPointcut() instanceof OrPointcut) {
+                                       OrPointcut op = (OrPointcut)ad.pointcutDesignator.getPointcut();
+                                       if (op.getLeft() instanceof ReferencePointcut) {
+                                               label += op.getLeft().toString() + "..";        
+                                       } else {
+                                               label += POINTCUT_ANONYMOUS + "..";
+                                       }
+                               } else {
+                                       label += POINTCUT_ANONYMOUS;
+                               }
+                       } else {
+                               label += POINTCUT_ABSTRACT;
+                       }
+                       node.setName(label);
+
                } else if (methodDeclaration instanceof PointcutDeclaration) { 
                        PointcutDeclaration pd = (PointcutDeclaration)methodDeclaration;
                        node.setKind( ProgramElementNode.Kind.POINTCUT);
@@ -43,29 +84,29 @@ public class AsmNodeFormatter {
                                
                                if (deow.isError()) {
                                        node.setKind( ProgramElementNode.Kind.DECLARE_ERROR);
-                                       label += "error: ";
+                                       label += DECLARE_ERROR;
                                } else {
                                        node.setKind( ProgramElementNode.Kind.DECLARE_WARNING);
-                                       label += "warning: ";
+                                       label += DECLARE_WARNING;
                                }
-                               node.setName(label + genDeclareMessage(deow.getMessage())) ;
+                               node.setName(label + "\"" + genDeclareMessage(deow.getMessage()) + "\"") ;
                                 
                        } else if (declare.declare instanceof DeclareParents) {
                                node.setKind( ProgramElementNode.Kind.DECLARE_PARENTS);
                                DeclareParents dp = (DeclareParents)declare.declare;
-                               node.setName(label + "parents: " + genTypePatternLabel(dp.getChild())); 
+                               node.setName(label + DECLARE_PARENTS + genTypePatternLabel(dp.getChild()));     
                                
                        } else if (declare.declare instanceof DeclareSoft) {
                                node.setKind( ProgramElementNode.Kind.DECLARE_SOFT);
                                DeclareSoft ds = (DeclareSoft)declare.declare;
-                               node.setName(label + "soft: " + genTypePatternLabel(ds.getException()));
+                               node.setName(label + DECLARE_SOFT + genTypePatternLabel(ds.getException()));
                        } else if (declare.declare instanceof DeclarePrecedence) {
                                node.setKind( ProgramElementNode.Kind.DECLARE_PRECEDENCE);
                                DeclarePrecedence ds = (DeclarePrecedence)declare.declare;
-                               node.setName(label + "precedence: " + genPrecedenceListLabel(ds.getPatterns()));
+                               node.setName(label + DECLARE_PRECEDENCE + genPrecedenceListLabel(ds.getPatterns()));
                        } else {
                                node.setKind( ProgramElementNode.Kind.ERROR);
-                               node.setName("<unknown declare>");
+                               node.setName(DECLARE_UNKNONWN);
                        }
                        
                } else if (methodDeclaration instanceof InterTypeDeclaration) {
@@ -83,11 +124,9 @@ public class AsmNodeFormatter {
                        } else {
                                node.setKind(ProgramElementNode.Kind.ERROR);
                        }
                        node.setName(label);
                        node.setReturnType(itd.returnType.toString());
                        
-                       
                } else {
                        node.setKind(ProgramElementNode.Kind.METHOD);
                        node.setName(new String(methodDeclaration.selector));   
@@ -112,11 +151,15 @@ public class AsmNodeFormatter {
                        String argName = new String(argArray[i].name);
                        String argType = argArray[i].type.toString();
 //                     TODO: fix this way of determing ajc-added arguments, make subtype of Argument with extra info
-                       if (!argName.startsWith("ajc$this_")) {   
-                               args += argType;
-                               if (i < argArray.length-1) args += ", ";
-                       }
+                       if (!argName.startsWith("ajc$this_") 
+                               && !argType.equals("org.aspectj.lang.JoinPoint.StaticPart")
+                               && !argType.equals("org.aspectj.lang.JoinPoint")
+                               && !argType.equals("org.aspectj.runtime.internal.AroundClosure")) {   
+                               args += argType + ", ";
+                       }  
                }
+               int lastSepIndex = args.lastIndexOf(',');
+               if (lastSepIndex != -1 && args.endsWith(", ")) args = args.substring(0, lastSepIndex);
                return args;
        }
 
@@ -144,14 +187,14 @@ public class AsmNodeFormatter {
                }
        }
        
-       // !!! move or replace
-       private String translateAdviceName(String label) {
-               if (label.indexOf("before") != -1) return "before";
-               if (label.indexOf("returning") != -1) return "after returning";
-               if (label.indexOf("after") != -1) return "after";
-               if (label.indexOf("around") != -1) return "around";
-               else return "<advice>";
-       }
+//     // TODO: 
+//     private String translateAdviceName(String label) {
+//             if (label.indexOf("before") != -1) return "before";
+//             if (label.indexOf("returning") != -1) return "after returning";
+//             if (label.indexOf("after") != -1) return "after";
+//             if (label.indexOf("around") != -1) return "around";
+//             else return "<advice>";
+//     }
        
 //     // !!! move or replace
 //     private String translateDeclareName(String name) {