Package javassist

Examples of javassist.CtClass.toClass()


                ctTranslatorClass.addMethod(newMethod);
            }

        }
        this.writeAdaptedClass();
        return ctTranslatorClass.toClass();
    }

    /**
     * Writes the class to the directory found by the class loader (since the class is a currently existing class)
     */
 
View Full Code Here


    public static void initEnv() throws Exception {
        ServiceFramwork.mode = ServiceFramwork.Mode.test;
        CtClass ctClass = ServiceFramwork.classPool.get("net.csdn.bootstrap.Bootstrap");
        //加载Guice容器
        Method method = ctClass.toClass().getDeclaredMethod("configureSystem");
        method.setAccessible(true);
        method.invoke(null);
    }

    public static Class[] findTestClass() throws Exception {
View Full Code Here

*/
public class Application {
    public static void main(String[] args) {
        try {
            CtClass ctClass = ServiceFramwork.classPool.get("net.csdn.bootstrap.Bootstrap");
            Method method = ctClass.toClass().getMethod("main", new Class[]{args.getClass()});
            method.invoke(null, new Object[]{args});
        } catch (Exception e) {
            e.printStackTrace();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
View Full Code Here

                        CtClass ctClass = ServiceFramwork.classPool.makeClass(classFile);
                        if (!ctClass.hasAnnotation(Util.class)) {
                            return null;
                        }
                        logger.info("util load :    "+ctClass.getName());
                        final Class clzz = ctClass.toClass();
                        final Util util = (Util) clzz.getAnnotation(Util.class);
                        if (clzz.isInterface())
                            throw new AnnotationException(format("{} util should not be interface", clzz.getName()));
                        moduleList.add(new AbstractModule() {
                            @Override
View Full Code Here

                    try {

                        CtClass ctClass = ServiceFramwork.classPool.makeClass(classFile);
                        TraceEnhancer.enhanceMethod(ctClass);
                        try {
                            ctClasses.add(ctClass.toClass());
                        } catch (Exception e) {
                            String name = ctClass.getName();
                            Class me = Class.forName(name);
                            if (!ctClasses.contains(me)) {
                                ctClasses.add(me);
View Full Code Here

            CtClass ctClass = ServiceFramwork.classPool.get("net.csdn.bootstrap.Bootstrap");
            if (checkClassLoaded(ctClass.getName())) {
                return;
            }
            //加载Guice容器
            Method method = ctClass.toClass().getDeclaredMethod("configureSystem");
            method.setAccessible(true);
            method.invoke(null);
            injector = ServiceFramwork.injector;
        } catch (Exception e) {
            e.printStackTrace();
View Full Code Here

    private Class<?> createArtificialApplicationResourcesClass() {
        try {
            ClassPool classPool = ClassPool.getDefault();
            CtClass applicationResourcesCtClass = classPool.makeClass(APP_FUSE_RESOURCE_FILE_NAME);
            return applicationResourcesCtClass.toClass();
        } catch (CannotCompileException e) {
            throw new RuntimeException("Unable to instantiate Wicket application", e);
        }
    }
View Full Code Here

      CtMethod theMethod = new CtMethod(
          classPool.get("java.lang.String"), "interfaceMethod",
          new CtClass[0], theClass);
      theMethod.setBody("return \"Hello, World!\";");
      theClass.addMethod(theMethod);
      Class clazz = theClass.toClass();
      return ( BeanInterface )clazz.newInstance();
    } catch (Exception e) {
      throw new ApplicationRuntimeException("Cannot construct instance.",
          e);
    }
View Full Code Here

      // Insert a classpath so that Maven does not complain about not finding the class
      pool.insertClassPath(new ClassClassPath(Car.class));
      CtClass carCt = pool.get(CAR);
      try {
         carCt.addField(CtField.make("public int year;", carCt));
         Class carClass = carCt.toClass();
         if (isNewExternalizer) {
            CtClass carExtCt = pool.get(CAR_EXT);
            CtMethod writeObjMeth = carExtCt.getMethod("writeObject",
                  "(Ljava/io/ObjectOutput;Ljava/lang/Object;)V");
            writeObjMeth.setBody("{\n" +
View Full Code Here

               "            ((0xFF & b3) << 8) | (0xFF & b4);\n" +
               "}\n" +
               "return o;\n" +
            "}\n"
            );
            carExtCt.toClass(); // Convert to class so that it gets loaded!!!
         }

         Object oldCarFromWire = unmarshall(oldCarbytes, method);

         Field plateField = carClass.getDeclaredField("plateNumber");
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.