Search in sources :

Example 26 with PackageSection

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

the class AadlUtil method isImportedPropertySet.

/**
 * check whether property set is in the with clause of the containing top level name space (PackageSection or Property set) of the context.
 * @param ps Property set
 * @param context location at which property set reference is encountered
 * @return aadl property set or null if not in import list
 */
public static boolean isImportedPropertySet(PropertySet ps, EObject context) {
    EList<ModelUnit> importedPropertySets;
    if (ps == null) {
        return false;
    }
    if (isPredeclaredPropertySet(ps.getName())) {
        return true;
    }
    context = AadlUtil.getContainingTopLevelNamespace(context);
    if (context instanceof PropertySet) {
        importedPropertySets = ((PropertySet) context).getImportedUnits();
    } else {
        importedPropertySets = ((PackageSection) context).getImportedUnits();
    }
    for (ModelUnit importedPropertySet : importedPropertySets) {
        if (importedPropertySet instanceof PropertySet && !importedPropertySet.eIsProxy() && (importedPropertySet == ps || (ps.getQualifiedName().equalsIgnoreCase(importedPropertySet.getQualifiedName())))) {
            return true;
        }
    }
    return false;
}
Also used : ModelUnit(org.osate.aadl2.ModelUnit) PropertySet(org.osate.aadl2.PropertySet)

Example 27 with PackageSection

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

the class AadlSubcomponentUtil method setClassifier.

public static void setClassifier(final Subcomponent sc, final SubcomponentType selectedSubcomponentType) {
    // Import as necessary
    if (selectedSubcomponentType != null) {
        // Import its package if necessary
        final AadlPackage pkg = (AadlPackage) sc.getElementRoot();
        if (selectedSubcomponentType instanceof ComponentClassifier && selectedSubcomponentType.getNamespace() != null && pkg != null) {
            final PackageSection section = pkg.getPublicSection();
            final AadlPackage selectedClassifierPkg = (AadlPackage) selectedSubcomponentType.getNamespace().getOwner();
            if (selectedClassifierPkg != null && pkg != selectedClassifierPkg) {
                AadlImportsUtil.addImportIfNeeded(section, selectedClassifierPkg);
            }
        }
    }
    if (sc instanceof SystemSubcomponent) {
        ((SystemSubcomponent) sc).setSystemSubcomponentType((SystemSubcomponentType) selectedSubcomponentType);
    } else if (sc instanceof AbstractSubcomponent) {
        ((AbstractSubcomponent) sc).setAbstractSubcomponentType((AbstractSubcomponentType) selectedSubcomponentType);
    } else if (sc instanceof ThreadGroupSubcomponent) {
        ((ThreadGroupSubcomponent) sc).setThreadGroupSubcomponentType((ThreadGroupSubcomponentType) selectedSubcomponentType);
    } else if (sc instanceof ThreadSubcomponent) {
        ((ThreadSubcomponent) sc).setThreadSubcomponentType((ThreadSubcomponentType) selectedSubcomponentType);
    } else if (sc instanceof SubprogramSubcomponent) {
        ((SubprogramSubcomponent) sc).setSubprogramSubcomponentType((SubprogramSubcomponentType) selectedSubcomponentType);
    } else if (sc instanceof SubprogramGroupSubcomponent) {
        ((SubprogramGroupSubcomponent) sc).setSubprogramGroupSubcomponentType((SubprogramGroupSubcomponentType) selectedSubcomponentType);
    } else if (sc instanceof DataSubcomponent) {
        ((DataSubcomponent) sc).setDataSubcomponentType((DataSubcomponentType) selectedSubcomponentType);
    } else if (sc instanceof VirtualBusSubcomponent) {
        ((VirtualBusSubcomponent) sc).setVirtualBusSubcomponentType((VirtualBusSubcomponentType) selectedSubcomponentType);
    } else if (sc instanceof VirtualProcessorSubcomponent) {
        ((VirtualProcessorSubcomponent) sc).setVirtualProcessorSubcomponentType((VirtualProcessorSubcomponentType) selectedSubcomponentType);
    } else if (sc instanceof BusSubcomponent) {
        ((BusSubcomponent) sc).setBusSubcomponentType((BusSubcomponentType) selectedSubcomponentType);
    } else if (sc instanceof ProcessSubcomponent) {
        ((ProcessSubcomponent) sc).setProcessSubcomponentType((ProcessSubcomponentType) selectedSubcomponentType);
    } else if (sc instanceof ProcessorSubcomponent) {
        ((ProcessorSubcomponent) sc).setProcessorSubcomponentType((ProcessorSubcomponentType) selectedSubcomponentType);
    } else if (sc instanceof DeviceSubcomponent) {
        ((DeviceSubcomponent) sc).setDeviceSubcomponentType((DeviceSubcomponentType) selectedSubcomponentType);
    } else if (sc instanceof MemorySubcomponent) {
        ((MemorySubcomponent) sc).setMemorySubcomponentType((MemorySubcomponentType) selectedSubcomponentType);
    } else {
        throw new RuntimeException("Unexpected type: " + sc.getClass().getName());
    }
}
Also used : ComponentClassifier(org.osate.aadl2.ComponentClassifier) ThreadSubcomponentType(org.osate.aadl2.ThreadSubcomponentType) PackageSection(org.osate.aadl2.PackageSection) AbstractSubcomponent(org.osate.aadl2.AbstractSubcomponent) ProcessorSubcomponentType(org.osate.aadl2.ProcessorSubcomponentType) VirtualProcessorSubcomponentType(org.osate.aadl2.VirtualProcessorSubcomponentType) SubprogramGroupSubcomponent(org.osate.aadl2.SubprogramGroupSubcomponent) AbstractSubcomponentType(org.osate.aadl2.AbstractSubcomponentType) VirtualBusSubcomponentType(org.osate.aadl2.VirtualBusSubcomponentType) BusSubcomponentType(org.osate.aadl2.BusSubcomponentType) DeviceSubcomponent(org.osate.aadl2.DeviceSubcomponent) MemorySubcomponentType(org.osate.aadl2.MemorySubcomponentType) ThreadGroupSubcomponent(org.osate.aadl2.ThreadGroupSubcomponent) SubprogramGroupSubcomponentType(org.osate.aadl2.SubprogramGroupSubcomponentType) ProcessorSubcomponent(org.osate.aadl2.ProcessorSubcomponent) VirtualProcessorSubcomponent(org.osate.aadl2.VirtualProcessorSubcomponent) MemorySubcomponent(org.osate.aadl2.MemorySubcomponent) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) VirtualBusSubcomponentType(org.osate.aadl2.VirtualBusSubcomponentType) AadlPackage(org.osate.aadl2.AadlPackage) VirtualBusSubcomponent(org.osate.aadl2.VirtualBusSubcomponent) VirtualProcessorSubcomponent(org.osate.aadl2.VirtualProcessorSubcomponent) BusSubcomponent(org.osate.aadl2.BusSubcomponent) VirtualBusSubcomponent(org.osate.aadl2.VirtualBusSubcomponent) ThreadSubcomponent(org.osate.aadl2.ThreadSubcomponent) SystemSubcomponent(org.osate.aadl2.SystemSubcomponent) ProcessSubcomponent(org.osate.aadl2.ProcessSubcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent)

Example 28 with PackageSection

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

the class DefaultCreateSelectClassifierDialogModel method validate.

private String validate(final ClassifierOperationPart op, final ClassifierOperationPart baseOperation) {
    if (ClassifierOperationPartType.isCreate(op.getType())) {
        // Check identifier validity
        if (!AadlNamingUtil.isValidIdentifier(op.getIdentifier())) {
            return "The specified identifier is not a valid AADL identifier";
        }
        // Check component category
        if (ClassifierOperationPartType.isComponentClassifierCreate(op.getType())) {
            if (op.getComponentCategory() == null) {
                return "Select a component category.";
            }
            if (baseOperation != null && baseOperation.getType() == ClassifierOperationPartType.EXISTING) {
                // Check for a compatible component category when selecting an existing base classifier
                final Classifier baseClassifier = classifierCreationHelper.getResolvedClassifier(baseOperation.getSelectedClassifier());
                if (baseClassifier instanceof ComponentClassifier) {
                    final ComponentClassifier baseCategory = (ComponentClassifier) baseClassifier;
                    if (baseCategory.getCategory() != op.getComponentCategory() && (op.getType() != ClassifierOperationPartType.NEW_COMPONENT_TYPE || baseCategory.getCategory() != ComponentCategory.ABSTRACT)) {
                        return "Base: category(" + baseCategory.getCategory() + ") of the selected classifier is not compatible with category type of the " + StringUtil.snakeCaseToLowercaseWords(op.getType().name()) + "(" + op.getComponentCategory() + ").";
                    }
                }
            }
        }
        // Check package.
        final AadlPackage pkg = classifierCreationHelper.getResolvedPackage(op.getSelectedPackage());
        if (pkg == null) {
            return "Select a package.";
        }
        final PackageSection section = pkg.getPublicSection();
        if (section == null) {
            return "Unable to retrieve public section of package.";
        }
        // New Component Implementation validation
        if (op.getType() == ClassifierOperationPartType.NEW_COMPONENT_IMPLEMENTATION) {
            if (baseOperation == null) {
                return "Base classifier is invalid";
            } else if (!ClassifierOperationPartType.isCreate(baseOperation.getType()) && baseOperation.getType() != ClassifierOperationPartType.EXISTING) {
                if (baseOperation.getType() == ClassifierOperationPartType.NONE) {
                    return "Select a base for the new component implementation.";
                } else {
                    return "Invalid base classifier: " + baseOperation.getType();
                }
            }
        }
        final String newName = classifierCreationHelper.getName(op, baseOperation);
        if (newName == null) {
            return "Unable to build name. Check for model errors.";
        }
        // Check if the name is in use
        if (AadlNamingUtil.isNameInUse(section, newName)) {
            return "The specified name conflicts with an existing member of the package.";
        }
    } else if (op.getType() == ClassifierOperationPartType.EXISTING) {
        // Check that the classifier can be resolved.
        if (classifierCreationHelper.getResolvedClassifier(op.getSelectedClassifier()) == null) {
            return "Select a classifier.";
        }
    } else if (op.getType() == null) {
        return "Select a classifier type.";
    }
    return null;
}
Also used : ComponentClassifier(org.osate.aadl2.ComponentClassifier) AadlPackage(org.osate.aadl2.AadlPackage) PackageSection(org.osate.aadl2.PackageSection) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier)

Example 29 with PackageSection

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

the class ClassifierOperationExecutor method addStep.

/**
 * @param operation
 * @param part
 * @param basePart
 * @param pkgBoc if non-null then the operation result will indicate that the object should be added to the diagram.
 * @return
 */
private OperationBuilder<Classifier> addStep(final OperationBuilder<?> operation, final ClassifierOperationPart part, final ClassifierOperationPart basePart, final BusinessObjectContext pkgBoc) {
    Objects.requireNonNull(part, "part must not be null");
    Objects.requireNonNull(part.getType(), "operation part type must not be null");
    switch(part.getType()) {
        case EXISTING:
            return operation.supply(() -> StepResultBuilder.create(classifierCreationHelper.getResolvedClassifier(part.getSelectedClassifier())).build());
        case NEW_COMPONENT_IMPLEMENTATION:
        case NEW_COMPONENT_TYPE:
        case NEW_FEATURE_GROUP_TYPE:
            final EClass creationEClass = getCreationEClass(part);
            final PackageSection unmodifiableSection = classifierCreationHelper.getResolvedPublicSection(part.getSelectedPackage());
            return operation.modifyModel(unmodifiableSection, (tag, prevResult) -> tag, (tag, section, prevResult) -> {
                // Create the new classifier
                final Classifier newClassifier = section.createOwnedClassifier(creationEClass);
                // Set name
                newClassifier.setName(classifierCreationHelper.getName(part, basePart));
                final Classifier baseOperationResult = resolveWithLiveResourceSetOrThrowIfProxy((Classifier) prevResult);
                // Handle component implementations
                if (newClassifier instanceof ComponentImplementation) {
                    final ComponentImplementation newImpl = (ComponentImplementation) newClassifier;
                    final ComponentType baseComponentType;
                    if (baseOperationResult instanceof ComponentType) {
                        final Realization realization = newImpl.createOwnedRealization();
                        baseComponentType = (ComponentType) baseOperationResult;
                        realization.setImplemented(baseComponentType);
                    } else if (baseOperationResult instanceof ComponentImplementation) {
                        final ComponentImplementation baseImpl = (ComponentImplementation) baseOperationResult;
                        final ImplementationExtension extension = newImpl.createOwnedExtension();
                        extension.setExtended(baseImpl);
                        final Realization realization = newImpl.createOwnedRealization();
                        realization.setImplemented(baseImpl.getType());
                        baseComponentType = baseImpl.getType();
                        // Import the base implementation's package
                        final AadlPackage baseImplPkg = (AadlPackage) baseImpl.getNamespace().getOwner();
                        AadlImportsUtil.addImportIfNeeded(section, baseImplPkg);
                    } else {
                        throw new RuntimeException("Invalid base classifier: " + baseOperationResult);
                    }
                    // Get the base component type
                    if (baseComponentType == null) {
                        throw new RuntimeException("Unable to determine base component type");
                    }
                    if (!AadlNameUtil.namesAreEqual(section, baseComponentType.getNamespace())) {
                        // Import the package if necessary
                        final AadlPackage baseComponentTypePkg = (AadlPackage) baseComponentType.getNamespace().getOwner();
                        AadlImportsUtil.addImportIfNeeded(section, baseComponentTypePkg);
                        // Create an alias for the component type
                        final ClassifierCreationHelper.RenamedTypeDetails aliasDetails = classifierCreationHelper.getRenamedType(section, baseComponentTypePkg, baseComponentType.getName());
                        if (!aliasDetails.exists) {
                            final ComponentTypeRename ctr = section.createOwnedComponentTypeRename();
                            ctr.setName(aliasDetails.aliasName);
                            ctr.setCategory(baseComponentType.getCategory());
                            ctr.setRenamedComponentType(baseComponentType);
                        }
                    }
                } else if (newClassifier instanceof ComponentType && baseOperationResult instanceof ComponentType) {
                    final ComponentType newType = (ComponentType) newClassifier;
                    final TypeExtension extension = newType.createOwnedExtension();
                    extension.setExtended((ComponentType) baseOperationResult);
                } else if (newClassifier instanceof FeatureGroupType && baseOperationResult instanceof FeatureGroupType) {
                    final FeatureGroupType newFgt = (FeatureGroupType) newClassifier;
                    final GroupExtension extension = newFgt.createOwnedExtension();
                    extension.setExtended((FeatureGroupType) baseOperationResult);
                }
                final StepResultBuilder<Classifier> resultBuilder = StepResultBuilder.create(newClassifier);
                // Hint for adding to diagram
                if (pkgBoc != null && newClassifier != null) {
                    resultBuilder.showNewBusinessObject(pkgBoc, newClassifier);
                }
                return resultBuilder.build();
            });
        case NONE:
            return operation.map(prevResult -> StepResultBuilder.create((Classifier) null).build());
        default:
            throw new RuntimeException("Unexpected operation: " + part.getType());
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentType(org.osate.aadl2.ComponentType) AadlPackage(org.osate.aadl2.AadlPackage) PackageSection(org.osate.aadl2.PackageSection) FeatureGroupType(org.osate.aadl2.FeatureGroupType) TypeExtension(org.osate.aadl2.TypeExtension) ImplementationExtension(org.osate.aadl2.ImplementationExtension) Classifier(org.osate.aadl2.Classifier) EClass(org.eclipse.emf.ecore.EClass) Realization(org.osate.aadl2.Realization) GroupExtension(org.osate.aadl2.GroupExtension) ComponentTypeRename(org.osate.aadl2.ComponentTypeRename)

Example 30 with PackageSection

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

the class AadlElementContentProvider method hasChildren.

@Override
public boolean hasChildren(Object element) {
    if (element instanceof IFile || element instanceof ContributedAadlStorage) {
        return true;
    } else {
        EObjectURIWrapper wrapper = (EObjectURIWrapper) element;
        EObject eObject = new ResourceSetImpl().getEObject(wrapper.getUri(), true);
        if (eObject instanceof AadlPackage || eObject instanceof PropertySet || eObject instanceof ComponentInstance) {
            return eObject.eContents().stream().anyMatch(member -> !(member instanceof SystemOperationMode || member instanceof PropertyAssociation));
        } else if (eObject instanceof PackageSection) {
            return eObject.eContents().stream().anyMatch(member -> member instanceof Classifier || member instanceof AnnexLibrary);
        } else if (eObject instanceof Classifier) {
            return eObject.eContents().stream().anyMatch(member -> member instanceof ClassifierFeature || member instanceof PropertyAssociation);
        } else {
            return false;
        }
    }
}
Also used : ComponentInstance(org.osate.aadl2.instance.ComponentInstance) URI(org.eclipse.emf.common.util.URI) PackageSection(org.osate.aadl2.PackageSection) EObject(org.eclipse.emf.ecore.EObject) AadlPackage(org.osate.aadl2.AadlPackage) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) PropertySet(org.osate.aadl2.PropertySet) UiUtil(org.osate.ui.UiUtil) PropertyAssociation(org.osate.aadl2.PropertyAssociation) Stream(java.util.stream.Stream) Classifier(org.osate.aadl2.Classifier) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) Resource(org.eclipse.emf.ecore.resource.Resource) IFile(org.eclipse.core.resources.IFile) ClassifierFeature(org.osate.aadl2.ClassifierFeature) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) AnnexLibrary(org.osate.aadl2.AnnexLibrary) EObjectURIWrapper(org.osate.aadl2.modelsupport.EObjectURIWrapper) ContributedAadlStorage(org.osate.xtext.aadl2.ui.resource.ContributedAadlStorage) IFile(org.eclipse.core.resources.IFile) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) AadlPackage(org.osate.aadl2.AadlPackage) PropertyAssociation(org.osate.aadl2.PropertyAssociation) PackageSection(org.osate.aadl2.PackageSection) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) Classifier(org.osate.aadl2.Classifier) ClassifierFeature(org.osate.aadl2.ClassifierFeature) ContributedAadlStorage(org.osate.xtext.aadl2.ui.resource.ContributedAadlStorage) EObjectURIWrapper(org.osate.aadl2.modelsupport.EObjectURIWrapper) EObject(org.eclipse.emf.ecore.EObject) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) PropertySet(org.osate.aadl2.PropertySet) AnnexLibrary(org.osate.aadl2.AnnexLibrary)

Aggregations

PackageSection (org.osate.aadl2.PackageSection)24 AadlPackage (org.osate.aadl2.AadlPackage)19 Classifier (org.osate.aadl2.Classifier)14 NamedElement (org.osate.aadl2.NamedElement)9 PropertySet (org.osate.aadl2.PropertySet)9 EObject (org.eclipse.emf.ecore.EObject)8 ModelUnit (org.osate.aadl2.ModelUnit)7 ComponentClassifier (org.osate.aadl2.ComponentClassifier)6 ComponentImplementation (org.osate.aadl2.ComponentImplementation)5 ClassifierFeature (org.osate.aadl2.ClassifierFeature)4 ComponentType (org.osate.aadl2.ComponentType)4 PrivatePackageSection (org.osate.aadl2.PrivatePackageSection)4 Property (org.osate.aadl2.Property)4 ArrayList (java.util.ArrayList)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 AnnexLibrary (org.osate.aadl2.AnnexLibrary)3 PropertyType (org.osate.aadl2.PropertyType)3 PublicPackageSection (org.osate.aadl2.PublicPackageSection)3 QualifiedNamedElement (org.osate.ba.declarative.QualifiedNamedElement)3 List (java.util.List)2