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;
}
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());
}
}
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;
}
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());
}
}
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;
}
}
}
Aggregations