/**
   * This default implementation asserts that the <tt>constraint</tt> is boolean-valued if it is an
   * invariant, pre-condition, or post-condition constraint and returns the value of its body
   * expression by delegation to {@link Visitable#accept(Visitor)}.
   */
  @Override
  public Object visitConstraint(@NonNull Constraint constraint) {
    LanguageExpression specification = constraint.getOwnedSpecification();
    if (!(specification instanceof ExpressionInOCL)) {
      return null;
    }
    OCLExpression body = ((ExpressionInOCL) specification).getOwnedBody();
    //		boolean isBoolean = BOOLEAN_CONSTRAINTS.contains(constraint.getStereotype());

    if (body == null) {
      throw new IllegalArgumentException("constraint has no body expression"); // $NON-NLS-1$
    }

    //		if (isBoolean && !(body.getType() != metamodelManager.getBooleanType())) {
    //			throw new IllegalArgumentException("constraint is not boolean"); //$NON-NLS-1$
    //		}

    Object result = body.accept(undecoratedVisitor);
    //		try {
    //			if (result == null) {
    //				return evaluationEnvironment.throwInvalidEvaluation("null constraint result");
    //			}
    return ValueUtil.asBoolean(result);
    //		} catch (InvalidValueException e) {
    //			return e.getValue();
    //		}
  }
示例#2
0
 public static String getStereotype(@NonNull Constraint object) {
   EStructuralFeature eContainingFeature = object.eContainingFeature();
   if (eContainingFeature == PivotPackage.Literals.CLASS__OWNED_INVARIANTS) {
     return PivotConstants.INVARIANT_NAME;
   } else if (eContainingFeature == PivotPackage.Literals.OPERATION__BODY_EXPRESSION) {
     return PivotConstants.BODY_NAME;
   } else if (eContainingFeature == PivotPackage.Literals.OPERATION__OWNED_POSTCONDITIONS) {
     return PivotConstants.POSTCONDITION_NAME;
   } else if (eContainingFeature == PivotPackage.Literals.OPERATION__OWNED_PRECONDITIONS) {
     return PivotConstants.PRECONDITION_NAME;
   } else if (eContainingFeature == PivotPackage.Literals.PROPERTY__OWNED_EXPRESSION) {
     return PivotConstants.DERIVATION_NAME;
   }
   return "";
 }