Search in sources :

Example 1 with BMMConstraintImposer

use of com.nedap.archie.adlparser.modelconstraints.BMMConstraintImposer 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)

Aggregations

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 CObject (com.nedap.archie.aom.CObject)1 CTerminologyCode (com.nedap.archie.aom.primitives.CTerminologyCode)1 Cardinality (com.nedap.archie.base.Cardinality)1 MultiplicityInterval (com.nedap.archie.base.MultiplicityInterval)1 Hover (org.eclipse.lsp4j.Hover)1 MarkupContent (org.eclipse.lsp4j.MarkupContent)1 Range (org.eclipse.lsp4j.Range)1 BmmClass (org.openehr.bmm.core.BmmClass)1 BmmProperty (org.openehr.bmm.core.BmmProperty)1