]> source.dussan.org Git - aspectj.git/commitdiff
tests and fix for pr121197
authoracolyer <acolyer>
Fri, 16 Dec 2005 18:52:29 +0000 (18:52 +0000)
committeracolyer <acolyer>
Fri, 16 Dec 2005 18:52:29 +0000 (18:52 +0000)
tests/bugs150/pr121197.aj [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java
tests/src/org/aspectj/systemtest/ajc150/ajc150.xml
weaver/src/org/aspectj/weaver/AjAttribute.java
weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java
weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java

diff --git a/tests/bugs150/pr121197.aj b/tests/bugs150/pr121197.aj
new file mode 100644 (file)
index 0000000..29fed9c
--- /dev/null
@@ -0,0 +1,57 @@
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import org.aspectj.lang.annotation.After;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.annotation.Pointcut;
+
+@Aspect( "perthis( readOperations() || writeOperations() )" )
+public abstract class pr121197 {
+       @Pointcut( "" )
+    protected abstract void readOperations();
+    
+    @Pointcut( "" )
+    protected abstract void writeOperations();
+    
+    private ReadWriteLock _lock = new ReentrantReadWriteLock();
+    
+    @Before( "readOperations()" )
+    public void beforeReading() {
+        _lock.readLock().lock();
+    }
+
+    @After( "readOperations()" )
+    public void afterReading() {
+        _lock.readLock().unlock();
+    }
+    
+    @Before( "writeOperations()" )
+    public void beforeWriting() {
+        _lock.writeLock().lock();
+    }
+
+    @After( "writeOperations()" )
+    public void afterWriting() {
+        _lock.writeLock().unlock();
+    }
+
+}
+
+@Aspect
+class ModelThreadSafety extends pr121197 {
+    @Pointcut( "execution( * C.read*(..) )" )
+    @Override
+    protected void readOperations() {}
+
+    @Pointcut( "execution( * C.write*(..) )" )
+    @Override
+    protected void writeOperations() { }
+}
+
+class C {
+       
+       public void readSomething() {}
+       public void writeSomething() {}
+       
+}
index 1d3f606005a296ad826a0cf1a6ccd30e8ca3b5ba..2382d8ac8a99c3564d96910c967f1d7d05a0039b 100644 (file)
@@ -852,6 +852,10 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
          runTest("modifier overrides");
   }
   
+  public void testAbstractPerThisInAtAspectJ() {
+         runTest("abstract perthis in @AspectJ");
+  }
+  
   // helper methods.....
   
   public SyntheticRepository createRepos(File cpentry) {
index 16368f7e667d80833e0212e2b4e33bd540c34ded..0f6a751983192ce0037c31b4db86859e91f5e4e6 100644 (file)
@@ -2,6 +2,12 @@
 
 <!-- AspectJ v1.5.0 Tests -->
 <suite>
+
+    <ajc-test dir="bugs150" title="abstract perthis in @AspectJ">
+        <compile files="pr121197.aj" options="-1.5"/>
+    </ajc-test>
+
+
     <ajc-test dir="bugs150" title="access to private ITD from nested type">
         <compile files="pr118698.aj"/>
         <run class="pr118698"/>
index e3a4c2457ea3fa5e61573cf2bf965cb2e3e07ab4..56e8a94ad88e1d893cc3176ab206644bec2b8236 100644 (file)
@@ -24,6 +24,7 @@ import org.aspectj.bridge.MessageUtil;
 import org.aspectj.bridge.Version;
 import org.aspectj.util.FileUtil;
 import org.aspectj.weaver.patterns.Declare;
+import org.aspectj.weaver.patterns.IScope;
 import org.aspectj.weaver.patterns.PerClause;
 import org.aspectj.weaver.patterns.Pointcut;
 
@@ -559,6 +560,7 @@ public abstract class AjAttribute {
                        return AttributeName;
                }               
                private PerClause perClause;
+               private IScope resolutionScope;
 
                public Aspect(PerClause perClause) {
                        this.perClause = perClause;
@@ -568,10 +570,19 @@ public abstract class AjAttribute {
                //XXXperClause.concretize(inAspect);
                return perClause;
            }
+           
+           public PerClause reifyFromAtAspectJ(ResolvedType inAspect) {
+             perClause.resolve(resolutionScope);
+             return perClause;
+           }
                
                public void write(DataOutputStream s) throws IOException {
                        perClause.write(s);
                }
+
+               public void setResolutionScope(IScope binding) {
+                       this.resolutionScope = binding;
+               }
        }
        
        public static class PrivilegedAttribute extends AjAttribute {
index a488376a29a7f5ca36d0d6c619a8da96ec1d4e61..e07f44c422c29ade0afd2954fb5a5fb644472ab1 100644 (file)
@@ -338,6 +338,7 @@ public class AtAjAttributes {
             }
             struct.ajAttributes.addAll(fstruct.ajAttributes);
         }
+        
         return struct.ajAttributes;
     }
 
@@ -462,7 +463,8 @@ public class AtAjAttributes {
         // Note: field annotation are for ITD and DEOW - processed at class level directly
         return Collections.EMPTY_LIST;
     }
-
+    
+    
     /**
      * Read @Aspect
      *
@@ -507,7 +509,8 @@ public class AtAjAttributes {
                 perClause.setLocation(struct.context, struct.context.getOffset(), struct.context.getOffset()+1);//FIXME AVASM
                 // FIXME asc see related comment way about about the version...
                 struct.ajAttributes.add(new AjAttribute.WeaverVersionInfo());
-                struct.ajAttributes.add(new AjAttribute.Aspect(perClause));
+                AjAttribute.Aspect aspectAttribute = new AjAttribute.Aspect(perClause);
+                struct.ajAttributes.add(aspectAttribute);
                 FormalBinding[] bindings = new org.aspectj.weaver.patterns.FormalBinding[0];
                 final IScope binding;
                 binding = new BindingScope(
@@ -515,7 +518,14 @@ public class AtAjAttributes {
                             struct.context,
                             bindings
                         );
-                perClause.resolve(binding);
+                
+//                // we can't resolve here since the perclause typically refers to pointcuts
+//                // defined in the aspect that we haven't told the BcelObjectType about yet.
+//                
+//                perClause.resolve(binding);
+                
+                // so we prepare to do it later...
+                aspectAttribute.setResolutionScope(binding);
                 return true;
             }
         }
@@ -531,25 +541,25 @@ public class AtAjAttributes {
      */
     private static PerClause parsePerClausePointcut(String perClauseString, AjAttributeStruct struct) {
         final String pointcutString;
-        Pointcut poincut = null;
+        Pointcut pointcut = null;
         TypePattern typePattern = null;
         final PerClause perClause;
         if (perClauseString.startsWith(PerClause.KindAnnotationPrefix.PERCFLOW.getName())) {
             pointcutString = PerClause.KindAnnotationPrefix.PERCFLOW.extractPointcut(perClauseString);
-            poincut = parsePointcut(pointcutString, struct, false);
-            perClause = new PerCflow(poincut, false);
+            pointcut = parsePointcut(pointcutString, struct, false);
+            perClause = new PerCflow(pointcut, false);
         } else if (perClauseString.startsWith(PerClause.KindAnnotationPrefix.PERCFLOWBELOW.getName())) {
             pointcutString = PerClause.KindAnnotationPrefix.PERCFLOWBELOW.extractPointcut(perClauseString);
-            poincut = parsePointcut(pointcutString, struct, false);
-            perClause = new PerCflow(poincut, true);
+            pointcut = parsePointcut(pointcutString, struct, false);
+            perClause = new PerCflow(pointcut, true);
         } else if (perClauseString.startsWith(PerClause.KindAnnotationPrefix.PERTARGET.getName())) {
             pointcutString = PerClause.KindAnnotationPrefix.PERTARGET.extractPointcut(perClauseString);
-            poincut = parsePointcut(pointcutString, struct, false);
-            perClause = new PerObject(poincut, false);
+            pointcut = parsePointcut(pointcutString, struct, false);
+            perClause = new PerObject(pointcut, false);
         } else if (perClauseString.startsWith(PerClause.KindAnnotationPrefix.PERTHIS.getName())) {
             pointcutString = PerClause.KindAnnotationPrefix.PERTHIS.extractPointcut(perClauseString);
-            poincut = parsePointcut(pointcutString, struct, false);
-            perClause = new PerObject(poincut, true);
+            pointcut = parsePointcut(pointcutString, struct, false);
+            perClause = new PerObject(pointcut, true);
         } else if (perClauseString.startsWith(PerClause.KindAnnotationPrefix.PERTYPEWITHIN.getName())) {
             pointcutString = PerClause.KindAnnotationPrefix.PERTYPEWITHIN.extractPointcut(perClauseString);
             typePattern = parseTypePattern(pointcutString, struct);
@@ -564,7 +574,7 @@ public class AtAjAttributes {
 
         if (!PerClause.SINGLETON.equals(perClause.getKind())
                 && !PerClause.PERTYPEWITHIN.equals(perClause.getKind())
-                && poincut == null) {
+                && pointcut == null) {
             // we could not parse the pointcut
             return null;
         }
index 59dcea1104f4e154f7a0b74aa52dde664a8a5b75..8ee6ab6384bbb75c461fc365d6fb89d09c350167 100644 (file)
@@ -273,20 +273,31 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
         List l = BcelAttributes.readAjAttributes(javaClass.getClassName(),javaClass.getAttributes(), getResolvedTypeX().getSourceContext(),getResolvedTypeX().getWorld().getMessageHandler(),AjAttribute.WeaverVersionInfo.UNKNOWN);
                processAttributes(l,pointcuts,false);
                l = AtAjAttributes.readAj5ClassAttributes(javaClass, getResolvedTypeX(), getResolvedTypeX().getSourceContext(), getResolvedTypeX().getWorld().getMessageHandler(),isCodeStyleAspect);
-               processAttributes(l,pointcuts,true);
+               AjAttribute.Aspect deferredAspectAttribute = processAttributes(l,pointcuts,true);
                
                this.pointcuts = (ResolvedPointcutDefinition[]) 
                        pointcuts.toArray(new ResolvedPointcutDefinition[pointcuts.size()]);
+
+               if (deferredAspectAttribute != null) {
+                       // we can finally process the aspect and its associated perclause...
+                       perClause = deferredAspectAttribute.reifyFromAtAspectJ(this.getResolvedTypeX());
+               }
+
        }
 
 
-    private void processAttributes(List attributeList, List pointcuts, boolean fromAnnotations) {
+    private AjAttribute.Aspect processAttributes(List attributeList, List pointcuts, boolean fromAnnotations) {
+       AjAttribute.Aspect deferredAspectAttribute = null;
                for (Iterator iter = attributeList.iterator(); iter.hasNext();) {
                        AjAttribute a = (AjAttribute) iter.next();
                        //System.err.println("unpacking: " + this + " and " + a);
                        if (a instanceof AjAttribute.Aspect) {
-                               perClause = ((AjAttribute.Aspect)a).reify(this.getResolvedTypeX());
-                               if (!fromAnnotations) isCodeStyleAspect = true;
+                               if (fromAnnotations) {
+                                       deferredAspectAttribute = (AjAttribute.Aspect) a;
+                               } else {
+                                       perClause = ((AjAttribute.Aspect)a).reify(this.getResolvedTypeX());
+                                       isCodeStyleAspect = true;
+                               }
                        } else if (a instanceof AjAttribute.PointcutDeclarationAttribute) {
                                pointcuts.add(((AjAttribute.PointcutDeclarationAttribute)a).reify());
                        } else if (a instanceof AjAttribute.WeaverState) {
@@ -307,6 +318,7 @@ public class BcelObjectType extends AbstractReferenceTypeDelegate {
                                throw new BCException("bad attribute " + a);
                        }
                }
+               return deferredAspectAttribute;
        }
 
        public PerClause getPerClause() {