Java Code Examples for org.eclipse.emf.ecore.EStructuralFeature.setLowerBound()

The following are Jave code examples for showing how to use setLowerBound() of the org.eclipse.emf.ecore.EStructuralFeature class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: JavaGraph   File: TypeToEcore.java   Source Code and License Vote up 4 votes
@Override
public void visit(Field field, String param) {
    if (hasElement(field)) {
        return;
    }

    Type fieldType = field.getType();
    // Ecore defaults, only changed if an container
    boolean ordered = true;
    boolean unique = true;
    if (fieldType instanceof Container) {
        Container cmContainer = (Container) fieldType;
        fieldType = cmContainer.getType();

        if (cmContainer.getContainerType() == Kind.SET
            || cmContainer.getContainerType() == Kind.BAG) {
            ordered = false;
        }
        if (cmContainer.getContainerType() == Kind.BAG
            || cmContainer.getContainerType() == Kind.SEQ) {
            unique = false;
        }
    }

    EStructuralFeature eFieldFeature = null;
    // Tuples/Containers are represented by classes, so would be a reference
    if (fieldType instanceof Class || fieldType instanceof Tuple
        || fieldType instanceof Container) {
        // Create EReference
        eFieldFeature = g_EcoreFactory.createEReference();
    } else {
        // Create EAttribute
        eFieldFeature = g_EcoreFactory.createEAttribute();
    }
    setElement(field, eFieldFeature);

    eFieldFeature.setName(field.getName()
        .toString());
    eFieldFeature.setOrdered(ordered);
    eFieldFeature.setUnique(unique);

    EObject eType = getElement(fieldType);
    eFieldFeature.setEType((EClassifier) eType);

    if (field.getUpperBound() == -1) {
        eFieldFeature.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY);
    } else {
        eFieldFeature.setUpperBound(field.getUpperBound());
    }
    if (field.getType() instanceof Class && !((Class) field.getType()).isProper()) {
        eFieldFeature.setLowerBound(0);
    } else {
        eFieldFeature.setLowerBound(field.getLowerBound());
    }
}
 
Example 2
Project: JavaGraph   File: TypeToEcore.java   Source Code and License Vote up 4 votes
@Override
public void visit(Container container, String param) {
    if (hasElement(container)) {
        return;
    }

    // Create class for container
    EClass eContainerClass = g_EcoreFactory.createEClass();
    setElement(container, eContainerClass);

    this.nrContainer++;
    eContainerClass.setName("ContainerClass_" + this.nrContainer);

    // Find matching field and package
    EPackage containerPackage = null;
    Container topContainer = container;
    while (topContainer.getParent() != null) {
        topContainer = topContainer.getParent();
    }
    if (topContainer.getField() != null) {
        Field f = topContainer.getField();
        Class c = f.getDefiningClass();
        EClass eClass = (EClass) getElement(c);
        containerPackage = eClass.getEPackage();
    } else {
        containerPackage = packageFromId(Id.ROOT);
    }
    containerPackage.getEClassifiers()
        .add(eContainerClass);

    // Create value reference
    EStructuralFeature eContainerFeature = null;
    if (container.getType() instanceof Class || container.getType() instanceof Tuple
        || container.getType() instanceof Container) {
        // Create EReference
        eContainerFeature = g_EcoreFactory.createEReference();
    } else {
        // Create EAttribute
        eContainerFeature = g_EcoreFactory.createEAttribute();
    }

    eContainerFeature.setName("value");
    if (container.getType() instanceof Container) {
        Container subType = (Container) container.getType();
        eContainerFeature.setOrdered(
            subType.getContainerType() == Kind.ORD || subType.getContainerType() == Kind.SEQ);
        eContainerFeature.setUnique(
            subType.getContainerType() == Kind.SET || subType.getContainerType() == Kind.ORD);
    } else {
        eContainerFeature.setOrdered(false);
        eContainerFeature.setUnique(true);
    }

    EObject eType = getElement(container.getType());
    eContainerFeature.setEType((EClassifier) eType);

    eContainerFeature.setUpperBound(ETypedElement.UNBOUNDED_MULTIPLICITY);
    eContainerFeature.setLowerBound(0);

    eContainerClass.getEStructuralFeatures()
        .add(eContainerFeature);
}