Search in sources :

Example 21 with AadlPackage

use of org.osate.aadl2.AadlPackage 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 AadlPackage

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

the class AnnexHandler method getAnnexLibraryIndex.

/**
 * Returns a 0 based index for referencing an annex library in a list that contains only annex libraries with the same type and owner
 * @param annexLibrary
 * @return
 */
private static int getAnnexLibraryIndex(AnnexLibrary annexLibrary) {
    // Get the default annex library if a parsed annex library was specified. This is needed for the comparison later in the function.
    if (!(annexLibrary instanceof DefaultAnnexLibrary)) {
        if (annexLibrary.eContainer() instanceof DefaultAnnexLibrary) {
            annexLibrary = (AnnexLibrary) annexLibrary.eContainer();
        } else {
            return -1;
        }
    }
    final String annexName = annexLibrary.getName();
    if (annexName == null) {
        return -1;
    }
    // Get the Aadl Package
    Element tmp = annexLibrary.getOwner();
    while (tmp != null && !(tmp instanceof AadlPackage)) {
        tmp = tmp.getOwner();
    }
    int index = 0;
    if (tmp instanceof AadlPackage) {
        for (final AnnexLibrary tmpLibrary : AnnexUtil.getAllDefaultAnnexLibraries((AadlPackage) tmp)) {
            if (tmpLibrary == annexLibrary) {
                return index;
            } else if (annexName.equalsIgnoreCase(tmpLibrary.getName())) {
                index++;
            }
        }
    }
    return -1;
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) Element(org.osate.aadl2.Element) NamedElement(org.osate.aadl2.NamedElement) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary) AnnexLibrary(org.osate.aadl2.AnnexLibrary) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary)

Example 23 with AadlPackage

use of org.osate.aadl2.AadlPackage 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 AadlPackage

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

the class ClassifierCreationHelper method getRenamedType.

// Gets the name to use to reference a type from a specified section in another package.
public RenamedTypeDetails getRenamedType(final PackageSection section, final AadlPackage typePackage, final String baseTypeName) {
    final String qualifiedTypeName = typePackage.getQualifiedName() + "::" + baseTypeName;
    // Look for an existing component type renames
    for (final ComponentTypeRename ctr : section.getOwnedComponentTypeRenames()) {
        if (AadlNameUtil.namesAreEqual(ctr.getRenamedComponentType().getQualifiedName(), qualifiedTypeName) && ctr.getName() != null) {
            return new RenamedTypeDetails(ctr.getName(), true);
        }
    }
    final String baseAlias = qualifiedTypeName.replace("::", "_");
    return new RenamedTypeDetails(AadlNamingUtil.buildUniqueIdentifier(section, baseAlias), false);
}
Also used : ComponentTypeRename(org.osate.aadl2.ComponentTypeRename)

Example 25 with AadlPackage

use of org.osate.aadl2.AadlPackage 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)

Aggregations

AadlPackage (org.osate.aadl2.AadlPackage)106 EObject (org.eclipse.emf.ecore.EObject)45 Classifier (org.osate.aadl2.Classifier)39 NamedElement (org.osate.aadl2.NamedElement)26 ArrayList (java.util.ArrayList)22 ComponentImplementation (org.osate.aadl2.ComponentImplementation)20 PackageSection (org.osate.aadl2.PackageSection)18 Element (org.osate.aadl2.Element)17 ComponentClassifier (org.osate.aadl2.ComponentClassifier)16 PropertySet (org.osate.aadl2.PropertySet)15 AnnexLibrary (org.osate.aadl2.AnnexLibrary)14 EList (org.eclipse.emf.common.util.EList)13 Optional (java.util.Optional)11 Test (org.junit.Test)11 SystemInstance (org.osate.aadl2.instance.SystemInstance)11 List (java.util.List)10 URI (org.eclipse.emf.common.util.URI)10 Subcomponent (org.osate.aadl2.Subcomponent)10 Inject (com.google.inject.Inject)9 IFile (org.eclipse.core.resources.IFile)9