use of org.osate.aadl2.properties.EvaluationContext in project AGREE by loonwerks.
the class ShowInSimulationVariablesViewHandler method calculateEnabled.
private boolean calculateEnabled(final Object evaluationContext) {
final SimulationUIService simulationUiService = EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext()).get(SimulationUIService.class);
if (simulationUiService == null) {
return false;
}
final List<BusinessObjectContext> selectedBocs = getSelectedDiagramElementsFromContext(evaluationContext);
if (simulationUiService.getCurrentState().getEngineState() == null || selectedBocs.size() != 1) {
return false;
}
final Object bo = selectedBocs.get(0).getBusinessObject();
// Make the command available if there is only one business object selected and it is not the root System instance
if ((bo instanceof FeatureInstance || bo instanceof ComponentInstance) && bo != ((InstanceObject) bo).getSystemInstance()) {
final InstanceObject io = (InstanceObject) bo;
// Compare the references from the diagram and simulation system instances. Only show the command if they match
final URI diagramSystemInstanceUri = EcoreUtil.getURI(io.getSystemInstance());
final URI simulationSystemInstanceUri = EcoreUtil.getURI(simulationUiService.getCurrentState().getSimulationEngine().getSystemInstance());
return diagramSystemInstanceUri != null && diagramSystemInstanceUri.equals(simulationSystemInstanceUri);
}
return false;
}
use of org.osate.aadl2.properties.EvaluationContext in project osate2 by osate.
the class OpenAssociatedDiagramHandler method setEnabled.
@Override
public void setEnabled(final Object evaluationContext) {
boolean enabled = false;
final List<BusinessObjectContext> selectedBusinessObjectContexts = AgeHandlerUtil.getSelectedBusinessObjectContexts();
if (selectedBusinessObjectContexts.size() == 1) {
final BusinessObjectContext selectedBusinessObjectContext = selectedBusinessObjectContexts.get(0);
final Object bo = selectedBusinessObjectContext.getBusinessObject();
enabled = (bo instanceof AadlPackage || bo instanceof Classifier || (bo instanceof Subcomponent && AadlSubcomponentUtil.getComponentClassifier(selectedBusinessObjectContext, (Subcomponent) bo) != null)) && ProjectUtil.getProjectForBo(bo).isPresent();
}
setBaseEnabled(enabled);
}
use of org.osate.aadl2.properties.EvaluationContext in project osate2 by osate.
the class ExecuteResoluteUtil method executeResoluteFunctionOnce.
/**
* invokes Resolute claim function on targetComponent or targetElement if not null.
* instanceroot is used to initialize the Resolute evaluation context.
* targetComponent is the evaluation context
* targetElement is the model element within the component instance or null.
* parameterObjects is a list of additional parameters of types RealLiteral, IntegerLiteral, StringLiteral, BooleanLiteral
* parameterObjects can be null or an empty list.
* The return value is an Issue object with subissues for the list of issues returned in the Resolute ClaimResult.
* If the proof fails then the top Issue is set to FAIL, if successful it is set to SUCCESS
*/
public Diagnostic executeResoluteFunctionOnce(EObject fundef, final SystemInstance instanceroot, final ComponentInstance targetComponent, final InstanceObject targetElement, List<PropertyExpression> parameterObjects) {
FunctionDefinition fd = (FunctionDefinition) fundef;
initializeResoluteContext(instanceroot);
EvaluationContext context = new EvaluationContext(targetComponent, sets, featToConnsMap);
// check for claim function
FnCallExpr fcncall = createWrapperFunctionCall(fd, targetComponent, targetElement, parameterObjects);
if (fcncall != null) {
// using com.rockwellcollins.atc.resolute.analysis.results.ClaimResult
ResoluteProver prover = new ResoluteProver(context) {
@Override
protected ResoluteEvaluator createResoluteEvaluator() {
return new ResoluteEvaluator(context, varStack.peek()) {
@Override
public ResoluteValue caseThisExpr(ThisExpr object) {
NamedElement curr = context.getThisInstance();
if (object.getSub() != null) {
curr = object.getSub().getBase();
}
return new NamedElementValue(curr);
}
};
}
};
ResoluteResult res = prover.doSwitch(fcncall);
return doResoluteResults(res);
} else {
return ResultUtil.createErrorDiagnostic("Could not find Resolute Function " + fd.getName(), fd);
}
}
use of org.osate.aadl2.properties.EvaluationContext in project osate2 by osate.
the class PropertyImpl method evaluate.
public PropertyEvaluationResult evaluate(EvaluationContext ctx, int depth) {
List<PropertyAssociation> pas = getPropertyValue(ctx).getAssociations();
List<EvaluatedProperty> vals = new LinkedList<EvaluatedProperty>();
for (PropertyAssociation pa : pas) {
vals.add(pa.evaluate(ctx, depth));
if (!pa.isAppend()) {
break;
}
}
/*
* NB. Do not fix Issue 2387 here! Doing so caused a different problem. Namely,
* if a property with a default value is explicit associated with a value in one place
* in the model, it's going to force model instantiation to create explicit property
* associations in the instance model that bind the default value to the property AT
* ALL OTHER PLACES THE PROPERTY IS APPLICABLE. This is undesirable.
*/
return new PropertyEvaluationResult(pas.isEmpty() ? null : pas.get(0), vals);
}
use of org.osate.aadl2.properties.EvaluationContext in project osate2 by osate.
the class CachePropertyAssociationsSwitch method cachePropertyAssociations.
protected void cachePropertyAssociations(InstanceObject io) {
try {
for (Property property : propertyFilter) {
if (io.acceptsProperty(property)) {
/*
* Just look up the property. The property doesn't yet have a
* local association, so lookup will get the value from the
* declarative model. Property lookup process now corrects
* reference values to instance reference values.
*/
PropertyEvaluationResult result = property.evaluate(new EvaluationContext(io, classifierCache), 0);
List<EvaluatedProperty> evaluated = result.getEvaluated();
if (!evaluated.isEmpty()) {
// OsateDebug.osateDebug ("[CachePropertyAssociation] io=" + io + ";property=" + property + ";value=" + value);
PropertyAssociationInstance newPA = InstanceFactory.eINSTANCE.createPropertyAssociationInstance();
io.removePropertyAssociations(property);
newPA.setProperty(property);
newPA.setPropertyAssociation(getDeclarativePA(result.getPa()));
fillPropertyValue(io, newPA, evaluated);
if (!newPA.getOwnedValues().isEmpty()) {
io.getOwnedPropertyAssociations().add(newPA);
}
}
}
checkIfCancelled();
if (cancelled()) {
break;
}
}
} catch (IllegalStateException e) {
// circular dependency
// xxx: this is a misleading place to put the marker
OsateDebug.osateDebug("IllegalStateException raised in cachePropertyAssociations");
error(io, e.getMessage());
return;
} catch (InvalidModelException e) {
OsateDebug.osateDebug("InvalidModelException raised in cachePropertyAssociations");
error(e.getElement(), e.getMessage());
return;
}
}
Aggregations