internal Directive( DirectiveType directiveType, DirectiveNode parsedDirective, object source) { Type = directiveType ?? throw new ArgumentNullException(nameof(directiveType)); _parsedDirective = parsedDirective ?? throw new ArgumentNullException(nameof(parsedDirective)); Source = source ?? throw new ArgumentNullException(nameof(source)); Name = directiveType.Name; }
protected override void VisitDirective( DirectiveNode directive, ImmutableStack <ISyntaxNode> path) { if (_directives.TryGetValue(directive.Name.Value, out Directive d)) { ValidateRequiredArguments( directive, directive.Arguments, d.Arguments); } base.VisitDirective(directive, path); }
public static IError DirectiveNotSupported( this IDocumentValidatorContext context, DirectiveNode node) { return(ErrorBuilder.New() .SetMessage( Resources.ErrorHelper_DirectiveNotSupported, node.Name.Value) .AddLocation(node) .SetPath(context.CreateErrorPath()) .SpecifiedBy("sec-Directives-Are-Defined") .Build()); }
protected override ISyntaxVisitorAction Enter( DirectiveNode node, IDocumentValidatorContext context) { if (context.Schema.TryGetDirectiveType(node.Name.Value, out DirectiveType d)) { context.Directives.Push(d); return(Continue); } context.UnexpectedErrorsDetected = true; return(Skip); }
void outlineTreeDataFunc(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter) { Gtk.CellRendererText txtRenderer = (Gtk.CellRendererText)cell; Node n = (Node)model.GetValue(iter, 0); string name = null; if (n is TagNode) { TagNode tn = (TagNode)n; name = tn.TagName; string att = null; if (tn.Attributes != null) { att = tn.Attributes["id"] as string; } if (att != null) { name = "<" + name + "#" + att + ">"; } else { name = "<" + name + ">"; } } else if (n is DirectiveNode) { DirectiveNode dn = (DirectiveNode)n; name = "<%@ " + dn.Name + " %>"; } else if (n is ExpressionNode) { ExpressionNode en = (ExpressionNode)n; string expr = en.Expression; if (string.IsNullOrEmpty(expr)) { name = "<% %>"; } else { if (expr.Length > 10) { expr = expr.Substring(0, 10) + "..."; } name = "<% " + expr + "%>"; } } if (name != null) { txtRenderer.Text = name; } }
private static bool HasSourceDirective( DirectiveNode directive, NameString schemaName) { if (DirectiveNames.Source.Equals(directive.Name.Value)) { ArgumentNode argument = directive.Arguments.FirstOrDefault(t => DirectiveFieldNames.Source_Schema.Equals(t.Name.Value)); return(argument != null && argument.Value is StringValueNode sv && schemaName.Equals(sv.Value)); } return(false); }
protected override void VisitDirective( DirectiveNode directive, ImmutableStack <ISyntaxNode> path) { if (_directives.TryGetValue(directive.Name.Value, out DirectiveType d) && TryLookupLocation(path.Peek(), out Types.DirectiveLocation location) && !d.Locations.Contains(location)) { Errors.Add(new ValidationError( "The specified directive is not valid the " + "current location.", directive)); } }
private Directive( DirectiveType directiveType, DirectiveNode parsedDirective, object?customDirective, object source) { Type = directiveType ?? throw new ArgumentNullException(nameof(directiveType)); _parsedDirective = parsedDirective ?? throw new ArgumentNullException(nameof(parsedDirective)); _customDirective = customDirective; Source = source ?? throw new ArgumentNullException(nameof(source)); Name = directiveType.Name; }
private static IValueNode GetIfArgumentValue(DirectiveNode directive) { if (directive.Arguments.Count == 1) { ArgumentNode argument = directive.Arguments[0]; if (string.Equals( argument.Name.Value, WellKnownDirectives.IfArgument, StringComparison.Ordinal)) { return(argument.Value); } } throw ThrowHelper.MissingIfArgument(directive); }
public static bool IsSchemaDirective( this DirectiveNode directive, string schemaName) { if (IsSchemaDirective(directive)) { ArgumentNode argument = directive.Arguments .SingleOrDefault(t => t.IsNameArgument()); if (argument.Value is StringValueNode value && value.Value.EqualsOrdinal(schemaName)) { return(true); } } return(false); }
private static Type?GetTypeFromDirective( CustomScalarType scalarType, string directiveName) { DirectiveNode typeDirective = scalarType.SyntaxNode.Directives .FirstOrDefault(t => t.Name.Value.Equals(directiveName)); if (typeDirective is null) { return(null); } ArgumentNode name = typeDirective.Arguments.First(t => t.Name.Value.Equals(GeneratorDirectives.Name)); return(Type.GetType(((StringValueNode)name.Value).Value)); }
protected sealed override ISyntaxVisitorAction Enter( ISyntaxNode node, ISyntaxVisitorContext context) { return(node switch { DocumentNode n => Enter(n, context), OperationDefinitionNode n => Enter(n, context), VariableDefinitionNode n => Enter(n, context), VariableNode n => Enter(n, context), SelectionSetNode n => Enter(n, context), FieldNode n => Enter(n, context), ArgumentNode n => Enter(n, context), FragmentSpreadNode n => Enter(n, context), InlineFragmentNode n => Enter(n, context), FragmentDefinitionNode n => Enter(n, context), DirectiveNode n => Enter(n, context), NamedTypeNode n => Enter(n, context), ListTypeNode n => Enter(n, context), NonNullTypeNode n => Enter(n, context), ListValueNode n => Enter(n, context), ObjectValueNode n => Enter(n, context), ObjectFieldNode n => Enter(n, context), IValueNode n => Enter(n, context), SchemaDefinitionNode n => Enter(n, context), OperationTypeDefinitionNode n => Enter(n, context), ScalarTypeDefinitionNode n => Enter(n, context), ObjectTypeDefinitionNode n => Enter(n, context), FieldDefinitionNode n => Enter(n, context), InputValueDefinitionNode n => Enter(n, context), InterfaceTypeDefinitionNode n => Enter(n, context), UnionTypeDefinitionNode n => Enter(n, context), EnumTypeDefinitionNode n => Enter(n, context), EnumValueDefinitionNode n => Enter(n, context), InputObjectTypeDefinitionNode n => Enter(n, context), DirectiveDefinitionNode n => Enter(n, context), SchemaExtensionNode n => Enter(n, context), ScalarTypeExtensionNode n => Enter(n, context), ObjectTypeExtensionNode n => Enter(n, context), InterfaceTypeExtensionNode n => Enter(n, context), UnionTypeExtensionNode n => Enter(n, context), EnumTypeExtensionNode n => Enter(n, context), InputObjectTypeExtensionNode n => Enter(n, context), _ => throw new NotSupportedException() });
private IEnumerable <IDirective> GetFieldSelectionDirectives( IObjectField field, FieldNode selection) { for (var i = 0; i < selection.Directives.Count; i++) { DirectiveNode directive = selection.Directives[i]; if (_schema.TryGetDirectiveType(directive.Name.Value, out DirectiveType? directiveType) && directiveType.HasMiddleware) { yield return(Directive.FromDescription( directiveType, new DirectiveDefinition(directive), field)); } } }
private bool TryDeserialize <T>( DirectiveNode directiveNode, out T directive) { ConstructorInfo?constructor = typeof(T).GetTypeInfo() .DeclaredConstructors.FirstOrDefault(t => { ParameterInfo[] parameters = t.GetParameters(); return(parameters.Length == 2 && parameters[0].ParameterType == typeof(SerializationInfo) && parameters[1].ParameterType == typeof(StreamingContext)); }); if (constructor is null) { directive = default !;
private bool TryGetTypeName( WithDirectives withDirectives, out string typeName) { DirectiveNode directive = withDirectives.Directives.FirstOrDefault(t => t.Name.Value.EqualsOrdinal(GeneratorDirectives.Type)); if (directive is null) { typeName = null; return(false); } typeName = (string)directive.Arguments.Single(a => a.Name.Value.EqualsOrdinal("name")).Value.Value; return(true); }
private static DirectiveNode?GetDirective( this IReadOnlyList <DirectiveNode> directives, string name) { if (directives.Count == 0) { return(null); } for (var i = 0; i < directives.Count; i++) { DirectiveNode directive = directives[i]; if (directive.Name.Value.EqualsOrdinal(name)) { return(directive); } } return(null); }
protected override ISyntaxVisitorAction Enter( DirectiveNode node, IDocumentValidatorContext context) { if (context.Schema.TryGetDirectiveType(node.Name.Value, out DirectiveType? dt)) { if (context.Path.TryPeek(out ISyntaxNode parent) && TryLookupLocation(parent, out DirectiveLoc location) && !dt.Locations.Contains(location)) { context.Errors.Add(ErrorHelper.DirectiveNotValidInLocation(context, node)); } } else { context.Errors.Add(ErrorHelper.DirectiveNotSupported(context, node)); } return(Skip); }
public void ConvertCustomDirectiveToDirectiveNode() { // arrange ISchema schema = CreateSchema(); DirectiveType directiveType = schema.GetDirectiveType("Foo"); var fooDirective = new FooDirective { Bar = "123", Child = new FooChild { Bar = "456" } }; // act var directive = Directive.FromDescription( directiveType, new DirectiveDefinition( fooDirective, _typeInspector.GetTypeRef(fooDirective.GetType())), new object()); DirectiveNode directiveNode = directive.ToNode(); // assert Assert.Equal(directiveType.Name, directiveNode.Name.Value); Assert.Collection(directiveNode.Arguments, t => { Assert.Equal("bar", t.Name.Value); Assert.Equal("123", ((StringValueNode)t.Value).Value); }, t => { Assert.Equal("child", t.Name.Value); Assert.Collection(((ObjectValueNode)t.Value).Fields, x => { Assert.Equal("bar", x.Name.Value); Assert.Equal("456", ((StringValueNode)x.Value).Value); }); }); }
protected override DirectiveNode RewriteDirective( DirectiveNode node, string context) { if (node.Name.Value.EqualsOrdinal(DirectiveNames.Delegate) && !node.Arguments.Any(a => a.Name.Value.EqualsOrdinal( DirectiveFieldNames.Delegate_Schema))) { var arguments = node.Arguments.ToList(); arguments.Add(new ArgumentNode( DirectiveFieldNames.Delegate_Schema, context)); return(node.WithArguments(arguments)); } return(node); }
private static bool?EvaluateDirective( this DirectiveNode directive, IVariableCollection variables) { if (directive == null) { return(null); } ArgumentNode argumentNode = directive.Arguments.SingleOrDefault(); if (argumentNode == null) { throw new QueryException( ErrorBuilder.New() .SetMessage(string.Format( CultureInfo.InvariantCulture, CoreResources .DirectiveCollectionExtensions_NotValid, directive.Name.Value)) .Build()); } if (argumentNode.Value is BooleanValueNode b) { return(b.Value); } if (argumentNode.Value is VariableNode v) { return(variables.GetVariable <bool>(v.Name.Value)); } throw new QueryException( ErrorBuilder.New() .SetMessage(string.Format( CultureInfo.InvariantCulture, CoreResources .DirectiveCollectionExtensions_IfNotBoolean, directive.Name.Value)) .Build()); }
public static Directive FromDescription( DirectiveType directiveType, DirectiveDefinition definition, object source) { if (directiveType is null) { throw new ArgumentNullException(nameof(directiveType)); } if (definition is null) { throw new ArgumentNullException(nameof(definition)); } if (source is null) { throw new ArgumentNullException(nameof(source)); } if (definition.CustomDirective is null) { return(new Directive( directiveType, CompleteArguments(directiveType, definition.ParsedDirective), null, source)); } else { DirectiveNode directiveNode = ParseValue( directiveType, definition.CustomDirective); return(new Directive( directiveType, CompleteArguments(directiveType, directiveNode), definition.CustomDirective, source)); } }
public static string DeprecationReason( this Language.IHasDirectives syntaxNode) { DirectiveNode directive = syntaxNode.Directives.FirstOrDefault(t => t.Name.Value == WellKnownDirectives.Deprecated); if (directive is null) { return(null); } if (directive.Arguments.Count != 0 && directive.Arguments[0].Name.Value == WellKnownDirectives.DeprecationReasonArgument && directive.Arguments[0].Value is StringValueNode s && !string.IsNullOrEmpty(s.Value)) { return(s.Value); } return(WellKnownDirectives.DeprecationDefaultReason); }
public DirectiveNode ToNode(bool removeNullArguments) { if (_parsedDirective is null) { var arguments = new List <ArgumentNode>(); Type type = _customDirective.GetType(); ILookup <string, PropertyInfo> properties = type.GetProperties() .ToLookup(t => t.Name, StringComparer.OrdinalIgnoreCase); foreach (Argument argument in Type.Arguments) { PropertyInfo property = properties[argument.Name].FirstOrDefault(); var value = property?.GetValue(_customDirective); IValueNode valueNode = argument.Type.ParseValue(value); arguments.Add(new ArgumentNode(argument.Name, valueNode)); } _parsedDirective = new DirectiveNode(Name, arguments); } if (removeNullArguments && _parsedDirective.Arguments.Count != 0 && _parsedDirective.Arguments.Any(t => t.Value.IsNull())) { var arguments = new List <ArgumentNode>(); foreach (ArgumentNode argument in _parsedDirective.Arguments) { if (!argument.Value.IsNull()) { arguments.Add(argument); } } return(_parsedDirective.WithArguments(arguments)); } return(_parsedDirective); }
public static Graph createGraph(SolutionProgram p) { Graph g = new Graph(); graphNode previous = createStartNode(); g.AddNode(previous); DirectiveNode d = p.getEntryPoint(); graphNode next = generateSubtree(d, g); g.AddEdge(previous.Id, next.Id); /* * while (d != null) * { * graphNode next = generateSubtree(d, g); * g.AddNode(next); * g.AddEdge(previous.Id, next.Id); * previous = next; * d = d.getNextDirective(); * } */ return(g); }
public DirectiveNode ToNode() { if (_parsedDirective is null) { var arguments = new List <ArgumentNode>(); Type type = _customDirective.GetType(); ILookup <string, PropertyInfo> properties = type.GetProperties() .ToLookup(t => t.Name, StringComparer.OrdinalIgnoreCase); foreach (InputField argument in Type.Arguments) { PropertyInfo property = properties[argument.Name].FirstOrDefault(); var value = property?.GetValue(_customDirective); IValueNode valueNode = argument.Type.ParseValue(value); arguments.Add(new ArgumentNode(argument.Name, valueNode)); } _parsedDirective = new DirectiveNode(Name, arguments); } return(_parsedDirective); }
private IWebFormsNode DirectiveNodeBuilder(Match match) { var node = new DirectiveNode { Directive = DirectiveType.Unknown, Type = NodeType.Directive }; attributesReader.ReadAttributes(match, node.Attributes); if (match.Groups.Count > 1 && match.Groups[1].Captures.Count > 0) { string directiveType = match.Groups[1].Captures[0].Value.ToLowerInvariant(); if (directiveType.Contains("page")) { node.Directive = DirectiveType.Page; } else if (directiveType.Contains("control")) { node.Directive = DirectiveType.Control; } } return(node); }
void SetSubtype(WebSubtype type, DirectiveNode node) { if (info.Subtype != WebSubtype.None) { Add(ErrorType.Error, node, "Unexpected directive {0}", node.Name); return; } info.Subtype = type; if (node.Attributes == null) { return; } info.InheritedClass = node.Attributes ["inherits"] as string; if (info.ClassName == null) { info.ClassName = node.Attributes ["classname"] as string; } info.CodeBehindFile = node.Attributes ["codebehind"] as string; info.Language = node.Attributes ["language"] as string; info.CodeFile = node.Attributes ["codefile"] as string; }
protected virtual ISyntaxVisitorAction Enter( DirectiveNode node, ISyntaxVisitorContext context) => DefaultAction;
public virtual void VisitDirective(DirectiveNode directiveNode) { this.ThrowIfCanceled(); VisitChildren(directiveNode); }
public virtual void VisitDirectiveNode(DirectiveNode node) { Visit(node.SemicolonNode); Visit(node.KeywordNode); Visit(node.ValueNode); Visit(node.DataNode); }
protected virtual ISyntaxVisitorAction Leave( DirectiveNode node, TContext context) => DefaultAction;