<commit_before>/*
 * Copyright (c) 2008 Mysema Ltd.
 * All rights reserved.
 * 
 */
package com.mysema.query.apt.util;

import java.util.Iterator;
import java.util.Locale;

import com.mysema.query.apt.Field;
import com.sun.mirror.type.*;
import com.sun.mirror.util.SimpleTypeVisitor;

/**
 * TypeInfo represents a single type
 * 
 * @author tiwe
 * @version $Id$
 */
public class TypeInfo {

    private Field.Type fieldType;

    private String simpleName, fullName, keyTypeName;

    private final TypeInfoVisitor visitor = new TypeInfoVisitor();

    public TypeInfo(TypeMirror type) {
        type.accept(visitor);
        if (fieldType == null) {
            fieldType = Field.Type.ENTITY;
        }
        if (fullName == null) {
            fullName = type.toString();
        }
        if (simpleName == null) {
            simpleName = fullName.substring(fullName.lastIndexOf('.') + 1);
        }
    }

    public Field.Type getFieldType() {
        return fieldType;
    }

    public String getFullName() {
        return fullName;
    }

    public String getKeyTypeName() {
        return keyTypeName;
    }

    public String getSimpleName() {
        return simpleName;
    }

    public String getValueTypeName() {
        return fullName;
    }

    public String toString() {
        return fullName;
    }

    private class TypeInfoVisitor extends SimpleTypeVisitor {
        public void visitAnnotationType(AnnotationType arg0) {
            //            
        }

        public void visitArrayType(ArrayType arg0) {
            TypeInfo valueInfo = new TypeInfo(arg0.getComponentType());
            fullName = valueInfo.getFullName();
            if (valueInfo.fieldType == Field.Type.ENTITY) {
                fieldType = Field.Type.ENTITYCOLLECTION;
            } else {
                fieldType = Field.Type.SIMPLECOLLECTION;
            }
        }

        public void visitClassType(ClassType arg0){
            try {
                fullName = arg0.toString();
                if (fullName.equals(String.class.getName())) {
                    fieldType = Field.Type.STRING;
                } else if (fullName.equals(Boolean.class.getName())) {
                    fieldType = Field.Type.BOOLEAN;
                } else if (fullName.equals(Locale.class.getName())) {
                    fieldType = Field.Type.SIMPLE;
                } else if (fullName.startsWith("java") && Number.class.isAssignableFrom(Class.forName(fullName))) {
                    fieldType = Field.Type.NUMERIC;
                } else if (fullName.startsWith("java") && Comparable.class.isAssignableFrom(Class.forName(fullName))) {
                    fieldType = Field.Type.COMPARABLE;
                }    
            }catch(Exception e){
                throw new RuntimeException("error", e);
            }            
        }

        public void visitEnumType(EnumType arg0) {
            fieldType = Field.Type.SIMPLE;
        }

        public void visitInterfaceType(InterfaceType arg0) {
            Iterator<TypeMirror> i = arg0.getActualTypeArguments().iterator();
            String typeName = arg0.toString();
            if (arg0.getActualTypeArguments().size() > 0) {
                typeName = typeName.substring(0, typeName.indexOf('<'));
            }

            if (typeName.equals(java.util.Map.class.getName())) {
                TypeInfo keyInfo = new TypeInfo(i.next());
                keyTypeName = keyInfo.getFullName();
                TypeInfo valueInfo = new TypeInfo(i.next());
                fullName = valueInfo.getFullName();
                if (valueInfo.fieldType == Field.Type.ENTITY) {
                    fieldType = Field.Type.ENTITYMAP;
                } else {
                    fieldType = Field.Type.SIMPLEMAP;
                }

            } else if (typeName.equals(java.util.Collection.class.getName())
                    || typeName.equals(java.util.Set.class.getName())) {
                TypeInfo valueInfo = new TypeInfo(i.next());
                fullName = valueInfo.getFullName();
                if (valueInfo.fieldType == Field.Type.ENTITY) {
                    fieldType = Field.Type.ENTITYCOLLECTION;
                } else {<commit_msg>fixed generic signature issues for field types<commit_after>/*
 * Copyright (c) 2008 Mysema Ltd.
 * All rights reserved.
 * 
 */
package com.mysema.query.apt.util;

import java.util.Iterator;
import java.util.Locale;

import com.mysema.query.apt.Field;
import com.sun.mirror.type.*;
import com.sun.mirror.util.SimpleTypeVisitor;

/**
 * TypeInfo represents a single type
 * 
 * @author tiwe
 * @version $Id$
 */
public class TypeInfo {

    private Field.Type fieldType;

    private String simpleName, fullName, keyTypeName;

    private final TypeInfoVisitor visitor = new TypeInfoVisitor();

    public TypeInfo(TypeMirror type) {
        type.accept(visitor);
        if (fieldType == null) {
            fieldType = Field.Type.ENTITY;
        }
        if (fullName == null) {
            fullName = type.toString();
        }
        if (simpleName == null) {
            simpleName = fullName.substring(fullName.lastIndexOf('.') + 1);
        }
    }

    public Field.Type getFieldType() {
        return fieldType;
    }

    public String getFullName() {
        return fullName;
    }

    public String getKeyTypeName() {
        return keyTypeName;
    }

    public String getSimpleName() {
        return simpleName;
    }

    public String getValueTypeName() {
        return fullName;
    }

    public String toString() {
        return fullName;
    }

    private class TypeInfoVisitor extends SimpleTypeVisitor {
        public void visitAnnotationType(AnnotationType arg0) {
            //            
        }

        public void visitArrayType(ArrayType arg0) {
            TypeInfo valueInfo = new TypeInfo(arg0.getComponentType());
            fullName = valueInfo.getFullName();
            if (valueInfo.fieldType == Field.Type.ENTITY) {
                fieldType = Field.Type.ENTITYCOLLECTION;
            } else {
                fieldType = Field.Type.SIMPLECOLLECTION;
            }
        }

        public void visitClassType(ClassType arg0){
            try {                
                fullName = arg0.getDeclaration().getQualifiedName();
                if (fullName.equals(String.class.getName())) {
                    fieldType = Field.Type.STRING;
                } else if (fullName.equals(Boolean.class.getName())) {
                    fieldType = Field.Type.BOOLEAN;
                } else if (fullName.equals(Locale.class.getName())) {
                    fieldType = Field.Type.SIMPLE;
                } else if (fullName.startsWith("java") && Number.class.isAssignableFrom(Class.forName(fullName))) {
                    fieldType = Field.Type.NUMERIC;
                } else if (fullName.startsWith("java") && Comparable.class.isAssignableFrom(Class.forName(fullName))) {
                    fieldType = Field.Type.COMPARABLE;
                }    
            }catch(Exception e){
                throw new RuntimeException("error", e);
            }            
        }

        public void visitEnumType(EnumType arg0) {
            fieldType = Field.Type.SIMPLE;
        }

        public void visitInterfaceType(InterfaceType arg0) {
            Iterator<TypeMirror> i = arg0.getActualTypeArguments().iterator();
            String typeName = arg0.getDeclaration().getQualifiedName();

            if (typeName.equals(java.util.Map.class.getName())) {
                TypeInfo keyInfo = new TypeInfo(i.next());
                keyTypeName = keyInfo.getFullName();
                TypeInfo valueInfo = new TypeInfo(i.next());
                fullName = valueInfo.getFullName();
                if (valueInfo.fieldType == Field.Type.ENTITY) {
                    fieldType = Field.Type.ENTITYMAP;
                } else {
                    fieldType = Field.Type.SIMPLEMAP;
                }

            } else if (typeName.equals(java.util.Collection.class.getName())
                    || typeName.equals(java.util.Set.class.getName())) {
                TypeInfo valueInfo = new TypeInfo(i.next());
                fullName = valueInfo.getFullName();
                if (valueInfo.fieldType == Field.Type.ENTITY) {
                    fieldType = Field.Type.ENTITYCOLLECTION;
                } else {
{'fraction_non_alphanumeric': 0.10479256080114449, 'fraction_numerical': 0.0036957558416785886, 'mean_word_length': 1.8010016694490818, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '2143350', 'n_tokens_mistral': 2323, 'n_tokens_neox': 2207, 'n_words': 446}