use of com.nedap.archie.base.Cardinality 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();
}
}
Aggregations