Пример #1
0
        public override List <Diagnostic> VisitTemplateDefinition([NotNull] LGFileParser.TemplateDefinitionContext context)
        {
            var result            = new List <Diagnostic>();
            var templateNameLine  = context.templateNameLine();
            var errorTemplateName = templateNameLine.errorTemplateName();

            if (errorTemplateName != null)
            {
                result.Add(BuildLGDiagnostic(TemplateErrors.InvalidTemplateName, context: errorTemplateName, includeTemplateNameInfo: false));
            }
            else
            {
                var templateName = context.templateNameLine().templateName().GetText();

                if (visitedTemplateNames.Contains(templateName))
                {
                    result.Add(BuildLGDiagnostic(TemplateErrors.DuplicatedTemplateInSameTemplate(templateName), context: templateNameLine));
                }
                else
                {
                    visitedTemplateNames.Add(templateName);
                    foreach (var reference in templates.References)
                    {
                        var sameTemplates = reference.Where(u => u.Name == templateName);
                        foreach (var sameTemplate in sameTemplates)
                        {
                            result.Add(BuildLGDiagnostic(TemplateErrors.DuplicatedTemplateInDiffTemplate(sameTemplate.Name, sameTemplate.Source), context: templateNameLine));
                        }
                    }

                    if (result.Count > 0)
                    {
                        return(result);
                    }
                    else
                    {
                        if (context.templateBody() == null)
                        {
                            result.Add(BuildLGDiagnostic(TemplateErrors.NoTemplateBody(templateName), DiagnosticSeverity.Warning, context.templateNameLine()));
                        }
                        else
                        {
                            result.AddRange(Visit(context.templateBody()));
                        }
                    }
                }
            }

            return(result);
        }
Пример #2
0
        /// <summary>
        /// Returns a list of Diagnostic instances.
        /// </summary>
        /// <returns>Report result.</returns>
        public List <Diagnostic> Check()
        {
            var result = new List <Diagnostic>();

            if (_templates.AllTemplates.Count == 0)
            {
                var diagnostic = new Diagnostic(Range.DefaultRange, TemplateErrors.NoTemplate, DiagnosticSeverity.Warning, _templates.Id);
                result.Add(diagnostic);
                return(result);
            }

            foreach (var template in _templates)
            {
                _currentTemplate = template;
                var templateDiagnostics = new List <Diagnostic>();

                // checker duplicated in different files
                foreach (var reference in _templates.References)
                {
                    var sameTemplates = reference.Where(u => u.Name == template.Name);
                    foreach (var sameTemplate in sameTemplates)
                    {
                        var startLine  = template.SourceRange.Range.Start.Line;
                        var range      = new Range(startLine, 0, startLine, template.Name.Length + 1);
                        var diagnostic = new Diagnostic(range, TemplateErrors.DuplicatedTemplateInDiffTemplate(sameTemplate.Name, sameTemplate.SourceRange.Source), source: _templates.Id);
                        templateDiagnostics.Add(diagnostic);
                    }
                }

                if (templateDiagnostics.Count == 0 && template.TemplateBodyParseTree != null)
                {
                    templateDiagnostics.AddRange(Visit(template.TemplateBodyParseTree));
                }

                result.AddRange(templateDiagnostics);
            }

            return(result);
        }