Search in sources :

Example 11 with ContainmentPathElement

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");
    }
}
Also used : ReferenceValue(org.osate.aadl2.ReferenceValue) ArrayRange(org.osate.aadl2.ArrayRange) AadlString(org.osate.aadl2.AadlString) OptionalLong(java.util.OptionalLong) PropertyExpression(org.osate.aadl2.PropertyExpression) ArrayableElement(org.osate.aadl2.ArrayableElement) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement) ArrayDimension(org.osate.aadl2.ArrayDimension) IntegerLiteral(org.osate.aadl2.IntegerLiteral) ArraySizeProperty(org.osate.aadl2.ArraySizeProperty) Check(org.eclipse.xtext.validation.Check)

Example 12 with ContainmentPathElement

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;
}
Also used : RealLiteral(org.osate.aadl2.RealLiteral) StringLiteral(org.osate.aadl2.StringLiteral) BooleanLiteral(org.osate.aadl2.BooleanLiteral) ReferenceValue(org.osate.aadl2.ReferenceValue) ListValue(org.osate.aadl2.ListValue) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) RecordValue(org.osate.aadl2.RecordValue) NamedValue(org.osate.aadl2.NamedValue) IntegerLiteral(org.osate.aadl2.IntegerLiteral) RangeValue(org.osate.aadl2.RangeValue)

Example 13 with ContainmentPathElement

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);
            }
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IOutlineTreeStructureProvider(org.eclipse.xtext.ui.editor.outline.impl.IOutlineTreeStructureProvider) BackgroundOutlineTreeProvider(org.eclipse.xtext.ui.editor.outline.impl.BackgroundOutlineTreeProvider) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) Element(org.osate.aadl2.Element) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) ConnectedElement(org.osate.aadl2.ConnectedElement) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) Connection(org.osate.aadl2.Connection) TypeExtension(org.osate.aadl2.TypeExtension) ImplementationExtension(org.osate.aadl2.ImplementationExtension) Realization(org.osate.aadl2.Realization) ConfigurationException(com.google.inject.ConfigurationException) Injector(com.google.inject.Injector) EObject(org.eclipse.emf.ecore.EObject) ConnectedElement(org.osate.aadl2.ConnectedElement) IParseResult(org.eclipse.xtext.parser.IParseResult)

Example 14 with ContainmentPathElement

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();
}
Also used : ContainmentPathElement(org.osate.aadl2.ContainmentPathElement)

Example 15 with ContainmentPathElement

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;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) ArrayRange(org.osate.aadl2.ArrayRange) NamedElement(org.osate.aadl2.NamedElement)

Aggregations

ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)52 ContainedNamedElement (org.osate.aadl2.ContainedNamedElement)27 NamedElement (org.osate.aadl2.NamedElement)24 PropertyAssociation (org.osate.aadl2.PropertyAssociation)19 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)15 ReferenceValue (org.osate.aadl2.ReferenceValue)14 Property (org.osate.aadl2.Property)12 Subcomponent (org.osate.aadl2.Subcomponent)12 IntegerLiteral (org.osate.aadl2.IntegerLiteral)11 ListValue (org.osate.aadl2.ListValue)11 NamedValue (org.osate.aadl2.NamedValue)11 ArrayRange (org.osate.aadl2.ArrayRange)10 RangeValue (org.osate.aadl2.RangeValue)10 RealLiteral (org.osate.aadl2.RealLiteral)10 RecordValue (org.osate.aadl2.RecordValue)10 BooleanLiteral (org.osate.aadl2.BooleanLiteral)9 ClassifierValue (org.osate.aadl2.ClassifierValue)9 ModalPropertyValue (org.osate.aadl2.ModalPropertyValue)9 StringLiteral (org.osate.aadl2.StringLiteral)9 EObject (org.eclipse.emf.ecore.EObject)7