Package javassist

Examples of javassist.CtMethod


   {
      HashMap<Long, CtMethod> allMethods = JavassistMethodHashing.getMethodMap(proxy.getSuperclass());

      for (Map.Entry<Long, CtMethod> entry : allMethods.entrySet())
      {
         CtMethod m = entry.getValue();
         if (!Modifier.isPublic(m.getModifiers()) || Modifier.isStatic(m.getModifiers()) || Modifier.isFinal(m.getModifiers())) continue;

         Long hash = entry.getKey();
         if (addedMethods.contains(hash)) continue;
         if (hardcodedMethods.contains(hash)) continue;
        
         addedMethods.add(hash);
         String aopReturnStr = (m.getReturnType().equals(CtClass.voidType)) ? "" : "return ($r)";
         String returnStr = (m.getReturnType().equals(CtClass.voidType)) ? "" : "return ";
         String args = "null";
        
         String name = null;
         if (isAdvised)
         {
            MethodInfo info = advisor.getMethodInfo(hash.longValue());
            Method originalMethod = info.getUnadvisedMethod();
            name = originalMethod.getName();
         }
         else
         {
            name = m.getName();
         }
        
         if (m.getParameterTypes().length > 0) args = "$args";
         String code = "{   " +
                       "    boolean handled = false;" +
                       "    try{" +
                       "       if (currentAdvisor != null) {" +
                       "          org.jboss.aop.MethodInfo mi = currentAdvisor.getMethodInfo(" + hash.longValue() + "L); " +
                       "          if (mi == null) " +
                       "             throw new java.lang.NoSuchMethodError(\"" + m.getName() + m.getSignature() + "\");" +
                       "          org.jboss.aop.advice.Interceptor[] interceptors = mi.getInterceptors(); " +
                       "          if (interceptors != (Object[])null && interceptors.length > 0) { " +
                       "             handled = true;" +
                       "             org.jboss.aop.proxy.container.ContainerProxyMethodInvocation invocation = new org.jboss.aop.proxy.container.ContainerProxyMethodInvocation(mi, interceptors, this); " +
                       "             invocation.setArguments(" + args + "); " +
                       "             invocation.setTargetObject(delegate); " +
                       "             invocation.setMetaData(metadata);" +
                       "             " + aopReturnStr + " invocation.invokeNext(); " +
                       "          }" +
                       "       }" +
                       "       if (!handled && delegate != null){ " +
                       "          " + returnStr + " delegate." + name + "($$); " +
                       "       }" +
                       "       return " + getNullType(m.getReturnType()) + ";" +
                       "    }finally{" +
                       "    }" +
                       "}";
         CtMethod newMethod = CtNewMethod.make(m.getReturnType(), m.getName(), m.getParameterTypes(), m.getExceptionTypes(), code, proxy);
         newMethod.setModifiers(Modifier.PUBLIC);
         proxy.addMethod(newMethod);

         copyAnnotations(m, newMethod);
         copySignature(m, newMethod);
      }
View Full Code Here


                          "       " + aopReturnStr + " invocation.invokeNext(); " +
                          "    }finally{" +
                          "    }" +
                          "}";
           
            CtMethod newMethod = CtNewMethod.make(methods[m].getReturnType(), methods[m].getName(), methods[m].getParameterTypes(), methods[m].getExceptionTypes(), code, proxy);
            newMethod.setModifiers(Modifier.PUBLIC);
            proxy.addMethod(newMethod);
           
            copySignature(methods[m], newMethod);
         }
View Full Code Here

                  body = "{ setInstanceAdvisor($1); }";
               }
              
               if (body != null)
               {
                  CtMethod m = CtNewMethod.make(methods[i].getReturnType(), methods[i].getName(), methods[i].getParameterTypes(), methods[i].getExceptionTypes(), body, proxy);
                  m.setModifiers(Modifier.PUBLIC);
                  Instrumentor.addSyntheticAttribute(m);
                  proxy.addMethod(m);
               }
            }
         }
View Full Code Here

   protected CtMethod addMixinMethod(Advisor advisor, CtMethod method, CtClass clazz, CtMethod delegate, long hash) throws Exception
   {
      CtClass[] exceptions = method.getExceptionTypes();

      // create base, delegating method.
      CtMethod newMethod = CtNewMethod.wrapped(method.getReturnType(),
                                               method.getName(),
                                               method.getParameterTypes(),
                                               exceptions,
                                               delegate,
                                               CtMethod.ConstParameter.integer(hash),
                                               clazz);
      newMethod.setModifiers(Modifier.PUBLIC);
      clazz.addMethod(newMethod);
     
      return newMethod;
   }
View Full Code Here

         Iterator<Map.Entry<Long, CtMethod>> entries = intfMap.entrySet().iterator();
         while (entries.hasNext())
         {
            Map.Entry<Long, CtMethod> entry = entries.next();
            Long hash = entry.getKey();
            CtMethod method = entry.getValue();
            CtMethod baseMethod = baseMethods.get(hash);
            if (baseMethod != null && !addedMethods.contains(hash))
            {
               String msg = "Mixin " + mixinClass.getName() +
                        " of pointcut " + pointcut.getName() +
                        " is trying to apply an already existing method" + method.getName() + " for class " + clazz.getName();

               if (baseMethod.getDeclaringClass().equals(clazz))
               {
                  throw new RuntimeException(msg);
               }
               else
               {
View Full Code Here

      if (!clazz.subtypeOf(iface) && !clazz.subclassOf(iface))
      {
         clazz.addInterface(iface);
      }

      CtMethod mixinInvokeMethod = createInvokeMethod(clazz);
      HashMap<Long, CtMethod> intfMap = JavassistMethodHashing.getMethodMap(iface);
      Iterator<Map.Entry<Long, CtMethod>> entries = intfMap.entrySet().iterator();
      while (entries.hasNext())
      {
         Map.Entry<Long, CtMethod> entry = entries.next();
         Long hash = entry.getKey();
         if (baseMethods.containsKey(hash)) continue;
         CtMethod method = entry.getValue();
         addMixinMethod(advisor, method, clazz, mixinInvokeMethod, hash.longValue());
         baseMethods.put(hash, method);
      }
   }
View Full Code Here

      return null;
   }
  
   private static SignatureAttribute.MethodSignature getMethodSignature(Method m)
   {
      CtMethod mtd = JavassistUtil.getCtMethod(m);
      MethodInfo info = mtd.getMethodInfo2();
      return getMethodSignature(info);
   }
View Full Code Here

   public void autoBox(ClassPool pool, CtClass autoboxClass, String boxed, String unboxed) throws NotFoundException, CannotCompileException
   {
      CtClass boxedClass = pool.get(boxed);
      CtClass unboxedClass = pool.get(unboxed);
      CtClass[] sig = { unboxedClass };
      CtMethod autoboxValueOf = autoboxClass.getDeclaredMethod("valueOf", sig);
      CtMethod originalValueOf = boxedClass.getDeclaredMethod("valueOf", sig);
      redirectMethodCall(originalValueOf, autoboxValueOf);
   }
View Full Code Here

        
         try
         {
            if (INIT.equals(name) == false)
            {
               CtMethod ctMethod = clazz.getMethod(name, descriptor);
               ctMethod.getReturnType();
            }
         }
         catch (NotFoundException e)
         {
            if (failed == 0)
               System.out.println("==== " + info.getFile());
            System.out.println("Return type not found for method " + name + "." + descriptor);
            ++failed;
         }
        
         if (INIT.equals(name))
         {
            try
            {
               CtConstructor ctConstructor = clazz.getConstructor(descriptor);
               ctConstructor.getParameterTypes();
            }
            catch (NotFoundException e)
            {
               if (failed == 0)
                  System.out.println("==== " + info.getFile());
               System.out.println("Cannot find constructor parameter types " + name + "." + descriptor);
               ++failed;
            }
            try
            {
               CtConstructor ctConstructor = clazz.getConstructor(descriptor);
               ctConstructor.getExceptionTypes();
            }
            catch (NotFoundException e)
            {
               if (failed == 0)
                  System.out.println("==== " + info.getFile());
               System.out.println("Cannot find constructor exception types " + name + "." + descriptor);
               ++failed;
            }
         }
         else
         {
            try
            {
               CtMethod ctMethod = clazz.getMethod(name, descriptor);
               ctMethod.getParameterTypes();
            }
            catch (NotFoundException e)
            {
               if (failed == 0)
                  System.out.println("==== " + info.getFile());
               System.out.println("Cannot find method parameter types " + name + "." + descriptor);
               ++failed;
            }
            try
            {
               CtMethod ctMethod = clazz.getMethod(name, descriptor);
               ctMethod.getExceptionTypes();
            }
            catch (NotFoundException e)
            {
               if (failed == 0)
                  System.out.println("==== " + info.getFile());
View Full Code Here

         code.append("}");

         String name = advisedClass.getName();
         CtClass ctTarget = clazz.getClassPool().get(name);
        
         CtMethod method = CtNewMethod.make(
               Modifier.PRIVATE,
               CtClass.voidType,
               INITIALISE_LIGHTWEIGHT_INSTANCE_ASPECTS,
               new CtClass[] {ctTarget},//target
               EMPTY_CTCLASS_ARRAY,
View Full Code Here

TOP

Related Classes of javassist.CtMethod

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.