protected IStructuralMatchResult Match(ITreeNode treeNode) { IInvocationExpression expression = GetMatchedExpression(treeNode); if (expression == null) { return(matcher.Match(treeNode)); } return(matcher.Match(expression)); }
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); }
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 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); }