예제 #1
0
  /**
   * Constructs new operation call for the given operation and execution context.
   *
   * @param operation a valid AST operation to be called. <code>Note:</code> This must be an
   *     operation owned by a valid QVT Library module
   * @param context non-QVT transformation context in which this operation will be called
   * @exception IllegalArgumentException If the passed <code>operation</code> or <code>context
   *     </code> are <code>null</code>; or the operation is not valid AST element for construction
   *     of the call
   */
  HelperOperationCall(Helper operation, NonTransformationExecutionContext context) {
    if (operation == null || context == null) {
      throw new IllegalArgumentException();
    }

    fOwningModule = QvtOperationalParserUtil.getOwningModule(operation);
    if (fOwningModule == null) {
      throw new IllegalArgumentException("Not a library query or helper"); // $NON-NLS-1$
    }

    fOperation = operation;
    fContextType = QvtOperationalParserUtil.getContextualType(fOperation);

    fArgumentTypes = new ArrayList<EClassifier>(fOperation.getEParameters().size());
    for (EParameter eParam : fOperation.getEParameters()) {
      EClassifier paramType = eParam.getEType();
      if (paramType == null) {
        throw new IllegalArgumentException("Parameter with no type"); // $NON-NLS-1$
      }

      fArgumentTypes.add(paramType);
    }

    fContext = context;
  }
  public void define(EcoreEnvironment env) {
    for (OperationProvider operation : getOperations()) {
      EOperation defOper = operation.define(env);
      if (operation.fIsStatic) {
        QvtOperationalParserUtil.markAsStaticOperation(defOper);
      }

      if (CallHandlerAdapter.getDispatcher(defOper) == UNSUPPORTED_OPER) {
        QvtOperationalParserUtil.markAsUnsupported(defOper);
      }
    }
  }
    public EOperation define(EcoreEnvironment env) {
      List<Variable<EClassifier, EParameter>> argList =
          new ArrayList<Variable<EClassifier, EParameter>>();
      int pos = 0;
      for (EClassifier cls : fParamTypes) {
        Variable<EClassifier, EParameter> stringVariable =
            ExpressionsFactory.eINSTANCE.createVariable();

        String paramName = cls.getName();
        if (fParamNames != null) {
          paramName = fParamNames[pos++];
        }
        stringVariable.setName(paramName);
        stringVariable.setType(cls);
        argList.add(stringVariable);
      }

      EOperation result =
          env.defineOperation(
              fContextType,
              fName,
              fReturnType,
              argList,
              org.eclipse.ocl.ecore.EcoreFactory.eINSTANCE.createConstraint());

      CallHandlerAdapter.attach(result, fDispatcher);

      if (fIsDeprecated) {
        if (fDeprecatedBy != null) {
          QvtOperationalParserUtil.markAsDeprecated(result, fDeprecatedBy);
        } else {
          QvtOperationalParserUtil.markAsDeprecated(result);
        }
      }
      return result;
    }