/** * Return the declared method with the given name and parameter types, * or null if none. If multiple methods are declared with the given name * and parameters, which is returned is undefined. * Note that in bytecode, constructors are named <code><init></code> * and static initializers are named <code><clinit></code>. */ public BCMethod getDeclaredMethod(String name, Class[] paramTypes) { if (paramTypes == null) return getDeclaredMethod(name, (String[]) null); String[] paramNames = new String[paramTypes.length]; for (int i = 0; i < paramTypes.length; i++) paramNames[i] = paramTypes[i].getName(); return getDeclaredMethod(name, paramNames); }
/** * Return the declared method with the given name and parameter types, * or null if none. If multiple methods are declared with the given name * and parameters, which is returned is undefined. * Note that in bytecode, constructors are named <code><init></code> * and static initializers are named <code><clinit></code>. */ public BCMethod getDeclaredMethod(String name, Class[] paramTypes) { if (paramTypes == null) return getDeclaredMethod(name, (String[]) null); String[] paramNames = new String[paramTypes.length]; for (int i = 0; i < paramTypes.length; i++) paramNames[i] = paramTypes[i].getName(); return getDeclaredMethod(name, paramNames); }
/** * Return the declared method with the given name and parameter types, * or null if none. If multiple methods are declared with the given name * and parameters, which is returned is undefined. * Note that in bytecode, constructors are named <code><init></code> * and static initializers are named <code><clinit></code>. */ public BCMethod getDeclaredMethod(String name, BCClass[] paramTypes) { if (paramTypes == null) return getDeclaredMethod(name, (String[]) null); String[] paramNames = new String[paramTypes.length]; for (int i = 0; i < paramTypes.length; i++) paramNames[i] = paramTypes[i].getName(); return getDeclaredMethod(name, paramNames); }
/** * Return the declared method with the given name and signature, * or null if none. * Note that in bytecode, constructors are named <code><init></code> * and static initializers are named <code><clinit></code>. */ public BCMethod getDeclaredMethod(String name, Class returnType, Class[] paramTypes) { if (paramTypes == null) return getDeclaredMethod(name, returnType.getName(), (String[]) null); String[] paramNames = new String[paramTypes.length]; for (int i = 0; i < paramTypes.length; i++) paramNames[i] = paramTypes[i].getName(); return getDeclaredMethod(name, returnType.getName(), paramNames); }
/** * Return the declared method with the given name and signature, * or null if none. * Note that in bytecode, constructors are named <code><init></code> * and static initializers are named <code><clinit></code>. */ public BCMethod getDeclaredMethod(String name, Class returnType, Class[] paramTypes) { if (paramTypes == null) return getDeclaredMethod(name, returnType.getName(), (String[]) null); String[] paramNames = new String[paramTypes.length]; for (int i = 0; i < paramTypes.length; i++) paramNames[i] = paramTypes[i].getName(); return getDeclaredMethod(name, returnType.getName(), paramNames); }
/** * Return the declared method with the given name and parameter types, * or null if none. If multiple methods are declared with the given name * and parameters, which is returned is undefined. * Note that in bytecode, constructors are named <code><init></code> * and static initializers are named <code><clinit></code>. */ public BCMethod getDeclaredMethod(String name, BCClass[] paramTypes) { if (paramTypes == null) return getDeclaredMethod(name, (String[]) null); String[] paramNames = new String[paramTypes.length]; for (int i = 0; i < paramTypes.length; i++) paramNames[i] = paramTypes[i].getName(); return getDeclaredMethod(name, paramNames); }
private BCMethod getBCMethod(Method meth) { BCClass bc = pc.getProject().loadClass(meth.getDeclaringClass()); return bc.getDeclaredMethod(meth.getName(), meth.getParameterTypes()); }
private BCMethod getBCMethod(Method meth) { BCClass bc = pc.getProject().loadClass(meth.getDeclaringClass()); return bc.getDeclaredMethod(meth.getName(), meth.getParameterTypes()); }
private BCMethod getBCMethod(Method meth) { BCClass bc = pc.getProject().loadClass(meth.getDeclaringClass()); return bc.getDeclaredMethod(meth.getName(), meth.getParameterTypes()); }
private BCMethod getBCMethod(Method meth) { BCClass bc = pc.getProject().loadClass(meth.getDeclaringClass()); return bc.getDeclaredMethod(meth.getName(), meth.getParameterTypes()); }
private BCMethod getBCMethod(Method meth) { BCClass bc = pc.getProject().loadClass(meth.getDeclaringClass()); return bc.getDeclaredMethod(meth.getName(), meth.getParameterTypes()); }
/** * Proxy setter methods of the given type. * * @return true if we find any setters, false otherwise */ private boolean proxySetters(BCClass bc, Class type) { Method[] meths = type.getMethods(); int setters = 0; for (int i = 0; i < meths.length; i++) { if (isSetter(meths[i]) && !Modifier.isFinal(meths[i].getModifiers()) && bc.getDeclaredMethod(meths[i].getName(), meths[i].getParameterTypes()) == null) { setters++; proxySetter(bc, type, meths[i]); } } return setters > 0; }
/** * Proxy setter methods of the given type. * * @return true if we find any setters, false otherwise */ private boolean proxySetters(BCClass bc, Class type) { Method[] meths = type.getMethods(); int setters = 0; for (int i = 0; i < meths.length; i++) { if (isSetter(meths[i]) && !Modifier.isFinal(meths[i].getModifiers()) && bc.getDeclaredMethod(meths[i].getName(), meths[i].getParameterTypes()) == null) { setters++; proxySetter(bc, type, meths[i]); } } return setters > 0; }
/** * Proxy setter methods of the given type. * * @return true if we find any setters, false otherwise */ private boolean proxySetters(BCClass bc, Class type) { Method[] meths = type.getMethods(); int setters = 0; for (int i = 0; i < meths.length; i++) { if (isSetter(meths[i]) && !Modifier.isFinal(meths[i].getModifiers()) && bc.getDeclaredMethod(meths[i].getName(), meths[i].getParameterTypes()) == null) { setters++; proxySetter(bc, type, meths[i]); } } return setters > 0; }
/** * Proxy setter methods of the given type. * * @return true if we find any setters, false otherwise */ private boolean proxySetters(BCClass bc, Class type) { Method[] meths = type.getMethods(); int setters = 0; for (int i = 0; i < meths.length; i++) { if (isSetter(meths[i]) && !Modifier.isFinal(meths[i].getModifiers()) && bc.getDeclaredMethod(meths[i].getName(), meths[i].getParameterTypes()) == null) { setters++; proxySetter(bc, type, meths[i]); } } return setters > 0; }
/** * Return the declared method with the given name and signature, * or null if none. * Note that in bytecode, constructors are named <code><init></code> * and static initializers are named <code><clinit></code>. */ public BCMethod getDeclaredMethod(String name, BCClass returnType, BCClass[] paramTypes) { if (paramTypes == null) return getDeclaredMethod(name, returnType.getName(), (String[]) null); String[] paramNames = new String[paramTypes.length]; for (int i = 0; i < paramTypes.length; i++) paramNames[i] = paramTypes[i].getName(); return getDeclaredMethod(name, returnType.getName(), paramNames); }
/** * Return the declared method with the given name and signature, * or null if none. * Note that in bytecode, constructors are named <code><init></code> * and static initializers are named <code><clinit></code>. */ public BCMethod getDeclaredMethod(String name, BCClass returnType, BCClass[] paramTypes) { if (paramTypes == null) return getDeclaredMethod(name, returnType.getName(), (String[]) null); String[] paramNames = new String[paramTypes.length]; for (int i = 0; i < paramTypes.length; i++) paramNames[i] = paramTypes[i].getName(); return getDeclaredMethod(name, returnType.getName(), paramNames); }
/** * Proxy setter methods of the given type. * * @return true if we find any setters, false otherwise */ private boolean proxySetters(BCClass bc, Class type) { Method[] meths = type.getMethods(); int setters = 0; for (int i = 0; i < meths.length; i++) { if (isSetter(meths[i]) && !Modifier.isFinal(meths[i].getModifiers()) && bc.getDeclaredMethod(meths[i].getName(), meths[i].getParameterTypes()) == null) { setters++; proxySetter(bc, type, meths[i]); } } return setters > 0; }
/** * Convenience method to add a default constructor to this class. * If a default constructor already exists, this method will return it * without modification. * This method can only be called if the superclass has been set. * * @return the default constructor */ public BCMethod addDefaultConstructor() { BCMethod method = getDeclaredMethod("<init>", (String[]) null); if (method != null) return method; method = declareMethod("<init>", void.class, null); Code code = method.getCode(true); code.setMaxStack(1); code.setMaxLocals(1); code.xload().setThis(); code.invokespecial() .setMethod(getSuperclassName(), "<init>", "void", null); code.vreturn(); return method; }
/** * Enhance constructor to initialize fields */ private void enhanceConstructor(BCClass bc) { BCMethod cons = bc.getDeclaredMethod("<init>", (String[]) null); Code code = cons.getCode(false); code.afterLast(); code.previous(); // private BitSet loaded = new BitSet(); BCField loaded = addBeanField(bc, "loaded", BitSet.class); loaded.setFinal(true); code.aload().setThis(); code.anew().setType(BitSet.class); code.dup(); code.constant().setValue(bc.getFields().length); code.invokespecial().setMethod(BitSet.class, "<init>", void.class, new Class[]{ int.class }); code.putfield().setField(loaded); code.calculateMaxStack(); code.calculateMaxLocals(); }