コード例 #1
0
  /**
   * Tests that operation call expressions involving generic arguments pass the constraint. These
   * are the generic <tt>T</tt> and <tt>T2</tt> parameters from collection operations in the
   * standard library.
   */
  public void test_OperationCallExp_checkArgumentsConform_generic_232028() {
    OperationCallExp o =
        (OperationCallExp) parseUnvalidated("context ecore::EString inv: Set{}->including('foo')");

    OCLExpression arg = factory.createUnspecifiedValueExp();
    arg.setType(getOCLStandardLibrary().getInteger());
    o.getArgument().add(arg);

    // wrong number of arguments does not trigger this constraint
    assertOK(o, ExpressionsValidator.OPERATION_CALL_EXP__ARGUMENTS_CONFORM);

    o.getArgument().remove(arg);

    // this is a well-formed expression
    assertOK(o, ExpressionsValidator.OPERATION_CALL_EXP__ARGUMENTS_CONFORM);

    o.getArgument().set(0, arg);

    assertOK(o, ExpressionsValidator.OPERATION_CALL_EXP__ARGUMENTS_CONFORM);
  }
コード例 #2
0
  /** Tests the case of a null operation (that it doesn't throw an NPE). */
  public void test_OperationCallExp_checkArgumentCount_nullOperation_231515() {
    OperationCallExp o = factory.createOperationCallExp();

    o.setReferredOperation(null); // be explicit on the purpose of the test

    OCLExpression arg = factory.createUnspecifiedValueExp();
    o.getArgument().add(arg);
    CollectionType ctype = factory.createOrderedSetType();
    ctype.setElementType(color);
    arg.setType(ctype);

    assertOK(o, ExpressionsValidator.OPERATION_CALL_EXP__ARGUMENT_COUNT);

    o.getArgument().add(factory.createCollectionLiteralExp());

    assertOK(o, ExpressionsValidator.OPERATION_CALL_EXP__ARGUMENT_COUNT);

    o.getArgument().clear();

    assertOK(o, ExpressionsValidator.OPERATION_CALL_EXP__ARGUMENT_COUNT);
  }
コード例 #3
0
  public void test_OperationCallExp_checkArgumentCount() {
    OperationCallExp o = factory.createOperationCallExp();

    EClass fruitUtil = (EClass) fruitPackage.getEClassifier("FruitUtil");
    EOperation oper = fruitUtil.getEOperations().get(0);
    o.setReferredOperation(oper);

    OCLExpression arg = factory.createUnspecifiedValueExp();
    o.getArgument().add(arg);
    CollectionType ctype = factory.createOrderedSetType();
    ctype.setElementType(color);
    arg.setType(ctype);

    assertOK(o, ExpressionsValidator.OPERATION_CALL_EXP__ARGUMENT_COUNT);

    o.getArgument().add(factory.createCollectionLiteralExp());

    assertProblem(o, ExpressionsValidator.OPERATION_CALL_EXP__ARGUMENT_COUNT);

    o.getArgument().clear();

    assertProblem(o, ExpressionsValidator.OPERATION_CALL_EXP__ARGUMENT_COUNT);
  }
コード例 #4
0
 /**
  * Check the '.emtl' file and report in the '.mtl' file some syntax errors when we use the
  * non-standard library.
  *
  * @param iFile is the '.mtl' file
  * @param oURI is the URI of the '.emtl' file
  */
 private void checkFullOMGCompliance(File iFile, URI oURI) {
   try {
     AcceleoSourceBuffer buffer = new AcceleoSourceBuffer(iFile);
     ResourceSet oResourceSet = new ResourceSetImpl();
     EObject oRoot = ModelUtils.load(oURI, oResourceSet);
     TreeIterator<EObject> oAllContents = oRoot.eAllContents();
     while (oAllContents.hasNext()) {
       EObject oNext = oAllContents.next();
       if (oNext instanceof OperationCallExp) {
         OperationCallExp oOperationCallExp = (OperationCallExp) oNext;
         if (oOperationCallExp.getReferredOperation() != null
             && oOperationCallExp.getReferredOperation().getEAnnotation("MTL non-standard")
                 != null) { //$NON-NLS-1$
           IFile workspaceFile =
               ResourcesPlugin.getWorkspace()
                   .getRoot()
                   .getFileForLocation(new Path(iFile.getAbsolutePath()));
           if (workspaceFile != null
               && workspaceFile.isAccessible()
               && oOperationCallExp.getStartPosition() > -1) {
             int line = buffer.getLineOfOffset(oOperationCallExp.getStartPosition());
             AcceleoMarkerUtils.createMarkerOnFile(
                 AcceleoMarkerUtils.PROBLEM_MARKER_ID,
                 workspaceFile,
                 line,
                 oOperationCallExp.getStartPosition(),
                 oOperationCallExp.getEndPosition(),
                 AcceleoUIMessages.getString(
                     "AcceleoCompileOperation.NotFullyCompliant",
                     oOperationCallExp //$NON-NLS-1$
                         .getReferredOperation()
                         .getName()));
           }
         }
       }
     }
   } catch (IOException e) {
     Status status = new Status(IStatus.WARNING, AcceleoUIActivator.PLUGIN_ID, e.getMessage(), e);
     AcceleoUIActivator.getDefault().getLog().log(status);
   } catch (CoreException e) {
     AcceleoUIActivator.getDefault().getLog().log(e.getStatus());
   }
 }