use of org.osate.aadl2.Subcomponent in project AGREE by loonwerks.
the class AgreeValidator method getFieldTypes.
private Map<String, TypeDef> getFieldTypes(DoubleDotRef recType) {
NamedElement rec = recType.getElm();
Map<String, TypeDef> typeMap = new HashMap<>();
if (rec instanceof RecordDef) {
RecordDef recDef = (RecordDef) rec;
for (Arg arg : recDef.getArgs()) {
typeMap.put(arg.getName(), AgreeTypeSystem.typeDefFromType(arg.getType()));
}
} else if (rec instanceof DataImplementation) {
DataImplementation dataImpl = (DataImplementation) rec;
for (Subcomponent sub : dataImpl.getAllSubcomponents()) {
typeMap.put(sub.getName(), AgreeTypeSystem.typeDefFromClassifier((sub.getClassifier())));
}
} else {
error(recType, "Record type '" + rec.getName() + "' must be a feature group or a record type definition");
}
return typeMap;
}
use of org.osate.aadl2.Subcomponent in project AGREE by loonwerks.
the class AgreeValidator method checkRecordDefExpr.
// =======
// // private List<AgreeType> getArgTypes(NestedDotID recId){
// //
// // NamedElement rec = getFinalNestId(recId);
// // List<AgreeType> types = new ArrayList<AgreeType>();
// //
// // if(rec instanceof RecordDefExpr){
// // RecordDefExpr recDef = (RecordDefExpr)rec;
// // for(Arg arg : recDef.getArgs()){
// // types.add(getAgreeType(arg.getType()));
// // }
// // }else if(rec instanceof FeatureGroupType){
// // FeatureGroupType featGroup = (FeatureGroupType)rec;
// // for(Feature feat : featGroup.getAllFeatures()){
// // types.add(getAgreeType(feat));
// // }
// // }
// //
// // return types;
// // }
//
// private void dataImplCycleCheck(NestedDotID dataID) {
// NamedElement finalId = dataID.getBase();
// DataImplementation dataImpl = (DataImplementation) finalId;
// dataImplCycleCheck(dataImpl, dataID);
// }
//
// private void dataImplCycleCheck(DoubleDotRef dataID) {
// NamedElement finalId = dataID.getElm();
// DataImplementation dataImpl = (DataImplementation) finalId;
// dataImplCycleCheck(dataImpl, dataID);
// }
//
//
// private void dataImplCycleCheck(DataImplementation dataImpl, EObject errorSource) {
// Set<DataImplementation> dataClosure = new HashSet<>();
// Set<DataImplementation> prevClosure = null;
//
// for (Subcomponent sub : dataImpl.getAllSubcomponents()) {
// ComponentImplementation subImpl = sub.getComponentImplementation();
// if (subImpl != null) {
// dataClosure.add((DataImplementation) subImpl);
// }
// }
//
// do {
// prevClosure = new HashSet<>(dataClosure);
// for (DataImplementation subImpl : prevClosure) {
// if (subImpl == dataImpl) {
// error(errorSource, "The component implementation '" + dataImpl.getName()
// + "' has a cyclic definition. This cannot be reasoned about by AGREE.");
// break;
// }
// for (Subcomponent subSub : subImpl.getAllSubcomponents()) {
// ComponentImplementation subSubImpl = subSub.getComponentImplementation();
// if (subSubImpl != null) {
// dataClosure.add((DataImplementation) subSubImpl);
// }
// }
//
// }
//
// } while (!prevClosure.equals(dataClosure));
//
// }
// >>>>>>> origin/develop
@Check(CheckType.FAST)
public void checkRecordDefExpr(RecordDef recordDef) {
Set<RecordDef> recordClosure = new HashSet<>();
Set<RecordDef> prevClosure = null;
for (Arg arg : recordDef.getArgs()) {
Type type = arg.getType();
if (type instanceof DoubleDotRef) {
NamedElement finalId = ((DoubleDotRef) type).getElm();
if (finalId instanceof RecordDef) {
recordClosure.add((RecordDef) finalId);
}
}
}
do {
prevClosure = new HashSet<>(recordClosure);
for (RecordDef subRecDef : prevClosure) {
if (subRecDef == recordDef) {
error(recordDef, "The definition of type '" + recordDef.getName() + "' is involved in a cyclic definition");
break;
}
for (Arg arg : subRecDef.getArgs()) {
Type type = arg.getType();
if (type instanceof DoubleDotRef) {
NamedElement subFinalEl = ((DoubleDotRef) type).getElm();
if (subFinalEl instanceof RecordDef) {
recordClosure.add((RecordDef) subFinalEl);
// =======
// if (type instanceof RecordType) {
// DoubleDotRef subRecId = ((RecordType) type).getRecord();
// NamedElement subFinalEl = subRecId.getElm();
// if (subFinalEl instanceof RecordDefExpr) {
// recordClosure.add((RecordDefExpr) subFinalEl);
// >>>>>>> origin/develop
}
}
}
}
} while (!prevClosure.equals(recordClosure));
}
use of org.osate.aadl2.Subcomponent in project osate2 by osate.
the class ConfigureInModesSection method addLocalMode.
private void addLocalMode(final Composite container, final Map.Entry<ModeFeature, ButtonState> entry, final Set<ModeFeature> derivedModesAvailable, final Map<ModeFeature, ModeFeature> localToDerivedModeMap, final Set<URI> urisOfElementsWhichRequireModes) {
final ModeFeature mf = entry.getKey();
final Button modeBtn = getWidgetFactory().createButton(container, mf.getName(), SWT.CHECK);
// Create derived mode drop down
final ComboViewer derivedModeFld;
final Label mappedLabel;
if (derivedModesAvailable == null) {
derivedModeFld = null;
mappedLabel = null;
} else {
mappedLabel = getWidgetFactory().createLabel(container, "->", SWT.CENTER);
mappedLabel.setText("->");
// Create mapped derived mode combo
derivedModeFld = new ComboViewer(container, SWT.DROP_DOWN | SWT.READ_ONLY);
derivedModeFld.setContentProvider(ArrayContentProvider.getInstance());
derivedModeFld.setLabelProvider(new LabelProvider() {
@Override
public String getText(final Object element) {
if (element instanceof ModeFeature) {
final ModeFeature modalFeature = (ModeFeature) element;
return modalFeature.getName();
}
return element.toString();
}
});
derivedModeFld.add(" ");
derivedModeFld.add(derivedModesAvailable.toArray());
final ModeFeature mappedDerivedMode = localToDerivedModeMap.get(mf);
// If child mode is contained in intersection of derived modes
if (derivedModesAvailable.contains(mappedDerivedMode)) {
derivedModeFld.setSelection(new StructuredSelection(mappedDerivedMode));
}
}
// Set button state
final ButtonState modeFeatureState = entry.getValue();
if (modeFeatureState == ButtonState.SELECTED) {
modeBtn.setSelection(true);
} else if (modeFeatureState == ButtonState.PARTIAL) {
modeBtn.setSelection(true);
modeBtn.setGrayed(true);
} else if (modeFeatureState == ButtonState.DISABLED_AND_PARTIAL || modeFeatureState == ButtonState.DISABLED) {
modeBtn.setEnabled(false);
boolean partialDisabled = modeFeatureState == ButtonState.DISABLED_AND_PARTIAL;
modeBtn.setGrayed(partialDisabled);
modeBtn.setSelection(partialDisabled);
if (derivedModeFld != null) {
derivedModeFld.getCombo().setEnabled(false);
mappedLabel.setEnabled(false);
}
}
final SelectionListener selectionListener = new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
// No changes if combo selection changes without enabled button
if (e.widget instanceof Combo && !modeBtn.getSelection()) {
return;
}
// Modify selected modal elements
final boolean modeBtnIsSelected = modeBtn.getSelection();
selectedBos.modify("Set In Modes", boc -> boc.getBusinessObject(NamedElement.class).isPresent(), boc -> {
final NamedElement ne = boc.getBusinessObject(NamedElement.class).get();
if (ne instanceof AnnexSubclause && ne.eContainer() instanceof DefaultAnnexSubclause) {
return (NamedElement) ne.eContainer();
}
return ne;
}, (ne, boc) -> {
final ModeFeature modeFeature = (ModeFeature) EcoreUtil.resolve(mf, ne.eResource());
if (ne instanceof Subcomponent && modeFeature instanceof Mode) {
final Subcomponent sc = (Subcomponent) ne;
// Remove mode binding always
for (final ModeBinding mb : sc.getOwnedModeBindings()) {
if (modeFeature.getName().equalsIgnoreCase(mb.getParentMode().getName())) {
sc.getOwnedModeBindings().remove(mb);
break;
}
}
// Add mode binding on button selection
if (modeBtnIsSelected) {
final ModeBinding newModeBinding = sc.createOwnedModeBinding();
newModeBinding.setParentMode((Mode) modeFeature);
final boolean isDerived = urisOfElementsWhichRequireModes.contains(EcoreUtil.getURI(ne));
// If modal element is derived, set derived mode
if (isDerived) {
final Object selection = ((StructuredSelection) derivedModeFld.getSelection()).getFirstElement();
final ModeFeature childMode = selection instanceof ModeFeature ? (ModeFeature) selection : null;
newModeBinding.setDerivedMode((Mode) childMode);
}
}
} else if (ne instanceof ModalPath) {
final ModalPath mp = (ModalPath) ne;
if (modeBtnIsSelected) {
mp.getInModeOrTransitions().add(modeFeature);
} else {
for (final ModeFeature mf : mp.getInModeOrTransitions()) {
if (modeFeature.getName().equalsIgnoreCase(mf.getName())) {
mp.getInModeOrTransitions().remove(mf);
break;
}
}
}
} else if (ne instanceof ModalElement && modeFeature instanceof Mode) {
final ModalElement modalElement = (ModalElement) ne;
if (modeBtnIsSelected) {
modalElement.getAllInModes().add((Mode) modeFeature);
} else {
for (final ModeFeature mf : modalElement.getInModes()) {
if (modeFeature.getName().equalsIgnoreCase(mf.getName())) {
modalElement.getAllInModes().remove(modeFeature);
break;
}
}
}
}
});
}
};
// Register selection listeners
modeBtn.addSelectionListener(selectionListener);
if (derivedModeFld != null) {
derivedModeFld.getCombo().addSelectionListener(selectionListener);
}
}
use of org.osate.aadl2.Subcomponent in project osate2 by osate.
the class ConfigureInModesSection method refresh.
@Override
public void refresh() {
if (composite != null) {
composite.dispose();
}
final Set<ModalElement> mes = selectedBos.boStream(ModalElement.class).collect(Collectors.toSet());
// Selected Modal Elements and if element is derived
final Set<URI> urisOfElementsWhichRequireModes = new HashSet<>();
// Local modes and button state map
Map<ModeFeature, ButtonState> localModes = null;
// Mode transitions and button state map. Only used when a ModalPath is selected
Map<ModeFeature, ButtonState> localModeTransitions = null;
// In modes map for each selected modal element, child can be null
final Map<ModeFeature, ModeFeature> localToDerivedModeMap = new TreeMap<ModeFeature, ModeFeature>(modeFeatureComparator);
// Required mode features
Set<ModeFeature> derivedModes = null;
boolean nonModePathSelected = false;
// Determine button states for mode features
for (final ModalElement modalElement : mes) {
if (modalElement.getContainingClassifier() instanceof ComponentClassifier) {
final ComponentClassifier cc = (ComponentClassifier) modalElement.getContainingClassifier();
// Use name for compatibility with flow implementations
final Set<String> inModes = getInModes(modalElement);
// Initial set
if (localModes == null) {
localModes = new TreeMap<ModeFeature, ButtonState>(modeFeatureComparator);
for (final ModeFeature mf : cc.getAllModes()) {
localModes.put(mf, inModes.contains(mf.getName()) ? ButtonState.SELECTED : ButtonState.NOT_SELECTED);
}
} else {
populateLocalModes(localModes, cc, inModes);
}
if (modalElement instanceof Subcomponent) {
final URI scUri = EcoreUtil.getURI(modalElement);
nonModePathSelected = true;
final Subcomponent sc = (Subcomponent) modalElement;
final ComponentClassifier scClassifier = sc.getAllClassifier();
if (scClassifier != null) {
final List<Mode> scClassifierAllModes = scClassifier.getAllModes();
for (final Mode mb : scClassifierAllModes) {
if (mb.isDerived()) {
// Mark the modal element as derived
urisOfElementsWhichRequireModes.add(scUri);
if (derivedModes == null) {
derivedModes = new HashSet<>();
derivedModes.addAll(scClassifierAllModes);
} else {
// Keep intersection of owned modes between selections
derivedModes.retainAll(scClassifierAllModes);
}
break;
}
}
}
for (final ModeBinding modeBinding : sc.getOwnedModeBindings()) {
final ModeFeature localMode = modeBinding.getParentMode();
final ModeFeature derivedMode = modeBinding.getDerivedMode();
if (urisOfElementsWhichRequireModes.contains(scUri)) {
if (localToDerivedModeMap.containsKey(localMode)) {
if (localToDerivedModeMap.get(localMode) != derivedMode) {
localToDerivedModeMap.put(localMode, null);
localModes.replace(localMode, ButtonState.PARTIAL);
}
} else {
// Add mode if not already added and override derived value if not null
localToDerivedModeMap.put(localMode, derivedMode);
}
}
}
} else if (modalElement instanceof ModalPath) {
final ModalPath modalPath = (ModalPath) modalElement;
// Use name for compatibility with flow implementations
final Set<String> inModeTransitions = getInModeTransitions(modalPath);
// Set Initial
if (localModeTransitions == null) {
localModeTransitions = new TreeMap<ModeFeature, ButtonState>(modeFeatureComparator);
for (final ModeFeature mf : cc.getAllModeTransitions()) {
localModeTransitions.put(mf, inModeTransitions.contains(mf.getName()) ? ButtonState.SELECTED : ButtonState.NOT_SELECTED);
}
} else {
populateModeTransitions(localModeTransitions, cc, inModeTransitions);
}
} else {
nonModePathSelected = true;
}
}
}
// Mode transitions are always partial if a modal path and any other type of modal element is selected
if (localModeTransitions != null && nonModePathSelected) {
for (final ModeFeature mf : localModeTransitions.keySet()) {
if (localModeTransitions.get(mf) == ButtonState.SELECTED) {
localModeTransitions.replace(mf, ButtonState.PARTIAL);
}
}
}
final int horizontalSpan = derivedModes == null ? 1 : 3;
composite = getWidgetFactory().createComposite(container);
FormData fd;
fd = new FormData();
fd.left = new FormAttachment(0, STANDARD_LABEL_WIDTH);
composite.setLayoutData(fd);
final GridLayout layout = new GridLayout(horizontalSpan, false);
composite.setLayout(layout);
// Determine if there is at least one mode feature is enabled. If no mode features are enabled then the selected elements do not have any
// applicable mode features in common.
final boolean hasEnabledModes = Stream.concat(localModes == null ? Stream.empty() : localModes.values().stream(), localModeTransitions == null ? Stream.empty() : localModeTransitions.values().stream()).anyMatch(ButtonState::isEnabled);
final boolean hasModeSelections = Stream.concat(localModes == null ? Stream.empty() : localModes.values().stream(), localModeTransitions == null ? Stream.empty() : localModeTransitions.values().stream()).anyMatch(ButtonState::isAtleastPartiallySelected);
final String inModesStatusTxt;
if (!hasEnabledModes) {
inModesStatusTxt = "<No Common Applicable Modes>";
} else if (anyRefinedElementHasInheritedModeFeatures(mes)) {
inModesStatusTxt = "<See Refined Element(s)>";
} else if (hasModeSelections) {
inModesStatusTxt = "Selected Modes";
} else {
inModesStatusTxt = "All";
}
final Label inModesStatus = getWidgetFactory().createLabel(composite, inModesStatusTxt);
GridDataFactory.fillDefaults().span(horizontalSpan, 1).applyTo(inModesStatus);
// Only show mode features if at least one mode feature is enabled.
if (hasEnabledModes) {
if (localModes != null && !localModes.isEmpty()) {
GridDataFactory.fillDefaults().grab(true, false).span(horizontalSpan, 1).applyTo(new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR));
for (final Map.Entry<ModeFeature, ButtonState> entry : localModes.entrySet()) {
addLocalMode(composite, entry, derivedModes, localToDerivedModeMap, urisOfElementsWhichRequireModes);
}
}
if (localModeTransitions != null && !localModeTransitions.isEmpty()) {
GridDataFactory.fillDefaults().grab(true, false).span(horizontalSpan, 1).applyTo(new Label(composite, SWT.HORIZONTAL | SWT.SEPARATOR));
for (final Map.Entry<ModeFeature, ButtonState> entry : localModeTransitions.entrySet()) {
addLocalMode(composite, entry, derivedModes, localToDerivedModeMap, urisOfElementsWhichRequireModes);
}
}
}
container.layout(true);
container.pack();
}
use of org.osate.aadl2.Subcomponent in project osate2 by osate.
the class CreateAadlConnectionPaletteCommand method canCreate.
private boolean canCreate(final BusinessObjectContext ownerBoc, final BusinessObjectContext srcBoc, final BusinessObjectContext dstBoc) {
// Get the connection elements for the source and destination
final ConnectedElement srcConnectedElement = getConnectedElementForBusinessObjectContext(srcBoc, connectionType, false, ownerBoc);
if (srcConnectedElement == null) {
return false;
}
final ConnectedElement dstConnectedElement = getConnectedElementForBusinessObjectContext(dstBoc, connectionType, !(srcConnectedElement.getContext() instanceof Subcomponent), ownerBoc);
// Ensure they are valid and are not the same
if (dstConnectedElement == null || EcoreUtil.equals(srcConnectedElement, dstConnectedElement)) {
return false;
}
// Don't allow connecting two features owned by the same classifier
if (!(srcConnectedElement.getContext() instanceof Subcomponent || srcConnectedElement.getContext() instanceof SubprogramCall) && srcConnectedElement.getConnectionEnd() instanceof Feature && !(dstConnectedElement.getContext() instanceof Subcomponent || dstConnectedElement.getContext() instanceof SubprogramCall) && dstConnectedElement.getConnectionEnd() instanceof Feature) {
return false;
}
final Class<?> connectionEndType = getConnectionEndType(connectionType);
if (connectionEndType == null || !connectionEndType.isInstance(dstConnectedElement.getConnectionEnd())) {
return false;
}
return ownerBoc == null ? false : getClassifierOpBuilder().canBuildOperation(ownerBoc.getBusinessObject());
}
Aggregations