private static void findObjectIndexedPropertyDescriptors()

in src/main/java/org/apache/commons/ognl/internal/entry/PropertyDescriptorCacheEntryFactory.java [95:170]


    private static void findObjectIndexedPropertyDescriptors( Class<?> targetClass,
                                                             Map<String, PropertyDescriptor> intoMap )
        throws OgnlException
    {
        Map<String, List<Method>> allMethods = OgnlRuntime.getMethods( targetClass, false );
        Map<String, List<Method>> pairs = new HashMap<String, List<Method>>( 101 );

        for ( Map.Entry<String, List<Method>> entry : allMethods.entrySet() )
        {
            String methodName = entry.getKey();
            List<Method> methods = entry.getValue();

            /*
             * Only process set/get where there is exactly one implementation of the method per class and those
             * implementations are all the same
             */
            if ( indexMethodCheck( methods ) )
            {
                boolean isGet = false, isSet;
                Method method = methods.get( 0 );

                if ( ( ( isSet = methodName.startsWith( OgnlRuntime.SET_PREFIX ) ) || ( isGet =
                    methodName.startsWith( OgnlRuntime.GET_PREFIX ) ) ) && ( methodName.length() > 3 ) )
                {
                    String propertyName = Introspector.decapitalize( methodName.substring( 3 ) );
                    Class<?>[] parameterTypes = OgnlRuntime.getParameterTypes( method );
                    int parameterCount = parameterTypes.length;

                    if ( isGet && ( parameterCount == 1 ) && ( method.getReturnType() != Void.TYPE ) )
                    {
                        List<Method> pair = pairs.computeIfAbsent(propertyName, k -> new ArrayList<Method>());

                        pair.add( method );
                    }
                    if ( isSet && ( parameterCount == 2 ) && ( method.getReturnType() == Void.TYPE ) )
                    {
                        List<Method> pair = pairs.computeIfAbsent(propertyName, k -> new ArrayList<Method>());

                        pair.add( method );
                    }
                }
            }
        }

        for ( Map.Entry<String, List<Method>> entry : pairs.entrySet() )
        {
            String propertyName = entry.getKey();
            List<Method> methods = entry.getValue();

            if ( methods.size() == 2 )
            {
                Method method1 = methods.get( 0 ), method2 = methods.get( 1 ), setMethod =
                    ( method1.getParameterTypes().length == 2 ) ? method1 : method2, getMethod =
                    ( setMethod == method1 ) ? method2 : method1;
                Class<?> keyType = getMethod.getParameterTypes()[0], propertyType = getMethod.getReturnType();

                if ( keyType == setMethod.getParameterTypes()[0] && propertyType == setMethod.getParameterTypes()[1] )
                {
                    ObjectIndexedPropertyDescriptor propertyDescriptor;

                    try
                    {
                        propertyDescriptor =
                            new ObjectIndexedPropertyDescriptor( propertyName, propertyType, getMethod, setMethod );
                    }
                    catch ( Exception ex )
                    {
                        throw new OgnlException(
                            "creating object indexed property descriptor for '" + propertyName + "' in "
                                + targetClass, ex );
                    }
                    intoMap.put( propertyName, propertyDescriptor );
                }
            }
        }
    }