public SpecificationResult ApplyLabel(SetDefinitionTarget target, Label label) { return(new SpecificationResult( SymbolValue, SetDefinitions, Targets, labelByTarget.ContainsKey(target) ? labelByTarget : labelByTarget.Add(target, label) )); }
public SpecificationResult WithTarget(SetDefinitionTarget target) { return(new SpecificationResult( SymbolValue, SetDefinitions, Targets.Add(target), labelByTarget )); }
private static bool IsJoinTargeting(SetDefinition set, SetDefinitionTarget target) { if (set is SetDefinitionJoin joinSet) { return(joinSet.Tail.TargetSetDefinition == target); } else { return(false); } }
public Label GetLabelOf(SetDefinitionTarget target) { return(labelByTarget[target]); }
public bool TryGetLabelOf(SetDefinitionTarget target, [MaybeNullWhen(false)] out Label label) { return(labelByTarget.TryGetValue(target, out label)); }
private static void ThrowSpecificationErrorWithoutLabel(SpecificationContext context, SpecificationResult result, SetDefinitionTarget?priorTarget, SetDefinitionTarget target) { string targetDescription; Type targetType; string targetName; if (priorTarget == null) { var parameter = context.GetFirstVariable(); targetDescription = $"parameter \"{parameter.Label.Name}\""; targetType = parameter.Type; targetName = parameter.Label.Name; } else if (result.TryGetLabelOf(priorTarget, out var priorLabel)) { targetDescription = $"prior variable \"{priorLabel.Name}\""; targetType = priorTarget.Type; targetName = priorLabel.Name; } else { targetDescription = $"prior variable"; targetType = priorTarget.Type; targetName = "x"; } var typeName = target.Type.Name; var variable = ToInitialLowerCase(typeName); var message = $"The set should be joined to the {targetDescription}."; var recommendation = RecommendationEngine.RecommendJoin( new CodeExpression(target.Type, variable), new CodeExpression(targetType, targetName) ); throw new SpecificationException(recommendation == null ? message : $"{message} Consider \"facts.OfType<{typeName}>({variable} => {recommendation})\"."); }