use of org.osate.aadl2.ContainmentPathElement in project osate2 by osate.
the class PropertiesValidator method checkArrayReference.
@Check(CheckType.FAST)
public void checkArrayReference(ContainmentPathElement pathElement) {
NamedElement element = pathElement.getNamedElement();
List<ArrayRange> providedRanges = pathElement.getArrayRanges();
if (element.eIsProxy() || providedRanges.isEmpty()) {
// Only validate if the name is resolvable and there really are array indicies.
return;
}
String name = element.getName();
if (element instanceof ArrayableElement) {
List<ArrayDimension> requiredDimensions = ((ArrayableElement) element).getArrayDimensions();
if (requiredDimensions.isEmpty()) {
error(providedRanges.get(0), "'" + name + "' is not an array");
} else if (providedRanges.size() < requiredDimensions.size()) {
error(providedRanges.get(providedRanges.size() - 1), "Too few array dimensions: '" + name + "' has " + requiredDimensions.size());
} else if (providedRanges.size() > requiredDimensions.size()) {
error(providedRanges.get(requiredDimensions.size()), "Too many array dimensions: '" + name + "' has " + requiredDimensions.size());
} else {
for (int i = 0; i < providedRanges.size(); i++) {
ArrayRange providedRange = providedRanges.get(i);
if (providedRange.getLowerBound() == 0) {
error("Array indices start at 1", providedRange, Aadl2Package.eINSTANCE.getArrayRange_LowerBound(), ARRAY_LOWER_BOUND_IS_ZERO);
}
// If the upper is zero, then we have an index. Otherwise, we have a range.
if (providedRange.getUpperBound() != 0) {
if (providedRange.getLowerBound() > providedRange.getUpperBound()) {
error("Range lower bound is greater than upper bound", providedRange, null, ARRAY_RANGE_UPPER_LESS_THAN_LOWER);
}
if (EcoreUtil2.getContainerOfType(pathElement, ReferenceValue.class) != null) {
warning(providedRange, "Array ranges in reference values are not property instantiated");
}
}
ArrayDimension requiredDimension = requiredDimensions.get(i);
if (requiredDimension.getSize() == null) {
error(providedRange, "'" + name + "' does not have an array size");
} else {
ArraySizeProperty sizeProperty = requiredDimension.getSize().getSizeProperty();
OptionalLong size = OptionalLong.empty();
/*
* If the size property is null, then an integer literal was specified for the size.
* If the size property is not null, but is a proxy, then the property could not be resolved.
*/
if (sizeProperty == null) {
size = OptionalLong.of(requiredDimension.getSize().getSize());
} else if (!sizeProperty.eIsProxy()) {
PropertyExpression constantValue = ((PropertyConstant) sizeProperty).getConstantValue();
if (constantValue instanceof IntegerLiteral) {
size = OptionalLong.of(((IntegerLiteral) constantValue).getValue());
}
}
size.ifPresent(requiredSize -> {
// If the upper is zero, then we have an index. Otherwise, we have a range.
if (providedRange.getUpperBound() == 0) {
long index = providedRange.getLowerBound();
if (index > requiredSize) {
error("Index is greater than array size " + requiredSize, providedRange, Aadl2Package.eINSTANCE.getArrayRange_LowerBound(), ARRAY_INDEX_GREATER_THAN_MAXIMUM, Long.toString(requiredSize));
}
} else if (providedRange.getUpperBound() > requiredSize) {
error("Upper bound is greater than array size " + requiredSize, providedRange, Aadl2Package.eINSTANCE.getArrayRange_UpperBound(), ARRAY_RANGE_UPPER_GREATER_THAN_MAXIMUM, Long.toString(requiredSize));
}
});
}
}
}
} else {
error(providedRanges.get(0), "'" + name + "' is not an array");
}
}
use of org.osate.aadl2.ContainmentPathElement in project osate2 by osate.
the class Aadl2LabelProvider method text.
String text(PropertyExpression pe) {
if (pe instanceof BooleanLiteral) {
return "boolean " + ((BooleanLiteral) pe).getValue() + "";
}
if (pe instanceof RealLiteral) {
return "real " + ((RealLiteral) pe).getValue() + "";
}
if (pe instanceof IntegerLiteral) {
return text((IntegerLiteral) pe);
}
if (pe instanceof StringLiteral) {
return text((StringLiteral) pe);
}
if (pe instanceof NamedValue) {
return text((NamedValue) pe);
}
if (pe instanceof ReferenceValue) {
ReferenceValue rv = ((ReferenceValue) pe);
List<ContainmentPathElement> cpe = rv.getContainmentPathElements();
return "reference " + cpe.get(0).getNamedElement().getName();
}
if (pe instanceof RangeValue) {
return text(((RangeValue) pe));
}
if (pe instanceof ListValue) {
return text(((ListValue) pe));
}
if (pe instanceof RecordValue) {
return text(((RecordValue) pe));
}
// OsateDebug.osateDebug("unknown pe=" + pe);
return null;
}
use of org.osate.aadl2.ContainmentPathElement in project osate2 by osate.
the class Aadl2OutlineTreeProvider method internalCreateChildren.
@Override
protected void internalCreateChildren(final IOutlineNode parentNode, final EObject modelElement) {
if (modelElement instanceof Element) {
final Element element = (Element) modelElement;
final EObject annexRoot = AnnexUtil.getAnnexRoot(element);
if (annexRoot != null) {
// delegate to annex specific outline tree provider
IParseResult annexParseResult = ParseResultHolder.Factory.INSTANCE.adapt(annexRoot).getParseResult();
if (annexParseResult != null) {
Injector injector = AnnexUtil.getInjector(annexParseResult);
if (injector != null) {
try {
final IOutlineTreeStructureProvider outlineTree = injector.getInstance(IOutlineTreeStructureProvider.class);
if (outlineTree instanceof BackgroundOutlineTreeProvider) {
outlineTree.createChildren(parentNode, element);
} else {
Aadl2Activator.getInstance().getLog().log(new Status(IStatus.ERROR, Aadl2Activator.PLUGIN_ID, IStatus.OK, "Annex outline tree structure provider '" + outlineTree.getClass().getCanonicalName() + "' does not implement BackgroundOutlineTreeProvider", null));
}
} catch (ConfigurationException e) {
// ignore: no outline provider for this annex
}
}
}
} else {
for (EObject childElement : element.getChildren()) {
if (childElement instanceof Realization || childElement instanceof TypeExtension || childElement instanceof ImplementationExtension || childElement instanceof ContainmentPathElement || childElement instanceof PropertyAssociation) {
continue;
}
if (element instanceof Connection && childElement instanceof ConnectedElement) {
continue;
}
createNode(parentNode, childElement);
}
}
}
}
use of org.osate.aadl2.ContainmentPathElement in project osate2 by osate.
the class PropertiesValidator method unparseAppliesTo.
private static String unparseAppliesTo(final ContainedNamedElement cna) {
final StringBuffer sb = new StringBuffer();
EList<ContainmentPathElement> path = cna.getContainmentPathElements();
for (final Iterator<ContainmentPathElement> it = path.iterator(); it.hasNext(); ) {
final ContainmentPathElement pc = it.next();
sb.append(pc.getNamedElement().getName());
if (it.hasNext()) {
sb.append(".");
}
}
return sb.toString();
}
use of org.osate.aadl2.ContainmentPathElement in project osate2 by osate.
the class InstanceObjectImpl method findInstanceObjectsHelper.
protected boolean findInstanceObjectsHelper(ListIterator<ContainmentPathElement> pathIter, List<InstanceObject> ios) {
boolean result = false;
if (!pathIter.hasNext()) {
ios.add(this);
result = true;
} else {
ContainmentPathElement cpe = pathIter.next();
NamedElement ne = cpe.getNamedElement();
for (EObject eo : eContents()) {
if (eo instanceof InstanceObjectImpl) {
InstanceObjectImpl next = (InstanceObjectImpl) eo;
List<? extends NamedElement> decls = next.getInstantiatedObjects();
if (decls != null && !decls.isEmpty()) {
NamedElement decl = decls.get(0);
if (decl.getName() != null && decl.getName().equalsIgnoreCase(ne.getName())) {
EList<ArrayRange> ranges = cpe.getArrayRanges();
if (next.matchesIndex(ranges)) {
next.findInstanceObjectsHelper(pathIter, ios);
}
result = true;
}
}
}
}
pathIter.previous();
}
return result;
}
Aggregations