// checks (3) and (1)
  private Expression genObjOperation(Context ctx, MClass srcClass, Expression srcExpr)
      throws SemanticException {
    Expression res = null;

    // find operation
    String opname = fOp.getText();
    MOperation op = srcClass.operation(opname, true);
    if (op != null) {
      // check for isQuery operation with OCL body
      if (!op.hasExpression())
        throw new SemanticException(
            fOp,
            "Operation `"
                + srcClass.name()
                + "::"
                + op.signature()
                + "' cannot be used in OCL expression "
                + "(only side effect-free operations with a return type and an OCL expression as body may be used).");

      try {
        // constructor performs additional checks
        res = new ExpObjOp(op, fArgExprs);
      } catch (ExpInvalidException ex) {
        throw new SemanticException(
            fOp, "In operation call `" + srcClass.name() + "::" + opname + "': " + ex.getMessage());
      }
    } else {
      // try standard operation
      res = genStdOperation(ctx, fOp, opname, fArgExprs);
    }
    return res;
  }
Beispiel #2
0
 /**
  * Returns a string that can be read and executed by the USE shell achieving the same effect of
  * this command.
  */
 public String getUSEcmd() {
   MOperation op = fOpCall.operation();
   return "!openter "
       + fOpCall.target()
       + " "
       + op.name()
       + "("
       + StringUtil.fmtSeq(fOpCall.argExprs(), ",")
       + ")";
 }
  /** Handles shorthand notation for collect and expands to an explicit collect expression. */
  private Expression collectShorthandWithArgs(String opname, Expression srcExpr)
      throws SemanticException {
    Expression res = null;
    // c.op()  201 (5) with implicit (3,1)
    CollectionType cType = (CollectionType) srcExpr.type();
    Type elemType = cType.elemType();
    if (elemType.isObjectType()) {
      MClass srcClass = ((ObjectType) elemType).cls();
      MOperation op = srcClass.operation(opname, true);
      if (op != null) {
        // check for isQuery operation with OCL body
        if (!op.hasExpression())
          throw new SemanticException(
              fOp,
              "Operation `"
                  + srcClass.name()
                  + "::"
                  + op.signature()
                  + "' cannot be used in OCL expression "
                  + "(only side effect-free operations with a return type and an OCL expression as body may be used).");

        // transform c.op(...) into c->collect($e | $e.op(...))
        ExpVariable eVar = new ExpVariable("$e", elemType);
        fArgExprs[0] = eVar;
        try {
          // constructor performs additional checks
          res = new ExpObjOp(op, fArgExprs);
        } catch (ExpInvalidException ex) {
          throw new SemanticException(
              fOp,
              "In operation call `" + srcClass.name() + "::" + opname + "': " + ex.getMessage());
        }
        res = genImplicitCollect(srcExpr, res, elemType);
      }
    }
    if (res == null) {
      // try (1) predefined OCL operation
      res = collectShorthandStdOp(opname, srcExpr, cType, elemType);
    }
    return res;
  }
Beispiel #4
0
 /** Returns a short name of command, e.g. 'Create class foo' for display in an undo menu item. */
 public String name() {
   MOperation op = fOpCall.operation();
   return "Enter operation " + op.cls().name() + "::" + op.signature();
 }