<commit_before>/*
 * Copyright 2014 the original author or authors.
 *
 * 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.gradle.model.internal.manage.schema;

import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.lang.StringUtils;
import org.gradle.model.internal.core.ModelType;

import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.*;

public class ModelSchemaExtractor {

    public <T> ModelSchema<T> extract(Class<T> type) throws InvalidManagedModelElementTypeException {
        validateType(type);

        List<Method> methodList = Arrays.asList(type.getDeclaredMethods());
        if (methodList.isEmpty()) {
            return new ModelSchema<T>(type, Collections.<ModelProperty<?>>emptyList());
        }

        List<ModelProperty<?>> properties = Lists.newLinkedList();

        Map<String, Method> methods = Maps.newHashMap();
        for (Method method : methodList) {
            String name = method.getName();
            if (methods.containsKey(name)) {
                throw invalidMethod(type, name, "overloaded methods are not supported");
            }
            methods.put(name, method);
        }

        List<String> methodNames = Lists.newLinkedList(methods.keySet());
        List<String> handled = Lists.newArrayList();

        for (ListIterator<String> iterator = methodNames.listIterator(); iterator.hasNext();) {
            String methodName = iterator.next();

            Method method = methods.get(methodName);
            if (methodName.startsWith("get") && !methodName.equals("get")) {
                if (method.getParameterCount() != 0) {
                    throw invalidMethod(type, methodName, "getter methods cannot take parameters");
                }

                Class<?> returnType = method.getReturnType();
                if (!returnType.equals(String.class)) {
                    throw invalidMethod(type, methodName, "only String properties are supported");
                }

                // hardcoded for now
                ModelType<String> propertyType = ModelType.of(String.class);

                Character getterPropertyNameFirstChar = methodName.charAt(3);
                if (!Character.isUpperCase(getterPropertyNameFirstChar)) {
                    throw invalidMethod(type, methodName, "the 4th character of the getter method name must be an uppercase character");
                }
<commit_msg>Remove JDK 8 usage.<commit_after>/*
 * Copyright 2014 the original author or authors.
 *
 * 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.gradle.model.internal.manage.schema;

import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.lang.StringUtils;
import org.gradle.model.internal.core.ModelType;

import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.*;

public class ModelSchemaExtractor {

    public <T> ModelSchema<T> extract(Class<T> type) throws InvalidManagedModelElementTypeException {
        validateType(type);

        List<Method> methodList = Arrays.asList(type.getDeclaredMethods());
        if (methodList.isEmpty()) {
            return new ModelSchema<T>(type, Collections.<ModelProperty<?>>emptyList());
        }

        List<ModelProperty<?>> properties = Lists.newLinkedList();

        Map<String, Method> methods = Maps.newHashMap();
        for (Method method : methodList) {
            String name = method.getName();
            if (methods.containsKey(name)) {
                throw invalidMethod(type, name, "overloaded methods are not supported");
            }
            methods.put(name, method);
        }

        List<String> methodNames = Lists.newLinkedList(methods.keySet());
        List<String> handled = Lists.newArrayList();

        for (ListIterator<String> iterator = methodNames.listIterator(); iterator.hasNext();) {
            String methodName = iterator.next();

            Method method = methods.get(methodName);
            if (methodName.startsWith("get") && !methodName.equals("get")) {
                if (method.getParameterTypes().length != 0) {
                    throw invalidMethod(type, methodName, "getter methods cannot take parameters");
                }

                Class<?> returnType = method.getReturnType();
                if (!returnType.equals(String.class)) {
                    throw invalidMethod(type, methodName, "only String properties are supported");
                }

                // hardcoded for now
                ModelType<String> propertyType = ModelType.of(String.class);

                Character getterPropertyNameFirstChar = methodName.charAt(3);
                if (!Character.isUpperCase(getterPropertyNameFirstChar)) {
                    throw invalidMethod(type, methodName, "the 4th character of the getter method name must be an uppercase character");
                }

{'fraction_non_alphanumeric': 0.10190239867659223, 'fraction_numerical': 0.00380479735318445, 'mean_word_length': 2.759950248756219, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, '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': '6894746', 'n_tokens_mistral': 1560, 'n_tokens_neox': 1489, 'n_words': 447}