[jboss-cvs] JBossAS SVN: r59841 - in projects/aop/trunk/aop/src: resources/test/field and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jan 19 11:18:56 EST 2007
Author: kabir.khan at jboss.com
Date: 2007-01-19 11:18:56 -0500 (Fri, 19 Jan 2007)
New Revision: 59841
Added:
projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/A.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/AccessFieldViaB.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/AccessFieldViaC.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/B.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/C.java
projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/ReplaceReadInterceptor.java
Modified:
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/FieldAccessTransformer.java
projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/Instrumentor.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-346] C extends B extends A. A has an advised field, B and C don't. Fix problem whereby references to C don't get the A.field intercepted
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/FieldAccessTransformer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/FieldAccessTransformer.java 2007-01-19 16:10:01 UTC (rev 59840)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/FieldAccessTransformer.java 2007-01-19 16:18:56 UTC (rev 59841)
@@ -105,6 +105,15 @@
if (skipFieldInterception)
{
+ //Need to check if any of the superclass fields are advised, since we may need to replace access to them
+ if (superClassHasAdvisedFields(clazz.getSuperclass()))
+ {
+ skipFieldInterception = false;
+ }
+ }
+
+ if (skipFieldInterception)
+ {
advisor.getManager().getInterceptionMarkers().skipFieldAccess(clazz.getName());
}
else
@@ -114,6 +123,58 @@
}
+ private boolean superClassHasAdvisedFields(CtClass superClass) throws NotFoundException
+ {
+ if (superClass == null || superClass.getName().indexOf("java.") == 0)
+ {
+ return false;
+ }
+
+ ClassAdvisor advisor;
+ try
+ {
+ //TODO Would ideally like to be able to use the existing advisor if class already exists
+ advisor = instrumentor.getManager().getTempClassAdvisor(superClass);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+
+ List fields = Instrumentor.getAdvisableFields(superClass);
+ if (fields.size() > 0)
+ {
+ for (Iterator it = fields.iterator(); it.hasNext(); )
+ {
+ CtField field = (CtField) it.next();
+ if (javassist.Modifier.isPrivate(field.getModifiers()))
+ {
+ continue;
+ }
+
+ JoinpointClassification classificationGet = instrumentor.joinpointClassifier.classifyFieldGet(field, advisor);
+ if (isPrepared(classificationGet))
+ {
+ return true;
+ }
+
+ JoinpointClassification classificationSet = instrumentor.joinpointClassifier.classifyFieldSet(field, advisor);
+ if (isPrepared(classificationSet))
+ {
+ return true;
+ }
+ }
+ }
+
+ //We had no advised fields, check superclass again
+ if (superClassHasAdvisedFields(superClass.getSuperclass()))
+ {
+ return true;
+ }
+
+ return false;
+ }
+
protected boolean isPrepared(JoinpointClassification classification)
{
return classification != JoinpointClassification.NOT_INSTRUMENTED;
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/Instrumentor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/Instrumentor.java 2007-01-19 16:10:01 UTC (rev 59840)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/Instrumentor.java 2007-01-19 16:18:56 UTC (rev 59841)
@@ -1141,4 +1141,8 @@
}
}
+ AspectManager getManager()
+ {
+ return manager;
+ }
}
\ No newline at end of file
Modified: projects/aop/trunk/aop/src/resources/test/field/jboss-aop.xml
===================================================================
--- projects/aop/trunk/aop/src/resources/test/field/jboss-aop.xml 2007-01-19 16:10:01 UTC (rev 59840)
+++ projects/aop/trunk/aop/src/resources/test/field/jboss-aop.xml 2007-01-19 16:18:56 UTC (rev 59841)
@@ -35,4 +35,8 @@
<bind pointcut="get(* org.jboss.test.aop.field.SetOrGetOnlyPOJO->getOnly)">
<interceptor class="org.jboss.test.aop.field.TraceInterceptor"/>
</bind>
+
+ <bind pointcut="get(* *->inheritedFieldInSubClassFieldA)">
+ <interceptor class="org.jboss.test.aop.field.ReplaceReadInterceptor"/>
+ </bind>
</aop>
\ No newline at end of file
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/A.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/A.java (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/A.java 2007-01-19 16:18:56 UTC (rev 59841)
@@ -0,0 +1,36 @@
+/*
+* 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 abstract class A
+{
+ /**
+ * This field is annotated.
+ * Any field access (get) should cause the interceptor to run
+ */
+ protected String inheritedFieldInSubClassFieldA = "vanillaA";
+}
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/AccessFieldViaB.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/AccessFieldViaB.java (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/AccessFieldViaB.java 2007-01-19 16:18:56 UTC (rev 59841)
@@ -0,0 +1,35 @@
+/*
+* 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 AccessFieldViaB
+{
+ public static String accessField(B b)
+ {
+ return b.inheritedFieldInSubClassFieldA;
+ }
+}
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/AccessFieldViaC.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/AccessFieldViaC.java (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/AccessFieldViaC.java 2007-01-19 16:18:56 UTC (rev 59841)
@@ -0,0 +1,35 @@
+/*
+* 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 AccessFieldViaC
+{
+ public static String accessField(C c)
+ {
+ return c.inheritedFieldInSubClassFieldA;
+ }
+}
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/B.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/B.java (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/B.java 2007-01-19 16:18:56 UTC (rev 59841)
@@ -0,0 +1,35 @@
+/*
+* 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 B extends A
+{
+ public String useField()
+ {
+ return inheritedFieldInSubClassFieldA;
+ }
+}
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/C.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/C.java (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/C.java 2007-01-19 16:18:56 UTC (rev 59841)
@@ -0,0 +1,35 @@
+/*
+* 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 C extends B
+{
+ public String useField()
+ {
+ return inheritedFieldInSubClassFieldA;
+ }
+}
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 2007-01-19 16:10:01 UTC (rev 59840)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/FieldTestCase.java 2007-01-19 16:18:56 UTC (rev 59841)
@@ -139,7 +139,7 @@
}
- public void testSuperPrivateField()
+ public void testSuperPrivateField()
{
POJO pojo = new POJO();
@@ -251,4 +251,15 @@
assertEquals(10, pojo.getOnly);
assertTrue(TraceInterceptor.intercepted);
}
+
+ public void testFieldsReplacedInSubClass()
+ {
+ C c = new C();
+ //Sanity
+ assertEquals("intercepted", c.inheritedFieldInSubClassFieldA);
+ //These are the real purpose of this test
+ assertEquals("intercepted", c.useField());
+ assertEquals("intercepted", AccessFieldViaB.accessField(c));
+ assertEquals("intercepted", AccessFieldViaC.accessField(c));
+ }
}
Added: projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/ReplaceReadInterceptor.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/ReplaceReadInterceptor.java (rev 0)
+++ projects/aop/trunk/aop/src/test/org/jboss/test/aop/field/ReplaceReadInterceptor.java 2007-01-19 16:18:56 UTC (rev 59841)
@@ -0,0 +1,43 @@
+/*
+* 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;
+
+import org.jboss.aop.advice.Interceptor;
+import org.jboss.aop.joinpoint.Invocation;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ReplaceReadInterceptor implements Interceptor
+{
+ public String getName()
+ {
+ return ReplaceReadInterceptor.class.getName();
+ }
+
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ return "intercepted";
+ }
+}
More information about the jboss-cvs-commits
mailing list