]> source.dussan.org Git - aspectj.git/commitdiff
test and fix for 158412: annotation style reference pointcuts don't work
authoraclement <aclement>
Mon, 25 Sep 2006 13:51:40 +0000 (13:51 +0000)
committeraclement <aclement>
Mon, 25 Sep 2006 13:51:40 +0000 (13:51 +0000)
org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/compiler/lookup/EclipseSourceType.java
tests/bugs153/pr158412/dao/Foo.java [new file with mode: 0644]
tests/bugs153/pr158412/layering/Layering.aj [new file with mode: 0644]
tests/bugs153/pr158412/layering/SystemArchitektur.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc153/Ajc153Tests.java
tests/src/org/aspectj/systemtest/ajc153/ajc153.xml

index 179410bc4452ba75c78319fa91f1abe29ce6f571..f933fff98acb99397116e154426957d98692804c 100644 (file)
@@ -67,9 +67,12 @@ import org.aspectj.weaver.TypeVariable;
 import org.aspectj.weaver.UnresolvedType;
 import org.aspectj.weaver.WeaverStateInfo;
 import org.aspectj.weaver.World;
+import org.aspectj.weaver.patterns.ParserException;
+import org.aspectj.weaver.patterns.PatternParser;
 import org.aspectj.weaver.patterns.PerClause;
 import org.aspectj.weaver.patterns.PerFromSuper;
 import org.aspectj.weaver.patterns.PerSingleton;
+import org.aspectj.weaver.patterns.Pointcut;
 
 /**
  * Supports viewing eclipse TypeDeclarations/SourceTypeBindings as a ResolvedType
@@ -150,6 +153,24 @@ public class EclipseSourceType extends AbstractReferenceTypeDelegate {
         }
         return false;
     }
+    
+    /** Returns "" if there is a problem */
+    private String getPointcutStringFromAnnotationStylePointcut(AbstractMethodDeclaration amd) {
+       Annotation[] ans = amd.annotations;
+           if (ans == null) return "";
+               for (int i = 0; i < ans.length; i++) {
+                       if (ans[i].resolvedType == null) continue; // XXX happens if we do this very early from buildInterTypeandPerClause
+                                                                  // may prevent us from resolving references made in @Pointcuts to
+                                                                  // an @Pointcut in a code-style aspect
+                       char[] sig = ans[i].resolvedType.signature();
+                       if (CharOperation.equals(pointcutSig,sig)) {
+                               if (ans[i].memberValuePairs().length==0) return ""; // empty pointcut expression
+                               StringLiteral sLit = ((StringLiteral)(ans[i].memberValuePairs()[0].value));
+                               return new String(sLit.source());
+                       }
+               }
+               return "";
+    }
 
        private boolean isAnnotationStylePointcut(Annotation[] annotations) {
                if (annotations == null) return false;
@@ -237,15 +258,28 @@ public class EclipseSourceType extends AbstractReferenceTypeDelegate {
 
        private ResolvedPointcutDefinition makeResolvedPointcutDefinition(AbstractMethodDeclaration md) {
                if (md.binding==null) return null; // there is another error that has caused this... pr138143
+
+               EclipseSourceContext eSourceContext = new EclipseSourceContext(md.compilationResult);
+               Pointcut pc = null;
+               if (!md.isAbstract()) {
+                       String expression = getPointcutStringFromAnnotationStylePointcut(md);
+                       try { 
+                               pc = new PatternParser(expression,eSourceContext).parsePointcut();
+                       } catch (ParserException pe) { // error will be reported by other means...
+                               pc = Pointcut.makeMatchesNothing(Pointcut.SYMBOLIC);
+                       }
+               }
+               
+               
                ResolvedPointcutDefinition resolvedPointcutDeclaration = new ResolvedPointcutDefinition(
             factory.fromBinding(md.binding.declaringClass), 
             md.modifiers, 
             new String(md.selector),
                        factory.fromBindings(md.binding.parameters),
-                       null); //??? might want to use null 
+                       pc); 
                        
                resolvedPointcutDeclaration.setPosition(md.sourceStart, md.sourceEnd);
-               resolvedPointcutDeclaration.setSourceContext(new EclipseSourceContext(md.compilationResult));
+               resolvedPointcutDeclaration.setSourceContext(eSourceContext);
                return resolvedPointcutDeclaration;
        }
 
diff --git a/tests/bugs153/pr158412/dao/Foo.java b/tests/bugs153/pr158412/dao/Foo.java
new file mode 100644 (file)
index 0000000..376414c
--- /dev/null
@@ -0,0 +1,4 @@
+package dao;
+
+public class Foo {
+}
diff --git a/tests/bugs153/pr158412/layering/Layering.aj b/tests/bugs153/pr158412/layering/Layering.aj
new file mode 100644 (file)
index 0000000..c78561e
--- /dev/null
@@ -0,0 +1,8 @@
+package layering;
+
+//import architektur.SystemArchitektur;
+
+public aspect Layering {
+    declare warning : (layering.SystemArchitektur.inDAOLayer() ) : "Whatever";
+
+}
diff --git a/tests/bugs153/pr158412/layering/SystemArchitektur.java b/tests/bugs153/pr158412/layering/SystemArchitektur.java
new file mode 100644 (file)
index 0000000..735b0ce
--- /dev/null
@@ -0,0 +1,14 @@
+package layering;
+
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Pointcut;
+
+
+@Aspect
+public class SystemArchitektur {
+    @Pointcut("within(dao.*)")
+    public void inDAOLayer() {}
+    
+}
+
+
index 0c4e59e8d437368d2fd264c3d7cfc0c3d0df50a9..3fdae37718cb78de64e95755384f1f01b97ff62a 100644 (file)
@@ -28,6 +28,8 @@ public class Ajc153Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
   // public void testCFlowXMLAspectLTW_pr149096() { runTest("cflow xml concrete aspect"); }
   // public void testAmbiguousBinding_pr121805() { runTest("ambiguous binding");}
 //  public void testNoIllegalStateExceptionWithGenericInnerAspect_pr156058() { runTest("no IllegalStateException with generic inner aspect"); }
+  public void testAnnotationStylePointcutNPE_pr158412() { runTest("annotation style pointcut npe"); }
+  public void testAnnotationStylePointcutNPE_pr158412_2() { runTest("annotation style pointcut npe - 2"); }
   public void testAnnotationsCallConstructors_pr158126() { runTest("annotations, call and constructors problem");}
   public void testIllegalStateExceptionGenerics_pr153845() { runTest("IllegalStateException at GenericSignatureParser.java"); }
   public void testNoIllegalStateExceptionFromAsmDelegate_pr153490_1() { runTest("no illegal state exception from AsmDelegate - 1");}
index 451bf3a8097e18cdf03924b4e4a20dbab5b14e8e..455f181b1e648505cfd123210500fa66090a3da9 100644 (file)
@@ -8,6 +8,16 @@
       <compile files="Nothing.java" aspectpath="blob.jar" options="-1.5" outjar="bang.jar"/>
     </ajc-test>
 
+    <ajc-test dir="bugs153/pr158412" title="annotation style pointcut npe">
+      <compile files="layering/Layering.aj,layering/SystemArchitektur.java" options="-1.5"/>
+    </ajc-test>
+
+    <ajc-test dir="bugs153/pr158412" title="annotation style pointcut npe - 2">
+      <compile files="layering/Layering.aj,layering/SystemArchitektur.java,dao/Foo.java" options="-1.5">
+        <message kind="warning" line="3" text="Whatever"/>
+      </compile>
+    </ajc-test>
+    
     <ajc-test dir="bugs153/pr158126" title="annotations, call and constructors problem">
       <compile files="A.java,B.java,MyAnnotation.java,MyAspect.java" options="-1.5 -showWeaveInfo">
         <message kind="weave" text="Join point 'constructor-call(void B.&lt;init&gt;())' in Type 'A' (A.java:5) advised by before advice from 'MyAspect' (MyAspect.java:3)"/>