import { flatMap } from "lodash" ; import { XMLDocument , XMLAstVisitor , XMLAttribute , XMLElement , } from "@xml-tools/ast" ; import { UI5SemanticModel } from "@ui5-language-assistant/semantic-model-types" ; import { UI5XMLViewIssue } from "../api" ; export interface UI5ValidatorsConfig { /**
     * Careful on abusing top level document validators.
     * If such validators need to traverse the whole AST there may
     * be performance implications.
     */ document : ( ( xmlNode : XMLDocument , model : UI5SemanticModel ) => UI5XMLViewIssue [ ] ) [ ] ; element : ( ( xmlNode : XMLElement , model : UI5SemanticModel ) => UI5XMLViewIssue [ ] ) [ ] ; attribute : ( ( xmlNode : XMLAttribute , model : UI5SemanticModel ) => UI5XMLViewIssue [ ] ) [ ] ; } export class ValidatorVisitor implements XMLAstVisitor { public collectedIssues : UI5XMLViewIssue [ ] = [ ] ; constructor ( private model , private validators ) { } visitXMLDocument ( node ) { const nodeIssues = flatMap ( this . validators . document , ( _ ) => _ ( node , this . model ) ) ; this . collectedIssues = this . collectedIssues . concat ( nodeIssues ) ; } visitXMLElement ( node ) { const nodeIssues = flatMap ( this . validators . element , ( _ ) => _ ( node , this . model ) ) ; this . collectedIssues = this . collectedIssues . concat ( nodeIssues ) ; } visitXMLAttribute ( node ) { const nodeIssues = flatMap ( this . validators . attribute , ( _ ) => _ ( node , this . model ) ) ; this . collectedIssues = this . collectedIssues . concat ( nodeIssues ) ; } }