public bool ProcessProjectItem <TResult>(IPsiSourceFile sourceFile, IFindResultConsumer <TResult> consumer)
        {
            if (!myDeferredCacheController.CompletedOnce.Value)
            {
                return(false);
            }

            foreach (var element in myElements)
            {
                if (element is IMethod || element is IProperty)
                {
                    var usages = myAssetMethodsElementContainer.GetAssetUsagesFor(sourceFile, element);
                    foreach (var assetMethodData in usages)
                    {
                        var hierarchyElement = myAssetDocumentHierarchyElementContainer.GetHierarchyElement(assetMethodData.Location, false);
                        if (hierarchyElement != null)
                        {
                            consumer.Accept(new UnityMethodsFindResult(sourceFile, element, assetMethodData, hierarchyElement));
                        }
                    }
                }

                if (element is ITypeElement typeElement)
                {
                    var usages = myAssetUsagesElementContainer.GetAssetUsagesFor(sourceFile, typeElement);

                    foreach (var assetUsage in usages)
                    {
                        var hierarchyElement = myAssetDocumentHierarchyElementContainer.GetHierarchyElement(assetUsage.Location, false);
                        if (hierarchyElement == null)
                        {
                            continue;
                        }

                        consumer.Accept(new UnityScriptsFindResults(sourceFile, element, assetUsage, hierarchyElement));
                    }
                }

                if (element is IField field)
                {
                    var usages = myAssetInspectorValuesContainer.GetAssetUsagesFor(sourceFile, field);
                    foreach (var assetUsage in usages)
                    {
                        var hierarchyElement = myAssetDocumentHierarchyElementContainer.GetHierarchyElement(assetUsage.Location, false);
                        if (hierarchyElement == null)
                        {
                            continue;
                        }

                        consumer.Accept(new UnityInspectorFindResults(sourceFile, element, assetUsage, hierarchyElement));
                    }
                }
            }

            return(false);
        }
        public bool ProcessProjectItem <TResult>(IPsiSourceFile sourceFile, IFindResultConsumer <TResult> consumer)
        {
            if (!myDeferredCacheController.CompletedOnce.Value)
            {
                return(false);
            }

            foreach (var element in myElements)
            {
                if (element is IMethod || element is IProperty)
                {
                    var usages = myUnityEventsElementContainer.GetAssetUsagesFor(sourceFile, element);
                    foreach (var findResult in usages)
                    {
                        consumer.Accept(findResult);
                    }
                }

                if (element is ITypeElement typeElement)
                {
                    var usages = myAssetScriptUsagesElementContainer.GetAssetUsagesFor(sourceFile, typeElement);

                    foreach (var assetUsage in usages)
                    {
                        consumer.Accept(new UnityScriptsFindResults(sourceFile, element, assetUsage, assetUsage.Location));
                    }
                }

                if (element is IField field)
                {
                    if (UnityApi.IsDescendantOfUnityEvent(field.Type.GetTypeElement()))
                    {
                        foreach (var findResult in myUnityEventsElementContainer.GetMethodsForUnityEvent(sourceFile, field))
                        {
                            consumer.Accept(findResult);
                        }
                    }
                    else
                    {
                        var usages = myAssetInspectorValuesContainer.GetAssetUsagesFor(sourceFile, field);
                        foreach (var findResult in usages)
                        {
                            consumer.Accept(findResult);
                        }
                    }
                }
            }

            return(false);
        }
 private void AddScriptUsages <TResult>([NotNull] IPsiSourceFile sourceFile,
                                        [NotNull] IFindResultConsumer <TResult> consumer,
                                        [NotNull] ITypeElement typeElement,
                                        [NotNull] IDeclaredElement element)
 {
     foreach (var scriptUsagesContainer in myScriptsUsagesElementContainers)
     {
         var scriptUsages = scriptUsagesContainer.GetScriptUsagesFor(sourceFile, typeElement);
         foreach (var scriptUsage in scriptUsages)
         {
             consumer.Accept(new UnityScriptsFindResults(sourceFile, element, scriptUsage, scriptUsage.Location));
         }
     }
 }
        public bool ProcessElement <TResult>(ITreeNode element, IFindResultConsumer <TResult> consumer)
        {
            Assertion.Assert(element != null, "The condition (element != null) is false.");

            var names = new JetHashSet <string>(this.myNames);

            FindExecution result;

            if (this.mySearchForLateBound)
            {
                result =
                    new LateBoundReferenceSourceFileProcessor <TResult>(
                        element,
                        consumer,
                        this.myElements,
                        this.myHasUnnamedElement
                            ? null
                            : names,
                        names).Run();
            }
            else
            {
                var psiSourceFile = element.GetSourceFile();
                foreach (var myElement in this.myElements)
                {
                    var declarations = myElement.GetDeclarationsIn(psiSourceFile);
                    foreach (var declaration in declarations)
                    {
                        var refs = declaration.GetFirstClassReferences();
                        foreach (var r in refs)
                        {
                            consumer.Accept(new FindResultReference(r, declaration.DeclaredElement));
                        }
                    }
                }

                result =
                    new ReferenceSearchSourceFileProcessor <TResult>(
                        element,
                        true,
                        consumer,
                        this.myElements,
                        this.myHasUnnamedElement
                            ? null
                            : names,
                        names).Run();
            }

            return(result == FindExecution.Stop);
        }
示例#5
0
        public bool ProcessElement <TResult>(ITreeNode element, IFindResultConsumer <TResult> consumer)
        {
            if (!element.Language.Is <GherkinLanguage>())
            {
                return(false);
            }
            var containingFile = element.GetContainingFile();

            if (containingFile == null)
            {
                return(false);
            }
            var projectFile = containingFile.GetSourceFile().ToProjectFile();

            if (projectFile == null || !projectFile.IsValid())
            {
                return(false);
            }

            foreach (var declaredElement in _declaredElements)
            {
                if (!(declaredElement is IMethod method))
                {
                    continue;
                }
                foreach (var gherkinStep in element.GetChildrenInSubtrees <GherkinStep>())
                {
                    var reference             = gherkinStep.GetStepReference();
                    var resolveResultWithInfo = reference.Resolve();
                    if (resolveResultWithInfo.ResolveErrorType == ResolveErrorType.OK)
                    {
                        foreach (var declarationMethod in resolveResultWithInfo.Result.Elements <IMethod>())
                        {
                            if (declarationMethod.Element.Equals(method) && consumer.Accept(new FindResultReference(reference)) == FindExecution.Stop)
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
            private void FetchTextOccurences([NotNull] ITreeNode textToken, IFindResultConsumer <TResult> consumer)
            {
                var file = textToken.GetContainingFile();

                if (file != null)
                {
                    var text       = textToken.GetText();
                    var textLength = text.Length;

                    foreach (string name in myTexts)
                    {
                        var nameLength = name.Length;
                        for (int start = 0; start < textLength;)
                        {
                            int pos = text.IndexOf(name, start, StringComparison.Ordinal);
                            if (pos < 0)
                            {
                                break;
                            }

                            var range = textToken.GetDocumentRange();
                            if (range.IsValid())
                            {
                                var textRange = new TextRange(range.TextRange.StartOffset + pos, range.TextRange.StartOffset + pos + nameLength);

                                var nameDocumentRange = new DocumentRange(range.Document, textRange);
                                var translatedRange   = file.Translate(nameDocumentRange);
                                if (!DeclarationExists(textToken, translatedRange) && !ReferenceExists(file, translatedRange))
                                {
                                    consumer.Accept(new FindResultText(file.GetSourceFile(), nameDocumentRange));
                                }
                            }

                            start = pos + nameLength;
                        }
                    }
                }
            }
        public bool ProcessProjectItem <TResult>(IPsiSourceFile sourceFile, IFindResultConsumer <TResult> consumer)
        {
            try
            {
                if (!myDeferredCacheController.CompletedOnce.Value)
                {
                    return(false);
                }

                foreach (var element in myElements)
                {
                    if (element is IMethod || element is IProperty)
                    {
                        var animationEventUsages = myAnimationEventUsagesContainer.GetEventUsagesFor(sourceFile, element);
                        foreach (var usage in animationEventUsages)
                        {
                            var occurence = new UnityAnimationEventFindResults(sourceFile, element, usage, usage.Location);
                            consumer.Accept(occurence);
                        }

                        var usages = myUnityEventsElementContainer.GetAssetUsagesFor(sourceFile, element);
                        foreach (var findResult in usages)
                        {
                            consumer.Accept(findResult);
                        }
                    }

                    if (element is ITypeElement typeElement)
                    {
                        AddScriptUsages(sourceFile, consumer, typeElement, element);
                    }

                    if (element is IField field)
                    {
                        if (field.Type.GetTypeElement().DerivesFromUnityEvent())
                        {
                            foreach (var findResult in myUnityEventsElementContainer.GetMethodsForUnityEvent(sourceFile, field))
                            {
                                consumer.Accept(findResult);
                            }
                        }
                        else
                        {
                            var usages = myAssetInspectorValuesContainer.GetAssetUsagesFor(sourceFile, field);
                            foreach (var findResult in usages)
                            {
                                consumer.Accept(findResult);
                            }
                        }
                    }
                }
            }
            catch (OperationCanceledException)
            {
                throw;
            }
            catch (Exception e)
            {
                ourLogger.Error(e, $"An error occurred while searching assets in: {sourceFile.GetPersistentIdForLogging()}");
            }

            return(false);
        }