import { JSONSchema } from "../../model/jsonSchema" ; import { ASTNode , IApplicableSchema } from "./ast-node" ; import { NoOpSchemaCollector , SchemaCollector } from "./schema-collector" ; import { IProblem , ValidationResult } from "./validation-result" ; export class JSONDocument { readonly uri : string ; readonly root : ASTNode ; readonly syntaxErrors : IProblem [ ] ; constructor ( uri , root , syntaxErrors ) { this . uri = uri ; this . root = root ; this . syntaxErrors = syntaxErrors ; } getNodeFromOffset ( offset ) { return this . root && this . root . getNodeFromOffset ( offset ) ; } getNodeFromOffsetEndInclusive ( offset ) { return this . root && this . root . getNodeFromOffsetEndInclusive ( offset ) ; } visit ( visitor ) { if ( this . root ) { this . root . visit ( visitor ) ; } } validate ( schema ) { if ( this . root && schema ) { const validationResult = new ValidationResult ( ) ; this . root . validate ( schema , validationResult , new NoOpSchemaCollector ( ) ) ; return validationResult . problems ; } return null ; } getMatchingSchemas ( schema , focusOffset = - 1 , exclude = null ) { const matchingSchemas = new SchemaCollector ( focusOffset , exclude ) ; const validationResult = new ValidationResult ( ) ; if ( this . root && schema ) { this . root . validate ( schema , validationResult , matchingSchemas ) ; } return matchingSchemas . schemas ; } getValidationProblems ( schema , focusOffset = - 1 , exclude = null ) { const matchingSchemas = new SchemaCollector ( focusOffset , exclude ) ; const validationResult = new ValidationResult ( ) ; if ( this . root && schema ) { this . root . validate ( schema , validationResult , matchingSchemas ) ; } return validationResult . problems ; } }