<commit_before>﻿using System.Collections.Generic;
using JetBrains.Annotations;
using JetBrains.Metadata.Utils;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Plugins.Unity.ProjectModel.Properties.Flavours;
using JetBrains.Util.Reflection;

namespace JetBrains.ReSharper.Plugins.Unity
{
    public static class ProjectExtensions
    {
        private static readonly AssemblyNameInfo ourUnityEngineReferenceName = AssemblyNameInfoFactory.Create2("UnityEngine", null);
        private static readonly AssemblyNameInfo ourUnityEditorReferenceName = AssemblyNameInfoFactory.Create2("UnityEditor", null);

        public static readonly ICollection<AssemblyNameInfo> UnityReferenceNames = new List<AssemblyNameInfo>()
        {
            ourUnityEditorReferenceName, ourUnityEngineReferenceName
        };

        public static bool IsUnityProject([CanBeNull] this IProject project)
        {
            // Only VSTU adds the Unity project flavour. Unity + Rider don't, so we have to look at references
            return project != null && (project.HasFlavour<UnityProjectFlavor>() || ReferencesUnity(project));
        }

        public static bool IsProjectCompiledByUnity([CanBeNull] this IProject project)
        {
            return project != null && project.HasSubItems("Assets") && IsUnityProject(project);
        }

        private static bool ReferencesUnity(IProject project)
        {
            return ReferencesAssembly(project, ourUnityEngineReferenceName) ||
                   ReferencesAssembly(project, ourUnityEditorReferenceName);
        }

        private static bool ReferencesAssembly(IProject project, AssemblyNameInfo name)
        {
            AssemblyNameInfo info;
            return ReferencedAssembliesService.IsProjectReferencingAssemblyByName(project,
                project.GetCurrentTargetFrameworkId(), name, out info);
        }
    }
}<commit_msg>Recognise Unity 2017.3 module references<commit_after>﻿using System.Collections.Generic;
using JetBrains.Annotations;
using JetBrains.Metadata.Utils;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Plugins.Unity.ProjectModel.Properties.Flavours;
using JetBrains.Util.Reflection;

namespace JetBrains.ReSharper.Plugins.Unity
{
    public static class ProjectExtensions
    {
        private static readonly AssemblyNameInfo ourUnityEngineReferenceName = AssemblyNameInfoFactory.Create2("UnityEngine", null);
        private static readonly AssemblyNameInfo ourUnityEditorReferenceName = AssemblyNameInfoFactory.Create2("UnityEditor", null);

        // Unity 2017.3 has refactored UnityEngine into modules. Generated projects will still
        // reference UnityEngine.dll as well as the new module assemblies. But non-generated
        // projects (with output copied to Assets) can now reference the modules. Transitive
        // dependencies mean that these projects will reference either UnityEngine.CoreModule or
        // UnityEngine.SharedInternalsModule. Best practice is still to reference UnityEngine.dll,
        // but we need to cater for all sorts of projects.
        private static readonly AssemblyNameInfo ourUnityEngineCoreModuleReferenceName = AssemblyNameInfoFactory.Create2("UnityEngine.CoreModule", null);
        private static readonly AssemblyNameInfo ourUnityEngineSharedInternalsModuleReferenceName = AssemblyNameInfoFactory.Create2("UnityEngine.SharedInternalsModule", null);

        public static readonly ICollection<AssemblyNameInfo> UnityReferenceNames = new List<AssemblyNameInfo>()
        {
            ourUnityEditorReferenceName, ourUnityEngineReferenceName, ourUnityEngineCoreModuleReferenceName, ourUnityEngineSharedInternalsModuleReferenceName
        };

        public static bool IsUnityProject([CanBeNull] this IProject project)
        {
            // Only VSTU adds the Unity project flavour. Unity + Rider don't, so we have to look at references
            return project != null && (project.HasFlavour<UnityProjectFlavor>() || ReferencesUnity(project));
        }

        public static bool IsProjectCompiledByUnity([CanBeNull] this IProject project)
        {
            return project != null && project.HasSubItems("Assets") && IsUnityProject(project);
        }

        private static bool ReferencesUnity(IProject project)
        {
            return ReferencesAssembly(project, ourUnityEngineReferenceName)
                   || ReferencesAssembly(project, ourUnityEditorReferenceName)
                   || ReferencesAssembly(project, ourUnityEngineCoreModuleReferenceName)
                   || ReferencesAssembly(project, ourUnityEngineSharedInternalsModuleReferenceName);
        }

        private static bool ReferencesAssembly(IProject project, AssemblyNameInfo name)
        {
            return ReferencedAssembliesService.IsProjectReferencingAssemblyByName(project,
                project.GetCurrentTargetFrameworkId(), name, out var _);
        }
    }
}
{'fraction_non_alphanumeric': 0.06601863102470636, 'fraction_numerical': 0.0032401782098015392, 'mean_word_length': 3.5858867223769733, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5904378', 'n_tokens_mistral': 1185, 'n_tokens_neox': 1123, 'n_words': 298}