Search in sources :

Example 1 with MultiplicityInterval

use of com.nedap.archie.base.MultiplicityInterval in project archetype-languageserver by nedap.

the class ArchetypeHoverInfo method extractHoverInfo.

private void extractHoverInfo(DocumentInformation documentInformation, CAttribute attribute, Archetype archetypeForTerms) {
    for (CObject object : attribute.getChildren()) {
        try {
            if (object instanceof CComplexObject) {
                extractHoverInfo(documentInformation, (CComplexObject) object, archetypeForTerms);
            } else if (object instanceof CTerminologyCode) {
                extractHoverInfo(documentInformation, (CTerminologyCode) object, archetypeForTerms);
            } else if (object instanceof ArchetypeSlot) {
                getHoverInfoForCObject(documentInformation, object, archetypeForTerms);
            }
        // for the other primitives, hovers should not be important
        } catch (Exception e) {
            // If this fails, fine, continue with the rest of the file!
            // TODO: report to client?
            e.printStackTrace();
        }
    }
    try {
        CAttribute flatAttribute = archetypeForTerms.itemAtPath(attribute.getPath());
        if (flatAttribute == null) {
            flatAttribute = attribute;
        }
        Cardinality cardinality = null;
        MultiplicityInterval existence = null;
        // TODO: do a proper path lookup through the RM model?
        CAttribute defaults = new BMMConstraintImposer(metaModels.getSelectedBmmModel()).getDefaultAttribute(flatAttribute.getParent().getRmTypeName(), flatAttribute.getRmAttributeName());
        if (flatAttribute.getCardinality() != null) {
            cardinality = flatAttribute.getCardinality();
        } else {
            if (defaults != null) {
                cardinality = defaults.getCardinality();
            }
        }
        if (flatAttribute.getExistence() != null) {
            existence = flatAttribute.getExistence();
        } else {
            if (defaults != null) {
                existence = flatAttribute.getExistence();
            }
        }
        boolean multiple = flatAttribute.isMultiple();
        StringBuilder content = new StringBuilder();
        if (cardinality != null) {
            content.append("Cardinality: ");
            content.append(cardinality.toString());
        }
        if (existence != null) {
            content.append(", existence: " + existence.toString());
        }
        content.append(multiple ? "\n multiple valued attribute" : "\n single valued attribute");
        BmmClass classDefinition = metaModels.getSelectedBmmModel().getClassDefinition(flatAttribute.getParent().getRmTypeName());
        if (classDefinition != null) {
            BmmProperty bmmProperty = classDefinition.getFlatProperties().get(flatAttribute.getRmAttributeName());
            if (bmmProperty != null) {
                content.append("\n\nRM type name: *" + bmmProperty.getType().toDisplayString() + "*");
            }
        }
        content.append("\n\n path: " + attribute.getPath());
        Hover hover = new Hover();
        hover.setContents(new MarkupContent(MARKDOWN, content.toString()));
        Range range = getHoverRange(documentInformation, attribute);
        if (range != null) {
            hoverRanges.addRange(range, hover);
        }
    } catch (Exception e) {
        // TODO: report to client?
        e.printStackTrace();
    }
}
Also used : BmmClass(org.openehr.bmm.core.BmmClass) Cardinality(com.nedap.archie.base.Cardinality) CObject(com.nedap.archie.aom.CObject) CComplexObject(com.nedap.archie.aom.CComplexObject) CAttribute(com.nedap.archie.aom.CAttribute) Range(org.eclipse.lsp4j.Range) MarkupContent(org.eclipse.lsp4j.MarkupContent) MultiplicityInterval(com.nedap.archie.base.MultiplicityInterval) BMMConstraintImposer(com.nedap.archie.adlparser.modelconstraints.BMMConstraintImposer) ArchetypeSlot(com.nedap.archie.aom.ArchetypeSlot) BmmProperty(org.openehr.bmm.core.BmmProperty) CTerminologyCode(com.nedap.archie.aom.primitives.CTerminologyCode) Hover(org.eclipse.lsp4j.Hover)

Example 2 with MultiplicityInterval

use of com.nedap.archie.base.MultiplicityInterval in project archetype-languageserver by nedap.

the class ArchetypeHoverInfo method getHoverInfoForCObject.

private void getHoverInfoForCObject(DocumentInformation documentInformation, CObject definition, Archetype archetypeForTerms) {
    ArchetypeTerm term = archetypeForTerms.getTerm(definition, language);
    String content;
    if (term != null) {
        content = "### " + definition.getRmTypeName() + ": " + term.getText() + "\n\n\t" + term.getDescription();
    } else {
        content = "### No term found";
    }
    CObject flattenedObject = (definition instanceof CPrimitiveObject) ? definition : archetypeForTerms.itemAtPath(definition.getPath());
    if (flattenedObject == null) {
        // fallback if something went wrong
        flattenedObject = definition;
    }
    MultiplicityInterval occurrences = flattenedObject.effectiveOccurrences(metaModels::referenceModelPropMultiplicity);
    content += "\n occurrences: " + occurrences;
    content += "\n\n path: " + definition.getPath();
    Hover hover = new Hover();
    hover.setContents(new MarkupContent(MARKDOWN, content.toString()));
    Range range = getHoverRange(documentInformation, definition);
    if (range != null) {
        hoverRanges.addRange(range, hover);
    }
}
Also used : TerminologyCodeWithArchetypeTerm(com.nedap.archie.aom.terminology.TerminologyCodeWithArchetypeTerm) ArchetypeTerm(com.nedap.archie.aom.terminology.ArchetypeTerm) CObject(com.nedap.archie.aom.CObject) Hover(org.eclipse.lsp4j.Hover) Range(org.eclipse.lsp4j.Range) CPrimitiveObject(com.nedap.archie.aom.CPrimitiveObject) MarkupContent(org.eclipse.lsp4j.MarkupContent) MultiplicityInterval(com.nedap.archie.base.MultiplicityInterval)

Aggregations

CObject (com.nedap.archie.aom.CObject)2 MultiplicityInterval (com.nedap.archie.base.MultiplicityInterval)2 Hover (org.eclipse.lsp4j.Hover)2 MarkupContent (org.eclipse.lsp4j.MarkupContent)2 Range (org.eclipse.lsp4j.Range)2 BMMConstraintImposer (com.nedap.archie.adlparser.modelconstraints.BMMConstraintImposer)1 ArchetypeSlot (com.nedap.archie.aom.ArchetypeSlot)1 CAttribute (com.nedap.archie.aom.CAttribute)1 CComplexObject (com.nedap.archie.aom.CComplexObject)1 CPrimitiveObject (com.nedap.archie.aom.CPrimitiveObject)1 CTerminologyCode (com.nedap.archie.aom.primitives.CTerminologyCode)1 ArchetypeTerm (com.nedap.archie.aom.terminology.ArchetypeTerm)1 TerminologyCodeWithArchetypeTerm (com.nedap.archie.aom.terminology.TerminologyCodeWithArchetypeTerm)1 Cardinality (com.nedap.archie.base.Cardinality)1 BmmClass (org.openehr.bmm.core.BmmClass)1 BmmProperty (org.openehr.bmm.core.BmmProperty)1