Package javassist

Examples of javassist.CtClass.addConstructor()


                    break;
                }
            }
            if (!hasDefaultConstructor && !ctClass.isInterface()) {
                CtConstructor defaultConstructor = CtNewConstructor.make("public " + ctClass.getSimpleName() + "() {}", ctClass);
                ctClass.addConstructor(defaultConstructor);
            }
        } catch (Exception e) {
            Logger.error(e, "Error in PropertiesEnhancer");
            throw new UnexpectedException("Error in PropertiesEnhancer", e);
        }
View Full Code Here


                    break;
                }
            }
            if (!hasDefaultConstructor) {
                CtConstructor defaultConstructor = CtNewConstructor.defaultConstructor(ctClass);
                ctClass.addConstructor(defaultConstructor);
            }
        } catch (Exception e) {
            Logger.error(e, "Error in PropertiesEnhancer");
            throw new UnexpectedException("Error in PropertiesEnhancer", e);
        }
View Full Code Here

        String[] methods = METHODS_PATTERN.split(body);
        for (String method : methods) {
            method = method.trim();
            if (method.length() > 0) {
                if (method.startsWith(className)) {
                    cls.addConstructor(CtNewConstructor.make("public " + method, cls));
                } else if (FIELD_PATTERN.matcher(method).matches()) {
                    cls.addField(CtField.make("private " + method, cls));
                } else {
                    cls.addMethod(CtNewMethod.make("public " + method, cls));
                }
View Full Code Here

            } catch (ClassNotFoundException e) {
                ClassPool pool = ClassGenerator.getClassPool(clazz.getClassLoader());
                CtClass ctClass = pool.makeClass(parameterClassName);
                ClassFile classFile = ctClass.getClassFile();
                classFile.setVersionToJava5();
                ctClass.addConstructor(CtNewConstructor.defaultConstructor(pool.getCtClass(parameterClassName)));
                // parameter fields
                Class<?>[] parameterTypes = method.getParameterTypes();
                Annotation[][] parameterAnnotations = method.getParameterAnnotations();
                for (int i = 0; i < parameterTypes.length; i ++) {
                    Class<?> type = parameterTypes[i];
View Full Code Here

        String[] methods = METHODS_PATTERN.split(body);
        for (String method : methods) {
            method = method.trim();
            if (method.length() > 0) {
                if (method.startsWith(className)) {
                    cls.addConstructor(CtNewConstructor.make("public " + method, cls));
                } else if (FIELD_PATTERN.matcher(method).matches()) {
                    cls.addField(CtField.make("private " + method, cls));
                } else {
                    cls.addMethod(CtNewMethod.make("public " + method, cls));
                }
View Full Code Here

      }*/
      result.addInterface(pool.get(JavassistMethod.class.getName()));
     
      CtConstructor constructor = new CtConstructor(null, result);
      constructor.setBody("super();");
      result.addConstructor(constructor);
     
      CtClass object = pool.get(Object.class.getName());
     
      JBossStringBuilder buffer = new JBossStringBuilder();
     
View Full Code Here

      CtClass newEnum = pool.makeClass(classname, baseEnum);

      // Create the enum ctor
      String ctorSrc = "protected " + newEnum.getSimpleName() + "(String name, int ord){super(name, ord);}";
      CtConstructor ctor = CtNewConstructor.make(ctorSrc, newEnum);
      newEnum.addConstructor(ctor);

      // Create the enum constants by iterating over the jdk5 class values
      for (Enum e : enums)
      {
         String fieldName = e.name();
View Full Code Here

/*  74 */       break;
/*     */     }
/*     */
/*  77 */     CtConstructor icon = CtNewConstructor.make(template.getParameterTypes(), template.getExceptionTypes(), invocation);
/*     */
/*  79 */     invocation.addConstructor(icon);
/*     */
/*  83 */     addArgumentFieldsAndAccessors(pool, invocation, con.getParameterTypes(), false);
/*     */
/*  87 */     addCopy(invocation, con.getParameterTypes());
/*     */
View Full Code Here

/*  66 */     CtClass invocation = makeInvocationClassNoCtors(pool, makeInnerClass, clazz, className, conInvocation);
/*     */
/*  69 */     CtConstructor template = conInvocation.getDeclaredConstructors()[0];
/*  70 */     CtConstructor icon = CtNewConstructor.make(template.getParameterTypes(), template.getExceptionTypes(), invocation);
/*     */
/*  72 */     invocation.addConstructor(icon);
/*     */
/*  76 */     CtClass[] params = con.getParameterTypes();
/*  77 */     addArgumentFieldsAndAccessors(pool, invocation, params, false);
/*     */
/*  81 */     addDispatch(invocation, "invokeTarget", con);
View Full Code Here

/*  72 */     for (int i = 0; i < cons.length; i++)
/*     */     {
/*  74 */       CtConstructor conTemplate = superInvocation.getDeclaredConstructors()[i];
/*  75 */       CtConstructor icon = CtNewConstructor.make(conTemplate.getParameterTypes(), conTemplate.getExceptionTypes(), invocation);
/*     */
/*  78 */       invocation.addConstructor(icon);
/*     */     }
/*     */
/*  81 */     return invocation;
/*     */   }
/*     */
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.