]> source.dussan.org Git - aspectj.git/commitdiff
ajdtcore for abstract @Pointcut
authoravasseur <avasseur>
Tue, 25 Oct 2005 13:04:26 +0000 (13:04 +0000)
committeravasseur <avasseur>
Tue, 25 Oct 2005 13:04:26 +0000 (13:04 +0000)
loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java
loadtime/src/org/aspectj/weaver/loadtime/ConcreteAspectCodeGen.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/PointcutDeclaration.java
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/ast/ValidateAtAspectJAnnotationsVisitor.java
tests/java5/ataspectj/ataspectj/ConcreteAtAspectTest.java
tests/src/org/aspectj/systemtest/ajc150/ataspectj/ltw.xml

index ebfdce18024eb2a208681c2e1d701e41adb3b100..cdccc0e09e1ffa7f2cc8cc42d47913e0c9445503 100644 (file)
@@ -113,23 +113,6 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
             messageHandler = bcelWorld.getMessageHandler();
             // after adding aspects
             weaver.prepareForWeave();
-//            // weave and flush what was registered so far
-//            for (Iterator iterator = m_codeGens.iterator(); iterator.hasNext();) {
-//                ConcreteAspectCodeGen concreteAspectCodeGen = (ConcreteAspectCodeGen) iterator.next();
-//                byte[] partiallyWoven = concreteAspectCodeGen.getBytes(this);
-//                this.generatedClassHandler.acceptClass(
-//                        concreteAspectCodeGen.m_concreteAspect.name,
-//                        partiallyWoven
-//                );
-//                ResolvedType aspect = weaver.addLibraryAspect(concreteAspectCodeGen.m_concreteAspect.name);
-//                //generate key for SC
-//                String aspectCode = readAspect(concreteAspectCodeGen.m_concreteAspect.name, loader);
-//                if(namespace==null){
-//                    namespace=new StringBuffer(aspectCode);
-//                }else{
-//                    namespace = namespace.append(";"+aspectCode);
-//                }
-//            }
         }
     }
 
@@ -161,7 +144,6 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
                        Enumeration xmls = weavingContext.getResources(st.nextToken());
 //                     System.out.println("? registerDefinitions: found-aop.xml=" + xmls.hasMoreElements() + ", loader=" + loader);
 
-
                        while (xmls.hasMoreElements()) {
                            URL xml = (URL) xmls.nextElement();
                            MessageUtil.info(messageHandler, "using " + xml.getFile());
index b90ddeda0fb79088c8f108a9d22f5ab2e798f7c2..85b718ac593a10c28acc4adf7cac77cecf137e96 100644 (file)
@@ -152,7 +152,7 @@ public class ConcreteAspectCodeGen {
                 if ("()V".equals(method.getSignature())) {
                     elligibleAbstractions.add(method.getName());
                 } else {
-                    reportError("Abstract member '" + method.getName() + "' cannot be concretized as a pointcut (illegal signature): " + stringify());
+                    reportError("Abstract method '" + method.getName() + "' cannot be concretized as a pointcut (illegal signature, must have no arguments, must return void): " + stringify());
                     return false;
                 }
             }
index abe77d9f0e1ff9c98957f077d30fc235abe9f8e3..533919a92b0a5eff390b4acf3fdbf0790ea107d8 100644 (file)
@@ -88,12 +88,17 @@ public class PointcutDeclaration extends AjMethodDeclaration {
                                
                if (Modifier.isAbstract(this.declaredModifiers)) {
                        if (!(typeDec instanceof AspectDeclaration)) {
-                               typeDec.scope.problemReporter().signalError(sourceStart, sourceEnd, 
-                                               "The abstract pointcut " + new String(declaredName) +
-                                               " can only be defined in an aspect");
-                               ignoreFurtherInvestigation = true;
-                               return;
-                       } else if (!Modifier.isAbstract(typeDec.modifiers)) {
+                // check for @Aspect
+                if (isAtAspectJ(typeDec)) {
+                   ;//no need to check abstract class as JDT does that
+                } else {
+                    typeDec.scope.problemReporter().signalError(sourceStart, sourceEnd,
+                            "The abstract pointcut " + new String(declaredName) +
+                            " can only be defined in an aspect");
+                    ignoreFurtherInvestigation = true;
+                    return;
+                }
+            } else if (!Modifier.isAbstract(typeDec.modifiers)) {
                                typeDec.scope.problemReporter().signalError(sourceStart, sourceEnd, 
                                                "The abstract pointcut " + new String(declaredName) +
                                                " can only be defined in an abstract aspect");
@@ -107,9 +112,22 @@ public class PointcutDeclaration extends AjMethodDeclaration {
                        pointcutDesignator.postParse(typeDec, this);
                }
        }
-    
-       
-       /**
+
+    private boolean isAtAspectJ(TypeDeclaration typeDec) {
+        if (typeDec.annotations == null)
+            return false;
+
+        for (int i = 0; i < typeDec.annotations.length; i++) {
+            Annotation annotation = typeDec.annotations[i];
+            if ("Lorg/aspectj/lang/annotation/Aspect;".equals(new String(annotation.resolvedType.signature()))) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+
+    /**
         * Called from the AtAspectJVisitor to create the @Pointcut annotation
         * (and corresponding method) for this pointcut
         *
index 7aae00ecd652eba3158ad2ff7e61fc0d93f4ac34..3a7fe62e3261a04289f3822933852cfc86178c76 100644 (file)
@@ -490,8 +490,13 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor {
                String pointcutExpression = getStringLiteralFor("value",ajAnnotations.pointcutAnnotation,pcLocation);
                try {
                        ISourceContext context = new EclipseSourceContext(unit.compilationResult,pcLocation[0]);
-                       Pointcut pc = new PatternParser(pointcutExpression,context).parsePointcut();
-                       pcDecl.pointcutDesignator = new PointcutDesignator(pc);
+            Pointcut pc = null;//abstract
+            if (pointcutExpression == null  || pointcutExpression.length() == 0) {
+                ;//will have to ensure abstract ()V method
+            } else {
+                pc = new PatternParser(pointcutExpression,context).parsePointcut();
+            }
+            pcDecl.pointcutDesignator = (pc==null)?null:new PointcutDesignator(pc);
                        pcDecl.setGenerateSyntheticPointcutMethod();
                        TypeDeclaration onType = (TypeDeclaration) typeStack.peek();
                        pcDecl.postParse(onType);
@@ -506,11 +511,14 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor {
 //                 bindings[i] = new FormalBinding(type, name, i, arg.sourceStart, arg.sourceEnd, "unknown");
 //             }
                        swap(onType,methodDeclaration,pcDecl);
-                       pc.resolve(new EclipseScope(bindings,methodDeclaration.scope));
-                       HasIfPCDVisitor ifFinder = new HasIfPCDVisitor();
-                       pc.traverse(ifFinder, null);
-                       containsIfPcd = ifFinder.containsIfPcd;
-               } catch(ParserException pEx) {
+                       if (pc != null) {
+                // has an expression
+                pc.resolve(new EclipseScope(bindings,methodDeclaration.scope));
+                HasIfPCDVisitor ifFinder = new HasIfPCDVisitor();
+                pc.traverse(ifFinder, null);
+                containsIfPcd = ifFinder.containsIfPcd;
+            }
+        } catch(ParserException pEx) {
                        methodDeclaration.scope.problemReporter().parseError(
                                        pcLocation[0] + pEx.getLocation().getStart(),
                                        pcLocation[0] + pEx.getLocation().getEnd() ,
@@ -543,7 +551,25 @@ public class ValidateAtAspectJAnnotationsVisitor extends ASTVisitor {
                                          methodDeclaration.returnType.sourceEnd, 
                                          "Pointcuts without an if() expression should have an empty method body");                     
                }
-       }
+
+        if (pcDecl.pointcutDesignator == null) {
+            if (Modifier.isAbstract(methodDeclaration.modifiers)
+                //those 2 checks makes sense for aop.xml concretization but NOT for regular abstraction of pointcut
+                //&& returnsVoid
+                //&& (methodDeclaration.arguments == null || methodDeclaration.arguments.length == 0)) {
+                ) {
+                ;//fine
+            } else {
+                methodDeclaration.scope.problemReporter().signalError(methodDeclaration.returnType.sourceStart,
+                          methodDeclaration.returnType.sourceEnd,
+                          "Method annotated with @Pointcut() for abstract pointcut must be abstract");
+            }
+        } else if (Modifier.isAbstract(methodDeclaration.modifiers)) {
+            methodDeclaration.scope.problemReporter().signalError(methodDeclaration.returnType.sourceStart,
+                      methodDeclaration.returnType.sourceEnd,
+                      "Method annotated with non abstract @Pointcut(\""+pointcutExpression+"\") is abstract");
+        }
+    }
        
        private void copyAllFields(MethodDeclaration from, MethodDeclaration to) {
                to.annotations = from.annotations;
index 180ec4f2b369273397cef823c7a48f01116311a8..2d673ca9fdd73b58045c199384cbe4b2b1c2e2eb 100644 (file)
@@ -40,7 +40,7 @@ public class ConcreteAtAspectTest extends TestCase {
         abstract void pc();
         // must be abstract
         // for concrete-aspect, must further be no-arg, void
-        // but can be more complex for non-xml inheritance
+        // !!! but can be more complex for non-xml inheritance !!! ie not error for AJDTcore
 
         @Before("pc()")
         public void before() {
index fd2b922f11b1689abbbafc6c02f935e22bf88fe6..d3bf28f7720f10990ecbe4205c9a57d1929ba49b 100644 (file)
     <ajc-test dir="java5/ataspectj" title="Concrete@Aspect">
         <compile
             files="ataspectj/ConcreteAtAspectTest.java,ataspectj/TestHelper.java"
-            options="-1.5 -Xdev:NoAtAspectJProcessing -XnoWeave"
+            options="-1.5 -XnoWeave"
             />
         <run class="ataspectj.ConcreteAtAspectTest" ltw="ataspectj/aop-concreteataspect.xml"/>
     </ajc-test>