private IEnumerable <DependencyRule> CreateDependencyRules([CanBeNull] ItemType usingItemTypeHint, [CanBeNull] ItemType usedItemTypeHint, [NotNull] string ruleSourceName, int lineNo, [NotNull] string usingPattern, [NotNull] string dependencyPattern, [NotNull] string usedPattern, [NotNull] string leftRepresentationPart, [NotNull] string rightRepresentationPart, bool questionableRule, bool ignoreCase) { string trimmedUsingPattern = usingPattern.Trim(); string trimmedDependencyPattern = dependencyPattern.Trim(); string trimmedUsedPattern = usedPattern.Trim(); string repString = trimmedUsingPattern + " " + leftRepresentationPart + trimmedDependencyPattern + rightRepresentationPart + trimmedUsedPattern; DependencyRuleSource rep = new DependencyRuleSource(ruleSourceName, lineNo, repString, questionableRule, trimmedUsingPattern); var match = new DependencyMatch(usingItemTypeHint, trimmedUsingPattern, trimmedDependencyPattern, usedItemTypeHint, trimmedUsedPattern, ignoreCase); var head = new DependencyRule(match, rep); var result = new List <DependencyRule> { head }; if (Log.IsVerboseEnabled) { Log.WriteInfo($"Matchers used for checking {repString} ({ruleSourceName}:{lineNo})"); // TODO: Put into DependencyMatch constructor ////Log.WriteInfo(" Using: " + string.Join<IMatcher>(", ", head.Using.Matchers)); ////Log.WriteInfo(" Used: " + string.Join<IMatcher>(", ", head.Used.Matchers)); } return(result); }
public DependencyRuleGroup([NotNull] string groupPattern, bool ignoreCase, ItemType usingTypeHint, ItemType usedTypeHint, string defaultName) : this(defaultName, groupPattern, groupPattern == "" ? null : DependencyMatch.Create(groupPattern, ignoreCase, usingTypeHint : usingTypeHint, usedTypeHint : usedTypeHint), Enumerable.Empty <DependencyRule>(), Enumerable.Empty <DependencyRule>(), Enumerable.Empty <DependencyRule>()) { // empty }
private IEnumerable <Dependency> LogOnlyDependencyCount(string pattern) { DependencyMatch m = pattern == null ? null : DependencyMatch.Create(pattern, IgnoreCase); IEnumerable <Dependency> matchingDependencies = CurrentGraph.VisibleDependencies.Where(d => m == null || m.IsMatch(d)); Log.WriteInfo(matchingDependencies.Count() + " dependencies" + (m == null ? "" : " matching " + pattern)); return(matchingDependencies); }
public DependencyRuleGroup([NotNull] string groupPattern, bool ignoreCase, ItemType usingTypeHint, ItemType usedTypeHint, string defaultName) : this(defaultName, groupPattern : groupPattern, groupMatchOrNullForMainGroup : groupPattern == "" ? null : DependencyMatch.Create(groupPattern, ignoreCase, usingTypeHint : usingTypeHint, usedTypeHint : usedTypeHint), allowed : Enumerable.Empty <DependencyRule>(), questionable : Enumerable.Empty <DependencyRule>(), forbidden : Enumerable.Empty <DependencyRule>()) { // empty }
public void TestItemDependencyItemMatch() { DependencyMatch.Create("a--'b->c", false); DependencyMatch.Create("!->c", false); DependencyMatch.Create("a--#'b", false); DependencyMatch.Create("'b", false); DependencyMatch.Create(" a -- ?'b -> c ", false); DependencyMatch.Create(" 'b -> c ", false); DependencyMatch.Create(" a -- 'b ", false); DependencyMatch.Create(" 'b ", false); }
private DependencyRuleGroup([CanBeNull] string defaultName, string groupPattern, DependencyMatch groupMatchOrNullForMainGroup, [NotNull] IEnumerable <DependencyRule> allowed, [NotNull] IEnumerable <DependencyRule> questionable, [NotNull] IEnumerable <DependencyRule> forbidden) { _groupPattern = string.IsNullOrWhiteSpace(groupPattern) ? "global" : groupPattern.Trim(); _groupMatchOrNullForMainGroup = groupMatchOrNullForMainGroup; _groupMarker = groupMatchOrNullForMainGroup == null ? null : AbstractMarkerSet.CreateReadableDefaultMarker( new[] { groupMatchOrNullForMainGroup.UsingMatch }, new[] { groupMatchOrNullForMainGroup.UsedMatch }, defaultName); _allowed = allowed.ToList(); _questionable = questionable.ToList(); _forbidden = forbidden.ToList(); }
private DependencyRuleGroup([CanBeNull] string defaultName, [NotNull] string groupPattern, [CanBeNull] DependencyMatch groupMatchOrNullForMainGroup, [NotNull] IEnumerable <DependencyRule> allowed, [NotNull] IEnumerable <DependencyRule> questionable, [NotNull] IEnumerable <DependencyRule> forbidden) { _groupPattern = groupPattern.Trim(); _groupMatchOrNullForMainGroup = groupMatchOrNullForMainGroup; //_groupMarker = groupMatchOrNullForMainGroup == null // ? null // : AbstractMarkerSet.CreateReadableDefaultMarker( // new[] { groupMatchOrNullForMainGroup.UsingMatch }, // new[] { groupMatchOrNullForMainGroup.UsedMatch }, defaultName); _allowed = allowed.ToList(); _questionable = questionable.ToList(); _forbidden = forbidden.ToList(); }
protected override TransformOptions CreateTransformOptions([NotNull] GlobalContext globalContext, [CanBeNull] string transformOptionsString, Func <string, IEnumerable <Dependency> > findOtherWorkingGraph) { var transformOptions = new TransformOptions(); Option.Parse(globalContext, transformOptionsString, BackwardsOption.Action((args, j) => { transformOptions.Backwards = true; return(j); }), MaxPathLengthOption.Action((args, j) => { transformOptions.MaxPathLength = Option.ExtractIntOptionValue(args, ref j, "Invalid maximum path length"); return(j); }), AddMarkerOption.Action((args, j) => { transformOptions.Marker = Option.ExtractRequiredOptionValue(args, ref j, "missing marker name"); return(j); }), AddIndexedMarkerOption.Action((args, j) => { transformOptions.Marker = Option.ExtractRequiredOptionValue(args, ref j, "missing marker name"); transformOptions.AddIndex = true; return(j); }), KeepOnlyPathsOption.Action((args, j) => { transformOptions.KeepOnlyPathEdges = true; return(j); }), IgnorePrefixPathsOption.Action((args, j) => { transformOptions.IgnorePrefixPaths = true; return(j); }), IgnoreSubpathsOption.Action((args, j) => { transformOptions.IgnoreSubpaths = true; return(j); }), AddDependencyOption.Action((args, j) => { transformOptions.AddTransitiveDependencyInsteadOfMarking = true; return(j); }), DefineDependencyMatchOption.Action((args, j) => { string name = Option.ExtractRequiredOptionValue(args, ref j, "missing name"); string pattern = Option.ExtractNextRequiredValue(args, ref j, "missing pattern"); transformOptions.DefinedDependencyMatches[name] = DependencyMatch.Create(pattern, globalContext.IgnoreCase); return(j); }), DefineItemMatchOption.Action((args, j) => { string name = Option.ExtractRequiredOptionValue(args, ref j, "missing name"); string pattern = Option.ExtractNextRequiredValue(args, ref j, "missing pattern"); transformOptions.DefinedItemMatches[name] = new ItemMatch(pattern, globalContext.IgnoreCase, anyWhereMatcherOk: true); return(j); }), RegexOption.Action((args, j) => { transformOptions.Regex = Option.ExtractRequiredOptionValue(args, ref j, "missing regex"); return(j); })); return(transformOptions); }
protected override Options CreateRenderOptions(GlobalContext globalContext, string options) { var result = new Options(); Option.Parse(globalContext, options, MatchOption.Action((args, j) => { result.ItemMatches.Add(new ItemMatch(Option.ExtractRequiredOptionValue(args, ref j, "Missing item match"), globalContext.IgnoreCase, anyWhereMatcherOk: true)); return(j); }), NoMatchOption.Action((args, j) => { result.ItemExcludes.Add(new ItemMatch(Option.ExtractRequiredOptionValue(args, ref j, "Missing item match"), globalContext.IgnoreCase, anyWhereMatcherOk: true)); return(j); }), IndegreeMatchOption.Action((args, j) => { result.IndegreeMatches.Add(DependencyMatch.Create(Option.ExtractRequiredOptionValue(args, ref j, "Missing dependency match"), globalContext.IgnoreCase)); return(j); }), IndegreeNoMatchOption.Action((args, j) => { result.IndegreeExcludes.Add(DependencyMatch.Create(Option.ExtractRequiredOptionValue(args, ref j, "Missing dependency match"), globalContext.IgnoreCase)); return(j); }), OutdegreeMatchOption.Action((args, j) => { result.OutdegreeMatches.Add(DependencyMatch.Create(Option.ExtractRequiredOptionValue(args, ref j, "Missing dependency match"), globalContext.IgnoreCase)); return(j); }), OutdegreeNoMatchOption.Action((args, j) => { result.OutdegreeExcludes.Add(DependencyMatch.Create(Option.ExtractRequiredOptionValue(args, ref j, "Missing dependency match"), globalContext.IgnoreCase)); return(j); }), IndegreeNotZeroOption.Action((args, j) => { result.WriteOnlyIfIndegreeNotZero = true; return(j); }), OutdegreeNotZeroOption.Action((args, j) => { result.WriteOnlyIfOutdegreeNotZero = true; return(j); }), ShowMarkersOption.Action((args, j) => { result.ShowMarkers = true; return(j); })); return(result); }
public DependencyRule([NotNull] DependencyMatch match, [NotNull] DependencyRuleSource source) { _match = match; Source = source; }
public void AddGraphFilter(string filter, bool ignorecase) { _filters.Add(DependencyMatch.Create(filter, ignorecase)); ClearAllCaches(); }
protected override bool IsDependencyMatch(DependencyMatch dependencyMatch, Dependency dependency) { return(dependencyMatch.IsMatch(dependency)); }
protected override DependencyMatch CreateDependencyMatch([NotNull] string pattern, bool ignoreCase) { return(DependencyMatch.Create(pattern, ignoreCase)); }
public DependencyPathMatch(string pattern, bool ignoreCase, bool multipleOccurrencesAllowed, bool mayContinue, IEnumerable <AbstractPathMatch <TDependency, TItem> > dontMatchesBeforeThis) : base(multipleOccurrencesAllowed, mayContinue, dontMatchesBeforeThis) { _dependencyMatch = DependencyMatch.Create(pattern, ignoreCase); }
protected abstract bool IsDependencyMatch(DependencyMatch dependencyMatch, TDependency dependency);
protected override bool IsDependencyMatch(DependencyMatch dependencyMatch, Dependency dependency) => dependencyMatch.IsMatch(dependency);
public DependencyAction(string line, bool ignoreCase, string fullConfigFileName, int startLineNo) { Match match = Regex.Match(line ?? "", PATTERN_PATTERN); if (!match.Success) { throw new ArgumentException($"Unexpected dependency pattern '{line}' at {fullConfigFileName}/{startLineNo}"); } else { GroupCollection groups = match.Groups; _match = new SingleDependencyMatch(null, groups[1].Value, groups[2].Value, null, groups[3].Value, ignoreCase); if (groups[4].Value != "-" && groups[4].Value != "delete") { var effects = new List <Action <Dependency> >(); var effectOptions = groups[4].Value.Split(' ', ',').Select(s => s.Trim()).Where(s => !string.IsNullOrWhiteSpace(s)); foreach (var effect in effectOptions) { if (effect == "-?" || effect == "reset-questionable") { effects.Add(d => d.ResetQuestionable()); } else if (effect == "+?" || effect == "mark-questionable") { effects.Add(d => d.MarkAsQuestionable(effect)); } else if (effect == "?" || effect == "increment-questionable") { effects.Add(d => d.IncrementQuestionable(effect)); } else if (effect == "-!" || effect == "reset-bad") { effects.Add(d => d.ResetBad()); } else if (effect == "+!" || effect == "mark-bad") { effects.Add(d => d.MarkAsBad(effect)); } else if (effect == "!" || effect == "increment-bad") { effects.Add(d => d.IncrementBad(effect)); } else if (effect == "" || effect == "ignore" || effect == "keep") { effects.Add(d => { }); } else if (effect.StartsWith("+")) { effects.Add(d => d.IncrementMarker(effect.Substring(1))); } else if (effect.StartsWith("-")) { effects.Add(d => d.RemoveMarkers(effect.Substring(1), ignoreCase)); } else { throw new ArgumentException($"Unexpected dependency directive '{effect}' at {fullConfigFileName}/{startLineNo}"); } } _effects = effects; } else { _effects = null; } } }
private RegexElement ParseSet(string s, ref int pos) { int startPos = pos; var itemMatches = new List <ItemMatch>(); var dependencyMatches = new List <DependencyMatch>(); bool invert = false; if (PeekSym(s, pos) == "^") { invert = true; AdvancePos(s, ref pos); } for (;;) { string peekSym = PeekSym(s, pos); if (peekSym == null) { // Error ... break; } else if (peekSym == "]") { break; } else { ItemMatch itemMatch; DependencyMatch dependencyMatch; string trimmedSym = peekSym.TrimStart('{').TrimEnd('}'); if (_definedDependencyMatches.TryGetValue(trimmedSym, out dependencyMatch)) { dependencyMatches.Add(dependencyMatch); } else if (_definedItemMatches.TryGetValue(trimmedSym, out itemMatch)) { itemMatches.Add(itemMatch); } else if (trimmedSym.Contains("--") || trimmedSym.Contains("->")) { // We try to parse it as a DependencyMatch dependencyMatches.Add(DependencyMatch.Create(trimmedSym, _ignoreCase)); } else if (trimmedSym.Contains(":") || trimmedSym.Contains(".")) { // We try to parse it as an ItemMatch itemMatches.Add(new ItemMatch(trimmedSym, _ignoreCase, anyWhereMatcherOk: false)); } else { throw new RegexSyntaxException(s, pos, "Name in set cannot be converted to item or dependency match"); } } } if (itemMatches.Any()) { if (dependencyMatches.Any()) { throw new RegexSyntaxException(s, startPos, "[...] must not contain both item and dependency matches"); } return(new ItemSet(startPos, invert, itemMatches)); } else if (dependencyMatches.Any()) { return(new DependencySet(startPos, invert, dependencyMatches)); } else { throw new RegexSyntaxException(s, startPos, "[...] must not be empty"); } }