use of org.osate.aadl2.Operation in project osate2 by osate.
the class CreateSubprogramCallSequencePaletteCommand method getOperation.
@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
final BusinessObjectContext targetBoc = ctx.getTarget();
final Object targetBo = targetBoc.getBusinessObject();
if (!getClassifierOpBuilder().canBuildOperation(targetBo)) {
return Optional.empty();
}
// Used to pass arguments between steps
class CreateArgs {
final BehavioredImplementation bi;
final CallContext callContext;
final CalledSubprogram calledSubprogram;
public CreateArgs(final BehavioredImplementation bi, final CallContext callContext, final CalledSubprogram calledSubprogram) {
this.bi = bi;
this.callContext = callContext;
this.calledSubprogram = calledSubprogram;
}
}
return Optional.of(Operation.createWithBuilder(createOp -> {
getClassifierOpBuilder().buildOperation(createOp, targetBo).map(ci -> {
final BehavioredImplementation bi = (BehavioredImplementation) ci;
final DefaultSelectSubprogramDialogModel subprogramSelectionModel = new DefaultSelectSubprogramDialogModel(bi);
final SelectSubprogramDialog dlg = new SelectSubprogramDialog(Display.getCurrent().getActiveShell(), subprogramSelectionModel);
if (dlg.open() == Window.CANCEL) {
return StepResult.abort();
}
// Get the CallContext and Called Subprogram
final CallContext callContext = subprogramSelectionModel.getCallContext(dlg.getSelectedContext());
final CalledSubprogram calledSubprogram = subprogramSelectionModel.getCalledSubprogram(dlg.getSelectedSubprogram());
return StepResult.forValue(new CreateArgs(bi, callContext, calledSubprogram));
}).modifyModel(null, (tag, createArgs) -> createArgs.bi, (tag, bi, createArgs) -> {
final String newScsName = AadlNamingUtil.buildUniqueIdentifier(bi, "new_call_sequence");
final String initialSubprogramCallName = AadlNamingUtil.buildUniqueIdentifier(bi, "new_call");
final SubprogramCallSequence newScs = bi.createOwnedSubprogramCallSequence();
newScs.setName(newScsName);
// Create an initial call. Needed because call sequences must have at least one call
final SubprogramCall initialSubprogramCall = newScs.createOwnedSubprogramCall();
initialSubprogramCall.setName(initialSubprogramCallName);
initialSubprogramCall.setContext(createArgs.callContext);
initialSubprogramCall.setCalledSubprogram(createArgs.calledSubprogram);
AadlImportsUtil.ensurePackageIsImportedForClassifier(bi, createArgs.callContext);
AadlImportsUtil.ensurePackageIsImportedForClassifier(bi, createArgs.calledSubprogram);
return StepResultBuilder.create().showNewBusinessObject(targetBoc, newScs).build();
});
}));
}
use of org.osate.aadl2.Operation 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;
}
use of org.osate.aadl2.Operation in project osate2 by osate.
the class CreateVariablePaletteCommand method getOperation.
@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
return ctx.getTarget().getBusinessObject(BehaviorAnnex.class).map(behaviorAnnex -> {
final PublicPackageSection section = getPackage(behaviorAnnex).map(AadlPackage::getPublicSection).orElse(null);
if (section == null) {
return null;
}
return Operation.createWithBuilder(builder -> {
final OperationBuilder<DataClassifier> prompt = builder.supply(() -> BehaviorAnnexUtil.promptForDataClassifier(behaviorAnnex.eResource()).filter(c -> BehaviorAnnexUtil.getPackage(c).isPresent()).map(StepResult::forValue).orElseGet(StepResult::abort));
final OperationBuilder<DataClassifier> addImportIfNeeded = prompt.modifyModel(null, (tag, prevResult) -> section, (tag, sectionToModify, dataClassifier) -> {
BehaviorAnnexUtil.getPackage(dataClassifier).ifPresent(classifierPkg -> AadlImportsUtil.addImportIfNeeded(sectionToModify, classifierPkg));
return StepResult.forValue(dataClassifier);
});
addImportIfNeeded.modifyModel(null, (tag, dataClassifier) -> behaviorAnnex, (tag, behaviorAnnexToModify, prevResult) -> {
final BehaviorVariable newVariable = (BehaviorVariable) EcoreUtil.create(AadlBaPackage.eINSTANCE.getBehaviorVariable());
final String newName = BehaviorAnnexNamingUtil.buildUniqueIdentifier(behaviorAnnexToModify, "new_behavior_variable");
newVariable.setName(newName);
newVariable.setDataClassifier(prevResult);
behaviorAnnexToModify.getVariables().add(newVariable);
return StepResultBuilder.create().showNewBusinessObject(ctx.getTarget(), newVariable).build();
});
});
});
}
use of org.osate.aadl2.Operation in project osate2 by osate.
the class PropertiesValidator method typeCheckPropertyValues.
/**
* checks and report mismatch in type of value and type
*
* @param pt:
* PropertyType or unresolved proxy or null
* @param pv:
* PropertyExpression or null
* @param prefix:
* String prefix to error message used for lists
* @since 2.0
*/
protected void typeCheckPropertyValues(PropertyType pt, PropertyExpression pv, String prefix, Element holder, String defName, int depth) {
if (Aadl2Util.isNull(pt) || pv == null || holder == null) {
return;
}
if (depth > 50) {
error(holder, "Cyclic value discovered for '" + defName + "'");
return;
}
depth++;
String msg = " to property '" + defName + "' of type '" + pt.eClass().getName() + "'";
if (!prefix.isEmpty() && !prefix.startsWith(" ")) {
prefix = prefix + " ";
}
if (pv instanceof ListValue) {
if (pt instanceof ListType) {
typeMatchListElements(((ListType) pt).getElementType(), ((ListValue) pv).getOwnedListElements(), holder, defName, depth);
} else {
error(holder, prefix + "Assigning a list of values" + msg);
}
} else if (pv instanceof Operation || pv instanceof BooleanLiteral) {
if (!(pt instanceof AadlBoolean)) {
error(holder, prefix + "Assigning a Boolean value" + msg);
}
} else if (pv instanceof StringLiteral) {
if (!(pt instanceof AadlString)) {
error(prefix + "Assigning String value" + msg, holder, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, Diagnostic.LINKING_DIAGNOSTIC);
}
} else if (pv instanceof EnumerationLiteral || (pv instanceof NamedValue && ((NamedValue) pv).getNamedValue() instanceof EnumerationLiteral)) {
if (!(pt instanceof EnumerationType)) {
error(holder, prefix + "Assigning Enumeration literal" + msg);
}
} else if (pv instanceof UnitLiteral || (pv instanceof NamedValue && ((NamedValue) pv).getNamedValue() instanceof UnitLiteral)) {
if (!(pt instanceof UnitsType)) {
error(holder, prefix + "Assigning Unit literal" + msg);
}
} else if (pv instanceof IntegerLiteral) {
if (!(pt instanceof AadlInteger)) {
error(holder, prefix + "Assigning Integer value" + msg);
} else if (checkUnits((AadlInteger) pt, (IntegerLiteral) pv, holder)) {
checkInRange((AadlInteger) pt, (IntegerLiteral) pv);
}
} else if (pv instanceof RealLiteral) {
if (!(pt instanceof AadlReal)) {
error(holder, prefix + "Assigning Real value" + msg);
} else if (checkUnits((AadlReal) pt, (RealLiteral) pv, holder)) {
checkInRange((AadlReal) pt, (RealLiteral) pv);
}
} else if (pv instanceof RangeValue) {
if (!(pt instanceof RangeType)) {
error(holder, prefix + "Assigning Range value" + msg);
} else {
typeCheckPropertyValues(((RangeType) pt).getNumberType(), ((RangeValue) pv).getMinimumValue(), holder, defName, depth);
typeCheckPropertyValues(((RangeType) pt).getNumberType(), ((RangeValue) pv).getMaximumValue(), holder, defName, depth);
typeCheckPropertyValues(((RangeType) pt).getNumberType(), ((RangeValue) pv).getDeltaValue(), holder, defName, depth);
}
} else if (pv instanceof ClassifierValue) {
if (!(pt instanceof ClassifierType)) {
error(holder, prefix + "Assigning incorrect Classifier value" + msg);
return;
}
ClassifierValue cv = (ClassifierValue) pv;
ClassifierType ct = (ClassifierType) pt;
if (ct.getClassifierReferences().isEmpty()) {
return;
}
for (MetaclassReference mcri : ct.getClassifierReferences()) {
if (mcri.getMetaclass() != null && mcri.getMetaclass().isSuperTypeOf(cv.getClassifier().eClass())) {
return;
}
}
error(holder, prefix + "Assigning classifier value with incorrect Classifier" + msg);
} else if (pv instanceof RecordValue) {
if (!(pt instanceof RecordType)) {
error(holder, prefix + "Assigning Record value" + msg);
} else {
typeMatchRecordFields(((RecordValue) pv).getOwnedFieldValues(), holder, defName, depth);
}
} else if (pv instanceof ReferenceValue) {
if (!(pt instanceof ReferenceType)) {
error(holder, prefix + "Assigning incorrect reference value" + msg);
} else {
ReferenceType ptrt = (ReferenceType) pt;
if (ptrt.getNamedElementReferences().isEmpty()) {
return;
}
ReferenceValue pvrv = (ReferenceValue) pv;
EList<ContainmentPathElement> cpes = pvrv.getContainmentPathElements();
if (!cpes.isEmpty()) {
NamedElement ne = cpes.get(cpes.size() - 1).getNamedElement();
for (MetaclassReference mcri : ptrt.getNamedElementReferences()) {
if (mcri.getMetaclass().isSuperTypeOf(ne.eClass())) {
return;
}
}
error(holder, prefix + "Assigning reference value with incorrect Named Element class" + msg);
}
}
} else if (pv instanceof NamedValue) {
AbstractNamedValue nv = ((NamedValue) pv).getNamedValue();
if (nv instanceof PropertyConstant) {
final PropertyConstant propertyConstant = (PropertyConstant) nv;
final PropertyType pct = propertyConstant.getPropertyType();
if (!Aadl2Util.isNull(pct) && !Aadl2Util.arePropertyTypesEqual(pt, pct)) {
final String expected = getTypeName(pt);
final String actual = getTypeName(pct);
if (actual != null) {
if (expected != null) {
error(holder, "Property value of type " + actual + "; expected type " + expected);
} else {
error(holder, "Propery value of type " + actual + " does not match expected type");
}
} else {
if (expected != null) {
error(holder, "Property value is not of expected type " + expected);
} else {
error(holder, "Propery value is not of expected type");
}
}
} else {
// Issue 2222: is this still really necessary?
typeCheckPropertyValues(pt, propertyConstant.getConstantValue(), holder, defName, depth);
}
} else if (nv instanceof Property) {
PropertyType pvt = ((Property) nv).getPropertyType();
if (!Aadl2Util.isNull(pvt)) {
if (pvt.eClass() != pt.eClass() || !Aadl2Util.arePropertyTypesEqual(pt, pvt)) {
final String expected = getTypeName(pt);
final String actual = getTypeName(pvt);
if (actual != null) {
if (expected != null) {
error(holder, "Property value of type " + actual + "; expected type " + expected);
} else {
error(holder, "Propery value of type " + actual + " does not match expected type");
}
} else {
if (expected != null) {
error(holder, "Property value is not of expected type " + expected);
} else {
error(holder, "Propery value is not of expected type");
}
}
}
}
} else {
error(holder, "Enum/Unit literal validation should have happened before");
}
}
}
use of org.osate.aadl2.Operation in project osate2 by osate.
the class AbstractPropertiesSemanticSequencer method sequence.
@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
EPackage epackage = semanticObject.eClass().getEPackage();
ParserRule rule = context.getParserRule();
Action action = context.getAssignedAction();
Set<Parameter> parameters = context.getEnabledBooleanParameters();
if (epackage == Aadl2Package.eINSTANCE)
switch(semanticObject.eClass().getClassifierID()) {
case Aadl2Package.ARRAY_RANGE:
sequence_ArrayRange(context, (ArrayRange) semanticObject);
return;
case Aadl2Package.BASIC_PROPERTY_ASSOCIATION:
sequence_FieldPropertyAssociation(context, (BasicPropertyAssociation) semanticObject);
return;
case Aadl2Package.BOOLEAN_LITERAL:
sequence_BooleanLiteral(context, (BooleanLiteral) semanticObject);
return;
case Aadl2Package.CLASSIFIER_VALUE:
sequence_ComponentClassifierTerm(context, (ClassifierValue) semanticObject);
return;
case Aadl2Package.COMPUTED_VALUE:
sequence_ComputedTerm(context, (ComputedValue) semanticObject);
return;
case Aadl2Package.CONTAINED_NAMED_ELEMENT:
sequence_ContainmentPath(context, (ContainedNamedElement) semanticObject);
return;
case Aadl2Package.CONTAINMENT_PATH_ELEMENT:
sequence_ContainmentPathElement(context, (ContainmentPathElement) semanticObject);
return;
case Aadl2Package.INTEGER_LITERAL:
sequence_IntegerTerm(context, (IntegerLiteral) semanticObject);
return;
case Aadl2Package.LIST_VALUE:
sequence_ListTerm(context, (ListValue) semanticObject);
return;
case Aadl2Package.MODAL_PROPERTY_VALUE:
if (rule == grammarAccess.getModalPropertyValueRule()) {
sequence_ModalPropertyValue(context, (ModalPropertyValue) semanticObject);
return;
} else if (rule == grammarAccess.getOptionalModalPropertyValueRule()) {
sequence_OptionalModalPropertyValue(context, (ModalPropertyValue) semanticObject);
return;
} else if (rule == grammarAccess.getPropertyValueRule()) {
sequence_PropertyValue(context, (ModalPropertyValue) semanticObject);
return;
} else
break;
case Aadl2Package.NAMED_VALUE:
if (rule == grammarAccess.getConstantValueRule() || rule == grammarAccess.getNumAltRule()) {
sequence_ConstantValue(context, (NamedValue) semanticObject);
return;
} else if (rule == grammarAccess.getPropertyExpressionRule() || rule == grammarAccess.getLiteralorReferenceTermRule()) {
sequence_LiteralorReferenceTerm(context, (NamedValue) semanticObject);
return;
} else
break;
case Aadl2Package.OPERATION:
sequence_SignedConstant(context, (Operation) semanticObject);
return;
case Aadl2Package.PROPERTY_ASSOCIATION:
if (rule == grammarAccess.getBasicPropertyAssociationRule()) {
sequence_BasicPropertyAssociation(context, (PropertyAssociation) semanticObject);
return;
} else if (rule == grammarAccess.getPModelRule() || rule == grammarAccess.getContainedPropertyAssociationRule()) {
sequence_ContainedPropertyAssociation(context, (PropertyAssociation) semanticObject);
return;
} else if (rule == grammarAccess.getPropertyAssociationRule()) {
sequence_PropertyAssociation(context, (PropertyAssociation) semanticObject);
return;
} else
break;
case Aadl2Package.RANGE_VALUE:
sequence_NumericRangeTerm(context, (RangeValue) semanticObject);
return;
case Aadl2Package.REAL_LITERAL:
sequence_RealTerm(context, (RealLiteral) semanticObject);
return;
case Aadl2Package.RECORD_VALUE:
if (rule == grammarAccess.getOldRecordTermRule()) {
sequence_OldRecordTerm(context, (RecordValue) semanticObject);
return;
} else if (rule == grammarAccess.getPropertyExpressionRule() || rule == grammarAccess.getRecordTermRule()) {
sequence_RecordTerm(context, (RecordValue) semanticObject);
return;
} else
break;
case Aadl2Package.REFERENCE_VALUE:
sequence_ReferenceTerm(context, (ReferenceValue) semanticObject);
return;
case Aadl2Package.STRING_LITERAL:
sequence_StringTerm(context, (StringLiteral) semanticObject);
return;
}
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Aggregations