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();
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations