<commit_before>package com.mistraltech.smog.core;

import org.hamcrest.Description;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ReflectingPropertyMatcher<T> extends PropertyMatcher<T> {

    public ReflectingPropertyMatcher(String propertyName, PropertyMatcherRegistry registry) {
        super(propertyName, registry);
    }

    public ReflectingPropertyMatcher(String propertyName, PropertyMatcherRegistry registry, PathProvider pathProvider) {
        super(propertyName, registry, pathProvider);
    }

    @Override
    public boolean matches(Object item) {
        return !super.isSpecified() || super.matches(getPropertyValue(item));
    }

    @Override
    public void describeMismatch(Object item, Description mismatchDescription) {
        super.describeMismatch(getPropertyValue(item), mismatchDescription);
    }

    private Object getPropertyValue(Object item) {
        PropertyDescriptor property = getPropertyDescriptor(getPropertyName(), item);

        final Method readMethod = property.getReadMethod();

        try {
            return readMethod.invoke(item);
        } catch (IllegalAccessException e) {
            throw new PropertyUnreadableException(item.getClass(), readMethod, getPropertyName(), e);
        } catch (InvocationTargetException e) {
            throw new PropertyUnreadableException(item.getClass(), readMethod, getPropertyName(), e);
        }
    }

    private PropertyDescriptor getPropertyDescriptor(String propertyName, Object item) {
        try {
            final BeanInfo beanInfo = Introspector.getBeanInfo(item.getClass(), null);
            final PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
            for (PropertyDescriptor property : propertyDescriptors) {
                if (property.getName().equals(propertyName)) {
                    return property;
                }
            }
        } catch (IntrospectionException e) {
            throw new IllegalArgumentException("Could not get property descriptors for " + item.getClass(), e);
        }

        throw new PropertyNotFoundException(item.getClass(), getPropertyName());
    }
}

<commit_msg>Minor refactoring of private implementation of ReflectingPropertyMatcher.<commit_after>package com.mistraltech.smog.core;

import org.hamcrest.Description;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ReflectingPropertyMatcher<T> extends PropertyMatcher<T> {

    public ReflectingPropertyMatcher(String propertyName, PropertyMatcherRegistry registry) {
        super(propertyName, registry);
    }

    public ReflectingPropertyMatcher(String propertyName, PropertyMatcherRegistry registry, PathProvider pathProvider) {
        super(propertyName, registry, pathProvider);
    }

    @Override
    public boolean matches(Object item) {
        return !super.isSpecified() || super.matches(getPropertyValue(item));
    }

    @Override
    public void describeMismatch(Object item, Description mismatchDescription) {
        super.describeMismatch(getPropertyValue(item), mismatchDescription);
    }

    private Object getPropertyValue(Object item) {
        PropertyDescriptor property = getPropertyDescriptor(getPropertyName(), item.getClass());

        final Method readMethod = property.getReadMethod();

        try {
            return readMethod.invoke(item);
        } catch (IllegalAccessException e) {
            throw new PropertyUnreadableException(item.getClass(), readMethod, getPropertyName(), e);
        } catch (InvocationTargetException e) {
            throw new PropertyUnreadableException(item.getClass(), readMethod, getPropertyName(), e);
        }
    }

    private static PropertyDescriptor getPropertyDescriptor(String propertyName, Class clazz) {
        try {
            final BeanInfo beanInfo = Introspector.getBeanInfo(clazz, null);
            final PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
            for (PropertyDescriptor property : propertyDescriptors) {
                if (property.getName().equals(propertyName)) {
                    return property;
                }
            }
        } catch (IntrospectionException e) {
            throw new IllegalArgumentException("Could not get property descriptors for " + clazz, e);
        }

        throw new PropertyNotFoundException(clazz, propertyName);
    }
}


{'fraction_non_alphanumeric': 0.08275426405559065, 'fraction_numerical': 0.0, 'mean_word_length': 3.476908576814326, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5045331', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1126, 'n_words': 265}