Example #1
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);
  }
Example #2
0
  /**
   * Implementation of the OCL <tt>Collection::product(c : Collection(T2)) : Set(Tuple(first : T,
   * second : T2))</tt> operations.
   *
   * @param evalEnv the current evaluation environment (for construction of tuples)
   * @param env the current OCL environment (for introspection of the tuple type)
   * @param self the source collection
   * @param c another collection
   * @return the product of the collections
   */
  public static <PK, C, O, P, EL, PM, S, COA, SSA, CT, CLS, E> Set<Tuple<O, P>> product(
      EvaluationEnvironment<C, O, P, CLS, E> evalEnv,
      Environment<PK, C, O, P, EL, PM, S, COA, SSA, CT, CLS, E> env,
      Collection<?> self,
      Collection<?> c,
      C tupleType) {

    Set<Tuple<O, P>> result = createNewSet();

    Map<P, Object> propertyValues = new HashMap<P, Object>();
    P firstProperty = env.lookupProperty(tupleType, OCLStandardLibraryUtil.PRODUCT_FIRST);
    P secondProperty = env.lookupProperty(tupleType, OCLStandardLibraryUtil.PRODUCT_SECOND);

    for (Object next1 : self) {
      for (Object next2 : c) {
        propertyValues.put(firstProperty, next1);
        propertyValues.put(secondProperty, next2);

        result.add(evalEnv.createTuple(tupleType, propertyValues));
      }
    }

    return result;
  }
Example #3
0
  /** Tests the parsing the def expression for static attributes and operations. */
  public void test_defExpression_static() {
    try {
      Environment<
              Package,
              Classifier,
              Operation,
              Property,
              EnumerationLiteral,
              Parameter,
              State,
              CallOperationAction,
              SendSignalAction,
              Constraint,
              Class,
              EObject>
          env = ocl.getEnvironment();
      UMLReflection<
              Package,
              Classifier,
              Operation,
              Property,
              EnumerationLiteral,
              Parameter,
              State,
              CallOperationAction,
              SendSignalAction,
              Constraint>
          umlReflection = env.getUMLReflection();

      ParsingOptions.setOption(ocl.getEnvironment(), ParsingOptions.SUPPORT_STATIC_FEATURES, true);
      parseDef(
          "package ocltest context Fruit "
              + "def: bestColor1() : Color = null "
              + "static def: bestColor2() : Color = null "
              + "def: goodColor1 : Color = null "
              + "static def: goodColor2 : Color = null "
              + "endpackage");
      Operation operation1 = env.lookupOperation(fruit, "bestColor1", null);
      assertNotNull(operation1);
      assertEquals(false, umlReflection.isStatic(operation1));
      Operation operation2 = env.lookupOperation(fruit, "bestColor2", null);
      assertNotNull(operation2);
      assertEquals(true, umlReflection.isStatic(operation2));
      Property property1 = env.lookupProperty(fruit, "goodColor1");
      assertNotNull(property1);
      assertEquals(false, umlReflection.isStatic(property1));
      Property property2 = env.lookupProperty(fruit, "goodColor2");
      assertNotNull(property2);
      assertEquals(true, umlReflection.isStatic(property2));

      ParsingOptions.setOption(ocl.getEnvironment(), ParsingOptions.SUPPORT_STATIC_FEATURES, false);
      try {
        ocl.parse(
            new OCLInput(
                "package ocltest context Fruit "
                    + "def: bestColor3() : Color = null "
                    + "static def: bestColor4() : Color = null "
                    + "endpackage"));
        fail("Should have failed to parse the unsupported static");
      } catch (ParserException e) {
        // success!
        assertEquals(OCLMessages.UnsupportedStatic_ERROR_, e.getMessage());
        System.out.println("Got the expected exception: " + e.getLocalizedMessage());
      }
    } catch (Exception e) {
      fail("Failed to parse or evaluate: " + e.getLocalizedMessage());
    }
  }
 public CachedTypeChecker(Environment<?, C, O, P, ?, PM, ?, ?, ?, ?, ?, ?> environment) {
   super(environment);
   this.uml = environment.getUMLReflection();
 }