Search in sources :

Example 6 with PropertyConstant

use of org.osate.aadl2.PropertyConstant in project osate2 by osate.

the class Aadl2OccurrenceComputer method createAnnotationMap.

@Override
public Map<Annotation, Position> createAnnotationMap(XtextEditor editor, final ITextSelection selection, final SubMonitor monitor) {
    final IXtextDocument document = editor.getDocument();
    if (document != null) {
        return document.tryReadOnly(new CancelableUnitOfWork<Map<Annotation, Position>, XtextResource>() {

            @Override
            public Map<Annotation, Position> exec(XtextResource resource, final CancelIndicator cancelIndicator) throws Exception {
                EObject target = eObjectAtOffsetHelper.resolveElementAt(resource, selection.getOffset());
                if (target != null && !target.eIsProxy()) {
                    final List<EObjectReferenceAndIndex> references = newArrayList();
                    IReferenceFinder.Acceptor acceptor = new IReferenceFinder.Acceptor() {

                        @Override
                        public void accept(IReferenceDescription reference) {
                            throw new UnsupportedOperationException("Local references are announced per object");
                        }

                        @Override
                        public void accept(EObject source, URI sourceURI, EReference eReference, int index, EObject targetOrProxy, URI targetURI) {
                            EObjectReferenceAndIndex acceptMe = new EObjectReferenceAndIndex();
                            acceptMe.source = source;
                            acceptMe.reference = eReference;
                            acceptMe.idx = index;
                            references.add(acceptMe);
                        }
                    };
                    Iterable<URI> targetURIs = getTargetURIs(target);
                    if (!(targetURIs instanceof TargetURIs)) {
                        TargetURIs result = targetURIsProvider.get();
                        result.addAllURIs(targetURIs);
                        targetURIs = result;
                    }
                    IProgressMonitor localMonitor = new NullProgressMonitor() {

                        @Override
                        public boolean isCanceled() {
                            return monitor.isCanceled() || cancelIndicator.isCanceled();
                        }
                    };
                    referenceFinder.findReferences((TargetURIs) targetURIs, resource, acceptor, localMonitor);
                    operationCanceledManager.checkCanceled(cancelIndicator);
                    Map<Annotation, Position> result = newHashMapWithExpectedSize(references.size() + 1);
                    if (target.eResource() == resource) {
                        if (!references.isEmpty() || canBeReferencedLocally(target)) {
                            ITextRegion declarationRegion = locationInFileProvider.getSignificantTextRegion(target);
                            addOccurrenceAnnotation(DECLARATION_ANNOTATION_TYPE, document, declarationRegion, result);
                            declarationRegion = ((Aadl2LocationInFile) locationInFileProvider).getSecondaryTextRegion(target, !(target instanceof ComponentImplementation));
                            if (declarationRegion != null) {
                                addOccurrenceAnnotation(OCCURRENCE_ANNOTATION_TYPE, document, declarationRegion, result);
                                if (target instanceof ComponentType) {
                                    ModelUnit pkg = EcoreUtil2.getContainerOfType(target, ModelUnit.class);
                                    for (ComponentImplementation impl : EcoreUtil2.getAllContentsOfType(pkg, ComponentImplementation.class)) {
                                        if (impl.getType() == target) {
                                            declarationRegion = ((Aadl2LocationInFile) locationInFileProvider).getSecondaryTextRegion(impl, true);
                                            if (declarationRegion != null) {
                                                addOccurrenceAnnotation(OCCURRENCE_ANNOTATION_TYPE, document, declarationRegion, result);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    for (EObjectReferenceAndIndex highlightMe : references) {
                        try {
                            if (localMonitor.isCanceled()) {
                                return emptyMap();
                            }
                            ITextRegion textRegion = locationInFileProvider.getSignificantTextRegion(highlightMe.source, highlightMe.reference, highlightMe.idx);
                            if (target instanceof ComponentImplementation) {
                                ComponentImplementation impl = (ComponentImplementation) target;
                                textRegion = getAdjustedRegion(document, textRegion, impl.getImplementationName(), textRegion);
                            } else if (target instanceof ComponentType || target instanceof Property || target instanceof PropertyType || target instanceof PropertyConstant) {
                                NamedElement named = (NamedElement) target;
                                textRegion = getAdjustedRegion(document, textRegion, named.getName(), textRegion);
                            } else if (target instanceof ModelUnit) {
                                NamedElement named = (NamedElement) target;
                                textRegion = getAdjustedRegion(document, textRegion, named.getName(), null);
                            }
                            if (textRegion != null) {
                                addOccurrenceAnnotation(OCCURRENCE_ANNOTATION_TYPE, document, textRegion, result);
                            }
                        } catch (Exception exc) {
                        // outdated index information. Ignore
                        }
                    }
                    return result;
                }
                return emptyMap();
            }
        }, () -> emptyMap());
    } else {
        return emptyMap();
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) XtextResource(org.eclipse.xtext.resource.XtextResource) TargetURIs(org.eclipse.xtext.findReferences.TargetURIs) PropertyType(org.osate.aadl2.PropertyType) URI(org.eclipse.emf.common.util.URI) Aadl2LocationInFile(org.osate.xtext.aadl2.util.Aadl2LocationInFile) EObject(org.eclipse.emf.ecore.EObject) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Property(org.osate.aadl2.Property) EReference(org.eclipse.emf.ecore.EReference) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) ComponentType(org.osate.aadl2.ComponentType) BadLocationException(org.eclipse.jface.text.BadLocationException) PropertyConstant(org.osate.aadl2.PropertyConstant) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IReferenceFinder(org.eclipse.xtext.findReferences.IReferenceFinder) ITextRegion(org.eclipse.xtext.util.ITextRegion) ModelUnit(org.osate.aadl2.ModelUnit) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap) NamedElement(org.osate.aadl2.NamedElement) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Example 7 with PropertyConstant

use of org.osate.aadl2.PropertyConstant in project osate2 by osate.

the class SetDimensionsPropertySection method getLabel.

private String getLabel(final ArrayDimension ad) {
    final ArraySize dimSize = ad.getSize();
    final String txt;
    if (dimSize == null) {
        txt = emptyString;
    } else if (dimSize.getSizeProperty() != null) {
        if (dimSize.getSizeProperty() instanceof Property) {
            txt = ((Property) dimSize.getSizeProperty()).getQualifiedName();
        } else if (dimSize.getSizeProperty() instanceof PropertyConstant) {
            txt = ((PropertyConstant) dimSize.getSizeProperty()).getQualifiedName();
        } else {
            txt = "<Unsupported case>";
        }
    } else {
        txt = Long.toString(dimSize.getSize());
    }
    return txt;
}
Also used : ArraySize(org.osate.aadl2.ArraySize) Property(org.osate.aadl2.Property) PropertyConstant(org.osate.aadl2.PropertyConstant)

Example 8 with PropertyConstant

use of org.osate.aadl2.PropertyConstant in project osate2 by osate.

the class AadlStructureBridge method canBeLandmark.

@Override
public boolean canBeLandmark(final String handle) {
    // Must be a component classifier, feature, subcomponent, etc, or a property declaration in a property set.
    final Element aadlElement = (Element) getObjectForHandle(handle);
    final boolean isLandmark = aadlElement instanceof PropertySet || aadlElement instanceof AadlPackage || aadlElement instanceof PackageSection || aadlElement instanceof Classifier || aadlElement instanceof ClassifierFeature || aadlElement instanceof PropertyConstant || aadlElement instanceof PropertyType || aadlElement instanceof Property;
    return isLandmark;
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) PackageSection(org.osate.aadl2.PackageSection) Element(org.osate.aadl2.Element) PropertySet(org.osate.aadl2.PropertySet) Classifier(org.osate.aadl2.Classifier) PropertyType(org.osate.aadl2.PropertyType) Property(org.osate.aadl2.Property) ClassifierFeature(org.osate.aadl2.ClassifierFeature) PropertyConstant(org.osate.aadl2.PropertyConstant)

Example 9 with PropertyConstant

use of org.osate.aadl2.PropertyConstant in project osate2 by osate.

the class PropertyUtils method getSimplePropertyListValue.

/**
 * get non-model proeprty list value
 */
public static PropertyExpression getSimplePropertyListValue(final NamedElement ph, final Property pd) throws InvalidModelException, PropertyNotPresentException, PropertyIsModalException, IllegalStateException, IllegalArgumentException, PropertyDoesNotApplyToHolderException, PropertyIsListException {
    PropertyExpression res;
    if (ph == null) {
        throw new IllegalArgumentException("NamedElement ph cannot be null.");
    }
    res = ph.getSimplePropertyValue(pd);
    if (res instanceof NamedValue) {
        AbstractNamedValue nv = ((NamedValue) res).getNamedValue();
        if (nv instanceof Property) {
            res = ph.getSimplePropertyValue((Property) nv);
        } else if (nv instanceof PropertyConstant) {
            res = ((PropertyConstant) nv).getConstantValue();
        }
    }
    return res;
}
Also used : AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) PropertyExpression(org.osate.aadl2.PropertyExpression) NamedValue(org.osate.aadl2.NamedValue) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) Property(org.osate.aadl2.Property) PropertyConstant(org.osate.aadl2.PropertyConstant)

Example 10 with PropertyConstant

use of org.osate.aadl2.PropertyConstant in project osate2 by osate.

the class PropertyUtils method getContainedSimplePropertyValue.

/**
 * get a property association from the properties section of the containing classifier if the context.
 * This method has been designed to work with end points of connections, i.e., consisting of a target and a context.
 * The context must be a NamedElement in its containing classifier, i.e., a feature, feature group, subcomponent.
 * The property holder is assumed to be contained in the context object, e.g., a feature in afeature group or a data subcomponent in a port, or feature in a subcomponent.
 * The association must match the property definition.
 * if the context is null then the containing classifier of the target is used and the path must be one or no path.
 * The applies to clause of the property association must be of size 2 if the context is set and point to the context and then the property holder.
 * The property value of the property association is assumed not to be modal.
 * @param context NamedElement whose containing classifier's properties section is searched for the desired property
 * @param target NamedElement the model element to which the property is applied to via the applies to clause
 * @param pd Property the property definition
 * @return
 */
public static PropertyExpression getContainedSimplePropertyValue(final NamedElement context, final NamedElement target, final Property pd) {
    if (context == null) {
        return target.getNonModalPropertyValue(pd);
    }
    Classifier cl = AadlUtil.getContainingClassifier(context);
    EList<PropertyAssociation> props = cl.getAllPropertyAssociations();
    for (PropertyAssociation propertyAssociation : props) {
        if (propertyAssociation.getProperty().equals(pd)) {
            // we found a property with the corect type
            // now we need to check whether the applies to points to the holder
            EList<ContainedNamedElement> appliestos = propertyAssociation.getAppliesTos();
            for (ContainedNamedElement containedNamedElement : appliestos) {
                EList<ContainmentPathElement> cpes = containedNamedElement.getContainmentPathElements();
                if (cpes.size() == 2) {
                    NamedElement pathcxt = cpes.get(0).getNamedElement();
                    NamedElement pathelement = cpes.get(1).getNamedElement();
                    if (context.equals(pathcxt) && target.equals(pathelement)) {
                        EList<ModalPropertyValue> vallist = propertyAssociation.getOwnedValues();
                        if (!vallist.isEmpty()) {
                            ModalPropertyValue elem = vallist.get(0);
                            PropertyExpression res = elem.getOwnedValue();
                            if (res instanceof NamedValue) {
                                AbstractNamedValue nv = ((NamedValue) res).getNamedValue();
                                if (nv instanceof Property) {
                                    res = target.getNonModalPropertyValue((Property) nv);
                                } else if (nv instanceof PropertyConstant) {
                                    res = ((PropertyConstant) nv).getConstantValue();
                                }
                            }
                            return res;
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : ModalPropertyValue(org.osate.aadl2.ModalPropertyValue) PropertyAssociation(org.osate.aadl2.PropertyAssociation) BasicPropertyAssociation(org.osate.aadl2.BasicPropertyAssociation) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) NamedValue(org.osate.aadl2.NamedValue) AbstractNamedValue(org.osate.aadl2.AbstractNamedValue) Classifier(org.osate.aadl2.Classifier) PropertyConstant(org.osate.aadl2.PropertyConstant) PropertyExpression(org.osate.aadl2.PropertyExpression) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement) Property(org.osate.aadl2.Property)

Aggregations

PropertyConstant (org.osate.aadl2.PropertyConstant)40 PropertyExpression (org.osate.aadl2.PropertyExpression)27 IntegerLiteral (org.osate.aadl2.IntegerLiteral)18 Property (org.osate.aadl2.Property)14 Classifier (org.osate.aadl2.Classifier)12 ClassifierValue (org.osate.aadl2.ClassifierValue)12 ListValue (org.osate.aadl2.ListValue)12 NamedValue (org.osate.aadl2.NamedValue)10 NamedElement (org.osate.aadl2.NamedElement)9 List (java.util.List)8 EObject (org.eclipse.emf.ecore.EObject)8 IntegerWithUnits (org.osate.pluginsupport.properties.IntegerWithUnits)7 AbstractNamedValue (org.osate.aadl2.AbstractNamedValue)6 ContainedNamedElement (org.osate.aadl2.ContainedNamedElement)6 ArraySize (org.osate.aadl2.ArraySize)5 BasicPropertyAssociation (org.osate.aadl2.BasicPropertyAssociation)5 ContainmentPathElement (org.osate.aadl2.ContainmentPathElement)5 PropertyType (org.osate.aadl2.PropertyType)5 Aadl2Package (org.osate.aadl2.Aadl2Package)4 ArrayDimension (org.osate.aadl2.ArrayDimension)4