public sealed override bool IsAvailable()
        {
            StructuralSearchEngine structuralSearchEngine =
                this.DataProvider.Solution.GetComponent <StructuralSearchEngine>();

            IStructuralMatcher structuralMatcher = structuralSearchEngine.CreateMatcherWithPlaceholdersBindingObject(
                this.Pattern,
                CSharpLanguage.Instance,
                this.GetType(),
                GetAdditionalPlaceholders()
                );

            if (structuralMatcher != null)
            {
                IStructuralMatchResult matchResult =
                    structuralMatcher.IsTreeNodeOrParentsMatched(this.DataProvider.SelectedElement, this);

                if (matchResult.Matched)
                {
                    this.MatchResult = matchResult;

                    return(IsAvailableCore());
                }
            }

            return(false);
        }
        private static bool Matched(
            ITreeNode treeNode,
            string pattern,
            StructuralSearchEngine structuralSearchEngine,
            int placeholdersCount,
            out IStructuralMatchResult matchResult,
            out List <string> orderedPlaceholderNames)
        {
            matchResult             = null;
            orderedPlaceholderNames = null;

            IStructuralSearchPattern structuralSearchPattern =
                structuralSearchEngine.GetFactory(CSharpLanguage.Instance).CreatePattern(pattern);

            if (!structuralSearchPattern.GuessPlaceholders() || structuralSearchPattern.Placeholders.Count != placeholdersCount)
            {
                return(false);
            }

            orderedPlaceholderNames = GetPatternOrderedPlaceholderNames(pattern);
            if (orderedPlaceholderNames.Count != placeholdersCount)
            {
                return(false);
            }

            IStructuralMatcher matcher = structuralSearchPattern.CreateMatcher();

            matchResult = matcher.Match(treeNode);

            return(matchResult.Matched);
        }
        public static IStructuralMatchResult IsTreeNodeOrParentsMatched(
            this IStructuralMatcher matcher,
            ITreeNode treeNode,
            object placeholdersBindingObject)
        {
            PropertyInfo[] placeholderProperties = GetPlaceholderProperties(placeholdersBindingObject.GetType());

            ITreeNode initialTreeNode = treeNode;

            while (treeNode != null)
            {
                IStructuralMatchResult matchResult = TreeNodeMatched(
                    matcher,
                    treeNode,
                    initialTreeNode,
                    placeholdersBindingObject,
                    placeholderProperties
                    );

                if (matchResult.Matched)
                {
                    return(matchResult);
                }

                treeNode = treeNode.Parent;
            }

            return(StructuralMatchResult.NOT_MATCHED);
        }
コード例 #4
0
 private void DoSearch(IStructuralMatcher matcher, IFindResultConsumer<IStructuralMatchResult> consumer, ISearchDomain searchDomain)
 {
     // todo add support for VB (eventually)
     var searcher = new StructuralSearcher(documentManager, CSharpLanguage.Instance, matcher);
     var searchDomainSearcher = new StructuralSearchDomainSearcher<IStructuralMatchResult>(
         searchDomain, searcher, consumer, NullProgressIndicator.Instance, true);
     //NarrowSearchDomain(matcher.Words, matcher.GetExtendedWords(solution), searchDomain, searchDomainFactory),
     //searcher, consumer, NullProgressIndicator.Instance, true);
     searchDomainSearcher.Run();
 }
コード例 #5
0
        private void DoSearch(IStructuralMatcher matcher, IFindResultConsumer <IStructuralMatchResult> consumer, ISearchDomain searchDomain)
        {
            // todo add support for VB (eventually)
            var searcher             = new StructuralSearcher(documentManager, CSharpLanguage.Instance, matcher);
            var searchDomainSearcher = new StructuralSearchDomainSearcher <IStructuralMatchResult>(
                searchDomain, searcher, consumer, NullProgressIndicator.Instance, true);

            //NarrowSearchDomain(matcher.Words, matcher.GetExtendedWords(solution), searchDomain, searchDomainFactory),
            //searcher, consumer, NullProgressIndicator.Instance, true);
            searchDomainSearcher.Run();
        }
コード例 #6
0
ファイル: PatternSearcher.cs プロジェクト: renana/AgentMulder
        private void DoSearch(IStructuralMatcher matcher, FindResultConsumer<IStructuralMatchResult> consumer)
        {
            ISolution solution = Shell.Instance.GetComponent<ISolutionManager>().CurrentSolution;

            var searchDomain = searchDomainFactory.CreateSearchDomain(solution, false);
            var documentManager = solution.GetComponent<DocumentManager>();

            // todo add support for VB (eventually)
            var structuralSearcher = new StructuralSearcher(documentManager, CSharpLanguage.Instance, matcher);
            var searchDomainSearcher = new StructuralSearchDomainSearcher<IStructuralMatchResult>(
                NarrowSearchDomain(solution, matcher.Words, matcher.GetExtendedWords(solution), searchDomain),
                structuralSearcher, consumer, NullProgressIndicator.Instance, true);
            searchDomainSearcher.Run();
        }
コード例 #7
0
        private static IEnumerable<IStructuralMatchResult> FindMatches(IStructuralMatcher matcher, ITreeNode statement)
        {
            if (statement == null || !statement.IsValid())
                yield break;

            var result = matcher.Match(statement);
            if (result.Matched)
            {
                yield return result;
                yield break;
            }
            foreach (var r in statement.Children().SelectMany(node => FindMatches(matcher, node)))
            {
                yield return r;
            }
        }
コード例 #8
0
        private void DoSearch(IStructuralMatcher matcher, FindResultConsumer <IStructuralMatchResult> consumer)
        {
#if SDK70
            ISolution solution = Shell.Instance.GetComponent <SolutionsManager>().Solution;
#else
            ISolution solution = Shell.Instance.GetComponent <ISolutionManager>().CurrentSolution;
#endif

            var searchDomain    = searchDomainFactory.CreateSearchDomain(solution, false);
            var documentManager = solution.GetComponent <DocumentManager>();

            // todo add support for VB (eventually)
            var structuralSearcher   = new StructuralSearcher(documentManager, CSharpLanguage.Instance, matcher);
            var searchDomainSearcher = new StructuralSearchDomainSearcher <IStructuralMatchResult>(
                NarrowSearchDomain(solution, matcher.Words, matcher.GetExtendedWords(solution), searchDomain),
                structuralSearcher, consumer, NullProgressIndicator.Instance, true);
            searchDomainSearcher.Run();
        }
コード例 #9
0
        private static IEnumerable <IStructuralMatchResult> FindMatches(IStructuralMatcher matcher, ITreeNode statement)
        {
            if (statement == null || !statement.IsValid())
            {
                yield break;
            }
            var result = matcher.Match(statement);

            if (result.Matched)
            {
                yield return(result);

                yield break;
            }
            foreach (var r in statement.Children().SelectMany(node => FindMatches(matcher, node)))
            {
                yield return(r);
            }
        }
        private static IStructuralMatchResult TreeNodeMatched(
            IStructuralMatcher matcher,
            ITreeNode treeNode,
            ITreeNode initialTreeNode,
            object placeholdersBindingObject,
            PropertyInfo[] placeholderProperties)
        {
            IStructuralMatchResult matchResult = matcher.Match(treeNode);

            if (matchResult.Matched && matchResult.MatchedElement.Contains(initialTreeNode))
            {
                var propertyToMatchedObjectPairs = new List <(PropertyInfo property, object matchedObject)>();

                foreach (PropertyInfo property in placeholderProperties)
                {
                    object matchedObject = matchResult.GetMatch(property.Name);
                    if (property.PropertyType.IsInstanceOfType(matchedObject))
                    {
                        propertyToMatchedObjectPairs.Add((property, matchedObject));
                    }
                    else
                    {
                        return(StructuralMatchResult.NOT_MATCHED);
                    }
                }

                foreach ((PropertyInfo property, object matchedObject) in propertyToMatchedObjectPairs)
                {
                    property.SetValue(placeholdersBindingObject, matchedObject);
                }

                return(matchResult);
            }

            return(StructuralMatchResult.NOT_MATCHED);
        }
コード例 #11
0
 protected RegistrationPatternBase(IStructuralSearchPattern pattern)
 {
     matcher = pattern.CreateMatcher();
 }
コード例 #12
0
        protected RegistrationPatternBase(IStructuralSearchPattern pattern)
        {
            this.pattern = pattern;

            matcher = pattern.CreateMatcher();
        }
コード例 #13
0
 protected RegistrationBasePattern(IStructuralSearchPattern pattern)
 {
     matcher = pattern.CreateMatcher();
 }