/** * Creates a copy of a method. This method is provided for creating * a new method based on an existing method. * This is a convenience method for calling * {@link CtMethod#CtMethod(CtMethod, CtClass, ClassMap) this constructor}. * See the description of the constructor for particular behavior of the copying. * * @param src the source method. * @param declaring the class to which the created method is added. * @param map the hash table associating original class names * with substituted names. * It can be <code>null</code>. * * @see CtMethod#CtMethod(CtMethod,CtClass,ClassMap) */ public static CtMethod copy(CtMethod src, CtClass declaring, ClassMap map) throws CannotCompileException { return new CtMethod(src, declaring, map); }
/** * Creates a copy of a method. This method is provided for creating * a new method based on an existing method. * This is a convenience method for calling * {@link CtMethod#CtMethod(CtMethod, CtClass, ClassMap) this constructor}. * See the description of the constructor for particular behavior of the copying. * * @param src the source method. * @param declaring the class to which the created method is added. * @param map the hash table associating original class names * with substituted names. * It can be <code>null</code>. * * @see CtMethod#CtMethod(CtMethod,CtClass,ClassMap) */ public static CtMethod copy(CtMethod src, CtClass declaring, ClassMap map) throws CannotCompileException { return new CtMethod(src, declaring, map); }
/** * Creates a public abstract method. * * @param returnType the type of the returned value * @param mname the method name * @param parameters a list of the parameter types * @param exceptions a list of the exception types * @param declaring the class to which the created method is added. * * @see CtMethod#CtMethod(CtClass,String,CtClass[],CtClass) */ public static CtMethod abstractMethod(CtClass returnType, String mname, CtClass[] parameters, CtClass[] exceptions, CtClass declaring) throws NotFoundException { CtMethod cm = new CtMethod(returnType, mname, parameters, declaring); cm.setExceptionTypes(exceptions); return cm; }
/** * Creates a copy of a method with a new name. * This method is provided for creating * a new method based on an existing method. * This is a convenience method for calling * {@link CtMethod#CtMethod(CtMethod, CtClass, ClassMap) this constructor}. * See the description of the constructor for particular behavior of the copying. * * @param src the source method. * @param name the name of the created method. * @param declaring the class to which the created method is added. * @param map the hash table associating original class names * with substituted names. * It can be <code>null</code>. * * @see CtMethod#CtMethod(CtMethod,CtClass,ClassMap) */ public static CtMethod copy(CtMethod src, String name, CtClass declaring, ClassMap map) throws CannotCompileException { CtMethod cm = new CtMethod(src, declaring, map); cm.setName(name); return cm; }
/** * Creates a public abstract method. * * @param returnType the type of the returned value * @param mname the method name * @param parameters a list of the parameter types * @param exceptions a list of the exception types * @param declaring the class to which the created method is added. * * @see CtMethod#CtMethod(CtClass,String,CtClass[],CtClass) */ public static CtMethod abstractMethod(CtClass returnType, String mname, CtClass[] parameters, CtClass[] exceptions, CtClass declaring) throws NotFoundException { CtMethod cm = new CtMethod(returnType, mname, parameters, declaring); cm.setExceptionTypes(exceptions); return cm; }
/** * Creates a copy of a method with a new name. * This method is provided for creating * a new method based on an existing method. * This is a convenience method for calling * {@link CtMethod#CtMethod(CtMethod, CtClass, ClassMap) this constructor}. * See the description of the constructor for particular behavior of the copying. * * @param src the source method. * @param name the name of the created method. * @param declaring the class to which the created method is added. * @param map the hash table associating original class names * with substituted names. * It can be <code>null</code>. * * @see CtMethod#CtMethod(CtMethod,CtClass,ClassMap) */ public static CtMethod copy(CtMethod src, String name, CtClass declaring, ClassMap map) throws CannotCompileException { CtMethod cm = new CtMethod(src, declaring, map); cm.setName(name); return cm; }
private void makeBehaviorCache(CtMember.Cache cache) { List list = getClassFile3(false).getMethods(); int n = list.size(); for (int i = 0; i < n; ++i) { MethodInfo minfo = (MethodInfo)list.get(i); if (minfo.isMethod()) { CtMethod newMethod = new CtMethod(minfo, this); cache.addMethod(newMethod); } else { CtConstructor newCons = new CtConstructor(minfo, this); cache.addConstructor(newCons); } } }
/** * Creates a method from a <code>MethodInfo</code> object. * * @param declaring the class declaring the method. * @throws CannotCompileException if the the <code>MethodInfo</code> * object and the declaring class have different * <code>ConstPool</code> objects * @since 3.6 */ public static CtMethod make(MethodInfo minfo, CtClass declaring) throws CannotCompileException { if (declaring.getClassFile2().getConstPool() != minfo.getConstPool()) throw new CannotCompileException("bad declaring class"); return new CtMethod(minfo, declaring); }
/** * Creates a method from a <code>MethodInfo</code> object. * * @param declaring the class declaring the method. * @throws CannotCompileException if the the <code>MethodInfo</code> * object and the declaring class have different * <code>ConstPool</code> objects * @since 3.6 */ public static CtMethod make(MethodInfo minfo, CtClass declaring) throws CannotCompileException { if (declaring.getClassFile2().getConstPool() != minfo.getConstPool()) throw new CannotCompileException("bad declaring class"); return new CtMethod(minfo, declaring); }
= new CtMethod(returnType, mname, parameters, declaring); cm.setModifiers(modifiers); cm.setExceptionTypes(exceptions);
private void makeBehaviorCache(CtMember.Cache cache) { List<MethodInfo> methods = getClassFile3(false).getMethods(); for (MethodInfo minfo:methods) if (minfo.isMethod()) cache.addMethod(new CtMethod(minfo, this)); else cache.addConstructor(new CtConstructor(minfo, this)); }
private static String addBodyMethod(CtClassType clazz, ClassFile classfile, CtMethod src) throws BadBytecode, CannotCompileException { Hashtable bodies = clazz.getHiddenMethods(); String bodyname = (String)bodies.get(src); if (bodyname == null) { do { bodyname = addedWrappedMethod + clazz.getUniqueNumber(); } while (classfile.getMethod(bodyname) != null); ClassMap map = new ClassMap(); map.put(src.getDeclaringClass().getName(), clazz.getName()); MethodInfo body = new MethodInfo(classfile.getConstPool(), bodyname, src.getMethodInfo2(), map); int acc = body.getAccessFlags(); body.setAccessFlags(AccessFlag.setPrivate(acc)); body.addAttribute(new SyntheticAttribute(classfile.getConstPool())); // a stack map is copied. rebuilding it is not needed. classfile.addMethod(body); bodies.put(src, bodyname); CtMember.Cache cache = clazz.hasMemberCache(); if (cache != null) cache.addMethod(new CtMethod(body, clazz)); } return bodyname; }
public static CtMethod wrapped(CtClass returnType, String mname, CtClass[] parameterTypes, CtClass[] exceptionTypes, CtMethod body, ConstParameter constParam, CtClass declaring) throws CannotCompileException { CtMethod mt = new CtMethod(returnType, mname, parameterTypes, declaring); mt.setModifiers(body.getModifiers()); try { mt.setExceptionTypes(exceptionTypes); } catch (NotFoundException e) { throw new CannotCompileException(e); } Bytecode code = makeBody(declaring, declaring.getClassFile2(), body, parameterTypes, returnType, constParam); MethodInfo minfo = mt.getMethodInfo2(); minfo.setCodeAttribute(code.toCodeAttribute()); // a stack map has been already created. return mt; }
private static String addBodyMethod(CtClassType clazz, ClassFile classfile, CtMethod src) throws BadBytecode, CannotCompileException { Map<CtMethod,String> bodies = clazz.getHiddenMethods(); String bodyname = bodies.get(src); if (bodyname == null) { do { bodyname = addedWrappedMethod + clazz.getUniqueNumber(); } while (classfile.getMethod(bodyname) != null); ClassMap map = new ClassMap(); map.put(src.getDeclaringClass().getName(), clazz.getName()); MethodInfo body = new MethodInfo(classfile.getConstPool(), bodyname, src.getMethodInfo2(), map); int acc = body.getAccessFlags(); body.setAccessFlags(AccessFlag.setPrivate(acc)); body.addAttribute(new SyntheticAttribute(classfile.getConstPool())); // a stack map is copied. rebuilding it is not needed. classfile.addMethod(body); bodies.put(src, bodyname); CtMember.Cache cache = clazz.hasMemberCache(); if (cache != null) cache.addMethod(new CtMethod(body, clazz)); } return bodyname; }
public static CtMethod wrapped(CtClass returnType, String mname, CtClass[] parameterTypes, CtClass[] exceptionTypes, CtMethod body, ConstParameter constParam, CtClass declaring) throws CannotCompileException { CtMethod mt = new CtMethod(returnType, mname, parameterTypes, declaring); mt.setModifiers(body.getModifiers()); try { mt.setExceptionTypes(exceptionTypes); } catch (NotFoundException e) { throw new CannotCompileException(e); } Bytecode code = makeBody(declaring, declaring.getClassFile2(), body, parameterTypes, returnType, constParam); MethodInfo minfo = mt.getMethodInfo2(); minfo.setCodeAttribute(code.toCodeAttribute()); // a stack map has been already created. return mt; }
throws CannotCompileException CtMethod method = new CtMethod(null, declaring); method.copy(this, false, map); if (isConstructor()) {
CtClass cc = field.getDeclaringClass(); return new CtMethod(minfo, cc);
CtClass cc = field.getDeclaringClass(); return new CtMethod(minfo, cc);
minfo.setCodeAttribute(code.toCodeAttribute()); return new CtMethod(minfo, declaring);
CtClass rtype = gen.resolver.lookupClass(r); recordReturnType(rtype, false); CtMethod method = new CtMethod(rtype, r.getVariable().get(), plist, gen.getThisClass()); method.setModifiers(mod);