<commit_before>using System;
using JetBrains.Annotations;
using JetBrains.Diagnostics;
using JetBrains.ReSharper.Plugins.Unity.Yaml.Psi.DeferredCaches.AssetHierarchy.References;
using JetBrains.ReSharper.Plugins.Yaml.Psi;
using JetBrains.ReSharper.Plugins.Yaml.Psi.Tree;
using JetBrains.ReSharper.Psi;

namespace JetBrains.ReSharper.Plugins.Unity.Yaml.Psi
{
    public static class UnityYamlPsiExtensions
    {
        [CanBeNull]
        public static string AsString([CanBeNull] this INode node)
        {
            return node?.GetPlainScalarText();
        }

        [CanBeNull]
        public static IHierarchyReference ToHierarchyReference([CanBeNull] this INode node, [NotNull] IPsiSourceFile assetSourceFile)
        {
            var (anchor, guid) = node.ExtractAnchorAndGuid();
            if (anchor is null || anchor == 0) return LocalReference.Null;
            if (guid != null) return new ExternalReference(guid.Value, anchor.Value);
            var persistentIndex = assetSourceFile
                .PsiStorage
                .PersistentIndex
                .NotNull("owningPsiPersistentIndex != null");
            return new LocalReference(persistentIndex, anchor.Value);
        }
        
        public static (long?, Guid?) ExtractAnchorAndGuid([CanBeNull] this INode node)
        {
            if (!(node is IFlowMappingNode flowMappingNode)) return (null, null);
            var anchor = flowMappingNode.FindMapEntryBySimpleKey("fileID")?.Value.AsString();
            if (anchor == null || !long.TryParse(anchor, out var result)) return (null, null);
            if (result == 0) return (0, null);
            var scriptGuid = flowMappingNode.FindMapEntryBySimpleKey("guid")?.Value.AsString();
            if (scriptGuid == null || !Guid.TryParse(scriptGuid, out var guid)) return (result, null);
            return (result, guid);

        }

        // This will open the Body chameleon
        [CanBeNull]
        public static INode GetUnityObjectPropertyValue([CanBeNull] this IYamlDocument document, [NotNull] string key)
        {
            return FindRootBlockMapEntries(document).FindMapEntryBySimpleKey(key)?.Content.Value;
        }

        // This will open the Body chameleon
        [CanBeNull]
        public static IBlockMappingNode FindRootBlockMapEntries([CanBeNull] this IYamlDocument document)
        {
            // A YAML document is a block mapping node with a single entry. The key is usually the type of the object,
            // while the value is another block mapping node. Those entries are the properties of the Unity object
            var rootBlockMappingNode = document?.Body.BlockNode as IBlockMappingNode;
            return rootBlockMappingNode?.EntriesEnumerable.FirstOrDefault()?.Content.Value as IBlockMappingNode;
        }

        public static INode GetValue(this IBlockMappingNode document, string key)
        {
            return document?.Entries.FirstOrDefault(t => t.Key.MatchesPlainScalarText(key))?.Content?.Value;
        }
    }
}<commit_msg>clean up: drop annotation<commit_after>using System;
using JetBrains.Annotations;
using JetBrains.Diagnostics;
using JetBrains.ReSharper.Plugins.Unity.Yaml.Psi.DeferredCaches.AssetHierarchy.References;
using JetBrains.ReSharper.Plugins.Yaml.Psi;
using JetBrains.ReSharper.Plugins.Yaml.Psi.Tree;
using JetBrains.ReSharper.Psi;

namespace JetBrains.ReSharper.Plugins.Unity.Yaml.Psi
{
    public static class UnityYamlPsiExtensions
    {
        [CanBeNull]
        public static string AsString([CanBeNull] this INode node)
        {
            return node?.GetPlainScalarText();
        }

        [CanBeNull]
        public static IHierarchyReference ToHierarchyReference([CanBeNull] this INode node, IPsiSourceFile assetSourceFile)
        {
            var (anchor, guid) = node.ExtractAnchorAndGuid();
            if (anchor is null || anchor == 0) return LocalReference.Null;
            if (guid != null) return new ExternalReference(guid.Value, anchor.Value);
            var persistentIndex = assetSourceFile
                .PsiStorage
                .PersistentIndex
                .NotNull("owningPsiPersistentIndex != null");
            return new LocalReference(persistentIndex, anchor.Value);
        }
        
        public static (long?, Guid?) ExtractAnchorAndGuid([CanBeNull] this INode node)
        {
            if (!(node is IFlowMappingNode flowMappingNode)) return (null, null);
            var anchor = flowMappingNode.FindMapEntryBySimpleKey("fileID")?.Value.AsString();
            if (anchor == null || !long.TryParse(anchor, out var result)) return (null, null);
            if (result == 0) return (0, null);
            var scriptGuid = flowMappingNode.FindMapEntryBySimpleKey("guid")?.Value.AsString();
            if (scriptGuid == null || !Guid.TryParse(scriptGuid, out var guid)) return (result, null);
            return (result, guid);

        }

        // This will open the Body chameleon
        [CanBeNull]
        public static INode GetUnityObjectPropertyValue([CanBeNull] this IYamlDocument document, [NotNull] string key)
        {
            return FindRootBlockMapEntries(document).FindMapEntryBySimpleKey(key)?.Content.Value;
        }

        // This will open the Body chameleon
        [CanBeNull]
        public static IBlockMappingNode FindRootBlockMapEntries([CanBeNull] this IYamlDocument document)
        {
            // A YAML document is a block mapping node with a single entry. The key is usually the type of the object,
            // while the value is another block mapping node. Those entries are the properties of the Unity object
            var rootBlockMappingNode = document?.Body.BlockNode as IBlockMappingNode;
            return rootBlockMappingNode?.EntriesEnumerable.FirstOrDefault()?.Content.Value as IBlockMappingNode;
        }

        public static INode GetValue(this IBlockMappingNode document, string key)
        {
            return document?.Entries.FirstOrDefault(t => t.Key.MatchesPlainScalarText(key))?.Content?.Value;
        }
    }
}
{'fraction_non_alphanumeric': 0.08750823994726434, 'fraction_numerical': 0.000988793671720501, 'mean_word_length': 2.7393715341959335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2768732', 'n_tokens_mistral': 1649, 'n_tokens_neox': 1608, 'n_words': 428}