public IncludeNode(DirectiveInfo info) : base(info) { Filename = ExpressionRewriter.Rewrite(Token.ReadTokens(info.ParametersReader)); this.parentParser = info.Parser; }
private void ProcessDirective([NotNull] IT4Directive directive) { IT4Token nameToken = directive.GetNameToken(); if (nameToken == null) { return; } DirectiveInfo directiveInfo = _directiveInfoManager.GetDirectiveByName(nameToken.GetText()); if (directiveInfo == null) { return; } IEnumerable <string> attributeNames = directive.GetAttributes().SelectNotNull(attr => attr.GetName()); var hashSet = new JetHashSet <string>(attributeNames, StringComparer.OrdinalIgnoreCase); foreach (DirectiveAttributeInfo attributeInfo in directiveInfo.SupportedAttributes) { if (attributeInfo.IsRequired && !hashSet.Contains(attributeInfo.Name)) { AddHighlighting(new HighlightingInfo(nameToken.GetHighlightingRange(), new MissingRequiredAttributeHighlighting(nameToken, attributeInfo.Name))); } } }
private void ProcessDirective([NotNull] IT4Directive directive) { IT4Token nameToken = directive.GetNameToken(); if (nameToken == null) { return; } DirectiveInfo directiveInfo = _directiveInfoManager.GetDirectiveByName(nameToken.GetText()); if (directiveInfo == null) { return; } // Notify of missing required attributes. IEnumerable <string> attributeNames = directive.GetAttributes().SelectNotNull(attr => attr.GetName()); var hashSet = new JetHashSet <string>(attributeNames, StringComparer.OrdinalIgnoreCase); foreach (DirectiveAttributeInfo attributeInfo in directiveInfo.SupportedAttributes) { if (attributeInfo.IsRequired && !hashSet.Contains(attributeInfo.Name)) { AddHighlighting(new HighlightingInfo(nameToken.GetHighlightingRange(), new MissingRequiredAttributeHighlighting(nameToken, attributeInfo.Name))); } } // Assembly attributes in preprocessed templates are useless. if (directiveInfo == _directiveInfoManager.Assembly && DaemonProcess.SourceFile.ToProjectFile().IsPreprocessedT4Template()) { AddHighlighting(new HighlightingInfo(directive.GetHighlightingRange(), new IgnoredAssemblyDirectiveHighlighting(directive))); } }
protected override bool AddLookupItems(T4CodeCompletionContext context, IItemsCollector collector) { ITreeNode node = context.BasicContext.File.FindNodeAt(context.BasicContext.SelectedTreeRange); Assertion.AssertNotNull(node, "node == null"); var ranges = context.BasicContext.GetRanges(node); collector.AddRanges(ranges); var attribute = node.GetContainingNode <IT4DirectiveAttribute>(); Assertion.AssertNotNull(attribute, "attribute != null"); var directive = attribute.GetContainingNode <IT4Directive>(); Assertion.AssertNotNull(directive, "directive != null"); DirectiveInfo directiveInfo = _directiveInfoManager.GetDirectiveByName(directive.GetName()); DirectiveAttributeInfo attributeInfo = directiveInfo?.GetAttributeByName(attribute.GetName()); if (attributeInfo == null) { return(false); } foreach (string intellisenseValue in attributeInfo.IntelliSenseValues) { var item = new TextLookupItem(intellisenseValue); item.InitializeRanges(ranges, context.BasicContext); collector.Add(item); } return(true); }
public LocalNode(DirectiveInfo info) : base(info) { VariableName = Token.ReadToken(info.ParametersReader); if(VariableName == null) { throw new MissingDataException("Expected a variable name", info.ParametersReader.Location); } if(VariableName.TokenType != TokenType.Identifier) { throw new BadDataException("Expected a variable name", VariableName.Location); } }
private static string GetSortValue([NotNull] IT4Directive directive, [CanBeNull] DirectiveInfo directiveInfo, [NotNull] DirectiveInfoManager directiveInfoManager) { if (directiveInfo == directiveInfoManager.Assembly) { return(directive.GetAttributeValue(directiveInfoManager.Assembly.NameAttribute.Name)); } if (directiveInfo == directiveInfoManager.Import) { return(directive.GetAttributeValue(directiveInfoManager.Import.NamespaceAttribute.Name)); } if (directiveInfo == directiveInfoManager.Parameter) { return(directive.GetAttributeValue(directiveInfoManager.Parameter.NameAttribute.Name)); } return(null); }
public EachNode(DirectiveInfo info) : base(info) { Token token = Token.ReadToken(info.ParametersReader); if(token == null) { throw new MissingDataException("Variable name", info.ParametersReader.Location); } if(token.TokenType != TokenType.Identifier) { throw new MissingDataException("Variable name", token.Location); } Variable = token.Value.ToString(); Values = ExpressionRewriter.Rewrite(Token.ReadTokens(info.ParametersReader)); }
private void ProcessAttributeValue([NotNull] T4Token valueNode) { var attribute = valueNode.Parent as IT4DirectiveAttribute; if (attribute == null) { return; } if (attribute.ValueError != null) { AddHighlighting(new HighlightingInfo(valueNode.GetHighlightingRange(), new InvalidAttributeValueHighlighting(valueNode, null, attribute.ValueError))); return; } var directive = attribute.Parent as IT4Directive; if (directive == null) { return; } DirectiveInfo directiveInfo = _directiveInfoManager.GetDirectiveByName(directive.GetName()); if (directiveInfo == null) { return; } DirectiveAttributeInfo attributeInfo = directiveInfo.GetAttributeByName(attribute.GetName()); if (attributeInfo == null) { return; } if (attributeInfo.IsValid(valueNode.GetText())) { return; } AddHighlighting(new HighlightingInfo(valueNode.GetHighlightingRange(), new InvalidAttributeValueHighlighting(valueNode, attributeInfo, "Invalid attribute value"))); }
public LetNode(DirectiveInfo info) : base(info) { Token token = Token.ReadToken(info.ParametersReader); if(token == null) { throw new MissingDataException("Variable name", info.ParametersReader.Location); } if(token.TokenType != TokenType.Identifier) { throw new MissingDataException("Variable name", token.Location); } Variable = token.Value.ToString(); info.ParametersReader.SkipWhiteSpace(); foreach(var node in (new Parser(info.Parser, info.ParametersReader)).ReadNodes()) { ChildrenNodes.Add(node); } }
private string GetDirectiveText() { IT4Directive directive = GetTreeNode(); string name = directive?.Name?.GetText(); if (name == null) { return("???"); } DirectiveInfo directiveInfo = T4DirectiveInfoManager.GetDirectiveByName(name); if (directiveInfo == null) { return(name); } // display the directive with the attributes that are marked with DisplayInCodeStructure var builder = new StringBuilder(name); foreach (IT4DirectiveAttribute attribute in directive.AttributesEnumerable) { DirectiveAttributeInfo attributeInfo = directiveInfo.GetAttributeByName(attribute.Name.GetText()); if (attributeInfo?.IsDisplayedInCodeStructure != true) { continue; } builder.Append(' '); builder.Append(attributeInfo.Name); if (attribute.Value != null) { builder.Append("=\""); builder.Append(attribute.Value.GetText()); builder.Append('"'); } } return(builder.ToString()); }
protected override bool AddLookupItems(T4CodeCompletionContext context, IItemsCollector collector) { ITreeNode node = context.BasicContext.File.FindNodeAt(context.BasicContext.SelectedTreeRange); Assertion.AssertNotNull(node, "node == null"); var ranges = context.BasicContext.GetRanges(node); collector.AddRanges(ranges); var directive = node.GetContainingNode <IT4Directive>(); Assertion.AssertNotNull(directive, "directive != null"); DirectiveInfo directiveInfo = _directiveInfoManager.GetDirectiveByName(directive.GetName()); if (directiveInfo == null) { return(false); } JetHashSet <string> existingNames = directive .GetAttributes() .Select(attr => attr.GetName()) .ToJetHashSet(s => s, StringComparer.OrdinalIgnoreCase); foreach (string attributeName in directiveInfo.SupportedAttributes.Select(attr => attr.Name)) { if (existingNames.Contains(attributeName)) { continue; } var item = new TextLookupItem(attributeName); item.InitializeRanges(ranges, context.BasicContext); collector.Add(item); } return(true); }
public ForNode(DirectiveInfo info) : base(info) { var node = ExpressionRewriter.Rewrite(Token.ReadTokens(info.ParametersReader)); if(!node.Token.IsSymbol(",")) { throw new DataTypeException("Expected comma-separated list", this); } var children = node.GetChildrenTokens(); if(children.Count < 3 || children.Count > 4) { throw new MissingDataException("#for directive requires 3 to 4 parameters", Location); } if(children[0].Token.TokenType != TokenType.Identifier) { throw new MissingDataException("Identifier", children[0].Location); } Variable = children[0].Token.ToString(); Start = children[1]; End = children[2]; Step = children.Count > 3 ? children[3] : null; }
/// <summary>Finds an anchor for a newly created directive inside a list of existing directives.</summary> /// <param name="newDirective">The directive to add.</param> /// <param name="existingDirectives">The existing directives.</param> /// <param name="directiveInfoManager">An instance of <see cref="DirectiveInfoManager"/>.</param> /// <returns>A pair indicating the anchor (can be null) and its relative position.</returns> public static Pair <IT4Directive, BeforeOrAfter> FindAnchor( [NotNull] this IT4Directive newDirective, [NotNull] IT4Directive[] existingDirectives, [NotNull] DirectiveInfoManager directiveInfoManager ) { // no anchor if (existingDirectives.Length == 0) { return(Pair.Of((IT4Directive)null, BeforeOrAfter.Before)); } // directive name should never be null, but you never know string newName = newDirective.GetName(); if (String.IsNullOrEmpty(newName)) { return(Pair.Of(existingDirectives.Last(), BeforeOrAfter.After)); } var lastDirectiveByName = new Dictionary <string, IT4Directive>(StringComparer.OrdinalIgnoreCase); DirectiveInfo directiveInfo = directiveInfoManager.GetDirectiveByName(newName); string newsortValue = GetSortValue(newDirective, directiveInfo, directiveInfoManager); foreach (IT4Directive existingDirective in existingDirectives) { string existingName = existingDirective.GetName(); if (existingName == null) { continue; } lastDirectiveByName[existingName] = existingDirective; // directive of the same type as the new one: // if the new directive comes alphabetically before the existing one, we got out anchor if (String.Equals(existingName, newName, StringComparison.OrdinalIgnoreCase)) { string existingSortValue = GetSortValue(existingDirective, directiveInfo, directiveInfoManager); if (String.Compare(newsortValue, existingSortValue, StringComparison.OrdinalIgnoreCase) < 0) { return(Pair.Of(existingDirective, BeforeOrAfter.Before)); } } } // no anchor being alphabetically after the new directive was found: // the last directive of the same type will be used as an anchor if (lastDirectiveByName.TryGetValue(newName, out IT4Directive lastDirective)) { return(Pair.Of(lastDirective, BeforeOrAfter.After)); } // there was no directive of the same type as the new one // the anchor will be the last directive of the type just before (determined by the position in DirectiveInfo.AllDirectives) if (directiveInfo != null) { int index = directiveInfoManager.AllDirectives.IndexOf(directiveInfo) - 1; while (index >= 0) { if (lastDirectiveByName.TryGetValue(directiveInfoManager.AllDirectives[index].Name, out lastDirective)) { return(Pair.Of(lastDirective, BeforeOrAfter.After)); } --index; } return(Pair.Of(existingDirectives.First(), BeforeOrAfter.Before)); } // we don't know the directive name (shouldn't happen), use the last directive as an anchor return(Pair.Of(existingDirectives.Last(), BeforeOrAfter.After)); }
public static IEnumerable <IT4Directive> GetDirectives([NotNull] this IT4DirectiveOwner directiveOwner, [NotNull] DirectiveInfo directiveInfo) => directiveOwner.GetDirectives().Where(d => directiveInfo.Name.Equals(d.GetName(), StringComparison.OrdinalIgnoreCase));
public static bool IsSpecificDirective([CanBeNull] this IT4Directive directive, [CanBeNull] DirectiveInfo directiveInfo) => directive != null && directiveInfo != null && directiveInfo.Name.Equals(directive.GetName(), StringComparison.OrdinalIgnoreCase);
/// <summary> /// Initializes a new instance of the <see cref="DirectiveNode"/> class. /// </summary> /// <param name="info">The directive's information.</param> protected DirectiveNode(DirectiveInfo info) : base(info.Location) { DirectiveName = info.DirectiveName; }
/// <summary> /// Creates an instance of a directive. /// </summary> /// <param name="nodeType">Type of the directive node.</param> /// <param name="info">The new instance's directive information.</param> /// <returns>The new <see cref="DirectiveNode"/> instance.</returns> private static DirectiveNode CreateInstance(Type nodeType, DirectiveInfo info) { return Activator.CreateInstance(nodeType, info) as DirectiveNode; }
public IfNode(DirectiveInfo info) : base(info) { Condition = ExpressionRewriter.Rewrite(Token.ReadTokens(info.ParametersReader)); }
public EndDirectiveNode(DirectiveInfo info) : base(info) { }
public static IEnumerable <IT4Directive> GetDirectives([NotNull] this IT4DirectiveOwner directiveOwner, [NotNull] DirectiveInfo directiveInfo) { if (directiveOwner == null) { throw new ArgumentNullException("directiveOwner"); } if (directiveInfo == null) { throw new ArgumentNullException("directiveInfo"); } return(directiveOwner.GetDirectives().Where(d => directiveInfo.Name.Equals(d.GetName(), StringComparison.OrdinalIgnoreCase))); }
public static IEnumerable <IT4Directive> GetDirectives( [NotNull] this IT4File file, [NotNull] DirectiveInfo directiveInfo ) => file.Blocks.OfType <IT4Directive>().Where(d => directiveInfo.Name.Equals(d.Name?.GetText(), StringComparison.OrdinalIgnoreCase));