[jboss-cvs] JBossAS SVN: r78523 - in tags/JBoss_AOP_1_5_5_GA_CP02/aop: src/main/org/jboss/aop/instrument and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Sep 15 06:59:50 EDT 2008


Author: kabir.khan at jboss.com
Date: 2008-09-15 06:59:50 -0400 (Mon, 15 Sep 2008)
New Revision: 78523

Added:
   tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/resources/test/synthetic/
   tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/resources/test/synthetic/jboss-aop.xml
   tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/
   tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/Called.java
   tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/Caller.java
   tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/Mixin.java
   tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/MixinInterface.java
   tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/POJO.java
   tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/Proxied.java
   tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/SimpleInterceptor.java
   tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/SomeInterface.java
   tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/SyntheticTestCase.java
Modified:
   tags/JBoss_AOP_1_5_5_GA_CP02/aop/build.xml
   tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/ClassicInstrumentor.java
   tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/ConstructorExecutionTransformer.java
   tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/FieldAccessTransformer.java
   tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/Instrumentor.java
   tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/NonOptimizedMethodExecutionTransformer.java
   tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/OptimizedMethodExecutionTransformer.java
   tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/TransformerCommon.java
Log:
[JBAOP-642] Make fields and wrappers introduced by JBoss AOP synthetic

Modified: tags/JBoss_AOP_1_5_5_GA_CP02/aop/build.xml
===================================================================
--- tags/JBoss_AOP_1_5_5_GA_CP02/aop/build.xml	2008-09-15 07:57:35 UTC (rev 78522)
+++ tags/JBoss_AOP_1_5_5_GA_CP02/aop/build.xml	2008-09-15 10:59:50 UTC (rev 78523)
@@ -766,7 +766,9 @@
       <antcall target="_run-bootclasspath-test" inheritRefs="true">
          <param name="test" value="precedence"/>
       </antcall>
-
+      <antcall target="_run-bootclasspath-test" inheritRefs="true">
+         <param name="test" value="synthetic"/>
+      </antcall>
    </target>
 
    <target name="_run-bootclasspath-test">
@@ -1003,6 +1005,9 @@
       <antcall target="_run-precompiled-test" inheritRefs="true">
          <param name="test" value="callerargs"/>
       </antcall>
+      <antcall target="_run-precompiled-test" inheritRefs="true">
+         <param name="test" value="synthetic"/>
+      </antcall>
 
       <!-- Tests with special requirements for parameters -->
       <antcall target="_run-precompiled-test" inheritRefs="true">

Modified: tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/ClassicInstrumentor.java
===================================================================
--- tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/ClassicInstrumentor.java	2008-09-15 07:57:35 UTC (rev 78522)
+++ tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/ClassicInstrumentor.java	2008-09-15 10:59:50 UTC (rev 78523)
@@ -119,6 +119,7 @@
                                         method.getExceptionTypes(), null, clazz);
       nmethod.setModifiers(method.getModifiers());
       nmethod.setBody(code);
+      addSyntheticAttribute(nmethod);
       clazz.addMethod(nmethod);
       
       
@@ -148,7 +149,6 @@
       clazz.addMethod(wmethod);
       
       return wmethod;
-   
    }
    
    protected void doSetupBasics(CtClass clazz) throws CannotCompileException, NotFoundException
@@ -164,7 +164,7 @@
    
    private void addHelperField(CtClass clazz) throws CannotCompileException, NotFoundException
    {
-      addStaticField(clazz,
+      CtField field = addStaticField(clazz,
                      ClassicInstrumentor.HELPER_FIELD_NAME,
                      ClassicInstrumentor.HELPER_CLASS_NAME,
                      CtField.Initializer.byExpr(ASPECT_MANAGER_CLASS_NAME + ".instance().getAdvisor(java.lang.Class#forName(\"" +
@@ -184,6 +184,7 @@
                                          "    return " + ClassicInstrumentor.HELPER_FIELD_NAME + ";" +
                                          "}",
                                          clazz);
+      addSyntheticAttribute(getter);
       clazz.addMethod(getter);
    }
    
@@ -204,6 +205,7 @@
                                  "    } " +
                                  "}",
                                  clazz);
+         addSyntheticAttribute(getter);
          clazz.addMethod(getter);
 
          CtMethod setter = CtNewMethod.make("public void _setInstanceAdvisor(org.jboss.aop.InstanceAdvisor newAdvisor)" +
@@ -213,10 +215,8 @@
                                  "    } " +
                                  "}",
                                  clazz);
+         addSyntheticAttribute(setter);
          clazz.addMethod(setter);
 
+   }
 }
-
-   
-   
-}

Modified: tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/ConstructorExecutionTransformer.java
===================================================================
--- tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/ConstructorExecutionTransformer.java	2008-09-15 07:57:35 UTC (rev 78522)
+++ tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/ConstructorExecutionTransformer.java	2008-09-15 10:59:50 UTC (rev 78523)
@@ -486,6 +486,7 @@
       CtMethod wmethod = CtNewMethod.make(type, constructorFactory(name), constructor.getParameterTypes(), exceptions, null, clazz);
       wmethod.setModifiers(mod);
       setTemporaryWrapperCode(type, wmethod);
+      Instrumentor.addSyntheticAttribute(wmethod);
       clazz.addMethod(wmethod);
       
       // prepare ForWrapping

Modified: tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/FieldAccessTransformer.java
===================================================================
--- tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/FieldAccessTransformer.java	2008-09-15 07:57:35 UTC (rev 78522)
+++ tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/FieldAccessTransformer.java	2008-09-15 10:59:50 UTC (rev 78523)
@@ -546,6 +546,7 @@
       CtMethod rmethod = CtNewMethod.make(ftype, wrapperName, readParam, null, null, clazz);
       rmethod.setModifiers(mod);
       rmethod.setBody(code);
+      Instrumentor.addSyntheticAttribute(rmethod);
       clazz.addMethod(rmethod);
       
       return rmethod;
@@ -578,6 +579,7 @@
       CtMethod wmethod = CtNewMethod.make(CtClass.voidType, wrapperName, writeParam, null, null, clazz);
       wmethod.setModifiers(mod);
       wmethod.setBody("{}");
+      Instrumentor.addSyntheticAttribute(wmethod);
       clazz.addMethod(wmethod);
       
       return wmethod;

Modified: tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/Instrumentor.java
===================================================================
--- tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/Instrumentor.java	2008-09-15 07:57:35 UTC (rev 78522)
+++ tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/Instrumentor.java	2008-09-15 10:59:50 UTC (rev 78523)
@@ -53,8 +53,11 @@
 import javassist.NotFoundException;
 import javassist.SerialVersionUID;
 import javassist.bytecode.AnnotationsAttribute;
+import javassist.bytecode.ClassFile;
+import javassist.bytecode.ConstPool;
 import javassist.bytecode.FieldInfo;
 import javassist.bytecode.MethodInfo;
+import javassist.bytecode.SyntheticAttribute;
 
 /**
  * Transforms byte code, making a class advisable. Implements
@@ -237,6 +240,26 @@
                                                clazz);
       newMethod.setModifiers(Modifier.PUBLIC);
       clazz.addMethod(newMethod);
+      
+      //TODO remove this hack once we have a version of javassist that makes the _added_m$ methods synthetic
+      //The following depends on javassist internals
+      try
+      {
+         ClassFile cf = clazz.getClassFile();
+         List infos = cf.getMethods();
+         MethodInfo info = (MethodInfo)infos.get(infos.size() - 2);
+         if (info.getName().startsWith("_added_m$"))
+         {
+            addSyntheticAttribute(info);
+         }
+      }
+      catch(Exception e)
+      {
+         if (AspectManager.verbose)
+         {
+            System.out.println("Error making added wrapper method synthetic for mixin method " + newMethod.getName());
+         }
+      }
    }
 
    private void addMixin(CtClass clazz, InterfaceIntroduction pointcut, InterfaceIntroduction.Mixin mixin, HashMap baseMethods) throws Exception
@@ -282,6 +305,7 @@
       int modifiers = Modifier.PRIVATE;
       if (mixin.isTransient()) modifiers = modifiers | Modifier.TRANSIENT;
       field.setModifiers(modifiers);
+      addSyntheticAttribute(field);
       clazz.addField(field, CtField.Initializer.byExpr(initializer));
       HashSet addedMethods = new HashSet();
 
@@ -849,6 +873,7 @@
       CtField field = new CtField(type, name, clazz);
       field.setModifiers(Modifier.PRIVATE | Modifier.STATIC);
       clazz.addField(field, initializer);
+      addSyntheticAttribute(field);
 
       return field;
    }
@@ -871,6 +896,7 @@
       {
          clazz.addField(field);
       }
+      addSyntheticAttribute(field);
       return field;
    }
 
@@ -1071,6 +1097,33 @@
       hotSwapper.hotSwap();
    }
    
+
+   public static void addSyntheticAttribute(CtMethod method)
+   {
+      MethodInfo info = method.getMethodInfo();
+      addSyntheticAttribute(info);
+   }
+   
+   public static void addSyntheticAttribute(MethodInfo info)
+   {
+      ConstPool cp = info.getConstPool();
+      info.addAttribute(new SyntheticAttribute(cp));
+   }
+
+   public static void addSyntheticAttribute(CtConstructor ctor)
+   {
+      MethodInfo info = ctor.getMethodInfo();
+      ConstPool cp = info.getConstPool();
+      info.addAttribute(new SyntheticAttribute(cp));
+   }
+
+   public static void addSyntheticAttribute(CtField field)
+   {
+      FieldInfo info = field.getFieldInfo();
+      ConstPool cp = info.getConstPool();
+      info.addAttribute(new SyntheticAttribute(cp));
+   }
+   
    protected abstract void doSetupBasics(CtClass clazz) throws CannotCompileException, NotFoundException;
    
    /**

Modified: tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/NonOptimizedMethodExecutionTransformer.java
===================================================================
--- tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/NonOptimizedMethodExecutionTransformer.java	2008-09-15 07:57:35 UTC (rev 78522)
+++ tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/NonOptimizedMethodExecutionTransformer.java	2008-09-15 10:59:50 UTC (rev 78523)
@@ -55,6 +55,7 @@
       trans.getClazz().addMethod(wmethod);
       moveAnnotations(trans.getMethod(), wmethod);
       trans.getMethod().setName(wrappedName);
+      Instrumentor.addSyntheticAttribute(trans.getMethod());
       wmethod.setName(originalName);
       
       trans.setWMethod(wmethod, wrappedName);

Modified: tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/OptimizedMethodExecutionTransformer.java
===================================================================
--- tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/OptimizedMethodExecutionTransformer.java	2008-09-15 07:57:35 UTC (rev 78522)
+++ tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/OptimizedMethodExecutionTransformer.java	2008-09-15 10:59:50 UTC (rev 78523)
@@ -55,6 +55,7 @@
       /* TODO FLAVIA COMMENTED THIS TEMPORARILY */
       String originalName = trans.getOriginalName();
       wmethod.setName(wrappedName);
+      Instrumentor.addSyntheticAttribute(wmethod);
       trans.getClazz().addMethod(wmethod);
       //moveAnnotations(trans.getMethod(), wmethod);
       String optimizedInvocation = OptimizedMethodInvocations.createOptimizedInvocationClass(trans.getInstrumentor(), trans.getClazz(), trans.getMethod());

Modified: tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/TransformerCommon.java
===================================================================
--- tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/TransformerCommon.java	2008-09-15 07:57:35 UTC (rev 78522)
+++ tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/main/org/jboss/aop/instrument/TransformerCommon.java	2008-09-15 10:59:50 UTC (rev 78523)
@@ -119,6 +119,7 @@
       CtField field = new CtField(type, infoName, addTo);
       field.setModifiers(modifiers);
       addTo.addField(field, init);
+      Instrumentor.addSyntheticAttribute(field);
    }
    
    private static void addStrongReferenceInfoField(Instrumentor instrumentor, String infoClassName, String infoName, 

Added: tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/resources/test/synthetic/jboss-aop.xml
===================================================================
--- tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/resources/test/synthetic/jboss-aop.xml	                        (rev 0)
+++ tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/resources/test/synthetic/jboss-aop.xml	2008-09-15 10:59:50 UTC (rev 78523)
@@ -0,0 +1,37 @@
+<aop>
+   <interceptor class="org.jboss.test.aop.synthetic.SimpleInterceptor"/>
+   <bind pointcut="execution(org.jboss.test.aop.synthetic.POJO->new())">
+      <interceptor-ref name="org.jboss.test.aop.synthetic.SimpleInterceptor"/>
+   </bind>
+   <bind pointcut="execution(* org.jboss.test.aop.synthetic.POJO->someMethod())">
+      <interceptor-ref name="org.jboss.test.aop.synthetic.SimpleInterceptor"/>
+   </bind>
+   <bind pointcut="execution(* org.jboss.test.aop.synthetic.POJO->staticMethod())">
+      <interceptor-ref name="org.jboss.test.aop.synthetic.SimpleInterceptor"/>
+   </bind>
+   <bind pointcut="field(* org.jboss.test.aop.synthetic.POJO->field)">
+      <interceptor-ref name="org.jboss.test.aop.synthetic.SimpleInterceptor"/>
+   </bind>
+   <bind pointcut="field(* org.jboss.test.aop.synthetic.POJO->staticField)">
+      <interceptor-ref name="org.jboss.test.aop.synthetic.SimpleInterceptor"/>
+   </bind>
+   <introduction class="org.jboss.test.aop.synthetic.POJO">
+      <mixin transient="false">
+         <interfaces>
+            org.jboss.test.aop.synthetic.MixinInterface
+         </interfaces>
+         <class>org.jboss.test.aop.synthetic.Mixin</class>
+      </mixin>
+   </introduction>
+   <introduction class="org.jboss.test.aop.synthetic.POJO">
+      <interfaces>
+         org.jboss.test.aop.synthetic.SomeInterface
+      </interfaces>
+   </introduction>
+   <bind pointcut="call(org.jboss.test.aop.synthetic.Called->new())">
+      <interceptor-ref name="org.jboss.test.aop.synthetic.SimpleInterceptor"/>
+   </bind>
+   <bind pointcut="call(* org.jboss.test.aop.synthetic.Called->called())">
+      <interceptor-ref name="org.jboss.test.aop.synthetic.SimpleInterceptor"/>
+   </bind>
+</aop>

Added: tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/Called.java
===================================================================
--- tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/Called.java	                        (rev 0)
+++ tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/Called.java	2008-09-15 10:59:50 UTC (rev 78523)
@@ -0,0 +1,38 @@
+/*
+* 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.synthetic;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class Called
+{
+   public Called()
+   {
+   }
+   
+   public void called()
+   {
+   }
+}

Added: tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/Caller.java
===================================================================
--- tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/Caller.java	                        (rev 0)
+++ tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/Caller.java	2008-09-15 10:59:50 UTC (rev 78523)
@@ -0,0 +1,64 @@
+/*
+* 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.synthetic;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class Caller
+{
+   public Caller()
+   {
+      SimpleInterceptor.intercepted = false;
+      Called called = new Called();
+      if (!SimpleInterceptor.intercepted)
+      {
+         throw new RuntimeException("SimpleInterceptor did not intercept");
+      }
+
+      SimpleInterceptor.intercepted = false;
+      called.called();
+      if (!SimpleInterceptor.intercepted)
+      {
+         throw new RuntimeException("SimpleInterceptor did not intercept");
+      }
+   }
+   
+   public void call()
+   {
+      SimpleInterceptor.intercepted = false;
+      Called called = new Called();
+      if (!SimpleInterceptor.intercepted)
+      {
+         throw new RuntimeException("SimpleInterceptor did not intercept");
+      }
+      
+      SimpleInterceptor.intercepted = false;
+      called.called();
+      if (!SimpleInterceptor.intercepted)
+      {
+         throw new RuntimeException("SimpleInterceptor did not intercept");
+      }
+   }
+}

Added: tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/Mixin.java
===================================================================
--- tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/Mixin.java	                        (rev 0)
+++ tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/Mixin.java	2008-09-15 10:59:50 UTC (rev 78523)
@@ -0,0 +1,34 @@
+/*
+* 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.synthetic;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class Mixin implements MixinInterface
+{
+   public void mixinMethod()
+   {
+   }
+}

Added: tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/MixinInterface.java
===================================================================
--- tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/MixinInterface.java	                        (rev 0)
+++ tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/MixinInterface.java	2008-09-15 10:59:50 UTC (rev 78523)
@@ -0,0 +1,32 @@
+/*
+* 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.synthetic;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface MixinInterface
+{
+   void mixinMethod();
+}

Added: tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/POJO.java
===================================================================
--- tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/POJO.java	                        (rev 0)
+++ tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/POJO.java	2008-09-15 10:59:50 UTC (rev 78523)
@@ -0,0 +1,65 @@
+/*
+* 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.synthetic;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class POJO
+{
+   public int field;
+   public int notAdvisedField;
+   public static int staticField;
+   public static int notAdvisedStaticField;
+   
+   public POJO()
+   {
+      
+   }
+   
+   public POJO(int i)
+   {
+      
+   }
+   
+   public void someMethod()
+   {
+      
+   }
+   
+   public static void staticMethod()
+   {
+      
+   }
+   
+   public void notAdvised()
+   {
+      
+   }
+   
+   public static void staticNotAdvised()
+   {
+      
+   }
+}

Added: tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/Proxied.java
===================================================================
--- tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/Proxied.java	                        (rev 0)
+++ tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/Proxied.java	2008-09-15 10:59:50 UTC (rev 78523)
@@ -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.synthetic;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class Proxied
+{
+   public void someMethod()
+   {
+      
+   }
+}

Added: tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/SimpleInterceptor.java
===================================================================
--- tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/SimpleInterceptor.java	                        (rev 0)
+++ tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/SimpleInterceptor.java	2008-09-15 10:59:50 UTC (rev 78523)
@@ -0,0 +1,46 @@
+/*
+* 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.synthetic;
+
+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 SimpleInterceptor implements Interceptor
+{
+   public static boolean intercepted;
+   public String getName()
+   {
+      return this.getClass().getName();
+   }
+
+   public Object invoke(Invocation invocation) throws Throwable
+   {
+      intercepted = true;
+      return invocation.invokeNext();
+   }
+   
+}

Added: tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/SomeInterface.java
===================================================================
--- tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/SomeInterface.java	                        (rev 0)
+++ tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/SomeInterface.java	2008-09-15 10:59:50 UTC (rev 78523)
@@ -0,0 +1,32 @@
+/*
+* 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.synthetic;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public interface SomeInterface
+{
+   void introducedMethod();
+}

Added: tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/SyntheticTestCase.java
===================================================================
--- tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/SyntheticTestCase.java	                        (rev 0)
+++ tags/JBoss_AOP_1_5_5_GA_CP02/aop/src/test/org/jboss/test/aop/synthetic/SyntheticTestCase.java	2008-09-15 10:59:50 UTC (rev 78523)
@@ -0,0 +1,185 @@
+/*
+* 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.synthetic;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.HashSet;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * Tests that fields and methods introduced by JBoss AOP have the synthetic attribute set
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class SyntheticTestCase extends TestCase
+{
+   public static void main(String[] args)
+   {
+      TestRunner.run(suite());
+   }
+
+   public static Test suite()
+   {
+      TestSuite suite = new TestSuite("SyntheticTestCase");
+      suite.addTestSuite(SyntheticTestCase.class);
+      return suite;
+   }
+
+   public SyntheticTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testWovenSynthetic()
+   {
+      HashSet fieldsAndMethods = new HashSet();
+      fieldsAndMethods.add("field");
+      fieldsAndMethods.add("notAdvisedField");
+      fieldsAndMethods.add("staticField");
+      fieldsAndMethods.add("notAdvisedStaticField");
+      fieldsAndMethods.add("someMethod");
+      fieldsAndMethods.add("staticMethod");
+      fieldsAndMethods.add("notAdvised");
+      fieldsAndMethods.add("staticNotAdvised");
+      fieldsAndMethods.add("introducedMethod");
+      fieldsAndMethods.add("mixinMethod");
+      
+      
+      //Check that we are woven first, and that the correct interceptions occur
+      SimpleInterceptor.intercepted = false;
+      POJO temp = new POJO(1);
+      assertFalse(SimpleInterceptor.intercepted);
+      temp.notAdvised();
+      assertFalse(SimpleInterceptor.intercepted);
+      temp.notAdvisedField = 1;
+      assertFalse(SimpleInterceptor.intercepted);
+      assertEquals(1, temp.notAdvisedField);
+      assertFalse(SimpleInterceptor.intercepted);
+      POJO.staticNotAdvised();
+      assertFalse(SimpleInterceptor.intercepted);
+      POJO.notAdvisedStaticField = 1;
+      assertFalse(SimpleInterceptor.intercepted);
+      assertEquals(1, POJO.notAdvisedStaticField);
+      assertFalse(SimpleInterceptor.intercepted);
+         
+      SimpleInterceptor.intercepted = false;
+      POJO pojo = new POJO();
+      assertTrue(SimpleInterceptor.intercepted);
+      
+      SimpleInterceptor.intercepted = false;
+      pojo.someMethod();
+      assertTrue(SimpleInterceptor.intercepted);
+      
+      SimpleInterceptor.intercepted = false;
+      POJO.staticMethod();
+      assertTrue(SimpleInterceptor.intercepted);
+      
+      SimpleInterceptor.intercepted = false;
+      pojo.field = 1;
+      assertTrue(SimpleInterceptor.intercepted);
+      
+      SimpleInterceptor.intercepted = false;
+      assertEquals(1, pojo.field);
+      assertTrue(SimpleInterceptor.intercepted);
+      
+      SimpleInterceptor.intercepted = false;
+      POJO.staticField = 2;
+      assertTrue(SimpleInterceptor.intercepted);
+      
+      SimpleInterceptor.intercepted = false;
+      assertEquals(2, POJO.staticField);
+      assertTrue(SimpleInterceptor.intercepted);
+      
+      MixinInterface mi = (MixinInterface)pojo;
+      SomeInterface si = (SomeInterface)pojo;
+
+      //Now check that we have the synthetic attributes
+      Constructor[] ctors = pojo.getClass().getDeclaredConstructors();
+      for (int i = 0 ; i < ctors.length ; i++)
+      {
+         assertFalse(ctors[i].toString() + " should not be synthetic", ctors[i].isSynthetic());
+      }
+      Field[] fields = pojo.getClass().getDeclaredFields();
+      for (int i = 0 ; i < fields.length ; i++)
+      {
+         if (fieldsAndMethods.contains(fields[i].getName()))
+         {
+            assertFalse(fields[i].toString() + " should not be synthetic", fields[i].isSynthetic());
+         }
+         else
+         {
+            assertTrue(fields[i].toString() + " should be synthetic", fields[i].isSynthetic());
+         }
+      }
+      Method[] methods = pojo.getClass().getDeclaredMethods();
+      for (int i = 0 ; i < methods.length ; i++)
+      {
+         if (fieldsAndMethods.contains(methods[i].getName()))
+         {
+            assertFalse(methods[i].toString() + " should not be synthetic", methods[i].isSynthetic());
+         }
+         else
+         {
+            assertTrue(methods[i].toString() + " should be synthetic", methods[i].isSynthetic());
+         }
+      }
+   }
+   
+   public void testCallerSynthetic() throws Exception
+   {
+      //These validate interception behind the scenes
+      Caller caller = new Caller();
+      caller.call();
+
+   
+      //Now check that we have the synthetic attributes
+      Constructor[] ctors = caller.getClass().getDeclaredConstructors();
+      for (int i = 0 ; i < ctors.length ; i++)
+      {
+         assertFalse(ctors[i].toString() + " should not be synthetic", ctors[i].isSynthetic());
+      }
+      Field[] fields = caller.getClass().getDeclaredFields();
+      for (int i = 0 ; i < fields.length ; i++)
+      {
+         assertTrue(fields[i].toString() + " should be synthetic", fields[i].isSynthetic());
+      }
+      Method[] methods = caller.getClass().getDeclaredMethods();
+      for (int i = 0 ; i < methods.length ; i++)
+      {
+         if (methods[i].getName().equals("call"))
+         {
+            assertFalse(methods[i].toString() + " should not be synthetic", methods[i].isSynthetic());
+         }
+         else
+         {
+            assertTrue(methods[i].toString() + " should be synthetic", methods[i].isSynthetic());
+         }
+      }
+   }
+}




More information about the jboss-cvs-commits mailing list