public override void ConsumeToken(IT4Token token) { if (token.NodeType != T4TokenNodeTypes.NEW_LINE) { Builder.Append(Convert(token)); } }
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))); } }
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 HandleIncludeDirective([NotNull] IT4Directive directive, [NotNull] CompositeElement parentElement) { var fileAttr = directive.GetAttribute(_directiveInfoManager.Include.FileAttribute.Name) as T4DirectiveAttribute; if (fileAttr == null) { return; } IT4Token valueToken = fileAttr.GetValueToken(); if (valueToken == null) { return; } bool once = false; if (_t4Environment.VsVersion2.Major >= VsVersions.Vs2013) { string onceString = directive.GetAttributeValue(_directiveInfoManager.Include.OnceAttribute.Name); once = Boolean.TrueString.Equals(onceString, StringComparison.OrdinalIgnoreCase); } HandleInclude(valueToken.GetText(), fileAttr, parentElement, once); }
public override void ConsumeToken(IT4Token token) { if (token.NodeType != T4TokenNodeTypes.NEW_LINE) { LastToken = token; } }
protected override ITreeNode GetSuperClassNodeFromOriginalFile(IFile originalFile) { var t4File = (IT4File)originalFile; foreach (IT4Directive templateDirective in t4File.GetDirectives(_directiveInfoManager.Template)) { IT4Token inheritsToken = templateDirective.GetAttributeValueToken(_directiveInfoManager.Template.InheritsAttribute.Name); if (inheritsToken != null) { return(inheritsToken); } } return(null); }
protected override bool IsAvailable(T4CodeCompletionContext context) { ITreeNode node = context.BasicContext.File.FindNodeAt(context.BasicContext.SelectedTreeRange); if (!(node?.Parent is IT4Directive directive)) { return(false); } TokenNodeType tokenType = node.GetTokenType(); IT4Token nameToken = directive.GetNameToken(); return(tokenType == T4TokenNodeTypes.Name ? nameToken == node : nameToken == null && node.SelfAndLeftSiblings().All(IsWhitespaceOrDirectiveStart)); }
public static Pair <IT4Token, string> GetAttributeValueIgnoreOnlyWhitespace([CanBeNull] this IT4Directive directive, [CanBeNull] string attributeName) { IT4Token valueToken = directive.GetAttributeValueToken(attributeName); if (valueToken == null) { return(new Pair <IT4Token, string>()); } string value = valueToken.GetText(); if (value.Trim().Length == 0) { return(new Pair <IT4Token, string>()); } return(new Pair <IT4Token, string>(valueToken, value)); }
private void HandleIncludeDirective([NotNull] IT4Directive directive, [NotNull] CompositeElement parentElement) { var fileAttr = (T4DirectiveAttribute)directive.GetAttribute(_directiveInfoManager.Include.FileAttribute.Name); if (fileAttr == null) { return; } IT4Token valueToken = fileAttr.GetValueToken(); if (valueToken == null) { return; } HandleInclude(valueToken.GetText(), fileAttr, parentElement); }
/// <summary> /// Handles a code block: depending of whether it's a feature or transform text result, /// it is not added to the same part of the C# file. /// </summary> /// <param name="codeBlock">The code block.</param> private void HandleCodeBlock([NotNull] IT4CodeBlock codeBlock) { IT4Token codeToken = codeBlock.GetCodeToken(); if (codeToken == null) { return; } GenerationResult result; var expressionBlock = codeBlock as T4ExpressionBlock; if (expressionBlock != null) { result = _rootFeatureStarted && _includeDepth == 0 ? _featureResult : _transformTextResult; result.Builder.Append("this.Write(__\x200CToString("); } else { if (codeBlock is T4FeatureBlock) { if (_includeDepth == 0) { _rootFeatureStarted = true; } result = _featureResult; } else { result = _transformTextResult; } } result.Builder.Append(CodeCommentStart); result.AppendMapped(codeToken); result.Builder.Append(CodeCommentEnd); if (expressionBlock != null) { result.Builder.Append("));"); } result.Builder.AppendLine(); }
/// <summary> /// Gets the code tree text range of a code block. /// </summary> /// <param name="codeBlock">The code block.</param> /// <returns>A <see cref="TreeTextRange"/> representing the code range in <paramref name="codeBlock"/>.</returns> protected override TreeTextRange GetCodeTreeTextRange(IT4CodeBlock codeBlock) { IT4Token codeToken = codeBlock.GetCodeToken(); return(codeToken != null?codeToken.GetTreeTextRange() : TreeTextRange.InvalidRange); }
/// <summary> /// Gets the name of the node. /// </summary> /// <returns>The node name, or <c>null</c> if none is available.</returns> public string GetName() { IT4Token nameToken = GetNameToken(); return(nameToken != null?nameToken.GetText() : null); }
public override void ConsumeToken(IT4Token token) => Builder.Append(Convert(token));
public static string GetAttributeValue([CanBeNull] this IT4Directive directive, [CanBeNull] string attributeName) { IT4Token token = directive.GetAttributeValueToken(attributeName); return(token != null?token.GetText() : null); }
/// <summary> /// Gets the value of this attribute. /// </summary> /// <returns>The attribute value, or <c>null</c> if none is available.</returns> public string GetValue() { IT4Token valueToken = GetValueToken(); return(valueToken != null?valueToken.GetText() : null); }
/// <summary> /// Gets the text of the code block. /// </summary> /// <returns>The code text, or <c>null</c> if none is available.</returns> public string GetCodeText() { IT4Token token = GetCodeToken(); return(token != null?token.GetText() : null); }