<commit_before>﻿//----------------------------------------------------------------------- 
// <copyright file="TypeExtensions.cs" company="Copacetic Software"> 
// Copyright (c) Copacetic Software.  
// <author><NAME></author> 
// <date>Monday, January 13, 2014 4:39:58 PM</date> 
// Licensed under the Apache License, Version 2.0,
// you may not use this file except in compliance with this 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.
// </copyright> 
//-----------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using CopaceticSoftware.Common.Extensions;
using CopaceticSoftware.Common.Infrastructure;
using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.CSharp.Refactoring;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
using JetBrains.Annotations;

namespace CopaceticSoftware.CodeGenerator.StarterKit.Extensions
{
    public static class TypeExtensions
    {
        public static AstType ToAstSyntaxType(this IType type)
        {
            Ensure.ArgumentNotNull(type, "type");

            return new TypeSystemAstBuilder().ConvertType(type);
        }

        /// <summary>
        /// "global::" + <see cref="GetOriginalFullName(ICSharpCode.NRefactory.TypeSystem.IType)"/>
        /// </summary>
        /// <param name="type">
        /// The type to work on.
        /// </param>
        /// <param name="rootDefinition">
        /// Optional parameter that is used to look up the <see cref="DefaultTypeParameter"/>
        /// </param>
        public static string GetOriginalFullNameWithGlobal(this IType type, IType rootDefinition = null)
        {
            if (type is VoidTypeDefinition)
                return "void";

            if (type is ParameterizedType)
                return
                    "global::" +
                    type.FullName +
                       "<" +
                       string.Join(
                            ",", 
                            (type as ParameterizedType).TypeArguments
                                .Select(x => x.GetOriginalFullNameWithGlobal(rootDefinition)))
                       + ">";


            var defaultTypeParam = type as DefaultTypeParameter;
            if (null != defaultTypeParam)
            {
                var rootDefinitionParamType = rootDefinition as ParameterizedType;

                if (null == rootDefinitionParamType || null == defaultTypeParam.Owner)
                    return type.Name;

                //Special handling for resolving the type of generic type parameters
                return rootDefinitionParamType.TypeArguments[defaultTypeParam.Index]
                    .GetOriginalFullNameWithGlobal(rootDefinition);
            }

            //Fall back case
            return "global::" + type.GetOriginalFullName();
        }

        /// <summary>
        /// Prints a generic type the way it would look in source code.
        /// Includes the namespace.
        /// </summary>
        /// <remarks>
        /// http://stackoverflow.com/questions/6402864/c-pretty-type-name-function
        /// </remarks>
        public static string GetOriginalFullName(this IType type)
        {
            Ensure.ArgumentNotNull(type, "type");

            if (type is VoidTypeDefinition)
                return "void";

            if (type is ArrayType)
            {
                var arrayType = type as ArrayType;

                return arrayType.ElementType.GetOriginalFullName() + arrayType.NameSuffix;
            }

            var astType = type.ToAstSyntaxType();
<commit_msg>Additional handling for Specialized Type Parameters<commit_after>﻿//----------------------------------------------------------------------- 
// <copyright file="TypeExtensions.cs" company="Copacetic Software"> 
// Copyright (c) Copacetic Software.  
// <author><NAME></author> 
// <date>Monday, January 13, 2014 4:39:58 PM</date> 
// Licensed under the Apache License, Version 2.0,
// you may not use this file except in compliance with this 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.
// </copyright> 
//-----------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using CopaceticSoftware.Common.Extensions;
using CopaceticSoftware.Common.Infrastructure;
using ICSharpCode.NRefactory.CSharp;
using ICSharpCode.NRefactory.CSharp.Refactoring;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
using JetBrains.Annotations;

namespace CopaceticSoftware.CodeGenerator.StarterKit.Extensions
{
    public static class TypeExtensions
    {
        public static AstType ToAstSyntaxType(this IType type)
        {
            Ensure.ArgumentNotNull(type, "type");

            return new TypeSystemAstBuilder().ConvertType(type);
        }

        /// <summary>
        /// "global::" + <see cref="GetOriginalFullName(ICSharpCode.NRefactory.TypeSystem.IType)"/>
        /// </summary>
        /// <param name="type">
        /// The type to work on.
        /// </param>
        /// <param name="rootDefinition">
        /// Optional parameter that is used to look up the <see cref="DefaultTypeParameter"/>
        /// </param>
        public static string GetOriginalFullNameWithGlobal(this IType type, IType rootDefinition = null)
        {
            if (type is VoidTypeDefinition)
                return "void";

            if (type is ParameterizedType)
                return
                    "global::" +
                    type.FullName +
                       "<" +
                       string.Join(
                            ",", 
                            (type as ParameterizedType).TypeArguments
                                .Select(x => x.GetOriginalFullNameWithGlobal(rootDefinition)))
                       + ">";


            var defaultTypeParam = type as DefaultTypeParameter;
            if (null != defaultTypeParam)
            {
                var rootDefinitionParamType = rootDefinition as ParameterizedType;

                if (null == rootDefinitionParamType || null == defaultTypeParam.Owner)
                    return type.Name;

                //Special handling for resolving the type of generic type parameters
                return rootDefinitionParamType.TypeArguments[defaultTypeParam.Index]
                    .GetOriginalFullNameWithGlobal(rootDefinition);
            }

            var specializedTypeParam = type as AbstractTypeParameter;
            if (null != specializedTypeParam)
            {
                return specializedTypeParam.Owner.DeclaringType.GetOriginalFullNameWithGlobal();
            }

            //Fall back case
            return "global::" + type.GetOriginalFullName();
        }

        /// <summary>
        /// Prints a generic type the way it would look in source code.
        /// Includes the namespace.
        /// </summary>
        /// <remarks>
        /// http://stackoverflow.com/questions/6402864/c-pretty-type-name-function
        /// </remarks>
        public static string GetOriginalFullName(this IType type)
        {
            Ensure.ArgumentNotNull(type, "type");

            if (type is VoidTypeDefinition)
                return "void";

            if (type is ArrayType)
            {
                var arrayType = type as ArrayType;

                return arrayType.ElementType.GetOriginalFullName() + arrayType.NameSuffix;
            }

            var astType = type.ToAstSyntaxType();

{'fraction_non_alphanumeric': 0.1257183908045977, 'fraction_numerical': 0.005268199233716475, 'mean_word_length': 1.8124579124579125, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 45, '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': '17812', 'n_tokens_mistral': 2065, 'n_tokens_neox': 1937, 'n_words': 561}