示例#1
0
        // Return a context object for the item being searched for, or null if the element isn't interesting.
        // CanContainReferences isn't called if we return null. Do the work once here, then use it multiple times for
        // each file in CanContainReferences
        public object GetElementId(IDeclaredElement element)
        {
            if (!UnityYamlUsageSearchFactory.IsInterestingElement(element))
            {
                return(null);
            }

            var set = new JetHashSet <IPsiSourceFile>();

            switch (element)
            {
            case IClass scriptClass:
                AddFilesWithPossibleScriptUsages(scriptClass, set);
                break;

            case IProperty _:
            case IMethod _:
                foreach (var file in myAnimationEventUsagesContainer.GetPossibleFilesWithUsage(element))
                {
                    set.Add(file);
                }
                foreach (var sourceFile in myUnityEventsElementContainer.GetPossibleFilesWithUsage(element))
                {
                    set.Add(sourceFile);
                }
                break;

            case IField field:
                if (field.Type.GetTypeElement().DerivesFromUnityEvent())
                {
                    foreach (var sourceFile in myUnityEventsElementContainer.GetPossibleFilesWithUsage(element))
                    {
                        set.Add(sourceFile);
                    }
                }
                else
                {
                    foreach (var sourceFile in myInspectorValuesContainer.GetPossibleFilesWithUsage(field))
                    {
                        set.Add(sourceFile);
                    }
                }

                break;
            }

            return(new UnityYamlSearchGuruId(set));
        }
示例#2
0
        // Return a context object for the item being searched for, or null if the element isn't interesting.
        // CanContainReferences isn't called if we return null. Do the work once here, then use it multiple times for
        // each file in CanContainReferences
        public object GetElementId(IDeclaredElement element)
        {
            if (!UnityYamlUsageSearchFactory.IsInterestingElement(element))
            {
                return(null);
            }

            var set = new JetHashSet <IPsiSourceFile>();

            switch (element)
            {
            case IClass _class:
                foreach (var sourceFile in myAssetScriptUsagesElementContainer.GetPossibleFilesWithUsage(_class))
                {
                    set.Add(sourceFile);
                }
                break;

            case IProperty _:
            case IMethod _:
                foreach (var sourceFile in myUnityEventsElementContainer.GetPossibleFilesWithUsage(element))
                {
                    set.Add(sourceFile);
                }
                break;

            case IField field:
                if (UnityApi.IsDescendantOfUnityEvent(field.Type.GetTypeElement()))
                {
                    foreach (var sourceFile in myUnityEventsElementContainer.GetPossibleFilesWithUsage(element))
                    {
                        set.Add(sourceFile);
                    }
                }
                else
                {
                    foreach (var sourceFile in myInspectorValuesContainer.GetPossibleFilesWithUsage(field))
                    {
                        set.Add(sourceFile);
                    }
                }

                break;
            }

            return(new UnityYamlSearchGuruId(set));
        }