/** * Return the methods with the given name and parameter types, including * those of all superclasses, or an empty array if none. * Note that in bytecode, constructors are named <code><init></code> * and static initializers are named <code><clinit></code>. */ public BCMethod[] getMethods(String name, Class[] paramTypes) { if (paramTypes == null) return getMethods(name, (String[]) null); String[] paramNames = new String[paramTypes.length]; for (int i = 0; i < paramTypes.length; i++) paramNames[i] = paramTypes[i].getName(); return getMethods(name, paramNames); }
/** * Return the methods with the given name and parameter types, including * those of all superclasses, or an empty array if none. * Note that in bytecode, constructors are named <code><init></code> * and static initializers are named <code><clinit></code>. */ public BCMethod[] getMethods(String name, Class[] paramTypes) { if (paramTypes == null) return getMethods(name, (String[]) null); String[] paramNames = new String[paramTypes.length]; for (int i = 0; i < paramTypes.length; i++) paramNames[i] = paramTypes[i].getName(); return getMethods(name, paramNames); }
/** * Return the methods with the given name and parameter types, including * those of all superclasses, or an empty array if none. * Note that in bytecode, constructors are named <code><init></code> * and static initializers are named <code><clinit></code>. */ public BCMethod[] getMethods(String name, BCClass[] paramTypes) { if (paramTypes == null) return getMethods(name, (String[]) null); String[] paramNames = new String[paramTypes.length]; for (int i = 0; i < paramTypes.length; i++) paramNames[i] = paramTypes[i].getName(); return getMethods(name, paramNames); }
/** * Return the methods with the given name and parameter types, including * those of all superclasses, or an empty array if none. * Note that in bytecode, constructors are named <code><init></code> * and static initializers are named <code><clinit></code>. */ public BCMethod[] getMethods(String name, BCClass[] paramTypes) { if (paramTypes == null) return getMethods(name, (String[]) null); String[] paramNames = new String[paramTypes.length]; for (int i = 0; i < paramTypes.length; i++) paramNames[i] = paramTypes[i].getName(); return getMethods(name, paramNames); }
/** * Return the methods with the given name, including those of all * superclasses, or an empty array if none. * Note that in bytecode, constructors are named <code><init></code> * and static initializers are named <code><clinit></code>. */ public BCMethod[] getMethods(String name) { Collection matches = new LinkedList(); BCMethod[] methods = getMethods(); for (int i = 0; i < methods.length; i++) if (methods[i].getName().equals(name)) matches.add(methods[i]); return (BCMethod[]) matches.toArray(new BCMethod[matches.size()]); }
/** * Return the methods with the given name, including those of all * superclasses, or an empty array if none. * Note that in bytecode, constructors are named <code><init></code> * and static initializers are named <code><clinit></code>. */ public BCMethod[] getMethods(String name) { Collection matches = new LinkedList(); BCMethod[] methods = getMethods(); for (int i = 0; i < methods.length; i++) if (methods[i].getName().equals(name)) matches.add(methods[i]); return (BCMethod[]) matches.toArray(new BCMethod[matches.size()]); }
BCMethod[] methods = getMethods(); Collection matches = new LinkedList(); for (int i = 0; i < methods.length; i++) {
/** * Return the method this instruction operates on, or null if not set. */ public BCMethod getMethod() { String dec = getMethodDeclarerName(); if (dec == null) return null; BCClass bc = getProject().loadClass(dec, getClassLoader()); BCMethod[] meths = bc.getMethods(getMethodName(),getMethodParamNames()); if (meths.length == 0) return null; return meths[0]; }
/** * Return the method this instruction operates on, or null if not set. */ public BCMethod getMethod() { String dec = getMethodDeclarerName(); if (dec == null) return null; BCClass bc = getProject().loadClass(dec, getClassLoader()); BCMethod[] meths = bc.getMethods(getMethodName(),getMethodParamNames()); if (meths.length == 0) return null; return meths[0]; }
/** * Adds a non-static getter that delegates to the super methods, and * performs any necessary field tracking. */ private void addSubclassGetMethod(FieldMetaData fmd) { String methName = "get" + StringUtils.capitalize(fmd.getName()); if (_managedType.getMethods(methName, new Class[0]).length == 0) methName = "is" + StringUtils.capitalize(fmd.getName()); BCMethod getter = _pc.declareMethod(methName, fmd.getDeclaredType(), null); setVisibilityToSuperMethod(getter); getter.makePublic(); Code code = getter.getCode(true); // if we're not already tracking field access via reflection, then we // must make the getter hook in lazy loading before accessing the super // method. if (!getRedefine()) addNotifyAccess(code, fmd); code.aload().setThis(); code.invokespecial().setMethod(_managedType.getType(), methName, fmd.getDeclaredType(), null); code.xreturn().setType(fmd.getDeclaredType()); code.calculateMaxLocals(); code.calculateMaxStack(); }
/** * Adds a non-static getter that delegates to the super methods, and * performs any necessary field tracking. */ private void addSubclassGetMethod(FieldMetaData fmd) { String methName = "get" + StringUtils.capitalize(fmd.getName()); if (_managedType.getMethods(methName, new Class[0]).length == 0) methName = "is" + StringUtils.capitalize(fmd.getName()); BCMethod getter = _pc.declareMethod(methName, fmd.getDeclaredType(), null); setVisibilityToSuperMethod(getter); getter.makePublic(); Code code = getter.getCode(true); // if we're not already tracking field access via reflection, then we // must make the getter hook in lazy loading before accessing the super // method. if (!getRedefine()) addNotifyAccess(code, fmd); code.aload().setThis(); code.invokespecial().setMethod(_managedType.getType(), methName, fmd.getDeclaredType(), null); code.xreturn().setType(fmd.getDeclaredType()); code.calculateMaxLocals(); code.calculateMaxStack(); }
/** * Adds a non-static getter that delegates to the super methods, and * performs any necessary field tracking. */ private void addSubclassGetMethod(FieldMetaData fmd) { String methName = "get" + StringUtils.capitalize(fmd.getName()); if (_managedType.getMethods(methName, new Class[0]).length == 0) methName = "is" + StringUtils.capitalize(fmd.getName()); BCMethod getter = _pc.declareMethod(methName, fmd.getDeclaredType(), null); setVisibilityToSuperMethod(getter); getter.makePublic(); Code code = getter.getCode(true); // if we're not already tracking field access via reflection, then we // must make the getter hook in lazy loading before accessing the super // method. if (!getRedefine()) addNotifyAccess(code, fmd); code.aload().setThis(); code.invokespecial().setMethod(_managedType.getType(), methName, fmd.getDeclaredType(), null); code.xreturn().setType(fmd.getDeclaredType()); code.calculateMaxLocals(); code.calculateMaxStack(); }
private boolean setVisibilityToSuperMethod(BCMethod method) { BCMethod[] methods = _managedType.getMethods(method.getName(), method.getParamTypes()); if (methods.length == 0) throw new UserException(_loc.get("no-accessor", _managedType.getName(), method.getName())); BCMethod superMeth = methods[0]; if (superMeth.isPrivate()) { method.makePrivate(); return true; } else if (superMeth.isPackage()) { method.makePackage(); return true; } else if (superMeth.isProtected()) { method.makeProtected(); return true; } else if (superMeth.isPublic()) { method.makePublic(); return true; } return false; }
private boolean setVisibilityToSuperMethod(BCMethod method) { BCMethod[] methods = _managedType.getMethods(method.getName(), method.getParamTypes()); if (methods.length == 0) throw new UserException(_loc.get("no-accessor", _managedType.getName(), method.getName())); BCMethod superMeth = methods[0]; if (superMeth.isPrivate()) { method.makePrivate(); return true; } else if (superMeth.isPackage()) { method.makePackage(); return true; } else if (superMeth.isProtected()) { method.makeProtected(); return true; } else if (superMeth.isPublic()) { method.makePublic(); return true; } return false; }
private boolean setVisibilityToSuperMethod(BCMethod method) { BCMethod[] methods = _managedType.getMethods(method.getName(), method.getParamTypes()); if (methods.length == 0) throw new UserException(_loc.get("no-accessor", _managedType.getName(), method.getName())); BCMethod superMeth = methods[0]; if (superMeth.isPrivate()) { method.makePrivate(); return true; } else if (superMeth.isPackage()) { method.makePackage(); return true; } else if (superMeth.isProtected()) { method.makeProtected(); return true; } else if (superMeth.isPublic()) { method.makePublic(); return true; } return false; }
private boolean setVisibilityToSuperMethod(BCMethod method) { BCMethod[] methods = _managedType.getMethods(method.getName(), method.getParamTypes()); if (methods.length == 0) throw new UserException(_loc.get("no-accessor", _managedType.getName(), method.getName())); BCMethod superMeth = methods[0]; if (superMeth.isPrivate()) { method.makePrivate(); return true; } else if (superMeth.isPackage()) { method.makePackage(); return true; } else if (superMeth.isProtected()) { method.makeProtected(); return true; } else if (superMeth.isPublic()) { method.makePublic(); return true; } return false; }
private void addEnhancement(BCClass bcc, ClassMetaData cmd) { Log log = cmd.getRepository().getConfiguration().getLog(OpenJPAConfiguration.LOG_RUNTIME); FetchStatsCollector.setlogger(log); for (BCMethod meth : bcc.getMethods()) { String methodName = meth.getName(); FieldMetaData fmd = getFieldName(methodName, cmd); if (fmd != null && needsTracking(fmd, methodName, cmd)) { String fqn = bcc.getName() + "." + fmd.getName(); FetchStatsCollector.registerField(fqn); FetchStatsCollector.registerEntity(cmd); Code code = meth.getCode(false); code.constant().setValue(fqn); code.invokestatic().setMethod(FetchStatsCollector.class, "hit", void.class, new Class[] { String.class }); } } }
private boolean setVisibilityToSuperMethod(BCMethod method) { BCMethod[] methods = _managedType.getMethods(method.getName(), method.getParamTypes()); if (methods.length == 0) throw new UserException(_loc.get("no-accessor", _managedType.getName(), method.getName())); BCMethod superMeth = methods[0]; if (superMeth.isPrivate()) { method.makePrivate(); return true; } else if (superMeth.isPackage()) { method.makePackage(); return true; } else if (superMeth.isProtected()) { method.makeProtected(); return true; } else if (superMeth.isPublic()) { method.makePublic(); return true; } return false; }
/** * Adds a non-static getter that delegates to the super methods, and * performs any necessary field tracking. */ private void addSubclassGetMethod(FieldMetaData fmd) { String methName = "get" + StringUtil.capitalize(fmd.getName()); if (_managedType.getMethods(methName, new Class[0]).length == 0) methName = "is" + StringUtil.capitalize(fmd.getName()); BCMethod getter = _pc.declareMethod(methName, fmd.getDeclaredType(), null); setVisibilityToSuperMethod(getter); getter.makePublic(); Code code = getter.getCode(true); // if we're not already tracking field access via reflection, then we // must make the getter hook in lazy loading before accessing the super // method. if (!getRedefine()) addNotifyAccess(code, fmd); code.aload().setThis(); code.invokespecial().setMethod(_managedType.getType(), methName, fmd.getDeclaredType(), null); code.xreturn().setType(fmd.getDeclaredType()); code.calculateMaxLocals(); code.calculateMaxStack(); }
/** * Adds a non-static getter that delegates to the super methods, and * performs any necessary field tracking. */ private void addSubclassGetMethod(FieldMetaData fmd) { String methName = "get" + StringUtil.capitalize(fmd.getName()); if (_managedType.getMethods(methName, new Class[0]).length == 0) methName = "is" + StringUtil.capitalize(fmd.getName()); BCMethod getter = _pc.declareMethod(methName, fmd.getDeclaredType(), null); setVisibilityToSuperMethod(getter); getter.makePublic(); Code code = getter.getCode(true); // if we're not already tracking field access via reflection, then we // must make the getter hook in lazy loading before accessing the super // method. if (!getRedefine()) addNotifyAccess(code, fmd); code.aload().setThis(); code.invokespecial().setMethod(_managedType.getType(), methName, fmd.getDeclaredType(), null); code.xreturn().setType(fmd.getDeclaredType()); code.calculateMaxLocals(); code.calculateMaxStack(); }