Esempio n. 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;
  }
Esempio n. 2
0
  private Helper defineOperation(
      org.eclipse.m2m.internal.qvt.oml.expressions.Library opModule,
      QvtOperationalModuleEnv opEnv,
      LibraryOperation libOp)
      throws LibraryCreationException {
    QvtLibraryOperation qvtLibOp = new QvtLibraryOperation(opEnv, libOp);

    Helper helper =
        org.eclipse.m2m.internal.qvt.oml.expressions.ExpressionsFactory.eINSTANCE.createHelper();
    helper.setName(libOp.getName());
    helper.setEType(qvtLibOp.getReturnType());
    int index = 1;
    for (EClassifier type : qvtLibOp.getParamTypes()) {
      VarParameter varParam =
          org.eclipse.m2m.internal.qvt.oml.expressions.ExpressionsFactory.eINSTANCE
              .createVarParameter();
      varParam.setKind(DirectionKind.IN);
      varParam.setEType(type);
      varParam.setName("arg" + index); // $NON-NLS-1$;
      ++index;
      helper.getEParameters().add(varParam);
    }
    if (qvtLibOp.getContextType() != opModule) {
      VarParameter varParam =
          org.eclipse.m2m.internal.qvt.oml.expressions.ExpressionsFactory.eINSTANCE
              .createVarParameter();
      varParam.setKind(DirectionKind.IN);
      varParam.setEType(qvtLibOp.getContextType());
      varParam.setName(Environment.SELF_VARIABLE_NAME);
      helper.setContext(varParam);
    }

    Class<?> returnClass =
        (helper.getEType() != null) ? helper.getEType().getInstanceClass() : null;
    CallHandlerAdapter.attach(helper, new Handler(libOp, returnClass));
    return helper;
  }