Esempio n. 1
0
        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)));
            }
        }
Esempio n. 2
0
        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)));
                }
            }
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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));
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        /// <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);
        }
Esempio n. 7
0
        public static string GetAttributeValue([CanBeNull] this IT4Directive directive, [CanBeNull] string attributeName)
        {
            IT4Token token = directive.GetAttributeValueToken(attributeName);

            return(token != null?token.GetText() : null);
        }
Esempio n. 8
0
        /// <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);
        }
Esempio n. 9
0
        /// <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);
        }