<commit_before>/*
 * Licensed to ObjectStyle LLC under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ObjectStyle LLC licenses
 * this file to you 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 io.bootique.meta.config;

import com.fasterxml.jackson.annotation.JsonTypeName;
import io.bootique.annotation.BQConfig;
import io.bootique.annotation.BQConfigProperty;
import io.bootique.help.ValueObjectDescriptor;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;

/**
 * A thread-safe caching compiler of configuration metadata for objects annotated with {@link BQConfig} and
 * {@link BQConfigProperty}.
 */
public class ConfigMetadataCompiler {

    private static final Pattern SETTER = Pattern.compile("^set([A-Z].*)$");

    private Function<Class<?>, Stream<Class<?>>> subclassProvider;
    private Map<Type, ConfigObjectMetadata> seen;
    private Map<Class<?>, ValueObjectDescriptor> descriptorMap;

    /**
     * @deprecated since 1.0.RC1 use {@link #ConfigMetadataCompiler(Function, Map)}
     */
    @Deprecated
    public ConfigMetadataCompiler(Function<Class<?>, Stream<Class<?>>> subclassProvider) {
        this.subclassProvider = subclassProvider;
        this.seen = new ConcurrentHashMap<>();
        this.descriptorMap = Collections.emptyMap();
    }

    public ConfigMetadataCompiler(Function<Class<?>, Stream<Class<?>>> subclassProvider, Map<Class<?>, ValueObjectDescriptor> descriptorMap) {
        this.subclassProvider = subclassProvider;
        this.seen = new ConcurrentHashMap<>();
        this.descriptorMap = descriptorMap;
    }

    private static Type propertyTypeFromSetter(Method maybeSetter) {
        Type[] paramTypes = maybeSetter.getGenericParameterTypes();
        if (paramTypes.length != 1) {
            throw new IllegalStateException("Method '" + maybeSetter.getDeclaringClass().getName() + "."
                    + maybeSetter.getName() +
                    "' is annotated with @BQConfigProperty, but does not match expected setter signature."
                    + " It must take exactly one parameter");
        }

        return paramTypes[0];
    }<commit_msg>removing API deprecated back in 1.x<commit_after>/*
 * Licensed to ObjectStyle LLC under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ObjectStyle LLC licenses
 * this file to you 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 io.bootique.meta.config;

import com.fasterxml.jackson.annotation.JsonTypeName;
import io.bootique.annotation.BQConfig;
import io.bootique.annotation.BQConfigProperty;
import io.bootique.help.ValueObjectDescriptor;

import java.lang.reflect.*;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;

/**
 * A thread-safe caching compiler of configuration metadata for objects annotated with {@link BQConfig} and
 * {@link BQConfigProperty}.
 */
public class ConfigMetadataCompiler {

    private static final Pattern SETTER = Pattern.compile("^set([A-Z].*)$");

    private Function<Class<?>, Stream<Class<?>>> subclassProvider;
    private Map<Type, ConfigObjectMetadata> seen;
    private Map<Class<?>, ValueObjectDescriptor> descriptorMap;

    public ConfigMetadataCompiler(Function<Class<?>, Stream<Class<?>>> subclassProvider, Map<Class<?>, ValueObjectDescriptor> descriptorMap) {
        this.subclassProvider = subclassProvider;
        this.seen = new ConcurrentHashMap<>();
        this.descriptorMap = descriptorMap;
    }

    private static Type propertyTypeFromSetter(Method maybeSetter) {
        Type[] paramTypes = maybeSetter.getGenericParameterTypes();
        if (paramTypes.length != 1) {
            throw new IllegalStateException("Method '" + maybeSetter.getDeclaringClass().getName() + "."
                    + maybeSetter.getName() +
                    "' is annotated with @BQConfigProperty, but does not match expected setter signature."
                    + " It must take exactly one parameter");
        }

        return paramTypes[0];
    }
{'fraction_non_alphanumeric': 0.09632468211113046, 'fraction_numerical': 0.0027869709109911165, 'mean_word_length': 3.8702290076335877, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '6274319', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1422, 'n_words': 480}