<commit_before>/*
   Copyright 2009-2012 <NAME>

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

package org.dynalang.dynalink.beans;

import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

class StaticClassIntrospector extends FacetIntrospector {
    private final Method[] methods;
    StaticClassIntrospector(Class<?> clazz) {
        super(clazz);
        methods = new AccessibleMethodsLookup(clazz, false).getMethods();
    }

    @Override
    Collection<PropertyDescriptor> getProperties() {
        // Discover getXxx()/isXxx() methods as property getters. Don't deal separately with property setters, as
        // AbstractJavaLinker will construct them directly from the setXxx() methods returned from the getMethods()
        // call.
        final Map<String, PropertyDescriptor> descs = new HashMap<String, PropertyDescriptor>();
        for(Method method: methods) {
            if(method.isBridge() || method.isSynthetic()) {
                continue;
            }
            if(method.getReturnType() == Void.TYPE) {
                continue;
            }
            final String name = method.getName();
            if(name.startsWith("get") && name.length() > 3 && method.getParameterTypes().length == 0) {
                addPropertyDescriptor(descs, method, Introspector.decapitalize(name.substring(3)));
            } else if(name.startsWith("is") && name.length() > 2 && method.getParameterTypes().length == 0) {
                addPropertyDescriptor(descs, method, Introspector.decapitalize(name.substring(3)));
            }
        }
        return descs.values();
    }

    private static void addPropertyDescriptor(Map<String, PropertyDescriptor> descs, Method method, String name) {
        if(!descs.containsKey(name)) {
            try {
                descs.put(name, new PropertyDescriptor(name, method, null));
            } catch(IntrospectionException e) {
                throw new UndeclaredThrowableException(e);
            }
        }

    }

    @Override
    boolean includeField(Field field) {
        return Modifier.isStatic(field.getModifiers());
    }
<commit_msg>No need to use UndeclaredThrowableException<commit_after>/*
   Copyright 2009-2012 <NAME>

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

package org.dynalang.dynalink.beans;

import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

class StaticClassIntrospector extends FacetIntrospector {
    private final Method[] methods;
    StaticClassIntrospector(Class<?> clazz) {
        super(clazz);
        methods = new AccessibleMethodsLookup(clazz, false).getMethods();
    }

    @Override
    Collection<PropertyDescriptor> getProperties() {
        // Discover getXxx()/isXxx() methods as property getters. Don't deal separately with property setters, as
        // AbstractJavaLinker will construct them directly from the setXxx() methods returned from the getMethods()
        // call.
        final Map<String, PropertyDescriptor> descs = new HashMap<String, PropertyDescriptor>();
        for(Method method: methods) {
            if(method.isBridge() || method.isSynthetic()) {
                continue;
            }
            if(method.getReturnType() == Void.TYPE) {
                continue;
            }
            final String name = method.getName();
            if(name.startsWith("get") && name.length() > 3 && method.getParameterTypes().length == 0) {
                addPropertyDescriptor(descs, method, Introspector.decapitalize(name.substring(3)));
            } else if(name.startsWith("is") && name.length() > 2 && method.getParameterTypes().length == 0) {
                addPropertyDescriptor(descs, method, Introspector.decapitalize(name.substring(3)));
            }
        }
        return descs.values();
    }

    private static void addPropertyDescriptor(Map<String, PropertyDescriptor> descs, Method method, String name) {
        if(!descs.containsKey(name)) {
            try {
                descs.put(name, new PropertyDescriptor(name, method, null));
            } catch(IntrospectionException e) {
                throw new RuntimeException(e);
            }
        }

    }

    @Override
    boolean includeField(Field field) {
        return Modifier.isStatic(field.getModifiers());
    }

{'fraction_non_alphanumeric': 0.09741648839888102, 'fraction_numerical': 0.0059239756458779, 'mean_word_length': 2.9777486910994764, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4556675', 'n_tokens_mistral': 1644, 'n_tokens_neox': 1576, 'n_words': 450}