[jboss-cvs] JBossAS SVN: r58756 - in projects/aop/trunk/aop/src: main/org/jboss/aop main/org/jboss/aop/instrument resources/test/field test/org/jboss/test/aop/field
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Nov 29 17:31:11 EST 2006
Author: kabir.khan at jboss.com
Date: 2006-11-29 17:31:06 -0500 (Wed, 29 Nov 2006)
New Revision: 58756
Added:
projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/SetOrGetOnlyPOJO.java
Modified:
projects/aop/trunk/aop/src/main/org/jboss/aop/FieldInfo.java
projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java
projects/aop/trunk/aop/src/resources/test/field/jboss-aop.xml
projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/FieldTestCase.java
Log:
[JBAOP-315] Fix bug in generated advisors for when a field only has a set() or a get() pointcut, in which case the interceptors would be ignored
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/FieldInfo.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/FieldInfo.java 2006-11-29 22:15:40 UTC (rev 58755)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/FieldInfo.java 2006-11-29 22:31:06 UTC (rev 58756)
@@ -51,6 +51,12 @@
}
+ public FieldInfo(Advisor advisor, boolean read)
+ {
+ super(advisor, null);
+ this.read = read;
+ }
+
public FieldInfo(Class clazz, int index, String fieldName, long wrapperHash, Advisor advisor, boolean read)
{
super(advisor, clazz);
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java 2006-11-29 22:15:40 UTC (rev 58755)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java 2006-11-29 22:31:06 UTC (rev 58756)
@@ -41,6 +41,7 @@
import org.jboss.aop.instrument.MethodByConJoinPointGenerator;
import org.jboss.aop.instrument.MethodByMethodJoinPointGenerator;
import org.jboss.aop.instrument.MethodJoinPointGenerator;
+import org.jboss.aop.joinpoint.FieldJoinpoint;
import org.jboss.aop.joinpoint.Joinpoint;
import org.jboss.aop.joinpoint.MethodJoinpoint;
import org.jboss.aop.pointcut.PointcutMethodMatch;
@@ -229,7 +230,7 @@
protected ArrayList initializeFieldReadChain()
{
- return mergeFieldInfos(fieldReadInfos);
+ return mergeFieldInfos(fieldReadInfos, true);
}
protected void addFieldWriteInfo(FieldInfo fi)
@@ -241,13 +242,13 @@
protected ArrayList initializeFieldWriteChain()
{
- return mergeFieldInfos(fieldWriteInfos);
+ return mergeFieldInfos(fieldWriteInfos, false);
}
/* Creates a full list of field infos for all fields, using the ones added by
* generated advisor for advised fields.
*/
- private ArrayList mergeFieldInfos(ArrayList advisedInfos)
+ private ArrayList mergeFieldInfos(ArrayList advisedInfos, boolean read)
{
ArrayList newInfos = new ArrayList(advisedFields.length);
@@ -279,9 +280,8 @@
}
else
{
- FieldInfo info = new FieldInfo();
+ FieldInfo info = new FieldInfo(this, read);
info.setAdvisedField(advisedFields[i]);
- info.setAdvisor(this);
info.setIndex(i);
newInfos.add(info);
}
@@ -668,4 +668,18 @@
{
return true;
}
+
+ @Override
+ public Object getFieldAspect(FieldJoinpoint joinpoint, AspectDefinition def)
+ {
+ Object instance = getPerClassJoinpointAspect(def, joinpoint);
+ if (instance == null)
+ {
+ addPerClassJoinpointAspect(def, joinpoint);
+ instance = getPerClassJoinpointAspect(def, joinpoint);
+ }
+ return instance;
+ }
+
+
}
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java 2006-11-29 22:15:40 UTC (rev 58755)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java 2006-11-29 22:31:06 UTC (rev 58756)
@@ -447,8 +447,6 @@
{
return
"{" +
-//"System.out.println(\"xxxx ME \" + this.getClass().getName() + this.getClass().getClassLoader());" +
-//"System.out.println(\"xxxx SUPER \" + super.getClass().getName() + super.getClass().getClassLoader());" +
" if (" + setup.getAspectFieldName() + " != null)" +
" {" +
" return " + setup.getAspectFieldName() + ";" +
@@ -1465,7 +1463,7 @@
System.out.print("[warn] No matching advice called '" + setups[i].getAdviceName() +
"' could be found in " + setups[i].getAspectClass().getName() +
" for joinpoint " + info + ":");
- System.out.println(AdviceMethodFactory.getAdviceMatchingMessage());
+// System.out.println(AdviceMethodFactory.getAdviceMatchingMessage());
}
}
beforeSetups = (beforeAspects == null) ? null : (AdviceSetup[])beforeAspects.toArray(new AdviceSetup[beforeAspects.size()]);
Modified: projects/aop/trunk/aop/src/resources/test/field/jboss-aop.xml
===================================================================
--- projects/aop/trunk/aop/src/resources/test/field/jboss-aop.xml 2006-11-29 22:15:40 UTC (rev 58755)
+++ projects/aop/trunk/aop/src/resources/test/field/jboss-aop.xml 2006-11-29 22:31:06 UTC (rev 58756)
@@ -24,4 +24,11 @@
<bind pointcut="field(* org.jboss.test.aop.field.ScopedPojo->staticField)">
<interceptor-ref name="staticField"/>
</bind>
+
+ <bind pointcut="set(* org.jboss.test.aop.field.SetOrGetOnlyPOJO->setOnly)">
+ <interceptor class="org.jboss.test.aop.field.TraceInterceptor"/>
+ </bind>
+ <bind pointcut="get(* org.jboss.test.aop.field.SetOrGetOnlyPOJO->getOnly)">
+ <interceptor class="org.jboss.test.aop.field.TraceInterceptor"/>
+ </bind>
</aop>
\ No newline at end of file
Modified: projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/FieldTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/FieldTestCase.java 2006-11-29 22:15:40 UTC (rev 58755)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/FieldTestCase.java 2006-11-29 22:31:06 UTC (rev 58756)
@@ -164,4 +164,28 @@
assertSame(advStatic, staticWrite);
}
+
+ public void testSetOnly() throws Exception
+ {
+ SetOrGetOnlyPOJO pojo = new SetOrGetOnlyPOJO();
+ TraceInterceptor.intercepted = false;
+ pojo.setOnly = 10;
+ assertTrue(TraceInterceptor.intercepted);
+
+ TraceInterceptor.intercepted = false;
+ assertEquals(10, pojo.setOnly);
+ assertFalse(TraceInterceptor.intercepted);
+ }
+
+ public void testGetOnly() throws Exception
+ {
+ SetOrGetOnlyPOJO pojo = new SetOrGetOnlyPOJO();
+ TraceInterceptor.intercepted = false;
+ pojo.getOnly = 10;
+ assertFalse(TraceInterceptor.intercepted);
+
+ TraceInterceptor.intercepted = false;
+ assertEquals(10, pojo.getOnly);
+ assertTrue(TraceInterceptor.intercepted);
+ }
}
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/SetOrGetOnlyPOJO.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/SetOrGetOnlyPOJO.java 2006-11-29 22:15:40 UTC (rev 58755)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/SetOrGetOnlyPOJO.java 2006-11-29 22:31:06 UTC (rev 58756)
@@ -0,0 +1,33 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.aop.field;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class SetOrGetOnlyPOJO
+{
+ int setOnly;
+ int getOnly;
+}
More information about the jboss-cvs-commits
mailing list