Search in sources :

Example 21 with Classifier

use of org.geotoolkit.sml.xml.v101.Classifier in project osate2 by osate.

the class AadlBusinessObjectProvider method getChildBusinessObjects.

@Override
public Stream<?> getChildBusinessObjects(final BusinessObjectProviderContext ctx) {
    final Object bo = ctx.getBusinessObjectContext().getBusinessObject();
    // An IProject is specified as the business object for contextless diagrams.
    if (bo instanceof IProject) {
        // Special handling for project
        final IProject project = (IProject) bo;
        // Perform an incremental project build to ensure new packages are included.
        try {
            project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new NullProgressMonitor());
        } catch (CoreException e) {
            throw new RuntimeException(e);
        }
        Stream<Object> packages = getPackages(project);
        // If no packages were found, assume that the project needs to be built. This can happen if the Eclipse process is forcefully terminated.
        if (packages == null) {
            try {
                project.build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
            } catch (CoreException e) {
                throw new RuntimeException(e);
            }
            packages = getPackages(project);
        }
        return packages;
    } else if (bo instanceof AadlPackage) {
        return getChildren((AadlPackage) bo, ctx.getExtensionRegistry());
    } else if (bo instanceof Classifier) {
        return getChildren((Classifier) bo, true, ctx.getExtensionRegistry());
    } else if (bo instanceof FeatureGroup) {
        final FeatureGroupType fgt = AadlFeatureUtil.getFeatureGroupType(ctx.getBusinessObjectContext(), (FeatureGroup) bo);
        return fgt == null ? Stream.empty() : AadlFeatureUtil.getAllFeatures(fgt).stream();
    } else if (bo instanceof Subcomponent) {
        return getChildren((Subcomponent) bo, ctx.getBusinessObjectContext(), ctx.getExtensionRegistry());
    } else if (bo instanceof SubprogramCall) {
        return getChildren((SubprogramCall) bo);
    } else if (bo instanceof SubprogramCallSequence) {
        return getChildren((SubprogramCallSequence) bo);
    } else if (bo instanceof ModeTransition) {
        final ModeTransition mt = ((ModeTransition) bo);
        final String modeTransitionTriggersDesc = mt.getOwnedTriggers().stream().map(mtt -> mttHandler.getName(mtt)).collect(Collectors.joining(","));
        return Stream.concat(mt.getOwnedTriggers().stream(), Stream.of(new Tag(Tag.KEY_MODE_TRANSITION_TRIGGERS, modeTransitionTriggersDesc)));
    } else if (bo instanceof ComponentInstance) {
        return getChildren((ComponentInstance) bo);
    } else if (bo instanceof FeatureInstance) {
        return ((FeatureInstance) bo).getFeatureInstances().stream();
    } else if (bo instanceof Connection) {
        if (!((Connection) bo).isAllBidirectional()) {
            return Stream.of(new Tag(Tag.KEY_UNIDIRECTIONAL, null));
        }
    } else if (bo instanceof ConnectionInstance) {
        if (!((ConnectionInstance) bo).isBidirectional()) {
            return Stream.of(new Tag(Tag.KEY_UNIDIRECTIONAL, null));
        }
    }
    return Stream.empty();
}
Also used : ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) FeatureGroup(org.osate.aadl2.FeatureGroup) AadlPackage(org.osate.aadl2.AadlPackage) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) SubprogramCallSequence(org.osate.aadl2.SubprogramCallSequence) FeatureGroupType(org.osate.aadl2.FeatureGroupType) Connection(org.osate.aadl2.Connection) ModeTransition(org.osate.aadl2.ModeTransition) Classifier(org.osate.aadl2.Classifier) SubprogramClassifier(org.osate.aadl2.SubprogramClassifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) EObject(org.eclipse.emf.ecore.EObject) Tag(org.osate.ge.aadl2.internal.model.Tag) SubprogramCall(org.osate.aadl2.SubprogramCall)

Example 22 with Classifier

use of org.geotoolkit.sml.xml.v101.Classifier in project osate2 by osate.

the class AnnexHandler method getAnnexSubclauseIndex.

/**
 * Returns a 0 based index for referencing an annex subclause in a list that contains only annex subclauses with the same type and owner
 * @return
 */
public static int getAnnexSubclauseIndex(AnnexSubclause annexSubclause, final boolean useExtended) {
    // Get the default annex library if a parsed annex subclause was specified. This is needed for the comparison later in the function.
    if (!(annexSubclause instanceof DefaultAnnexSubclause)) {
        if (annexSubclause.eContainer() instanceof DefaultAnnexSubclause) {
            annexSubclause = (AnnexSubclause) annexSubclause.eContainer();
        } else {
            return -1;
        }
    }
    final String annexName = annexSubclause.getName();
    if (annexName == null) {
        return -1;
    }
    final Classifier cl = annexSubclause.getContainingClassifier();
    final List<Classifier> classifiers;
    if (useExtended) {
        classifiers = cl.getSelfPlusAllExtended();
        // Get all related classifiers
        if (cl instanceof ComponentImplementation) {
            final ComponentType ct = ((ComponentImplementation) cl).getType();
            if (ct != null) {
                classifiers.addAll(ct.getSelfPlusAllExtended());
            }
        }
    } else {
        classifiers = Arrays.asList(cl);
    }
    int index = 0;
    // Use reversed view of list so that base classifiers will be first. This is needed to ensure subclauses have unique indices
    for (final Classifier tmpClassifier : Lists.reverse(classifiers)) {
        for (final AnnexSubclause tmpSubclause : tmpClassifier.getOwnedAnnexSubclauses()) {
            if (tmpSubclause == annexSubclause) {
                return index;
            } else if (annexName.equalsIgnoreCase(tmpSubclause.getName())) {
                index++;
            }
        }
    }
    return -1;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentType(org.osate.aadl2.ComponentType) Classifier(org.osate.aadl2.Classifier) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) AnnexSubclause(org.osate.aadl2.AnnexSubclause)

Example 23 with Classifier

use of org.geotoolkit.sml.xml.v101.Classifier in project osate2 by osate.

the class ClassifierCreationHelper method buildName.

public String buildName(final ClassifierOperationPartType primaryType, final Supplier<AadlPackage> primaryPkgSupplier, final String identifier, final ClassifierOperationPart basePart) {
    final String newName;
    if (primaryType == ClassifierOperationPartType.NEW_COMPONENT_IMPLEMENTATION) {
        if (basePart == null) {
            throw new RuntimeException("Base operation in invalid");
        }
        final AadlPackage primaryPkg = primaryPkgSupplier.get();
        final PackageSection section = primaryPkg.getPublicSection();
        // Determine details about the type specified by the base operation part.
        final String baseTypeName;
        final AadlPackage typePackage;
        // Get the name of the type and the package in which it is contained.
        if (ClassifierOperationPartType.isCreate(basePart.getType())) {
            typePackage = getResolvedPackage(basePart.getSelectedPackage());
            baseTypeName = basePart.getIdentifier();
        } else if (basePart.getType() == ClassifierOperationPartType.EXISTING) {
            final Classifier classifier = getResolvedClassifier(basePart.getSelectedClassifier());
            final ComponentType ct = getResolvedComponentType(classifier);
            if (ct == null) {
                return null;
            }
            typePackage = getPackage(ct);
            baseTypeName = ct.getName();
        } else {
            throw new RuntimeException("Invalid base operation part: " + basePart.getType());
        }
        // Handle type not being in same package as implementation
        final boolean samePackage = AadlNameUtil.namesAreEqual(primaryPkg, typePackage);
        final String localBaseTypeName = samePackage ? baseTypeName : getRenamedType(section, typePackage, baseTypeName).aliasName;
        newName = localBaseTypeName + "." + identifier;
    } else {
        newName = identifier;
    }
    return newName;
}
Also used : ComponentType(org.osate.aadl2.ComponentType) AadlPackage(org.osate.aadl2.AadlPackage) PackageSection(org.osate.aadl2.PackageSection) PublicPackageSection(org.osate.aadl2.PublicPackageSection) Classifier(org.osate.aadl2.Classifier)

Example 24 with Classifier

use of org.geotoolkit.sml.xml.v101.Classifier in project osate2 by osate.

the class AadlPropertyResolver method processContainedPropertyAssociationsInChildren.

private void processContainedPropertyAssociationsInChildren(final BusinessObjectContext q) {
    // Process contained property associations contained in children
    for (final BusinessObjectContext childQueryable : q.getChildren()) {
        final Object childBo = childQueryable.getBusinessObject();
        if (childBo instanceof InstanceObject) {
            processPropertyAssociationsForInstanceObjectsNotInTree(childQueryable, (InstanceObject) childBo);
        } else {
            if (childBo instanceof Subcomponent || childBo instanceof FeatureGroup) {
                final NamedElement childNamedElement = (NamedElement) childBo;
                // Handle refinements
                RefinableElement tmpRefinable = (RefinableElement) childNamedElement;
                do {
                    processDeclarativeContainedPropertyAssociations(childQueryable, tmpRefinable.getOwnedPropertyAssociations());
                    tmpRefinable = tmpRefinable.getRefinedElement();
                } while (tmpRefinable != null);
                // Process contained property associations contained in the element's classifier
                if (childBo instanceof FeatureGroup) {
                    final FeatureGroupType featureGroupType = AadlPrototypeUtil.getFeatureGroupType(AadlPrototypeUtil.getPrototypeBindingContext(childQueryable), (FeatureGroup) childBo);
                    if (featureGroupType != null) {
                        processDeclarativeContainedPropertyAssociations(childQueryable, featureGroupType);
                    }
                } else if (childBo instanceof Subcomponent) {
                    final Classifier subcomponentClassifier = AadlPrototypeUtil.getComponentClassifier(AadlPrototypeUtil.getPrototypeBindingContext(childQueryable), (Subcomponent) childBo);
                    if (subcomponentClassifier != null) {
                        processDeclarativeContainedPropertyAssociations(childQueryable, subcomponentClassifier);
                    }
                }
            } else if (childBo instanceof Classifier) {
                processDeclarativeContainedPropertyAssociations(childQueryable, ((Classifier) childBo));
            } else if (childBo instanceof AadlPackage) {
                processContainedPropertyAssociationsInChildren(childQueryable);
            }
        }
    }
}
Also used : InstanceObject(org.osate.aadl2.instance.InstanceObject) FeatureGroup(org.osate.aadl2.FeatureGroup) AadlPackage(org.osate.aadl2.AadlPackage) Subcomponent(org.osate.aadl2.Subcomponent) FeatureGroupType(org.osate.aadl2.FeatureGroupType) InstanceObject(org.osate.aadl2.instance.InstanceObject) RefinableElement(org.osate.aadl2.RefinableElement) Classifier(org.osate.aadl2.Classifier) BusinessObjectContext(org.osate.ge.BusinessObjectContext) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement)

Example 25 with Classifier

use of org.geotoolkit.sml.xml.v101.Classifier in project osate2 by osate.

the class AadlClassifierUtil method getComponentImplementation.

/**
 * Returns a component implementation for a specified business object. Only component implementations and subcomponents are supported.
 * @param bo
 * @return
 */
public static Optional<ComponentImplementation> getComponentImplementation(final Object bo) {
    final ComponentImplementation ci;
    if (bo instanceof BusinessObjectContext) {
        return getComponentImplementation(((BusinessObjectContext) bo).getBusinessObject());
    } else if (bo instanceof ComponentImplementation) {
        ci = (ComponentImplementation) bo;
    } else if (bo instanceof Subcomponent) {
        final Classifier scClassifier = ((Subcomponent) bo).getAllClassifier();
        ci = scClassifier instanceof ComponentImplementation ? (ComponentImplementation) scClassifier : null;
    } else {
        ci = null;
    }
    return Optional.ofNullable(ci);
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) Subcomponent(org.osate.aadl2.Subcomponent) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Aggregations

Classifier (org.osate.aadl2.Classifier)203 ComponentClassifier (org.osate.aadl2.ComponentClassifier)90 ComponentImplementation (org.osate.aadl2.ComponentImplementation)49 NamedElement (org.osate.aadl2.NamedElement)40 AadlPackage (org.osate.aadl2.AadlPackage)38 Subcomponent (org.osate.aadl2.Subcomponent)37 ComponentType (org.osate.aadl2.ComponentType)34 EObject (org.eclipse.emf.ecore.EObject)31 ArrayList (java.util.ArrayList)29 BasicEList (org.eclipse.emf.common.util.BasicEList)28 Feature (org.osate.aadl2.Feature)26 DataClassifier (org.osate.aadl2.DataClassifier)22 FeatureGroupType (org.osate.aadl2.FeatureGroupType)21 ProcessorClassifier (org.osate.aadl2.ProcessorClassifier)21 AnnexSubclause (org.osate.aadl2.AnnexSubclause)17 Element (org.osate.aadl2.Element)17 EList (org.eclipse.emf.common.util.EList)15 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)15 FeatureGroup (org.osate.aadl2.FeatureGroup)14 PropertyExpression (org.osate.aadl2.PropertyExpression)14