示例#1
1
 public OCL createOCL(ResourceSet resourceSet) {
   return OCL.newInstance(resourceSet);
 }
示例#2
0
  /** Tests the definition of additional attributes on an OCL pre-defined type. */
  public void test_defOperationOnPredefinedType_172782() {
    // context is the predefined OCL String type
    helper.setContext(ocl.getEnvironment().getOCLStandardLibrary().getString());

    try {
      Operation feature =
          helper.defineOperation(
              "reversed() : String = "
                  + "Sequence{1..size()}->sortedBy(i | -i)->iterate(i; s : String = '' |"
                  + " s.concat(self.substring(i, i)))");

      // the other representation of 'String'
      helper.setContext(getUMLString());

      Collection<Choice> choices = helper.getSyntaxHelp(ConstraintKind.INVARIANT, "self.");

      assertChoice(choices, ChoiceKind.OPERATION, "reversed");

      OCLExpression<Classifier> expr = helper.createQuery("self.reversed()");

      assertEquals("ablE was i ere I saw elbA", ocl.evaluate("Able was I ere i saw Elba", expr));

      // verify that TypeUtil produces the correct result
      assertTrue(
          TypeUtil.getOperations(
                  ocl.getEnvironment(), ocl.getEnvironment().getOCLStandardLibrary().getString())
              .contains(feature));
      assertTrue(TypeUtil.getOperations(ocl.getEnvironment(), getUMLString()).contains(feature));
    } catch (Exception e) {
      fail("Failed to parse or evaluate: " + e.getLocalizedMessage());
    }

    // now, make sure that this definition was local to the OCL that
    //   parsed it (that it is not shared via the standard library package)
    OCL localOCL = OCL.newInstance();
    OCL.Helper localHelper = localOCL.createOCLHelper();
    localHelper.setContext(ocl.getEnvironment().getOCLStandardLibrary().getString());

    try {
      Collection<Choice> choices = localHelper.getSyntaxHelp(ConstraintKind.INVARIANT, "self.");

      assertNotChoice(choices, ChoiceKind.OPERATION, "reversed");

      localHelper.createQuery("self.reversed()");

      fail("Should have failed to parse the undefined operation");
    } catch (ParserException e) {
      // success!
      System.out.println("Got the expected exception: " + e.getLocalizedMessage());
    }
  }
示例#3
0
 public static OCL createOCL(ResourceSet resourceSet) {
   OCL newInstance = OCL.newInstance(resourceSet);
   String repairs = System.getProperty(PLUGIN_ID + ".repairs");
   if (repairs != null) newInstance.setParserRepairCount(Integer.parseInt(repairs));
   return newInstance;
 }