Search in sources :

Example 1 with BehaviorVariable

use of org.osate.ba.aadlba.BehaviorVariable in project osate2 by osate.

the class AadlBaNameResolver method parentComponentIdentifiersUniquenessCheck.

/**
 * Check behavior annex's sub component uniqueness within behavior annex's
 * parent component scope. Conflicts are reported.
 */
private boolean parentComponentIdentifiersUniquenessCheck() {
    boolean result = true;
    EList<org.osate.aadl2.NamedElement> lcc = new BasicEList<org.osate.aadl2.NamedElement>(0);
    // Merges parent component' subcomponents lists.
    lcc.addAll(Aadl2Visitors.getElementsInNamespace(_baParentContainer, Data.class));
    lcc.addAll(Aadl2Visitors.getElementsInNamespace(_baParentContainer, Mode.class));
    lcc.addAll(Aadl2Visitors.getElementsInNamespace(_baParentContainer, Feature.class));
    EList<BehaviorVariable> lvars = _ba.getVariables();
    EList<BehaviorState> lstates = _ba.getStates();
    EList<BehaviorTransition> ltrans = _ba.getTransitions();
    // Check uniqueness within the parent component.
    for (org.osate.aadl2.NamedElement ne : lcc) {
        for (BehaviorVariable v : lvars) {
            String bvName = v.getName();
            String neName = ne.getName();
            if (bvName.equalsIgnoreCase(neName)) {
                reportDuplicateNameError(v, ne);
                result = false;
            }
        }
        for (BehaviorState s : lstates) {
            String bsName = s.getName();
            if (bsName.equalsIgnoreCase(ne.getName())) {
                // Links the identifier with the mode.
                if (ne instanceof Mode) {
                    if (s.isComplete() == false) {
                        _errManager.error(s, "Behavior state " + bsName + " must be declared complete in order to represent " + "mode " + ne.getName() + " located at line " + Aadl2Utils.getLocationReference(ne).getLine());
                        result = false;
                    } else {
                        s.setBindedMode((Mode) ne);
                    }
                } else {
                    reportDuplicateNameError(s, ne);
                    result = false;
                }
            }
        }
        for (BehaviorTransition t : ltrans) {
            String btName = t.getName();
            if (btName != null && btName.equalsIgnoreCase(ne.getName())) {
                reportDuplicateNameError(t, ne);
                result = false;
            }
        }
    }
    return result;
}
Also used : BehaviorVariable(org.osate.ba.aadlba.BehaviorVariable) BasicEList(org.eclipse.emf.common.util.BasicEList) Mode(org.osate.aadl2.Mode) Data(org.osate.aadl2.Data) Feature(org.osate.aadl2.Feature) ClassifierFeature(org.osate.aadl2.ClassifierFeature) BehaviorTransition(org.osate.ba.aadlba.BehaviorTransition) DeclarativeBehaviorTransition(org.osate.ba.declarative.DeclarativeBehaviorTransition) BehaviorState(org.osate.ba.aadlba.BehaviorState) NamedElement(org.osate.aadl2.NamedElement) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) NamedElement(org.osate.aadl2.NamedElement)

Example 2 with BehaviorVariable

use of org.osate.ba.aadlba.BehaviorVariable in project osate2 by osate.

the class AadlBaNameResolver method behaviorVariableResolver.

/**
 * Resolves the behavior annex's variables.
 *
 * @return {@code true} if all names are resolved. {@code false} otherwise.
 */
private boolean behaviorVariableResolver() {
    boolean result = true;
    QualifiedNamedElement uccr;
    // classifier reference exists.
    for (BehaviorVariable v : _ba.getVariables()) {
        uccr = (QualifiedNamedElement) v.getDataClassifier();
        result &= qualifiedNamedElementResolver(uccr, true);
        for (ArrayDimension tmp : v.getArrayDimensions()) {
            IntegerValueConstant ivc = ((DeclarativeArrayDimension) tmp).getDimension();
            result &= integerValueConstantResolver(ivc);
        }
        List<PropertyAssociation> paList = v.getOwnedPropertyAssociations();
        List<PropertyAssociation> paPropertyNotFound = new ArrayList<PropertyAssociation>();
        Set<PropertyAssociation> paPropertyValueError = new HashSet<PropertyAssociation>();
        for (PropertyAssociation pa : paList) {
            QualifiedNamedElement p = (QualifiedNamedElement) pa.getProperty();
            boolean valid = qualifiedNamedElementResolver(p, false);
            if (valid) {
                for (ModalPropertyValue mpv : pa.getOwnedValues()) {
                    result &= propertyExpressionResolver(v, p, mpv.getOwnedValue());
                    paPropertyValueError.add(pa);
                }
            }
            if (!valid) {
                paPropertyNotFound.add(pa);
            }
            result &= valid;
        }
        StringBuilder msg = new StringBuilder();
        if (paPropertyNotFound.size() > 1) {
            msg.append("Properties ");
        } else {
            msg.append("Property ");
        }
        boolean first = true;
        for (PropertyAssociation paToRemove : paPropertyNotFound) {
            QualifiedNamedElement p = (QualifiedNamedElement) paToRemove.getProperty();
            StringBuilder qualifiedName = new StringBuilder();
            if (p.getBaNamespace() != null) {
                qualifiedName.append(p.getBaNamespace().getId());
                qualifiedName.append("::");
            }
            qualifiedName.append(p.getBaName().getId());
            if (first) {
                msg.append("\'" + qualifiedName + "\' ");
            } else {
                msg.append(" and \'" + qualifiedName + "\' ");
            }
            first = false;
        }
        paList.removeAll(paPropertyNotFound);
        paList.removeAll(paPropertyValueError);
        if (paPropertyNotFound.size() > 0) {
            msg.append("not found");
            _errManager.error(v, msg.toString());
        }
    }
    return result;
}
Also used : ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) BehaviorVariable(org.osate.ba.aadlba.BehaviorVariable) PropertyAssociation(org.osate.aadl2.PropertyAssociation) DeclarativeBasicPropertyAssociation(org.osate.ba.declarative.DeclarativeBasicPropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) ArrayList(java.util.ArrayList) QualifiedNamedElement(org.osate.ba.declarative.QualifiedNamedElement) DeclarativeArrayDimension(org.osate.ba.declarative.DeclarativeArrayDimension) IntegerValueConstant(org.osate.ba.aadlba.IntegerValueConstant) ArrayDimension(org.osate.aadl2.ArrayDimension) DeclarativeArrayDimension(org.osate.ba.declarative.DeclarativeArrayDimension) HashSet(java.util.HashSet)

Example 3 with BehaviorVariable

use of org.osate.ba.aadlba.BehaviorVariable in project osate2 by osate.

the class AadlBaUtils method getClassifier.

/**
 * Returns the given Element object's classifier.
 * If the Element object is a prototype, it will try to resolve it as
 * follow: returns the data prototype binded classifier at first withing the
 * element's parent container otherwise the constraining classifier.
 * It returns {@code null} if the prototype is not defined.
 * <BR><BR>
 * This method support instances of:<BR>
 * <BR>_Feature (port, data access, subprogram access, parameter, etc.)
 * <BR>_Subcomponent (data subcomponent, subprogram subcomponent, etc.)
 * <BR>_BehaviorVariable
 * <BR>_IterativeVariable (for/forall's iterative variable)
 * <BR>_Prototype (all excepted FeatureGroupPrototype)
 * <BR>_PrototypeBinding (all excepted FeatureGroupPrototypeBinding)
 * <BR>_ClassifierValue (struct or union data subcomponent)
 * <BR><BR>
 * If the given Element object is not one of those types, an
 * UnsupportedOperationException is thrown.
 *
 * @param el the given Element object
 * @param parentContainer the element's parent component.
 * @return the given element's classifier or {@code null} if the prototype is
 * not defined
 * @exception UnsupportedOperationException for unsupported element
 * object types.
 */
public static Classifier getClassifier(Element el, Classifier parentContainer) {
    Classifier result = null;
    if (el instanceof Feature) {
        Feature f = (Feature) el;
        if (el instanceof FeatureGroup) {
            org.osate.aadl2.FeatureType ft = ((FeatureGroup) el).getFeatureType();
            if (ft != null) {
                if (ft instanceof FeatureGroupType) {
                    result = (FeatureGroupType) ft;
                } else // FeatureGroupPrototype case
                {
                    result = getClassifier((FeatureGroupPrototype) ft, parentContainer);
                }
            }
        } else {
            // Feature case.
            result = f.getClassifier();
            // Feature without classifier returns null.
            if (result == null && f.getPrototype() != null) {
                result = prototypeResolver(f.getPrototype(), parentContainer);
            }
        }
    } else if (el instanceof Subcomponent) {
        Subcomponent sub = (Subcomponent) el;
        if (el instanceof SubprogramGroupSubcomponent) {
            result = ((SubprogramGroupSubcomponent) el).getClassifier();
        } else {
            // Subcomponent case.
            result = sub.getClassifier();
            // Subcomponent without classifier returns null.
            if (result == null && sub.getPrototype() != null) {
                result = prototypeResolver(sub.getPrototype(), parentContainer);
            }
        }
    } else if (el instanceof BehaviorVariable) {
        // Local variable case (BehaviorVariable).
        BehaviorVariable bv = (BehaviorVariable) el;
        result = bv.getDataClassifier();
    } else if (el instanceof IterativeVariable) {
        // Iterative variable case.
        result = ((IterativeVariable) el).getDataClassifier();
    } else if (el instanceof Prototype) {
        result = prototypeResolver((Prototype) el, parentContainer);
    } else if (el instanceof PrototypeBinding) {
        // Prototype binding case.
        result = prototypeBindingResolver((PrototypeBinding) el);
    } else if (el instanceof ClassifierValue) {
        // struct or union member case (ClassifierValue).
        result = ((ClassifierValue) el).getClassifier();
    } else if (el instanceof StructUnionElement) {
        return ((StructUnionElement) el).getDataClassifier();
    } else {
        // Reports error.
        String errorMsg = "getClassifier : " + el.getClass().getSimpleName() + " is not supported yet.";
        System.err.println(errorMsg);
        throw new UnsupportedOperationException(errorMsg);
    }
    return result;
}
Also used : IterativeVariable(org.osate.ba.aadlba.IterativeVariable) FeatureGroup(org.osate.aadl2.FeatureGroup) Prototype(org.osate.aadl2.Prototype) DataPrototype(org.osate.aadl2.DataPrototype) FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) FeaturePrototype(org.osate.aadl2.FeaturePrototype) ComponentPrototype(org.osate.aadl2.ComponentPrototype) ClassifierValue(org.osate.aadl2.ClassifierValue) BehaviorVariable(org.osate.ba.aadlba.BehaviorVariable) FeatureGroupType(org.osate.aadl2.FeatureGroupType) SubprogramGroupSubcomponent(org.osate.aadl2.SubprogramGroupSubcomponent) SubprogramClassifier(org.osate.aadl2.SubprogramClassifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) ProcessClassifier(org.osate.aadl2.ProcessClassifier) DataClassifier(org.osate.aadl2.DataClassifier) ProcessorClassifier(org.osate.aadl2.ProcessorClassifier) AadlString(org.osate.aadl2.AadlString) StructUnionElement(org.osate.ba.aadlba.StructUnionElement) Feature(org.osate.aadl2.Feature) AbstractFeature(org.osate.aadl2.AbstractFeature) DirectedFeature(org.osate.aadl2.DirectedFeature) FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) Subcomponent(org.osate.aadl2.Subcomponent) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) SubprogramGroupSubcomponent(org.osate.aadl2.SubprogramGroupSubcomponent) SystemSubcomponent(org.osate.aadl2.SystemSubcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent) PrototypeBinding(org.osate.aadl2.PrototypeBinding) FeaturePrototypeBinding(org.osate.aadl2.FeaturePrototypeBinding) FeatureGroupPrototypeBinding(org.osate.aadl2.FeatureGroupPrototypeBinding) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding)

Example 4 with BehaviorVariable

use of org.osate.ba.aadlba.BehaviorVariable in project osate2 by osate.

the class CreateVariablePaletteCommand method getOperation.

@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
    return ctx.getTarget().getBusinessObject(BehaviorAnnex.class).map(behaviorAnnex -> {
        final PublicPackageSection section = getPackage(behaviorAnnex).map(AadlPackage::getPublicSection).orElse(null);
        if (section == null) {
            return null;
        }
        return Operation.createWithBuilder(builder -> {
            final OperationBuilder<DataClassifier> prompt = builder.supply(() -> BehaviorAnnexUtil.promptForDataClassifier(behaviorAnnex.eResource()).filter(c -> BehaviorAnnexUtil.getPackage(c).isPresent()).map(StepResult::forValue).orElseGet(StepResult::abort));
            final OperationBuilder<DataClassifier> addImportIfNeeded = prompt.modifyModel(null, (tag, prevResult) -> section, (tag, sectionToModify, dataClassifier) -> {
                BehaviorAnnexUtil.getPackage(dataClassifier).ifPresent(classifierPkg -> AadlImportsUtil.addImportIfNeeded(sectionToModify, classifierPkg));
                return StepResult.forValue(dataClassifier);
            });
            addImportIfNeeded.modifyModel(null, (tag, dataClassifier) -> behaviorAnnex, (tag, behaviorAnnexToModify, prevResult) -> {
                final BehaviorVariable newVariable = (BehaviorVariable) EcoreUtil.create(AadlBaPackage.eINSTANCE.getBehaviorVariable());
                final String newName = BehaviorAnnexNamingUtil.buildUniqueIdentifier(behaviorAnnexToModify, "new_behavior_variable");
                newVariable.setName(newName);
                newVariable.setDataClassifier(prevResult);
                behaviorAnnexToModify.getVariables().add(newVariable);
                return StepResultBuilder.create().showNewBusinessObject(ctx.getTarget(), newVariable).build();
            });
        });
    });
}
Also used : GetTargetedOperationContext(org.osate.ge.palette.GetTargetedOperationContext) BehaviorAnnexNamingUtil(org.osate.ge.ba.util.BehaviorAnnexNamingUtil) StepResult(org.osate.ge.operations.StepResult) Operation(org.osate.ge.operations.Operation) BehaviorVariable(org.osate.ba.aadlba.BehaviorVariable) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) AadlPackage(org.osate.aadl2.AadlPackage) AadlImportsUtil(org.osate.ge.aadl2.AadlImportsUtil) BehaviorAnnex(org.osate.ba.aadlba.BehaviorAnnex) BehaviorAnnexUtil.getPackage(org.osate.ge.ba.util.BehaviorAnnexUtil.getPackage) StepResultBuilder(org.osate.ge.operations.StepResultBuilder) PublicPackageSection(org.osate.aadl2.PublicPackageSection) BasePaletteCommand(org.osate.ge.palette.BasePaletteCommand) DataClassifier(org.osate.aadl2.DataClassifier) BehaviorAnnexUtil(org.osate.ge.ba.util.BehaviorAnnexUtil) Optional(java.util.Optional) OperationBuilder(org.osate.ge.operations.OperationBuilder) AadlBaPackage(org.osate.ba.aadlba.AadlBaPackage) TargetedPaletteCommand(org.osate.ge.palette.TargetedPaletteCommand) PublicPackageSection(org.osate.aadl2.PublicPackageSection) BehaviorVariable(org.osate.ba.aadlba.BehaviorVariable) BehaviorAnnex(org.osate.ba.aadlba.BehaviorAnnex) DataClassifier(org.osate.aadl2.DataClassifier) StepResult(org.osate.ge.operations.StepResult)

Example 5 with BehaviorVariable

use of org.osate.ba.aadlba.BehaviorVariable in project osate2 by osate.

the class BehaviorVariableHandler method rename.

@Override
public void rename(final RenameContext ctx) {
    final BehaviorVariable behaviorVariable = ctx.getBusinessObject(BehaviorVariable.class).orElseThrow();
    behaviorVariable.setName(ctx.getNewName());
}
Also used : BehaviorVariable(org.osate.ba.aadlba.BehaviorVariable)

Aggregations

BehaviorVariable (org.osate.ba.aadlba.BehaviorVariable)14 DataClassifier (org.osate.aadl2.DataClassifier)7 QualifiedNamedElement (org.osate.ba.declarative.QualifiedNamedElement)6 NamedElement (org.osate.aadl2.NamedElement)5 Classifier (org.osate.aadl2.Classifier)4 ComponentClassifier (org.osate.aadl2.ComponentClassifier)4 Element (org.osate.aadl2.Element)4 ProcessorClassifier (org.osate.aadl2.ProcessorClassifier)4 BehaviorElement (org.osate.ba.aadlba.BehaviorElement)4 PropertyAssociation (org.osate.aadl2.PropertyAssociation)3 ArrayableIdentifier (org.osate.ba.declarative.ArrayableIdentifier)3 Identifier (org.osate.ba.declarative.Identifier)3 AbstractFeature (org.osate.aadl2.AbstractFeature)2 ArrayDimension (org.osate.aadl2.ArrayDimension)2 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)2 ClassifierFeature (org.osate.aadl2.ClassifierFeature)2 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)2 DataSubcomponent (org.osate.aadl2.DataSubcomponent)2 Feature (org.osate.aadl2.Feature)2 BehaviorAnnex (org.osate.ba.aadlba.BehaviorAnnex)2