Search in sources :

Example 46 with ComponentClassifier

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

the class CheckBindingConstraints method runAnalysis.

public static List<Issue> runAnalysis(IProgressMonitor monitor, SystemInstance si) {
    List<Issue> issuesList = new ArrayList<>();
    SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
    System.out.println(si.getSystemOperationModes().size());
    SubMonitor loopMonitor = subMonitor.split(100).setWorkRemaining(si.getSystemOperationModes().size());
    for (SOMIterator somIter = new SOMIterator(si); somIter.hasNext(); ) {
        SystemOperationMode som = somIter.next();
        SubMonitor iterationMonitor = loopMonitor.split(1);
        iterationMonitor.setWorkRemaining(8);
        // Processor binding
        SubMonitor processorChild = iterationMonitor.split(2);
        subMonitor.setTaskName("Getting Processor Binding Components");
        processorChild.split(1);
        List<ComponentInstance> processorBindingComponents = getComponents(monitor, si, ComponentCategory.THREAD, ComponentCategory.VIRTUAL_PROCESSOR, ComponentCategory.DEVICE).collect(Collectors.toList());
        processorChild.setTaskName("Checking Processor Bindings");
        processorChild.split(1);
        issuesList.addAll(checkBindingConstraints(processorBindingComponents.stream(), "processor", GetProperties::getActualProcessorBinding, GetProperties::getAllowedProcessorBinding, GetProperties::getAllowedProcessorBindingClass, som));
        // Dispatch Protocol
        subMonitor.setTaskName("Checking Dispacth Protocols");
        SubMonitor dispatchChild = iterationMonitor.split(1);
        issuesList.addAll(checkDispatchProtocol(processorBindingComponents.stream(), som));
        // Memory binding
        subMonitor.setTaskName("Getting Memory Components");
        SubMonitor memrChild = iterationMonitor.split(2);
        memrChild.split(1);
        Stream<ComponentInstance> memoryBindingComponents = getComponents(monitor, si, ComponentCategory.THREAD, ComponentCategory.DEVICE, ComponentCategory.DATA, ComponentCategory.SUBPROGRAM, ComponentCategory.PROCESSOR, ComponentCategory.VIRTUAL_PROCESSOR);
        subMonitor.setTaskName("Checking Memory Bindings");
        memrChild.split(1);
        Stream<FeatureInstance> memoryBindingFeatures = getFeatures(monitor, si, FeatureCategory.DATA_PORT, FeatureCategory.EVENT_DATA_PORT);
        Stream<InstanceObject> memoryBindingElements = Stream.concat(memoryBindingComponents, memoryBindingFeatures);
        issuesList.addAll(checkBindingConstraints(memoryBindingElements, "memory", GetProperties::getActualMemoryBinding, GetProperties::getAllowedMemoryBinding, GetProperties::getAllowedMemoryBindingClass, som));
        // Connection binding (only handles connection and virtual bus)
        subMonitor.setTaskName("Checking Connection Bindings");
        SubMonitor conenctionChild = iterationMonitor.split(1);
        Stream<ComponentInstance> connectionBindingComponents = getComponents(monitor, si, ComponentCategory.VIRTUAL_BUS);
        Stream<ConnectionInstance> connectionBindingConnections = getConnections(monitor, si);
        List<InstanceObject> connectionBindingElements = Stream.concat(connectionBindingComponents, connectionBindingConnections).collect(Collectors.toList());
        issuesList.addAll(checkBindingConstraints(connectionBindingElements.stream(), "connection", GetProperties::getActualConnectionBinding, GetProperties::getAllowedConnectionBinding, GetProperties::getAllowedConnectionBindingClass, som));
        // Connection Quality of Service
        subMonitor.setTaskName("Checking Connection Quality of Services");
        SubMonitor qualityChild = iterationMonitor.split(1);
        issuesList.addAll(checkRequiredAndProvided(connectionBindingElements.stream(), GetProperties::getRequiredConnectionQualityOfService, "Required_Connection_Quality_Of_Service", GetProperties::getProvidedConnectionQualityOfService, qos -> qos.getName(), som));
        // Virtual Bus Class
        subMonitor.setTaskName("Checking Virtual Bus Bindings");
        SubMonitor busChild = iterationMonitor.split(1);
        Function<ComponentInstance, Collection<ComponentClassifier>> getProvidedVBClass = boundElement -> {
            Stream<ComponentClassifier> providedProperty = GetProperties.getProvidedVirtualBusClass(boundElement).stream();
            Stream<ComponentClassifier> providedBySubcomponent = boundElement.getComponentInstances().stream().map(subcomponent -> subcomponent.getClassifier());
            return Stream.concat(providedProperty, providedBySubcomponent).collect(Collectors.toSet());
        };
        issuesList.addAll(checkRequiredAndProvided(connectionBindingElements.stream(), GetProperties::getRequiredVirtualBusClass, "Required_Virtual_Bus_Class", getProvidedVBClass, vbClass -> vbClass.getName(), som));
        busChild.setWorkRemaining(0);
    }
    subMonitor.setWorkRemaining(0);
    return issuesList;
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) Arrays(java.util.Arrays) Element(org.osate.aadl2.Element) Spliterators(java.util.Spliterators) SubMonitor(org.eclipse.core.runtime.SubMonitor) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) DeploymentProperties(org.osate.aadl2.contrib.deployment.DeploymentProperties) StreamSupport(java.util.stream.StreamSupport) GetProperties(org.osate.xtext.aadl2.properties.util.GetProperties) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) EnumSet(java.util.EnumSet) EnumerationLiteral(org.osate.aadl2.EnumerationLiteral) FeatureCategory(org.osate.aadl2.instance.FeatureCategory) SystemInstance(org.osate.aadl2.instance.SystemInstance) SOMIterator(org.osate.aadl2.modelsupport.modeltraversal.SOMIterator) AadlUtil(org.osate.aadl2.modelsupport.util.AadlUtil) Iterator(java.util.Iterator) Aadl2Util(org.osate.aadl2.util.Aadl2Util) Collection(java.util.Collection) Set(java.util.Set) EObject(org.eclipse.emf.ecore.EObject) Collectors(java.util.stream.Collectors) ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Consumer(java.util.function.Consumer) List(java.util.List) Stream(java.util.stream.Stream) ComponentCategory(org.osate.aadl2.ComponentCategory) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) Optional(java.util.Optional) AaxlReadOnlyHandlerAsJob(org.osate.ui.handlers.AaxlReadOnlyHandlerAsJob) StringExtensions(org.eclipse.xtext.xbase.lib.StringExtensions) NamedElement(org.osate.aadl2.NamedElement) Collections(java.util.Collections) Spliterator(java.util.Spliterator) Dialog(org.osate.ui.dialogs.Dialog) InstanceObject(org.osate.aadl2.instance.InstanceObject) SOMIterator(org.osate.aadl2.modelsupport.modeltraversal.SOMIterator) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) ArrayList(java.util.ArrayList) SubMonitor(org.eclipse.core.runtime.SubMonitor) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) InstanceObject(org.osate.aadl2.instance.InstanceObject) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) Collection(java.util.Collection) Stream(java.util.stream.Stream)

Example 47 with ComponentClassifier

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

the class AadlContribUtils method getDataSize.

private static double getDataSize(final NamedElement ne, final SizeUnits unit, final int nesting) {
    final double elementSize = PropertyUtils.getScaled(MemoryProperties::getDataSize, ne, unit).orElseGet(() -> {
        final ComponentCategory cc = ne instanceof ComponentClassifier ? ((ComponentClassifier) ne).getCategory() : (ne instanceof ComponentInstance ? ((ComponentInstance) ne).getCategory() : null);
        if (cc != ComponentCategory.BUS && cc != ComponentCategory.VIRTUAL_BUS) {
            return PropertyUtils.getScaled(MemoryProperties::getSourceDataSize, ne, unit).orElse(0.0);
        } else {
            return 0.0;
        }
    });
    final long multiplier = ne instanceof DataSubcomponent ? AadlUtil.getMultiplicity(ne) : 1;
    if (elementSize != 0.0) {
        return elementSize * multiplier;
    } else {
        if ((nesting <= 10) && (ne instanceof DataSubcomponent || ne instanceof DataImplementation)) {
            // mult is one or the array size of the data subcomponent.
            return sumElementsDataSize(ne, unit, nesting + 1) * multiplier;
        } else {
            return 0.0;
        }
    }
}
Also used : ComponentClassifier(org.osate.aadl2.ComponentClassifier) DataSubcomponent(org.osate.aadl2.DataSubcomponent) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) DataImplementation(org.osate.aadl2.DataImplementation) ComponentCategory(org.osate.aadl2.ComponentCategory)

Example 48 with ComponentClassifier

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

the class AadlUtil method getElement.

// TODO: [ASKLUTZ] Uncomment after Joe asks Lutz about
// Classifier.allFeatures().
// /**
// * get list of packages referenced by the features of the specified list
// of component classifiers or port group classifiers
// * @param aobjlist
// * @return list of packages
// */
// public static EList<AadlPackage> getUsedPackages(List<? extends Element>
// aobjlist){
// return doGetUsedPackages(aobjlist, false);
// }
// TODO: [ASKLUTZ] Uncomment after Joe asks Lutz about
// Classifier.allFeatures().
// /**
// * get list of packages referenced by the features of the specified list
// of component classifiers or port group classifiers
// * recursively consider the features in port groups
// * @param aobjlist
// * @return list of packages
// */
// public static EList<AadlPackage> getAllUsedPackages(List<? extends
// Element> aobjlist){
// return doGetUsedPackages(aobjlist, true);
// }
// TODO: [ASKLUTZ] Uncomment after Joe asks Lutz about
// Classifier.allFeatures().
// /**
// * get list of packages referenced by the features of the specified list
// of component classifiers or port group classifiers
// * recursively consider the features in port groups if so indicated
// * @param aobjlist
// * @param recurse
// * @return list of packages
// */
// private static EList<AadlPackage> doGetUsedPackages(List<? extends
// Element> aobjlist, boolean recurse){
// EList<AadlPackage> packagerefFound = new UniqueEList<AadlPackage>();
// for (Element ao : aobjlist){
// if (ao instanceof ComponentType){
// usedPackages(packagerefFound, (ComponentType)ao, recurse);
// } else if (ao instanceof ComponentImplementation){
// usedPackages(packagerefFound, (ComponentImplementation)ao);
// } else if (ao instanceof FeatureGroupType){
// usedPackages(packagerefFound, (FeatureGroupType)ao, recurse);
// }
// }
// return packagerefFound;
// }
// TODO: [ASKLUTZ] Uncomment after Joe asks Lutz about
// Classifier.allFeatures().
// /**
// * get list of packages referenced by the features of the specified
// component type
// * @param ct ComponentType
// * @return list of packages
// */
// public static List<AadlPackage> getUsedPackages(ComponentType ct){
// EList<AadlPackage> packagerefFound = new UniqueEList<AadlPackage>();
// return usedPackages(packagerefFound,ct,false);
// }
// TODO: [ASKLUTZ] Uncomment after Joe asks Lutz about
// Classifier.allFeatures().
// /**
// * get list of packages referenced by the features of the specified
// component type
// * recurseively consider the features in port groups
// * @param ct ComponentType
// * @return list of packages
// */
// public static List<AadlPackage> getAllUsedPackages(ComponentType ct){
// EList<AadlPackage> packagerefFound = new UniqueEList<AadlPackage>();
// return usedPackages(packagerefFound,ct,true);
// }
// TODO: [ASKLUTZ] Uncomment after Joe asks Lutz about
// Classifier.allFeatures().
// /**
// * get list of packages referenced by the features of the specified
// component type
// * @param ci ComponentImpl
// * @return list of packages
// */
// public static List<AadlPackage> getUsedPackages(ComponentImplementation
// ci){
// EList<AadlPackage> packagerefFound = new UniqueEList<AadlPackage>();
// return usedPackages(packagerefFound,ci);
// }
// TODO: [ASKLUTZ] Uncomment after Joe asks Lutz about
// Classifier.allFeatures().
// /**
// * get list of packages referenced by the features of the specified port
// group type
// * @param pgt PortGroupType
// * @return list of packages
// */
// public static List<AadlPackage> getUsedPackages(FeatureGroupType pgt){
// EList<AadlPackage> packagerefFound = new UniqueEList<AadlPackage>();
// return usedPackages(packagerefFound,pgt, false);
// }
// TODO: [ASKLUTZ] Rewrite after Joe asks Lutz about
// ComponentType.allFeatures().
// /**
// * add packages referenced by the component type's features to the list of
// package references
// * @param packrefFound
// * @param obj
// */
// private static List<AadlPackage> usedPackages(List<AadlPackage>
// packrefFound, ComponentType obj, boolean recurse){
// EList featurelist = obj.getXAllFeature();
// for (Iterator it = featurelist.iterator(); it.hasNext();){
// Feature f = (Feature) it.next();
// Classifier dc = f.getXAllClassifier();
// if (dc != null){
// Element root = dc.getElementRoot();
// if (root instanceof AadlPackage){
// packrefFound.add((AadlPackage)root);
// }
// if (recurse && dc instanceof PortGroup){
// PortGroupType pgt = ((PortGroup)dc).getPortGroupType();
// if (pgt != null){
// usedPackages(packrefFound,pgt, recurse);
// }
// }
// }
// }
// return packrefFound;
// }
// TODO: [ASKLUTZ] Rewrite after Joe asks Lutz about
// FeatureGroupType.allFeatures().
// /**
// * add packages referenced by the component type's features to the list of
// package references
// * @param packrefFound
// * @param obj
// */
// private static List<AadlPackage> usedPackages(List<AadlPackage>
// packrefFound, FeatureGroupType obj, boolean recurse){
// EList featurelist = obj.getXAllFeature();
// for (Iterator it = featurelist.iterator(); it.hasNext();){
// Feature f = (Feature) it.next();
// Classifier dc = f.getXAllClassifier();
// if (dc != null){
// Element root = dc.getElementRoot();
// if (root instanceof AadlPackage){
// packrefFound.add((AadlPackage)root);
// }
// if (recurse && dc instanceof PortGroup){
// PortGroupType pgt = ((PortGroup)dc).getPortGroupType();
// if (pgt != null){
// usedPackages(packrefFound,pgt, recurse);
// }
// }
// }
// }
// return packrefFound;
// }
// TODO: [SUBCOMPONENTS] Rewrite after
// ComponentImplementation.getSubcomponents() is created.
// /**
// * add packages referenced by the component type's features to the list of
// package references
// * @param packrefFound
// * @param obj
// */
// private static List<AadlPackage> usedPackages(List<AadlPackage>
// packrefFound, ComponentImplementation obj){
// EList subcomplist = obj.getXAllSubcomponent();
// for (Iterator it = subcomplist.iterator(); it.hasNext();){
// Subcomponent f = (Subcomponent) it.next();
// Classifier cc = f.getXAllClassifier();
// if (cc != null){
// Element root = cc.getElementRoot();
// if (root instanceof AadlPackage){
// packrefFound.add((AadlPackage)root);
// }
// }
// }
// EList calls = obj.getXAllCallSequence();
// for (Iterator iit = calls.iterator(); iit.hasNext();) {
// EList calllist = ((CallSequence) iit.next()).getCall();
// for (Iterator it = calllist.iterator(); it.hasNext();) {
// Subcomponent sc = (Subcomponent) it.next();
// ComponentClassifier cc = sc.getXAllClassifier();
// if (cc != null){
// Element root = cc.getElementRoot();
// if (root instanceof AadlPackage){
// packrefFound.add((AadlPackage)root);
// }
// }
// }
// }
// return packrefFound;
// }
/**
 * Try to retrieve an {@link org.osate.aadl2.Element} from an object.
 * This method is intended to be used with objects that obtained from a
 * selection event, i.e., from the
 * {@link org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)}
 * method.
 * <p>
 * If the object is an Element, it is returned. Otherwise, the method tries
 * to adapt the object to an Element. The Object could be an Element, IAdaptable, an instance model resource,
 * or a TreeSelection of a IFile in the Navigator
 *
 * @param object The object to get an Element from.
 * @return The Element, or <code>null</code> if no Element can be obtained
 *         from the given object.
 */
public static Element getElement(final Object object) {
    Element theElement = null;
    // Is it an Element?
    if (object instanceof Element) {
        theElement = (Element) object;
        if (theElement != null) {
            return theElement;
        }
    }
    if (object instanceof IAdaptable) {
        theElement = ((IAdaptable) object).getAdapter(Element.class);
        if (theElement != null) {
            return theElement;
        }
    }
    if (object instanceof IFile && FileNameConstants.INSTANCE_FILE_EXT.equalsIgnoreCase(((IFile) object).getFileExtension())) {
        Resource res = new ResourceSetImpl().getResource(OsateResourceUtil.toResourceURI((IResource) object), true);
        EList<EObject> rl = res.getContents();
        if (!rl.isEmpty() && rl.get(0) instanceof Element) {
            return (Element) rl.get(0);
        }
    }
    if (object instanceof IFile && FileNameConstants.SOURCE_FILE_EXT.equalsIgnoreCase(((IFile) object).getFileExtension())) {
        Resource res = new ResourceSetImpl().getResource(OsateResourceUtil.toResourceURI((IResource) object), true);
        EList<EObject> rl = res.getContents();
        if (!rl.isEmpty() && rl.get(0) instanceof LazyLinkingResource) {
            if ((((LazyLinkingResource) rl.get(0)).getContents().size() > 0) && (((LazyLinkingResource) rl.get(0)).getContents().get(0) instanceof Element)) {
                theElement = (Element) ((LazyLinkingResource) rl.get(0)).getContents().get(0);
                return theElement;
            }
        }
        if (!rl.isEmpty() && rl.get(0) instanceof Element) {
            theElement = (Element) rl.get(0);
            return theElement;
        }
    }
    if (object instanceof TreeSelection) {
        for (Iterator<?> iterator = ((TreeSelection) object).iterator(); iterator.hasNext(); ) {
            Object f = iterator.next();
            if (f instanceof IResource) {
                URI uri = OsateResourceUtil.toResourceURI((IResource) f);
                Resource res = new ResourceSetImpl().getResource(uri, true);
                EList<EObject> rl = res.getContents();
                if (!rl.isEmpty() && rl.get(0) instanceof Element) {
                    return (Element) rl.get(0);
                }
            }
        }
        return null;
    }
    if (object instanceof EObjectURIWrapper) {
        EObjectURIWrapper wrapper = (EObjectURIWrapper) object;
        EObject eObject = new ResourceSetImpl().getEObject(wrapper.getUri(), true);
        if (eObject instanceof Element) {
            return (Element) eObject;
        }
    }
    return null;
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IFile(org.eclipse.core.resources.IFile) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) EndToEndFlowElement(org.osate.aadl2.EndToEndFlowElement) NamedElement(org.osate.aadl2.NamedElement) ArrayableElement(org.osate.aadl2.ArrayableElement) ModalElement(org.osate.aadl2.ModalElement) Element(org.osate.aadl2.Element) RefinableElement(org.osate.aadl2.RefinableElement) FlowElement(org.osate.aadl2.FlowElement) ConnectedElement(org.osate.aadl2.ConnectedElement) Resource(org.eclipse.emf.ecore.resource.Resource) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) IResource(org.eclipse.core.resources.IResource) URI(org.eclipse.emf.common.util.URI) LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) TreeSelection(org.eclipse.jface.viewers.TreeSelection) EObject(org.eclipse.emf.ecore.EObject) EObjectURIWrapper(org.osate.aadl2.modelsupport.EObjectURIWrapper) InstanceObject(org.osate.aadl2.instance.InstanceObject) EObject(org.eclipse.emf.ecore.EObject) AObject(org.osate.aadl2.parsesupport.AObject) IResource(org.eclipse.core.resources.IResource)

Example 49 with ComponentClassifier

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

the class AbstractTopDownComponentTraversal method hasUsageReferences.

private boolean hasUsageReferences(final ComponentClassifier aobj, final EList<ComponentImplementation> allci) {
    for (Iterator<ComponentImplementation> all = allci.iterator(); processingMethod.notCancelled() && all.hasNext(); ) {
        ComponentImplementation ci = all.next();
        EList<Subcomponent> sublist = ci.getAllSubcomponents();
        for (Iterator<Subcomponent> it = sublist.iterator(); it.hasNext(); ) {
            Subcomponent sc = it.next();
            ComponentClassifier cc = sc.getAllClassifier();
            if (cc == aobj) {
                return true;
            }
        }
    }
    return false;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Subcomponent(org.osate.aadl2.Subcomponent)

Example 50 with ComponentClassifier

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

the class SubcomponentImpl method getPropertyValue.

public void getPropertyValue(Property prop, PropertyAcc pas, Classifier cl, final boolean all) {
    final ComponentImplementation owner = (ComponentImplementation) getContainingClassifier();
    if (pas.addLocalContained(this, owner)) {
        return;
    }
    // get local value
    if (pas.addLocal(this)) {
        return;
    }
    // collect values from refined subcomponents
    Subcomponent refined = getRefined();
    while (refined != null) {
        if (pas.addLocal(refined)) {
            return;
        }
        refined = refined.getRefined();
    }
    // get values from classifier
    if (cl != null) {
        cl.getPropertyValueInternal(prop, pas, true, all);
    } else {
        final ComponentClassifier cc = getClassifier();
        if (cc != null) {
            cc.getPropertyValueInternal(prop, pas, true, all);
        }
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Subcomponent(org.osate.aadl2.Subcomponent)

Aggregations

ComponentClassifier (org.osate.aadl2.ComponentClassifier)76 Subcomponent (org.osate.aadl2.Subcomponent)26 Classifier (org.osate.aadl2.Classifier)22 EObject (org.eclipse.emf.ecore.EObject)19 NamedElement (org.osate.aadl2.NamedElement)19 ComponentImplementation (org.osate.aadl2.ComponentImplementation)16 ArrayList (java.util.ArrayList)15 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)14 AadlPackage (org.osate.aadl2.AadlPackage)13 FeatureGroupType (org.osate.aadl2.FeatureGroupType)12 List (java.util.List)11 ComponentPrototype (org.osate.aadl2.ComponentPrototype)11 Element (org.osate.aadl2.Element)11 ComponentType (org.osate.aadl2.ComponentType)10 Feature (org.osate.aadl2.Feature)9 Mode (org.osate.aadl2.Mode)8 BusinessObjectContext (org.osate.ge.BusinessObjectContext)8 Collectors (java.util.stream.Collectors)7 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)7 ComponentCategory (org.osate.aadl2.ComponentCategory)7