Search in sources :

Example 11 with UnitsType

use of org.osate.aadl2.UnitsType in project osate2 by osate.

the class NumberTypeImpl method basicSetOwnedUnitsType.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetOwnedUnitsType(UnitsType newOwnedUnitsType, NotificationChain msgs) {
    UnitsType oldOwnedUnitsType = ownedUnitsType;
    ownedUnitsType = newOwnedUnitsType;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, Aadl2Package.NUMBER_TYPE__OWNED_UNITS_TYPE, oldOwnedUnitsType, newOwnedUnitsType);
        if (msgs == null) {
            msgs = notification;
        } else {
            msgs.add(notification);
        }
    }
    return msgs;
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) UnitsType(org.osate.aadl2.UnitsType)

Example 12 with UnitsType

use of org.osate.aadl2.UnitsType in project osate2 by osate.

the class NumberValueImpl method getScaledValue.

/*
	 * DB Added for OCL
	 * (non-Javadoc)
	 *
	 * @see org.osate.aadl2.NumberValue#getScaledValue(java.lang.String)
	 */
public double getScaledValue(String target) {
    final UnitLiteral currentUnit = getUnit();
    final UnitLiteral targetUnit;
    if (currentUnit == null) {
        targetUnit = null;
    } else {
        targetUnit = ((UnitsType) currentUnit.eContainer()).findLiteral(target);
    }
    return getScaledValue(targetUnit);
}
Also used : UnitLiteral(org.osate.aadl2.UnitLiteral)

Example 13 with UnitsType

use of org.osate.aadl2.UnitsType in project osate2 by osate.

the class PropertyUtils method checkUnitsAndGetSimplePropertyValue.

/**
 * Check that UnitLiteral unit is part of Property pd's UnitsType and
 * returns the property value by calling ph.getSimplePropertyValue(pd)
 *
 * @param ph The property holder from which to retrieve the property value.
 * @param pd The property to retrieve.
 * @param unit The literal to test against pd's units type.
 * @return The retrieved property value.
 * @throws InvalidModelException Thrown if the property value cannot be
 *             retrieved because the model is incomplete or otherwise
 *             invalid.
 * @throws PropertyNotPresentException Thrown if the property is undefined
 *             for ph.
 * @throws PropertyIsModalException Thrown if ph is modal and declarative.
 * @throws IllegalStateException Thrown if the lookup encounters a cycle of
 *             property reference dependencies.
 * @throws IllegalArgumentException Thrown if the given unit literal is not
 *             from the property's unit type or if ph, pd, or unit is null.
 * @throws PropertyDoesNotApplyToHolderException Thrown if pd does not apply
 *             to ph.
 * @throws PropertyIsListException Thrown if the property is not scalar.
 * @throws ClassCastException Thrown if the property's type is not a
 *             RangeType or a NumberType.
 */
private static PropertyExpression checkUnitsAndGetSimplePropertyValue(final NamedElement ph, final Property pd, final UnitLiteral unit) throws InvalidModelException, PropertyNotPresentException, PropertyIsModalException, IllegalStateException, IllegalArgumentException, PropertyDoesNotApplyToHolderException, PropertyIsListException, ClassCastException {
    if (unit == null) {
        throw new IllegalArgumentException("UnitLiteral unit cannot be null.");
    }
    final PropertyExpression pv = getSimplePropertyValue(ph, pd);
    PropertyType pt = (PropertyType) pd.getType();
    if (pt instanceof RangeType) {
        pt = ((RangeType) pt).getNumberType();
    }
    final UnitsType theUnitsType = ((NumberType) pt).getUnitsType();
    if (unit.eContainer() != theUnitsType) {
        throw new IllegalArgumentException("Unit literal " + unit.getName() + " is not from the property's type " + theUnitsType.getName());
    }
    return pv;
}
Also used : RangeType(org.osate.aadl2.RangeType) NumberType(org.osate.aadl2.NumberType) PropertyExpression(org.osate.aadl2.PropertyExpression) PropertyType(org.osate.aadl2.PropertyType) UnitsType(org.osate.aadl2.UnitsType)

Example 14 with UnitsType

use of org.osate.aadl2.UnitsType in project osate2 by osate.

the class PropertiesValidator method checkUnits.

/**
 * Returns true if the units are valid. Returns false if an error was reported.
 */
protected boolean checkUnits(NumberType nt, NumberValue nv, Element holder) {
    UnitsType ut = nt.getUnitsType();
    UnitLiteral ul = nv.getUnit();
    if (Aadl2Util.isNull(ut) && Aadl2Util.isNull(ul)) {
        return true;
    }
    if (ul == null) {
        boolean doQuickFix = false;
        EObject container = nv;
        while (null != container) {
            if (container.equals(holder)) {
                doQuickFix = true;
                break;
            }
            container = container.eContainer();
        }
        if (doQuickFix) {
            EList<EnumerationLiteral> allUTElements = ut.getOwnedLiterals();
            String[] unitNamesAndURIs = new String[allUTElements.size() * 2];
            int i = 0;
            for (EnumerationLiteral elem : allUTElements) {
                unitNamesAndURIs[i] = elem.getName();
                i++;
                unitNamesAndURIs[i] = EcoreUtil.getURI(elem).toString();
                i++;
            }
            error("Number value is missing a unit", holder, null, MISSING_NUMBERVALUE_UNITS, unitNamesAndURIs);
            return false;
        } else {
            error(holder, "Number value is missing a unit");
            return false;
        }
    } else if (!ut.getOwnedLiterals().contains(ul)) {
        error(holder, "Unit '" + ul.getName() + "'of number value is not of Units type " + ut.getQualifiedName());
        return false;
    } else {
        return true;
    }
}
Also used : EObject(org.eclipse.emf.ecore.EObject) UnitLiteral(org.osate.aadl2.UnitLiteral) AadlString(org.osate.aadl2.AadlString) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral) UnitsType(org.osate.aadl2.UnitsType)

Example 15 with UnitsType

use of org.osate.aadl2.UnitsType in project AGREE by loonwerks.

the class AgreeLinkingService method findUnitLiteral.

private static UnitLiteral findUnitLiteral(Element context, String name) {
    // expression?
    for (IEObjectDescription desc : Aadl2GlobalScopeUtil.getAllEObjectDescriptions(context, UNITS_TYPE)) {
        UnitsType unitsType = (UnitsType) EcoreUtil.resolve(desc.getEObjectOrProxy(), context);
        UnitLiteral literal = unitsType.findLiteral(name);
        if (literal != null) {
            return literal;
        }
    }
    return null;
}
Also used : UnitLiteral(org.osate.aadl2.UnitLiteral) UnitsType(org.osate.aadl2.UnitsType) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Aggregations

UnitsType (org.osate.aadl2.UnitsType)11 UnitLiteral (org.osate.aadl2.UnitLiteral)9 RangeType (org.osate.aadl2.RangeType)4 AadlString (org.osate.aadl2.AadlString)3 EnumerationLiteral (org.osate.aadl2.EnumerationLiteral)3 IntegerLiteral (org.osate.aadl2.IntegerLiteral)3 PropertyType (org.osate.aadl2.PropertyType)3 EObject (org.eclipse.emf.ecore.EObject)2 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)2 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)2 AadlBoolean (org.osate.aadl2.AadlBoolean)2 AadlInteger (org.osate.aadl2.AadlInteger)2 AadlReal (org.osate.aadl2.AadlReal)2 BooleanLiteral (org.osate.aadl2.BooleanLiteral)2 ClassifierType (org.osate.aadl2.ClassifierType)2 ClassifierValue (org.osate.aadl2.ClassifierValue)2 ContainedNamedElement (org.osate.aadl2.ContainedNamedElement)2 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)2 EnumerationType (org.osate.aadl2.EnumerationType)2 ListType (org.osate.aadl2.ListType)2