Search in sources :

Example 1 with ADLParseException

use of com.nedap.archie.adlparser.ADLParseException in project archetype-languageserver by nedap.

the class ADL14ConvertingStorage method addFile.

public void addFile(TextDocumentItem item) {
    ADL14Parser adl14Parser = new ADL14Parser(BuiltinReferenceModels.getMetaModels());
    Archetype archetype = null;
    try {
        archetype = adl14Parser.parse(item.getText(), configuration);
        textService.pushDiagnostics(new VersionedTextDocumentIdentifier(item.getUri(), item.getVersion()), null, new ValidationResult(archetype));
        adl14Files.put(item.getUri(), archetype);
    } catch (ADLParseException ex) {
        textService.pushDiagnostics(new VersionedTextDocumentIdentifier(item.getUri(), item.getVersion()), ex.getErrors());
    }
}
Also used : VersionedTextDocumentIdentifier(org.eclipse.lsp4j.VersionedTextDocumentIdentifier) Archetype(com.nedap.archie.aom.Archetype) ADL14Parser(com.nedap.archie.adl14.ADL14Parser) ValidationResult(com.nedap.archie.archetypevalidator.ValidationResult) ADLParseException(com.nedap.archie.adlparser.ADLParseException)

Example 2 with ADLParseException

use of com.nedap.archie.adlparser.ADLParseException in project archetype-languageserver by nedap.

the class BroadcastingArchetypeRepository method extractADL2Info.

private void extractADL2Info(TextDocumentItem textDocumentItem) {
    try {
        ADL2SymbolExtractor adl2SymbolExtractor = new ADL2SymbolExtractor();
        DocumentInformation documentInformation = adl2SymbolExtractor.extractSymbols(textDocumentItem.getUri(), textDocumentItem.getText());
        symbolsByUri.put(textDocumentItem.getUri(), documentInformation);
        if (documentInformation.getArchetypeId() != null) {
            documentsByArchetypeId.put(documentInformation.getArchetypeId(), textDocumentItem);
        }
        if (documentInformation.getErrors().hasNoErrors()) {
            ADLParser adlParser = new ADLParser(BuiltinReferenceModels.getMetaModels());
            // no console output please :)
            adlParser.setLogEnabled(false);
            Archetype archetype = null;
            try {
                archetype = adlParser.parse(textDocumentItem.getText());
                addArchetype(archetype);
                // perform incremental compilation here
                invalidateAndRecompileArchetypes(archetype);
                ValidationResult result = getValidationResult(archetype.getArchetypeId().toString());
                Archetype archetypeForTerms = archetype;
                if (result != null && result.getFlattened() != null) {
                    archetypeForTerms = result.getFlattened();
                }
                String language = archetype.getOriginalLanguage() != null ? archetype.getOriginalLanguage().getCodeString() : null;
                if (language == null) {
                    language = "en";
                }
                documentInformation.setHoverInfo(new ArchetypeHoverInfo(documentInformation, archetype, archetypeForTerms, language));
                SymbolNameFromTerminologyHelper.giveNames(documentInformation.getSymbols(), archetypeForTerms, language);
            // diagnostics will now be pushed from within the invalidateArchetypesAndRecompile method
            } catch (ADLParseException e) {
                // this should have been checked in the previous step. But still, it could happen.
                textDocumentService.pushDiagnostics(new VersionedTextDocumentIdentifier(textDocumentItem.getUri(), textDocumentItem.getVersion()), e.getErrors());
            } catch (Exception ex) {
                // this particular exce[tion is a parse error, usually when extracting JSON. be sure to post taht
                textDocumentService.pushDiagnostics(new VersionedTextDocumentIdentifier(textDocumentItem.getUri(), textDocumentItem.getVersion()), ex);
            }
        } else {
            textDocumentService.pushDiagnostics(new VersionedTextDocumentIdentifier(textDocumentItem.getUri(), textDocumentItem.getVersion()), documentInformation.getErrors());
        }
    } catch (IOException e) {
        // shouldn't happen, ever, just in memory processing
        throw new RuntimeException(e);
    }
}
Also used : ADLParser(com.nedap.archie.adlparser.ADLParser) ADL2SymbolExtractor(com.nedap.openehr.lsp.symbolextractor.ADL2SymbolExtractor) Archetype(com.nedap.archie.aom.Archetype) DocumentInformation(com.nedap.openehr.lsp.document.DocumentInformation) IOException(java.io.IOException) ValidationResult(com.nedap.archie.archetypevalidator.ValidationResult) ArchetypeHoverInfo(com.nedap.openehr.lsp.document.ArchetypeHoverInfo) ADLParseException(com.nedap.archie.adlparser.ADLParseException) IOException(java.io.IOException) ADLParseException(com.nedap.archie.adlparser.ADLParseException)

Aggregations

ADLParseException (com.nedap.archie.adlparser.ADLParseException)2 Archetype (com.nedap.archie.aom.Archetype)2 ValidationResult (com.nedap.archie.archetypevalidator.ValidationResult)2 ADL14Parser (com.nedap.archie.adl14.ADL14Parser)1 ADLParser (com.nedap.archie.adlparser.ADLParser)1 ArchetypeHoverInfo (com.nedap.openehr.lsp.document.ArchetypeHoverInfo)1 DocumentInformation (com.nedap.openehr.lsp.document.DocumentInformation)1 ADL2SymbolExtractor (com.nedap.openehr.lsp.symbolextractor.ADL2SymbolExtractor)1 IOException (java.io.IOException)1 VersionedTextDocumentIdentifier (org.eclipse.lsp4j.VersionedTextDocumentIdentifier)1