Exemplo n.º 1
0
  /** Tests that unrecognized data types are represented by themselves, not by OclAny. */
  public void test_dataTypes_137158() {
    Package upackage = umlf.createPackage();
    upackage.setName("mypkg");
    Class uclass = upackage.createOwnedClass("B", false);
    DataType datatype = (DataType) pkg.createOwnedType("Thread", uml.getDataType());
    Operation operation = uclass.createOwnedOperation("f", null, null, datatype);
    operation.setIsQuery(true);

    helper.setContext(uclass);

    try {
      OCLExpression<Classifier> expr = helper.createQuery("self.f()");

      Classifier type = expr.getType();
      assertSame(datatype, type);

      operation.setUpper(LiteralUnlimitedNatural.UNLIMITED);

      expr = helper.createQuery("self.f()");

      type = expr.getType();
      assertTrue(type instanceof CollectionType<?, ?>);
      type = ((org.eclipse.ocl.uml.CollectionType) type).getElementType();
      assertSame(datatype, type);

      operation.setUpper(1);
      operation.setType(ocl.getEnvironment().getOCLStandardLibrary().getOclAny());

      expr = helper.createQuery("self.f()");

      type = expr.getType();
      assertSame(getOCLStandardLibrary().getOclAny(), type);
    } catch (Exception e) {
      fail("Failed to parse or evaluate: " + e.getLocalizedMessage());
    }
  }
Exemplo n.º 2
0
 public Class createOwnedClass(Package aPackage, String name, boolean isAbstract) {
   return aPackage.createOwnedClass(name, isAbstract);
 }
Exemplo n.º 3
0
  @Override
  protected void setUp() {
    super.setUp();

    pkg = umlf.createPackage();
    pkg.setName("pkg");

    valueType = pkg.createOwnedPrimitiveType("Value");
    valueType
        .createOwnedOperation(
            "<",
            new BasicEList<String>(Collections.singleton("v")),
            new BasicEList<Type>(Collections.singleton(valueType)),
            getUMLBoolean())
        .setIsQuery(true);
    valueType
        .createOwnedOperation(
            "<=",
            new BasicEList<String>(Collections.singleton("v")),
            new BasicEList<Type>(Collections.singleton(valueType)),
            getUMLBoolean())
        .setIsQuery(true);
    valueType
        .createOwnedOperation(
            ">",
            new BasicEList<String>(Collections.singleton("v")),
            new BasicEList<Type>(Collections.singleton(valueType)),
            getUMLBoolean())
        .setIsQuery(true);
    valueType
        .createOwnedOperation(
            ">=",
            new BasicEList<String>(Collections.singleton("v")),
            new BasicEList<Type>(Collections.singleton(valueType)),
            getUMLBoolean())
        .setIsQuery(true);

    thingType = pkg.createOwnedClass("Thing", false);

    values = thingType.createOwnedAttribute("values", valueType);
    values.setUpper(LiteralUnlimitedNatural.UNLIMITED);
    values.setIsOrdered(true);
    values.setIsUnique(true);

    bdValue = thingType.createOwnedAttribute("bdValue", getEcoreBigDecimal());
    biValue = thingType.createOwnedAttribute("biValue", getEcoreBigInteger());

    numeroType = pkg.createOwnedClass("Numero", false);

    numeroType
        .createOwnedOperation(
            "+",
            new BasicEList<String>(Collections.singleton("n")),
            new BasicEList<Type>(Collections.singleton(numeroType)),
            numeroType)
        .setIsQuery(true);
    numeroType
        .createOwnedOperation(
            "-",
            new BasicEList<String>(Collections.singleton("n")),
            new BasicEList<Type>(Collections.singleton(numeroType)),
            numeroType)
        .setIsQuery(true);
    numeroType
        .createOwnedOperation(
            "*",
            new BasicEList<String>(Collections.singleton("n")),
            new BasicEList<Type>(Collections.singleton(numeroType)),
            numeroType)
        .setIsQuery(true);
    numeroType
        .createOwnedOperation(
            "/",
            new BasicEList<String>(Collections.singleton("n")),
            new BasicEList<Type>(Collections.singleton(numeroType)),
            numeroType)
        .setIsQuery(true);

    numeroType
        .createOwnedOperation(
            "-", ECollections.<String>emptyEList(), ECollections.<Type>emptyEList(), numeroType)
        .setIsQuery(true);

    numeroType
        .createOwnedOperation(
            "<",
            new BasicEList<String>(Collections.singleton("n")),
            new BasicEList<Type>(Collections.singleton(numeroType)),
            getUMLBoolean())
        .setIsQuery(true);
    numeroType
        .createOwnedOperation(
            "<=",
            new BasicEList<String>(Collections.singleton("n")),
            new BasicEList<Type>(Collections.singleton(numeroType)),
            getUMLBoolean())
        .setIsQuery(true);
    numeroType
        .createOwnedOperation(
            ">",
            new BasicEList<String>(Collections.singleton("n")),
            new BasicEList<Type>(Collections.singleton(numeroType)),
            getUMLBoolean())
        .setIsQuery(true);
    numeroType
        .createOwnedOperation(
            ">=",
            new BasicEList<String>(Collections.singleton("n")),
            new BasicEList<Type>(Collections.singleton(numeroType)),
            getUMLBoolean())
        .setIsQuery(true);
    numeroType
        .createOwnedOperation(
            "asLong",
            ECollections.<String>emptyEList(),
            ECollections.<Type>emptyEList(),
            getEcoreLong())
        .setIsQuery(true);

    numeros = thingType.createOwnedAttribute("numeros", numeroType);
    numeros.setUpper(LiteralUnlimitedNatural.UNLIMITED);
    numeros.setIsOrdered(true);
    numeros.setIsUnique(true);

    comparable = pkg.createOwnedClass("Comparable", true);
    comparable
        .createOwnedOperation(
            "compareTo",
            new BasicEList<String>(Collections.singleton("c")),
            new BasicEList<Type>(Collections.singleton(comparable)),
            getUMLInteger())
        .setIsQuery(true);

    // the Ecore counterpart

    epkg = UMLUtil.convertToEcore(pkg, null).iterator().next();

    ethingType = (EClass) epkg.getEClassifier(thingType.getName());
    enumeros = (EReference) ethingType.getEStructuralFeature(numeros.getName());
    evalues = (EAttribute) ethingType.getEStructuralFeature(values.getName());
    ebdValue = (EAttribute) ethingType.getEStructuralFeature(bdValue.getName());
    ebiValue = (EAttribute) ethingType.getEStructuralFeature(biValue.getName());

    enumeroType = (EClass) epkg.getEClassifier(numeroType.getName());
    enumeroType.setInstanceClass(Numero.class);

    evalueType = (EDataType) epkg.getEClassifier(valueType.getName());
    evalueType.setInstanceClass(Value.class);

    efactory = epkg.getEFactoryInstance();
    thing = efactory.create(ethingType);

    EPackage.Registry.INSTANCE.put(epkg.getNsURI(), epkg);

    @SuppressWarnings("unchecked")
    EList<Numero> list = (EList<Numero>) thing.eGet(enumeros);
    list.add(new Numero(6));
    list.add(new Numero(2));
  }