use of com.google.api.expr.v1alpha1.ListValue in project osate2 by osate.
the class PropertyUtils method getListValue.
public static ListValue getListValue(NamedElement ne, String propertyName) {
PropertyAssociation pa = findPropertyAssociation(propertyName, ne);
if (pa != null) {
Property p = pa.getProperty();
if (p.getName().equalsIgnoreCase(propertyName)) {
List<ModalPropertyValue> values = pa.getOwnedValues();
if (values.size() == 1) {
ModalPropertyValue v = values.get(0);
PropertyExpression expr = v.getOwnedValue();
if (expr instanceof ListValue) {
return (ListValue) expr;
}
}
}
}
return null;
}
use of com.google.api.expr.v1alpha1.ListValue in project osate2 by osate.
the class PropertyUtils method getIntListValue.
/**
* TODO: DOC ME !
*
* May return null.
*
* @param object
* @param propertyName
* @return
*/
public static List<Long> getIntListValue(NamedElement object, String propertyName) {
List<Long> res = new ArrayList<Long>();
PropertyAssociation pa = findPropertyAssociation(propertyName, object);
if (pa == null) {
return null;
} else {
Property p = pa.getProperty();
if (p.getName().equalsIgnoreCase(propertyName)) {
List<ModalPropertyValue> values = pa.getOwnedValues();
if (values.size() == 1) {
ModalPropertyValue v = values.get(0);
PropertyExpression expr = v.getOwnedValue();
if (expr instanceof ListValue) {
ListValue lv = (ListValue) expr;
for (PropertyExpression pe : lv.getOwnedListElements()) {
if (pe instanceof IntegerLiteral) {
Long c = ((IntegerLiteral) pe).getValue();
res.add(c);
}
}
}
}
}
}
// try on a refined NamedElement
if (object instanceof RefinableElement) {
RefinableElement re = (RefinableElement) object;
if (re.getRefinedElement() != null) {
List<Long> l = getIntListValue(re.getRefinedElement(), propertyName);
if (l != null) {
res.addAll(l);
}
}
}
return res;
}
use of com.google.api.expr.v1alpha1.ListValue in project osate2 by osate.
the class PropertyUtils method getSubcomponentList.
/**
* May return an empty list.
*
* @param object
* @param propertyName
* @return
*/
public static List<Subcomponent> getSubcomponentList(NamedElement object, String propertyName) {
List<Subcomponent> res = new ArrayList<Subcomponent>();
PropertyAssociation pa = findPropertyAssociation(propertyName, object);
if (pa == null) {
return null;
} else {
Property p = pa.getProperty();
if (p.getName().equalsIgnoreCase(propertyName)) {
List<ModalPropertyValue> values = pa.getOwnedValues();
if (values.size() == 1) {
ModalPropertyValue v = values.get(0);
PropertyExpression expr = v.getOwnedValue();
if (expr instanceof ListValue) {
ListValue lv = (ListValue) expr;
for (PropertyExpression pe : lv.getOwnedListElements()) {
if (pe instanceof ReferenceValue) {
ReferenceValue c = ((ReferenceValue) pe);
for (ContainmentPathElement cpe : c.getContainmentPathElements()) {
res.add((Subcomponent) cpe.getNamedElement());
}
}
}
}
}
}
return res;
}
}
use of com.google.api.expr.v1alpha1.ListValue in project osate2 by osate.
the class PropertyUtils method getComponentInstanceList.
/**
* TODO: DOC ME !
*
* May return null.
*
* @param object
* @param propertyName
* @return
*/
public static List<ComponentInstance> getComponentInstanceList(NamedElement object, String propertyName) {
List<ComponentInstance> res = null;
PropertyAssociation pa = findPropertyAssociation(propertyName, object);
if (pa != null) {
res = new ArrayList<ComponentInstance>();
Property p = pa.getProperty();
if (p.getName().equals(propertyName)) {
List<ModalPropertyValue> values = pa.getOwnedValues();
if (values.size() == 1) {
ModalPropertyValue v = values.get(0);
PropertyExpression expr = v.getOwnedValue();
if (expr instanceof ListValue) {
ListValue lv = (ListValue) expr;
for (PropertyExpression pe : lv.getOwnedListElements()) {
if (pe instanceof InstanceReferenceValue) {
InstanceReferenceValue c = ((InstanceReferenceValue) pe);
res.add((ComponentInstance) c.getReferencedInstanceObject());
}
}
}
}
}
}
return res;
}
use of com.google.api.expr.v1alpha1.ListValue in project osate2 by osate.
the class ModelingProperties method getAcceptableArraySize.
public static Optional<List<IntegerRange>> getAcceptableArraySize(NamedElement lookupContext, Optional<Mode> mode) {
Property property = getAcceptableArraySize_Property(lookupContext);
try {
PropertyExpression value = CodeGenUtil.lookupProperty(property, lookupContext, mode);
PropertyExpression resolved = CodeGenUtil.resolveNamedValue(value, lookupContext, mode);
return Optional.of(((ListValue) resolved).getOwnedListElements().stream().map(element1 -> {
PropertyExpression resolved1 = CodeGenUtil.resolveNamedValue(element1, lookupContext, mode);
return new IntegerRange(resolved1, lookupContext, mode);
}).collect(Collectors.toList()));
} catch (PropertyNotPresentException e) {
return Optional.empty();
}
}
Aggregations