public Method getMethod(final DeploymentReflectionIndex reflectionIndex, final Class<?> clazz) throws DeploymentUnitProcessingException { final ClassReflectionIndex classIndex = reflectionIndex.getClassIndex(clazz); Collection<Method> methods = null; final String paramType = getDeclaredValueClassName(); final String name = getName(); final String className = getClassName(); if (paramType != null) { // find the methods with the specific name and the param types methods = ClassReflectionIndexUtil.findMethods(reflectionIndex, classIndex, name, paramType); } // either paramType is not set, or we may need to find autoboxing methods // e.g. setMyBoolean(boolean) for a Boolean if (methods == null || methods.isEmpty()) { // find all the methods with the specific name and which accept just 1 parameter. methods = ClassReflectionIndexUtil.findAllMethods(reflectionIndex, classIndex, name, 1); } Iterator<Method> iterator = methods.iterator(); if (!iterator.hasNext()) { throw EeLogger.ROOT_LOGGER.methodNotFound(name, paramType, className); } Method method = iterator.next(); if (iterator.hasNext()) { throw EeLogger.ROOT_LOGGER.multipleMethodsFound(name, paramType, className); } return method; } }
/** * Finds and returns all methods corresponding to the passed method <code>name</code> and method <code>paramCount</code>. * The passed <code>classReflectionIndex</code> will be used to traverse the class hierarchy while finding the method. * <p/> * Returns empty collection if no such method is found * * @param deploymentReflectionIndex The deployment reflection index * @param classReflectionIndex The class reflection index which will be used to traverse the class hierarchy to find the method * @param methodName The name of the method * @param paramCount The number of params accepted by the method * @return */ public static Collection<Method> findAllMethods(final DeploymentReflectionIndex deploymentReflectionIndex, final ClassReflectionIndex classReflectionIndex, final String methodName, int paramCount) { Collection<Method> methods = classReflectionIndex.getAllMethods(methodName, paramCount); if (!methods.isEmpty()) { return methods; } // find on super class Class<?> superClass = classReflectionIndex.getIndexedClass().getSuperclass(); if (superClass != null) { ClassReflectionIndex superClassIndex = deploymentReflectionIndex.getClassIndex(superClass); if (superClassIndex != null) { return findAllMethods(deploymentReflectionIndex, superClassIndex, methodName, paramCount); } } return methods; }
/** * Finds and returns all methods corresponding to the passed method <code>name</code> and method <code>paramCount</code>. * The passed <code>classReflectionIndex</code> will be used to traverse the class hierarchy while finding the method. * <p/> * Returns empty collection if no such method is found * * @param deploymentReflectionIndex The deployment reflection index * @param classReflectionIndex The class reflection index which will be used to traverse the class hierarchy to find the method * @param methodName The name of the method * @param paramCount The number of params accepted by the method * @return */ public static Collection<Method> findAllMethods(final DeploymentReflectionIndex deploymentReflectionIndex, final ClassReflectionIndex classReflectionIndex, final String methodName, int paramCount) { Collection<Method> methods = classReflectionIndex.getAllMethods(methodName, paramCount); if (!methods.isEmpty()) { return methods; } // find on super class Class<?> superClass = classReflectionIndex.getIndexedClass().getSuperclass(); if (superClass != null) { ClassReflectionIndex<?> superClassIndex = deploymentReflectionIndex.getClassIndex(superClass); if (superClassIndex != null) { return findAllMethods(deploymentReflectionIndex, superClassIndex, methodName, paramCount); } } return methods; }
/** * Finds and returns all methods corresponding to the passed method <code>name</code> and method <code>paramCount</code>. * The passed <code>classReflectionIndex</code> will be used to traverse the class hierarchy while finding the method. * <p/> * Returns empty collection if no such method is found * * @param deploymentReflectionIndex The deployment reflection index * @param classReflectionIndex The class reflection index which will be used to traverse the class hierarchy to find the method * @param methodName The name of the method * @param paramCount The number of params accepted by the method * @return */ public static Collection<Method> findAllMethods(final DeploymentReflectionIndex deploymentReflectionIndex, final ClassReflectionIndex classReflectionIndex, final String methodName, int paramCount) { Collection<Method> methods = classReflectionIndex.getAllMethods(methodName, paramCount); if (!methods.isEmpty()) { return methods; } // find on super class Class<?> superClass = classReflectionIndex.getIndexedClass().getSuperclass(); if (superClass != null) { ClassReflectionIndex<?> superClassIndex = deploymentReflectionIndex.getClassIndex(superClass); if (superClassIndex != null) { return findAllMethods(deploymentReflectionIndex, superClassIndex, methodName, paramCount); } } return methods; }
/** * Finds and returns all methods corresponding to the passed method <code>name</code> and method <code>paramCount</code>. * The passed <code>classReflectionIndex</code> will be used to traverse the class hierarchy while finding the method. * <p/> * Returns empty collection if no such method is found * * @param deploymentReflectionIndex The deployment reflection index * @param classReflectionIndex The class reflection index which will be used to traverse the class hierarchy to find the method * @param methodName The name of the method * @param paramCount The number of params accepted by the method * @return */ public static Collection<Method> findAllMethods(final DeploymentReflectionIndex deploymentReflectionIndex, final ClassReflectionIndex classReflectionIndex, final String methodName, int paramCount) { Collection<Method> methods = classReflectionIndex.getAllMethods(methodName, paramCount); if (!methods.isEmpty()) { return methods; } // find on super class Class<?> superClass = classReflectionIndex.getIndexedClass().getSuperclass(); if (superClass != null) { ClassReflectionIndex superClassIndex = deploymentReflectionIndex.getClassIndex(superClass); if (superClassIndex != null) { return findAllMethods(deploymentReflectionIndex, superClassIndex, methodName, paramCount); } } return methods; }
public Method getMethod(final DeploymentReflectionIndex reflectionIndex, final Class<?> clazz) throws DeploymentUnitProcessingException { final ClassReflectionIndex classIndex = reflectionIndex.getClassIndex(clazz); Collection<Method> methods = null; final String paramType = getDeclaredValueClassName(); final String name = getName(); final String className = getClassName(); if (paramType != null) { // find the methods with the specific name and the param types methods = ClassReflectionIndexUtil.findMethods(reflectionIndex, classIndex, name, paramType); } // either paramType is not set, or we may need to find autoboxing methods // e.g. setMyBoolean(boolean) for a Boolean if (methods == null || methods.isEmpty()) { // find all the methods with the specific name and which accept just 1 parameter. methods = ClassReflectionIndexUtil.findAllMethods(reflectionIndex, classIndex, name, 1); } Iterator<Method> iterator = methods.iterator(); if (!iterator.hasNext()) { throw EeLogger.ROOT_LOGGER.methodNotFound(name, paramType, className); } Method method = iterator.next(); if (iterator.hasNext()) { throw EeLogger.ROOT_LOGGER.multipleMethodsFound(name, paramType, className); } return method; } }
public Method getMethod(final DeploymentReflectionIndex reflectionIndex, final Class<?> clazz) throws DeploymentUnitProcessingException { final ClassReflectionIndex classIndex = reflectionIndex.getClassIndex(clazz); Collection<Method> methods = null; final String paramType = getDeclaredValueClassName(); final String name = getName(); final String className = getClassName(); if (paramType != null) { // find the methods with the specific name and the param types methods = ClassReflectionIndexUtil.findMethods(reflectionIndex, classIndex, name, paramType); } // either paramType is not set, or we may need to find autoboxing methods // e.g. setMyBoolean(boolean) for a Boolean if (methods == null || methods.isEmpty()) { // find all the methods with the specific name and which accept just 1 parameter. methods = ClassReflectionIndexUtil.findAllMethods(reflectionIndex, classIndex, name, 1); } Iterator<Method> iterator = methods.iterator(); if (!iterator.hasNext()) { throw EeLogger.ROOT_LOGGER.methodNotFound(name, paramType, className); } Method method = iterator.next(); if (iterator.hasNext()) { throw EeLogger.ROOT_LOGGER.multipleMethodsFound(name, paramType, className); } return method; } }
methods = ClassReflectionIndexUtil.findAllMethods(reflectionIndex, classIndex, name, 1);