/** * Returns a constructor receiving the specified parameters. * * @param params parameter types. */ public CtConstructor getDeclaredConstructor(CtClass[] params) throws NotFoundException { String desc = Descriptor.ofConstructor(params); return getConstructor(desc); }
/** * Returns a constructor receiving the specified parameters. * * @param params parameter types. */ public CtConstructor getDeclaredConstructor(CtClass[] params) throws NotFoundException { String desc = Descriptor.ofConstructor(params); return getConstructor(desc); }
/** * 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); }
/** * 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); }
stacksize = code.addLoadParameters(parameters, 1) + 1; code.addInvokespecial(superclazz, "<init>", Descriptor.ofConstructor(parameters));
stacksize = code.addLoadParameters(parameters, 1) + 1; code.addInvokespecial(superclazz, "<init>", Descriptor.ofConstructor(parameters));
/** * Returns a constructor receiving the specified parameters. * * @param params parameter types. */ public CtConstructor getDeclaredConstructor(CtClass[] params) throws NotFoundException { String desc = Descriptor.ofConstructor(params); return getConstructor(desc); }
/** * Returns a constructor receiving the specified parameters. * * @param params parameter types. */ public CtConstructor getDeclaredConstructor(CtClass[] params) throws NotFoundException { String desc = Descriptor.ofConstructor(params); return getConstructor(desc); }
/** * Returns a constructor receiving the specified parameters. * * @param params parameter types. */ public CtConstructor getDeclaredConstructor(CtClass[] params) throws NotFoundException { String desc = Descriptor.ofConstructor(params); return getConstructor(desc); }
/** * Returns a constructor receiving the specified parameters. * * @param params parameter types. */ public CtConstructor getDeclaredConstructor(CtClass[] params) throws NotFoundException { String desc = Descriptor.ofConstructor(params); return getConstructor(desc); }
/** * Returns a constructor receiving the specified parameters. * * @param params parameter types. */ public CtConstructor getDeclaredConstructor(CtClass[] params) throws NotFoundException { String desc = Descriptor.ofConstructor(params); return getConstructor(desc); }
private CtConstructor getDefaultConstructor(CtClass ctClass) { try { return ctClass.getConstructor(Descriptor.ofConstructor(new CtClass[0])); } catch (NotFoundException e) { return null; } }
private CtConstructor getDefaultConstructor(CtClass ctClass) { try { return ctClass.getConstructor(Descriptor.ofConstructor(new CtClass[0])); } catch (NotFoundException e) { return null; } }
/** * Get the javassist constructor * * @param constructor the constructor * @return the javassist constructor */ static CtConstructor getCtConstructor(Constructor constructor) { CtClass clazz = getCtClass(constructor.getDeclaringClass()); Class[] parameters = constructor.getParameterTypes(); CtClass[] params = new CtClass[parameters.length]; for (int i = 0; i < parameters.length; ++i) params[i] = getCtClass(parameters[i]); String descriptor = Descriptor.ofConstructor(params); try { return clazz.getConstructor(descriptor); } catch (NotFoundException e) { throw new RuntimeException("Unable to find constructor descriptor=" + descriptor, e); } }
private static SignatureAttribute copyConstructorGenericsSignature( final ConstPool constPool, final CtClass[] params, final CtClass source, final CtClass anchor) throws Exception { final CtConstructor ctConstructor = source.getConstructor(Descriptor.ofConstructor(params)); String signature = null; for (Object attr : ctConstructor.getMethodInfo().getAttributes()) { if (attr instanceof SignatureAttribute) { signature = ((SignatureAttribute) attr).getSignature(); break; } } if (signature != null && anchor != null) { // add anchor to generics signature final String type = "L" + (anchor.getName().replaceAll("\\.", "/")) + ";"; final int idx = signature.lastIndexOf(')'); signature = signature.substring(0, idx) + type + signature.substring(idx); } return signature == null ? null : new SignatureAttribute(constPool, signature); } }
private void initAllowMountedHarvest() { try { ClassPool classPool = HookManager.getInstance().getClassPool(); // com.wurmonline.server.behaviours.Action.Action(Creature, long, long, short, float, float, float, float) CtClass ctAction = classPool.get("com.wurmonline.server.behaviours.Action"); String descriptor = Descriptor.ofConstructor(new CtClass[] { classPool.get("com.wurmonline.server.creatures.Creature"), CtClass.longType, CtClass.longType, CtClass.shortType, CtClass.floatType, CtClass.floatType, CtClass.floatType, CtClass.floatType }); CtConstructor constructor = ctAction.getConstructor(descriptor); constructor.instrument(new ExprEditor() { @Override public void edit(MethodCall methodCall) throws CannotCompileException { if (methodCall.getClassName().equals("com.wurmonline.server.behaviours.Action") && methodCall.getMethodName().equals("isFatigue")) { methodCall.replace("$_ = this.action == com.wurmonline.server.behaviours.Actions.HARVEST && this.performer.getVehicle() != -10L ? false : $proceed($$);"); } } }); } catch (NotFoundException | CannotCompileException e) { throw new HookException(e); } }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }