Esempio n. 1
0
        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);

            var attribute = node.GetContainingNode <IT4DirectiveAttribute>();

            Assertion.AssertNotNull(attribute, "attribute != null");

            var directive = attribute.GetContainingNode <IT4Directive>();

            Assertion.AssertNotNull(directive, "directive != null");

            DirectiveInfo          directiveInfo = T4DirectiveInfoManager.GetDirectiveByName(directive.Name.GetText());
            DirectiveAttributeInfo attributeInfo = directiveInfo?.GetAttributeByName(attribute.Name.GetText());

            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);
        }
Esempio n. 2
0
        protected override void Run(
            IT4Directive element,
            ElementProblemAnalyzerData data,
            IHighlightingConsumer consumer
            )
        {
            var nameToken = element.Name;

            if (nameToken == null)
            {
                return;
            }
            var directiveInfo = T4DirectiveInfoManager.GetDirectiveByName(nameToken.GetText());
            var missingInfos  = directiveInfo?.SupportedAttributes
                                .Where(requiredAttributeInfo =>
                                       requiredAttributeInfo.IsRequired &&
                                       !element
                                       .AttributesEnumerable
                                       .Select(attribute => attribute.Name)
                                       .Any(name => name
                                            .GetText()
                                            .Equals(requiredAttributeInfo.Name, StringComparison.OrdinalIgnoreCase)
                                            )
                                       )
                                .AsList();

            if (missingInfos?.Any() != true)
            {
                return;
            }
            consumer.AddHighlighting(new MissingRequiredAttributeError(nameToken, CreateMessage(missingInfos)));
        }
Esempio n. 3
0
        protected override void Run(IT4Directive directive, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
        {
            var directiveInfo = T4DirectiveInfoManager.GetDirectiveByName(directive.Name?.GetText());

            if (directiveInfo == null)
            {
                return;
            }

            var badAttributes = directive
                                .Attributes
                                .Where(attribute => directiveInfo.GetAttributeByName(attribute.Name.GetText()) == null);

            foreach (var attribute in badAttributes)
            {
                consumer.AddHighlighting(new UnexpectedAttributeWarning(attribute.Name));
            }
        }
        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());
        }
Esempio n. 5
0
        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 = T4DirectiveInfoManager.GetDirectiveByName(directive.Name.GetText());

            if (directiveInfo == null)
            {
                return(false);
            }

            JetHashSet <string> existingNames = directive
                                                .Attributes
                                                .Select(attr => attr.Name.GetText())
                                                .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);
        }
        protected override void Run(
            IT4AttributeValue element,
            ElementProblemAnalyzerData data,
            IHighlightingConsumer consumer
            )
        {
            if (!(element.Parent is IT4DirectiveAttribute attribute))
            {
                return;
            }
            if (!(attribute.Parent is IT4Directive directive))
            {
                return;
            }
            var attributeInfo = T4DirectiveInfoManager
                                .GetDirectiveByName(directive.Name.GetText())
                                ?.GetAttributeByName(attribute.Name.GetText());

            if (attributeInfo?.IsValid(element.GetText()) != false)
            {
                return;
            }
            consumer.AddHighlighting(new InvalidAttributeValueError(element));
        }