use of mb.nabl2.constraints.sets.CSubsetEq in project nabl by metaborg.
the class SetComponent method solve.
// ------------------------------------------------------------------------------------------------------//
private Optional<SolveResult> solve(CSubsetEq constraint) {
ITerm left = unifier().findRecursive(constraint.getLeft());
ITerm right = unifier().findRecursive(constraint.getRight());
if (!left.isGround() && right.isGround()) {
return Optional.empty();
}
Optional<Set<IElement<ITerm>>> maybeLeftSet = evaluator.match(left, unifier());
Optional<Set<IElement<ITerm>>> maybeRightSet = evaluator.match(right, unifier());
if (!(maybeLeftSet.isPresent() && maybeRightSet.isPresent())) {
return Optional.empty();
}
Multimap<Object, IElement<ITerm>> leftProj = SetEvaluator.project(maybeLeftSet.get(), constraint.getProjection());
Multimap<Object, IElement<ITerm>> rightProj = SetEvaluator.project(maybeRightSet.get(), constraint.getProjection());
Multimap<Object, IElement<ITerm>> result = HashMultimap.create();
result.putAll(leftProj);
result.keySet().removeAll(rightProj.keySet());
if (result.isEmpty()) {
return Optional.of(SolveResult.empty());
} else {
MessageContent content = MessageContent.builder().append(B.newAppl(NAME_OP)).append(" not in ").append(right).build();
Iterable<IMessageInfo> messages = makeMessages(constraint.getMessageInfo().withDefaultContent(content), result.values());
return Optional.of(SolveResult.messages(messages));
}
}
Aggregations