[jboss-cvs] JBossAS SVN: r59827 - in branches/Branch_AOP_1_5/aop/src: main/org/jboss/aop/instrument and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jan 19 09:22:44 EST 2007
Author: kabir.khan at jboss.com
Date: 2007-01-19 09:22:44 -0500 (Fri, 19 Jan 2007)
New Revision: 59827
Added:
branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/A.java
branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/AccessFieldViaB.java
branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/AccessFieldViaC.java
branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/B.java
branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/C.java
branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/ReplaceReadInterceptor.java
Modified:
branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/AspectManager.java
branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/instrument/FieldAccessTransformer.java
branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/instrument/Instrumentor.java
branches/Branch_AOP_1_5/aop/src/resources/test/field/jboss-aop.xml
branches/Branch_AOP_1_5/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: branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/AspectManager.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/AspectManager.java 2007-01-19 14:11:19 UTC (rev 59826)
+++ branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/AspectManager.java 2007-01-19 14:22:44 UTC (rev 59827)
@@ -909,6 +909,7 @@
if (transformed)
{
pool.lockInCache(clazz);
+ clazz.debugWriteFile();
byte[] rtn = clazz.toBytecode();
if (AspectManager.getPrune()) clazz.prune();
return rtn;
Modified: branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/instrument/FieldAccessTransformer.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/instrument/FieldAccessTransformer.java 2007-01-19 14:11:19 UTC (rev 59826)
+++ branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/instrument/FieldAccessTransformer.java 2007-01-19 14:22:44 UTC (rev 59827)
@@ -99,9 +99,19 @@
doBuildFieldWrappers(clazz, field, fieldIndex, classificationGet, classificationSet);
}
- }
+ }
+
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().skipFieldAccess(clazz.getName());
}
else
@@ -110,6 +120,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: branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/instrument/Instrumentor.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/instrument/Instrumentor.java 2007-01-19 14:11:19 UTC (rev 59826)
+++ branches/Branch_AOP_1_5/aop/src/main/org/jboss/aop/instrument/Instrumentor.java 2007-01-19 14:22:44 UTC (rev 59827)
@@ -1131,4 +1131,9 @@
}
}
}
+
+ AspectManager getManager()
+ {
+ return manager;
+ }
}
\ No newline at end of file
Modified: branches/Branch_AOP_1_5/aop/src/resources/test/field/jboss-aop.xml
===================================================================
--- branches/Branch_AOP_1_5/aop/src/resources/test/field/jboss-aop.xml 2007-01-19 14:11:19 UTC (rev 59826)
+++ branches/Branch_AOP_1_5/aop/src/resources/test/field/jboss-aop.xml 2007-01-19 14:22:44 UTC (rev 59827)
@@ -34,4 +34,9 @@
<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: branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/A.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/A.java (rev 0)
+++ branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/A.java 2007-01-19 14:22:44 UTC (rev 59827)
@@ -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: branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/AccessFieldViaB.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/AccessFieldViaB.java (rev 0)
+++ branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/AccessFieldViaB.java 2007-01-19 14:22:44 UTC (rev 59827)
@@ -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: branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/AccessFieldViaC.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/AccessFieldViaC.java (rev 0)
+++ branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/AccessFieldViaC.java 2007-01-19 14:22:44 UTC (rev 59827)
@@ -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: branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/B.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/B.java (rev 0)
+++ branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/B.java 2007-01-19 14:22:44 UTC (rev 59827)
@@ -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: branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/C.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/C.java (rev 0)
+++ branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/C.java 2007-01-19 14:22:44 UTC (rev 59827)
@@ -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: branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/FieldTestCase.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/FieldTestCase.java 2007-01-19 14:11:19 UTC (rev 59826)
+++ branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/FieldTestCase.java 2007-01-19 14:22:44 UTC (rev 59827)
@@ -253,4 +253,17 @@
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: branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/ReplaceReadInterceptor.java
===================================================================
--- branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/ReplaceReadInterceptor.java (rev 0)
+++ branches/Branch_AOP_1_5/aop/src/test/org/jboss/test/aop/field/ReplaceReadInterceptor.java 2007-01-19 14:22:44 UTC (rev 59827)
@@ -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