/** * Creates a constructor with no constructor body. * The created constructor * must be added to a class with <code>CtClass.addConstructor()</code>. * * <p>The created constructor does not include a constructor body, * which must be specified with <code>setBody()</code>. * * @param declaring the class to which the created method is added. * @param parameters a list of the parameter types * * @see CtClass#addConstructor(CtConstructor) * @see CtConstructor#setBody(String) * @see CtConstructor#setBody(CtConstructor,ClassMap) */ public CtConstructor(CtClass[] parameters, CtClass declaring) { this((MethodInfo)null, declaring); ConstPool cp = declaring.getClassFile2().getConstPool(); String desc = Descriptor.ofConstructor(parameters); methodInfo = new MethodInfo(cp, "<init>", desc); setModifiers(Modifier.PUBLIC); }
constructor.setModifiers(Modifier.PUBLIC); constructor.setBody("{super(new " + UselessInvocationHandler.class.getName() + "());}"); mCtc.addConstructor(constructor);
constructor.setModifiers(Modifier.PUBLIC); constructor.setBody("{super(new " + UselessInvocationHandler.class.getName() + "());}"); mCtc.addConstructor(constructor);
/** * Creates a constructor with no constructor body. * The created constructor * must be added to a class with <code>CtClass.addConstructor()</code>. * * <p>The created constructor does not include a constructor body, * which must be specified with <code>setBody()</code>. * * @param declaring the class to which the created method is added. * @param parameters a list of the parameter types * * @see CtClass#addConstructor(CtConstructor) * @see CtConstructor#setBody(String) * @see CtConstructor#setBody(CtConstructor,ClassMap) */ public CtConstructor(CtClass[] parameters, CtClass declaring) { this((MethodInfo)null, declaring); ConstPool cp = declaring.getClassFile2().getConstPool(); String desc = Descriptor.ofConstructor(parameters); methodInfo = new MethodInfo(cp, "<init>", desc); setModifiers(Modifier.PUBLIC); }
= CtNewConstructor.make(c.getParameterTypes(), c.getExceptionTypes(), this); cons.setModifiers(mod & (Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE)); addConstructor(cons); ++n;
private void ensureNullaryCtor(CtClass cc) throws NotFoundException, CannotCompileException { // Build a null-ary constructor if needed String clzname = cc.getSimpleName(); if( !hasExisting(clzname,"()V",cc.getDeclaredConstructors()) ) { String body = "public "+clzname+"() { }"; cc.addConstructor(CtNewConstructor.make(body,cc)); } else { CtConstructor ctor = cc.getConstructor("()V"); ctor.setModifiers(javassist.Modifier.setPublic(ctor.getModifiers())); } }
= CtNewConstructor.make(c.getParameterTypes(), c.getExceptionTypes(), this); cons.setModifiers(mod & (Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE)); addConstructor(cons); ++n;
CtConstructor cons = new CtConstructor(plist, gen.getThisClass()); cons.setModifiers(mod); md.accept(gen); cons.getMethodInfo().setCodeAttribute(
CtConstructor cons = new CtConstructor(plist, gen.getThisClass()); cons.setModifiers(mod); md.accept(gen); cons.getMethodInfo().setCodeAttribute(
public CtConstructor merge() throws Exception { CtConstructor constructor = versions.lastEntry().getValue(); wipeBody(constructor); constructor.setModifiers(mergedModifiers()); return constructor; }
private void makeDeferConstructorNonPublic(final CtClass clazz) { for (final CtConstructor constr : clazz.getConstructors()) { try { for (CtClass paramType : constr.getParameterTypes()) { if (IndicateReloadClass.class.getName() .equals(paramType.getName())) { /* Found defer constructor ... */ final int modifiers = constr.getModifiers(); if (Modifier.isPublic(modifiers)) { constr.setModifiers(Modifier.setProtected(modifiers)); } break; } } } catch (NotFoundException thereAreNoParameters) { /* ... but to get an exception here seems odd. */ } } } }
public static CtClass makeMirrorSubclass(CtClass target, CtClass parent, String name) throws CannotCompileException { CtClass mirrorClass = parent.makeNestedClass(name, true); mirrorClass.setModifiers(Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL); AnnotationUtil.annotateReflectionAccessor(mirrorClass, target.getName(), null, null); CtConstructor constructor = CtNewConstructor.defaultConstructor(mirrorClass); constructor.setModifiers(Modifier.PRIVATE); mirrorClass.addConstructor(constructor); return mirrorClass; }
private CtConstructor createConstructor(ConstPool constPool, CtClass declaringClass) throws NotFoundException, CannotCompileException { CtConstructor cc = new CtConstructor(new CtClass[]{ declaringClass.getClassPool().getCtClass(Object.class.getName() + "[]") }, declaringClass); // Define the constructor behavior cc.setBody("super($1);"); cc.setModifiers(Modifier.PUBLIC); // Add the @Inject annotation to the constructor addInjectAnnotation(constPool, cc); // Add the @Assisted annotation to the constructor parameter addAssistedAnnotation(constPool, cc); return cc; }
@Override public CtClass transform(final CtClass clazz) { if (clazz.isInterface()) { return clazz; } if (getStrategy() == CLASSLOADER) { for (CtConstructor c : clazz.getDeclaredConstructors()) { final int modifiers = c.getModifiers(); if (!Modifier.isPublic(modifiers)) { c.setModifiers(Modifier.setPublic(modifiers)); } } } return clazz; }
public MutableConstructorInfo createMutableConstructor(int modifiers, ClassInfo[] parameters, ClassInfo[] exceptions) { try { CtConstructor constructor = CtNewConstructor.make(JavassistUtil.toCtClass(parameters), JavassistUtil.toCtClass(exceptions), ctClass); constructor.setModifiers(modifiers); return new JavassistConstructorInfo(null, factory, this, constructor); } catch (CannotCompileException e) { throw new org.jboss.reflect.spi.CannotCompileException(e.toString()); } }
public void addToClassInitializer(final String fullClass, final String code) { final CtClass classRef = getClass(fullClass); try { CtConstructor method = classRef.getClassInitializer(); if (method != null) { method.insertAfter(code); } else { method = CtNewConstructor.make(new CtClass[0], new CtClass[0], code, classRef); method.getMethodInfo().setName("<clinit>"); method.setModifiers(Modifier.STATIC); classRef.addConstructor(method); } } catch (final Throwable e) { maybeThrow(new IllegalArgumentException("Cannot add " + code + " to class initializer of " + fullClass, e)); } }
public void addToClassInitializer(final String fullClass, final String code) { final CtClass classRef = getClass(fullClass); try { CtConstructor method = classRef.getClassInitializer(); if (method != null) { method.insertAfter(code); } else { method = CtNewConstructor.make(new CtClass[0], new CtClass[0], code, classRef); method.getMethodInfo().setName("<clinit>"); method.setModifiers(Modifier.STATIC); classRef.addConstructor(method); } } catch (final Throwable e) { maybeThrow(new IllegalArgumentException("Cannot add " + code + " to class initializer of " + fullClass, e)); } }
public MutableConstructorInfo createMutableConstructor(int modifiers, Body body, ClassInfo[] parameters, ClassInfo[] exceptions) { try { CtConstructor constructor = CtNewConstructor.make(JavassistUtil.toCtClass(parameters), JavassistUtil.toCtClass(exceptions), body.getBody(), ctClass); constructor.setModifiers(modifiers); return new JavassistConstructorInfo(null, factory, this, constructor); } catch (CannotCompileException e) { throw new org.jboss.reflect.spi.CannotCompileException(e.toString()); } }
public MutableConstructorInfo createMutableConstructor(int modifiers, String[] parameters, String[] exceptions) { try { CtConstructor constructor = CtNewConstructor.make(JavassistUtil.toCtClass(ctClass.getClassPool(), parameters), JavassistUtil.toCtClass(ctClass.getClassPool(), exceptions), ctClass); constructor.setModifiers(modifiers); return new JavassistConstructorInfo(null, factory, this, constructor); } catch (CannotCompileException e) { throw new org.jboss.reflect.spi.CannotCompileException(e.toString()); } }
public MutableConstructorInfo createMutableConstructor(int modifiers, Body body, String[] parameters, String[] exceptions) { try { CtConstructor constructor = CtNewConstructor.make(JavassistUtil.toCtClass(ctClass.getClassPool(), parameters), JavassistUtil.toCtClass(ctClass.getClassPool(), exceptions), body.getBody(), ctClass); constructor.setModifiers(modifiers); return new JavassistConstructorInfo(null, factory, this, constructor); } catch (CannotCompileException e) { throw new org.jboss.reflect.spi.CannotCompileException(e.toString()); } }