Пример #1
0
  public void test_IteratorExp_checkCollectType() {
    EClassifier set = getOCLStandardLibrary().getSet();
    EClassifier orderedSet = getOCLStandardLibrary().getOrderedSet();
    EClassifier sequence = getOCLStandardLibrary().getSequence();
    EClassifier bag = getOCLStandardLibrary().getBag();
    List<EClassifier[]> badPairs = new java.util.ArrayList<EClassifier[]>();
    badPairs.add(new EClassifier[] {set, sequence});
    badPairs.add(new EClassifier[] {bag, sequence});
    badPairs.add(new EClassifier[] {sequence, bag});
    badPairs.add(new EClassifier[] {sequence, set});
    badPairs.add(new EClassifier[] {orderedSet, bag});
    List<EClassifier[]> goodPairs = new java.util.ArrayList<EClassifier[]>();
    goodPairs.add(new EClassifier[] {set, bag});
    goodPairs.add(new EClassifier[] {bag, bag});
    goodPairs.add(new EClassifier[] {sequence, sequence});
    goodPairs.add(new EClassifier[] {orderedSet, sequence});

    IteratorExp i = factory.createIteratorExp();
    i.setName("collect");

    OCLExpression source = factory.createBooleanLiteralExp();
    i.setSource(source);

    for (EClassifier[] pair : badPairs) {
      source.setType(pair[0]);
      i.setType(pair[1]);
      assertProblem(i, ExpressionsValidator.ITERATOR_EXP__COLLECT_TYPE);
    }

    for (EClassifier[] pair : goodPairs) {
      source.setType(pair[0]);
      i.setType(pair[1]);
      assertOK(i, ExpressionsValidator.ITERATOR_EXP__COLLECT_TYPE);
    }
  }
Пример #2
0
  public void test_IfExp_checkBooleanCondition() {
    IfExp ie = factory.createIfExp();
    OCLExpression cond = factory.createBooleanLiteralExp();
    cond.setType(getOCLStandardLibrary().getInteger());

    ie.setCondition(cond);

    assertProblem(ie, ExpressionsValidator.IF_EXP__BOOLEAN_CONDITION);

    cond.setType(getOCLStandardLibrary().getBoolean());

    assertOK(ie, ExpressionsValidator.IF_EXP__BOOLEAN_CONDITION);
  }
Пример #3
0
  public RowSourceHandler(ContainerHandler parent, RowSource rowSource) throws ParserException {
    this.parent = parent;
    OCL ocl = OCL.newInstance(parent.getEnvironment());
    Helper helper = ocl.createOCLHelper();
    OCLExpression expression = helper.createQuery(rowSource.getExpression());
    query = ocl.createQuery(expression);

    environment = parent.getEnvironment().getFactory().createEnvironment(parent.getEnvironment());
    Variable variable = EcoreFactory.eINSTANCE.createVariable();
    variable.setType(((CollectionType) expression.getType()).getElementType());
    varName = rowSource.getVar();
    environment.addElement(varName, variable, true);
  }
Пример #4
0
  public void test_LoopExp_checkSourceCollection() {
    LoopExp l = factory.createIterateExp();

    OCLExpression source = factory.createBooleanLiteralExp();
    l.setSource(source);

    source.setType(getOCLStandardLibrary().getBoolean());

    assertProblem(l, ExpressionsValidator.LOOP_EXP__SOURCE_COLLECTION);

    source.setType(getOCLStandardLibrary().getSet());

    assertOK(l, ExpressionsValidator.LOOP_EXP__SOURCE_COLLECTION);
  }
Пример #5
0
  public void test_LetExp_checkLetType() {
    LetExp l = factory.createLetExp();
    l.setType(getOCLStandardLibrary().getBag());

    OCLExpression in = factory.createBooleanLiteralExp();
    in.setType(getOCLStandardLibrary().getBoolean());
    l.setIn(in);

    assertProblem(l, ExpressionsValidator.LET_EXP__LET_TYPE);

    l.setType(in.getType());

    assertOK(l, ExpressionsValidator.LET_EXP__LET_TYPE);
  }
Пример #6
0
  public void test_PropertyCallExp_checkPropertyType() {
    PropertyCallExp p = factory.createPropertyCallExp();

    p.setReferredProperty(apple_label);
    p.setType(getOCLStandardLibrary().getBoolean());

    OCLExpression source = factory.createUnspecifiedValueExp();
    source.setType(apple);
    p.setSource(source);

    assertProblem(p, ExpressionsValidator.PROPERTY_CALL_EXP__PROPERTY_TYPE);

    p.setType(getOCLStandardLibrary().getString());

    assertOK(p, ExpressionsValidator.PROPERTY_CALL_EXP__PROPERTY_TYPE);
  }
Пример #7
0
  public void test_Variable_checknitType() {
    Variable v = factory.createVariable();
    v.setName("a");
    v.setType(fruit);

    assertOK(v, ExpressionsValidator.VARIABLE__INIT_TYPE);

    OCLExpression init = factory.createUnspecifiedValueExp();
    init.setType(color);
    v.setInitExpression(init);

    assertProblem(v, ExpressionsValidator.VARIABLE__INIT_TYPE);

    init.setType(apple);

    assertOK(v, ExpressionsValidator.VARIABLE__INIT_TYPE);
  }
Пример #8
0
  public void test_TupleLiteralExp_checkValueType() {
    TupleLiteralPart p = factory.createTupleLiteralPart();
    p.setName("a");
    p.setType(fruit);

    OCLExpression value = factory.createUnspecifiedValueExp();
    value.setType(apple);
    p.setValue(value);

    EStructuralFeature a = ocl.getEnvironment().getUMLReflection().createProperty("a", fruit);
    p.setAttribute(a);

    assertProblem(p, ExpressionsValidator.TUPLE_LITERAL_PART__VALUE_TYPE);

    value.setType(fruit);

    assertOK(p, ExpressionsValidator.TUPLE_LITERAL_PART__VALUE_TYPE);
  }
Пример #9
0
  public void test_IfExp_checkIfType() {
    IfExp ie = factory.createIfExp();
    ie.setType(fruit);

    OCLExpression thenPart = factory.createBooleanLiteralExp();
    thenPart.setType(apple);
    OCLExpression elsePart = factory.createTupleLiteralExp();
    elsePart.setType(color);

    ie.setThenExpression(thenPart);
    ie.setElseExpression(elsePart);

    assertProblem(ie, ExpressionsValidator.IF_EXP__IF_TYPE);

    elsePart.setType(fruit);

    assertOK(ie, ExpressionsValidator.IF_EXP__IF_TYPE);
  }
Пример #10
0
  public void test_IterateExp_checkBodyType() {
    IterateExp i = factory.createIterateExp();
    i.setType(fruit);

    Variable resultVar = factory.createVariable();
    resultVar.setType(fruit);
    i.setResult(resultVar);

    OCLExpression body = factory.createBooleanLiteralExp();
    body.setType(color);
    i.setBody(body);

    assertProblem(i, ExpressionsValidator.ITERATE_EXP__BODY_TYPE);

    body.setType(apple);

    assertOK(i, ExpressionsValidator.ITERATE_EXP__BODY_TYPE);
  }
Пример #11
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);
  }
Пример #12
0
  public void test_IteratorExp_checkSelectRejectType() {
    IteratorExp i = factory.createIteratorExp();
    i.setType(getOCLStandardLibrary().getSet());

    OCLExpression source = factory.createBooleanLiteralExp();
    source.setType(getOCLStandardLibrary().getBag());
    i.setSource(source);

    for (String name : Arrays.asList("select", "reject")) {
      i.setName(name);
      assertProblem(i, ExpressionsValidator.ITERATOR_EXP__SELECT_REJECT_TYPE);
    }

    i.setType(getOCLStandardLibrary().getBag());

    for (String name : Arrays.asList("select", "reject")) {
      i.setName(name);
      assertOK(i, ExpressionsValidator.ITERATOR_EXP__SELECT_REJECT_TYPE);
    }
  }
Пример #13
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);
  }
Пример #14
0
  public void test_MessageExp_checkTargetNotCollection() {
    MessageExp m = factory.createMessageExp();

    CallOperationAction action = factory.createCallOperationAction();
    m.setCalledOperation(action);
    action.setOperation(fruit_ripen);

    UnspecifiedValueExp arg = factory.createUnspecifiedValueExp();
    arg.setType(color);
    m.getArgument().add(arg);

    OCLExpression target = factory.createBooleanLiteralExp();
    m.setTarget(target);
    target.setType(factory.createSequenceType());

    assertProblem(m, ExpressionsValidator.MESSAGE_EXP__TARGET_NOT_COLLECTION);

    target.setType(fruit);

    assertOK(m, ExpressionsValidator.MESSAGE_EXP__TARGET_NOT_COLLECTION);
  }
Пример #15
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);
  }
Пример #16
0
  public void test_LoopExp_checkLoopVariableType() {
    LoopExp l = factory.createIterateExp();

    CollectionType ctype = factory.createCollectionType();
    ctype.setElementType(fruit);
    OCLExpression source = factory.createCollectionLiteralExp();
    source.setType(ctype);
    l.setSource(source);

    Variable iter = factory.createVariable();
    iter.setType(fruit);
    l.getIterator().add(iter);

    iter = factory.createVariable();
    iter.setType(apple);
    l.getIterator().add(iter);

    assertProblem(l, ExpressionsValidator.LOOP_EXP__LOOP_VARIABLE_TYPE);

    iter.setType(fruit);

    assertOK(l, ExpressionsValidator.LOOP_EXP__LOOP_VARIABLE_TYPE);
  }
Пример #17
0
  public void test_IteratorExp_checkBooleanBodyType() {
    List<String> names = Arrays.asList("select", "reject", "forAll", "exists", "any", "one");
    IteratorExp i = factory.createIteratorExp();
    i.setType(getOCLStandardLibrary().getSet());

    OCLExpression body = factory.createBooleanLiteralExp();
    body.setType(getOCLStandardLibrary().getBag());
    i.setBody(body);

    i.setName("collect");
    assertOK(i, ExpressionsValidator.ITERATOR_EXP__BOOLEAN_BODY_TYPE);

    for (String name : names) {
      i.setName(name);
      assertProblem(i, ExpressionsValidator.ITERATOR_EXP__BOOLEAN_BODY_TYPE);
    }

    body.setType(getOCLStandardLibrary().getBoolean());

    for (String name : names) {
      i.setName(name);
      assertOK(i, ExpressionsValidator.ITERATOR_EXP__BOOLEAN_BODY_TYPE);
    }
  }
Пример #18
0
 /**
  * @param oppositeEndFinder used during partial navigation and for metamodel queries
  * @param notifyOnNewContextElements The analyzer can be parameterized during construction such
  *     that it either registers for creation events on the context type or not. Registering for
  *     element creation on the context type is useful for invariants / constraints because when a
  *     new element is created, validating the constraint may be useful. For other use cases,
  *     registering for element creation may not be so useful. For example, when a type inferencer
  *     defines its rules using OCL, it only wants to receive <em>update</em> events after the
  *     element has been fully initialized from those OCL expressions. In those cases, some
  *     framework may be responsible for the initial evaluation of those OCL expressions on new
  *     element, and therefore, context element creation events are not of interest.
  */
 public ImpactAnalyzerImpl(
     OCLExpression expression,
     EClass context,
     boolean notifyOnNewContextElements,
     OppositeEndFinder oppositeEndFinder,
     ActivationOption configuration,
     OCLFactory oclFactory) {
   this.expression = expression;
   this.context = context;
   EClass inferredContext = expression.accept(createContextTypeRetriever());
   if (inferredContext != null && inferredContext != context) {
     throw new IllegalArgumentException(
         "Redundant, incorrect context type specification. Expression has "
             + inferredContext
             + " as context type, but explicitly-provided context type was "
             + context);
   }
   this.oppositeEndFinder = oppositeEndFinder;
   this.configuration = configuration;
   this.notifyOnNewContextElements = notifyOnNewContextElements;
   this.oclFactory = oclFactory;
 }
Пример #19
0
 /**
  * @param oppositeEndFinder used during partial navigation and for metamodel queries
  * @param notifyOnNewContextElements The analyzer can be parameterized during construction such
  *     that it either registers for creation events on the context type or not. Registering for
  *     element creation on the context type is useful for invariants / constraints because when a
  *     new element is created, validating the constraint may be useful. For other use cases,
  *     registering for element creation may not be so useful. For example, when a type inferencer
  *     defines its rules using OCL, it only wants to receive <em>update</em> events after the
  *     element has been fully initialized from those OCL expressions. In those cases, some
  *     framework may be responsible for the initial evaluation of those OCL expressions on new
  *     element, and therefore, context element creation events are not of interest.
  */
 public ImpactAnalyzerImpl(
     OCLExpression expression,
     boolean notifyOnNewContextElements,
     OppositeEndFinder oppositeEndFinder,
     ActivationOption configuration,
     OCLFactory oclFactory) {
   this.expression = expression;
   this.context = expression.accept(createContextTypeRetriever());
   if (this.context == null) {
     throw new IllegalArgumentException(
         "Expression "
             + expression
             + " does not contain a \"self\" variable reference. "
             + "Therefore, its context type cannot be inferred and needs to be provided explicitly. Consider using "
             + getClass().getName()
             + "(OCLExpression, EClass, OppositeEndFinder) instead.");
   }
   this.oppositeEndFinder = oppositeEndFinder;
   this.configuration = configuration;
   this.notifyOnNewContextElements = notifyOnNewContextElements;
   this.oclFactory = oclFactory;
 }