<commit_before>/*
 * Copyright 2004-2009 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.compass.annotations.config.binding;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Collection;

import org.compass.annotations.Cascade;
import org.compass.annotations.Index;
import org.compass.annotations.ManagedId;
import org.compass.annotations.ManagedIdIndex;
import org.compass.annotations.OmitNorms;
import org.compass.annotations.OmitTf;
import org.compass.annotations.Reverse;
import org.compass.annotations.Store;
import org.compass.annotations.TermVector;
import org.compass.core.Property;
import org.compass.core.mapping.ExcludeFromAll;
import org.compass.core.mapping.ReverseType;

/**
 * @author kimchy
 */
public abstract class AnnotationsBindingUtils {

    public static String getCollectionParameterClassName(Class<?> clazz, Type type) {
        Class retVal = getCollectionParameterClass(clazz, type);
        if (retVal == null) {
            return null;
        }
        return retVal.getName();
    }

    public static Class getCollectionParameterClass(Class<?> clazz, Type type) {
        if (Collection.class.isAssignableFrom(clazz)) {
            if (type instanceof ParameterizedType) {
                ParameterizedType paramType = (ParameterizedType) type;
                Type[] actualTypeArguments = paramType.getActualTypeArguments();
                if (actualTypeArguments != null && actualTypeArguments.length == 1) {
                    return (Class) actualTypeArguments[0];
                }
            }
        }
        return null;
    }

    public static org.compass.core.mapping.osem.ManagedId convert(ManagedId managedId) throws IllegalArgumentException {
        if (managedId == ManagedId.NA) {
            return null;
        } else if (managedId == ManagedId.AUTO) {
            return org.compass.core.mapping.osem.ManagedId.AUTO;<commit_msg>CMP-912 Wrong handling of annotations on fields which are collections of parametrized type<commit_after>/*
 * Copyright 2004-2009 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.compass.annotations.config.binding;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Collection;

import org.compass.annotations.Cascade;
import org.compass.annotations.Index;
import org.compass.annotations.ManagedId;
import org.compass.annotations.ManagedIdIndex;
import org.compass.annotations.OmitNorms;
import org.compass.annotations.OmitTf;
import org.compass.annotations.Reverse;
import org.compass.annotations.Store;
import org.compass.annotations.TermVector;
import org.compass.core.Property;
import org.compass.core.mapping.ExcludeFromAll;
import org.compass.core.mapping.ReverseType;

/**
 * @author kimchy
 */
public abstract class AnnotationsBindingUtils {

    public static String getCollectionParameterClassName(Class<?> clazz, Type type) {
        Class retVal = getCollectionParameterClass(clazz, type);
        if (retVal == null) {
            return null;
        }
        return retVal.getName();
    }

    public static Class getCollectionParameterClass(Class<?> clazz, Type type) {
        if (Collection.class.isAssignableFrom(clazz)) {
            if (type instanceof ParameterizedType) {
                ParameterizedType paramType = (ParameterizedType) type;
                Type[] actualTypeArguments = paramType.getActualTypeArguments();
                if (actualTypeArguments != null && actualTypeArguments.length == 1) {
                    Type actualType = actualTypeArguments[0];
                    if (actualType instanceof Class) {
                        return (Class) actualTypeArguments[0];
                    } else if (actualType instanceof ParameterizedType) {
                        return (Class) ((ParameterizedType) actualType).getRawType();
                    }
                }
            }
        }
        return null;
    }

    public static org.compass.core.mapping.osem.ManagedId convert(ManagedId managedId) throws IllegalArgumentException {
        if (managedId == ManagedId.NA) {
            return null;
        } else if (managedId == ManagedId.AUTO) {
            return org.compass.core.mapping.osem.ManagedId.AUTO;
{'fraction_non_alphanumeric': 0.08675373134328358, 'fraction_numerical': 0.005970149253731343, 'mean_word_length': 3.0986238532110093, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '7490927', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1348, 'n_words': 407}