use of com.google.api.expr.v1alpha1.ListValue in project osate2 by osate.
the class PropertyResult method convertValue.
private static Object convertValue(final QueryService queryService, final PropertyExpression propertyExpression, final int processedAppliedToPathElements) {
if (propertyExpression == null) {
return null;
}
if (propertyExpression instanceof ListValue) {
// Convert the ListValue to a java list
final ListValue lv = (ListValue) propertyExpression;
final List<Object> convertedList = new LinkedList<>();
for (final PropertyExpression innerExpression : lv.getOwnedListElements()) {
final Object innerValue = convertValue(queryService, innerExpression, processedAppliedToPathElements);
if (innerValue != null) {
convertedList.add(innerValue);
}
}
return convertedList;
} else if (propertyExpression instanceof ReferenceValue) {
return new ReferenceValueWithContext((ReferenceValue) propertyExpression, processedAppliedToPathElements);
} else {
return propertyExpression;
}
}
use of com.google.api.expr.v1alpha1.ListValue in project osate2 by osate.
the class CachePropertyAssociationsSwitch method cacheConnectionPropertyAssociations.
protected void cacheConnectionPropertyAssociations(final ConnectionInstance conni) {
PropertyAssociation setPA;
PropertyExpression defaultvalue;
try {
/*
* propertyFilter contains all properties used by the system, so, we try to
* use the one associated to the connection instance and their reference and
* see if the user declares a specific value.
*/
for (Property prop : propertyFilter) {
setPA = null;
defaultvalue = prop.getDefaultValue();
for (final ConnectionReference connRef : conni.getConnectionReferences()) {
/*
* In the following piece of code, we check that a property
* is consistent all along the connection reference.
* For example, we check that the timing property (immediate, delayed)
* is consistent for each connection.
*/
if (connRef.acceptsProperty(prop)) {
/*
* 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.
*/
final PropertyAssociation propAssociation = scProps.retrieveSCProperty(conni, prop, connRef.getConnection());
final EvaluationContext ctx = new EvaluationContext(connRef, classifierCache, propAssociation);
PropertyEvaluationResult result = prop.evaluate(ctx, 0);
List<EvaluatedProperty> evaluated = result.getEvaluated();
if (!evaluated.isEmpty()) {
PropertyAssociationInstance newPA = InstanceFactory.eINSTANCE.createPropertyAssociationInstance();
newPA.setProperty(prop);
newPA.setPropertyAssociation(getDeclarativePA(result.getPa()));
fillPropertyValue(connRef, newPA, evaluated);
if (!newPA.getOwnedValues().isEmpty()) {
/*
* FIXME JD
*
* Try to look if the property references a component or not.
* This was done to fix the issue related to the Bound Bus analysis plugin
*/
for (Iterator<Element> content = EcoreUtil.getAllProperContents(newPA, false); content.hasNext(); ) {
Element elem = content.next();
if (elem instanceof ModalPropertyValue) {
ModalPropertyValue mpv = (ModalPropertyValue) elem;
if (mpv.getOwnedValue() instanceof ListValue) {
ListValue lv = (ListValue) mpv.getOwnedValue();
for (Element e : lv.getOwnedListElements()) {
if (e instanceof ReferenceValue) {
PropertyExpression irv = ((ReferenceValue) e).instantiate(conni.getContainingComponentInstance());
if (irv != null) {
EcoreUtil.replace(e, irv);
}
}
}
}
}
if (elem instanceof ReferenceValue) {
PropertyExpression irv = ((ReferenceValue) elem).instantiate(conni.getContainingComponentInstance());
if (irv != null) {
EcoreUtil.replace(elem, irv);
}
}
}
scProps.recordSCProperty(conni, prop, connRef.getConnection(), newPA);
if (setPA == null) {
setPA = newPA;
conni.getOwnedPropertyAssociations().add(newPA);
} else {
// check consistency
for (Mode m : conni.getSystemInstance().getSystemOperationModes()) {
PropertyExpression newVal = newPA.valueInMode(m);
PropertyExpression setVal = setPA.valueInMode(m);
if (!newVal.sameAs(setVal)) {
error(conni, "Value for property " + setPA.getProperty().getQualifiedName() + " not consistent along connection");
break;
}
}
}
}
}
}
}
checkIfCancelled();
if (cancelled()) {
break;
}
}
} catch (IllegalStateException e) {
// circular dependency
// xxx: this is a misleading place to put the marker
error(conni, e.getMessage());
System.out.println("IllegalStateException raised in cacheConnectionPropertyAssociations");
} catch (InvalidModelException e) {
error(conni, e.getMessage());
System.out.println("InvalidModelException raised in cacheConnectionPropertyAssociations");
}
}
use of com.google.api.expr.v1alpha1.ListValue in project osate2 by osate.
the class InstantiateModel method getIndices.
private List<Long> getIndices(RecordValue rv, String field) {
List<Long> indices = new ArrayList<Long>();
for (BasicPropertyAssociation fv : rv.getOwnedFieldValues()) {
if (fv.getProperty().getName().equalsIgnoreCase(field)) {
ListValue lv = (ListValue) fv.getOwnedValue();
EList<PropertyExpression> vlist = lv.getOwnedListElements();
// PropertyExpression elem = vlist.get(i);
for (PropertyExpression elem : vlist) {
indices.add(((IntegerLiteral) elem).getValue());
}
}
}
return indices;
}
use of com.google.api.expr.v1alpha1.ListValue in project osate2 by osate.
the class ValidateConnectionsSwitch method classifiersFoundInSupportedClassifierSubsetMatchesProperty.
// XXX How can I avoid duplicating this method for the instance and the declarative models?
private boolean classifiersFoundInSupportedClassifierSubsetMatchesProperty(ConnectionInstance connection, Classifier source, Classifier destination) {
PropertyConstant matchesPropertyConstant = GetProperties.lookupPropertyConstant(connection, AadlProject.SUPPORTED_CLASSIFIER_SUBSET_MATCHES);
if (matchesPropertyConstant == null) {
return false;
}
PropertyExpression constantValue = matchesPropertyConstant.getConstantValue();
if (!(constantValue instanceof ListValue)) {
return false;
}
for (PropertyExpression classifierPair : ((ListValue) constantValue).getOwnedListElements()) {
if (classifierPair instanceof ListValue) {
EList<PropertyExpression> innerListElements = ((ListValue) classifierPair).getOwnedListElements();
if (innerListElements.size() == 2 && innerListElements.get(0) instanceof ClassifierValue && innerListElements.get(1) instanceof ClassifierValue) {
Classifier firstPairElement = ((ClassifierValue) innerListElements.get(0)).getClassifier();
Classifier secondPairElement = ((ClassifierValue) innerListElements.get(1)).getClassifier();
if (firstPairElement == source && secondPairElement == destination) {
return true;
}
}
}
}
return false;
}
use of com.google.api.expr.v1alpha1.ListValue in project osate2 by osate.
the class ValidateConnectionsSwitch method classifiersFoundInSupportedClassifierEquivalenceMatchesProperty.
// XXX How can I avoid duplicating this method for the instance and the declarative models?
private boolean classifiersFoundInSupportedClassifierEquivalenceMatchesProperty(final ConnectionInstance connection, Classifier source, Classifier destination) {
final PropertyConstant matchesPropertyConstant = GetProperties.lookupPropertyConstant(connection, AadlProject.SUPPORTED_CLASSIFIER_EQUIVALENCE_MATCHES);
if (matchesPropertyConstant == null) {
return false;
}
final PropertyExpression constantValue = matchesPropertyConstant.getConstantValue();
if (!(constantValue instanceof ListValue)) {
return false;
}
for (final PropertyExpression classifierPair : ((ListValue) constantValue).getOwnedListElements()) {
if (classifierPair instanceof ListValue) {
EList<PropertyExpression> innerListElements = ((ListValue) classifierPair).getOwnedListElements();
if (innerListElements.size() == 2 && innerListElements.get(0) instanceof ClassifierValue && innerListElements.get(1) instanceof ClassifierValue) {
Classifier firstPairElement = ((ClassifierValue) innerListElements.get(0)).getClassifier();
Classifier secondPairElement = ((ClassifierValue) innerListElements.get(1)).getClassifier();
if ((firstPairElement == source && secondPairElement == destination) || (firstPairElement == destination && secondPairElement == source)) {
return true;
}
}
}
}
return false;
}
Aggregations