use of org.osate.aadl2.ModelUnit in project osate2 by osate.
the class Aadl2LocationInFile method getSecondaryTextRegion.
public ITextRegion getSecondaryTextRegion(EObject obj, boolean typeName) {
if (obj instanceof ModelUnit || obj instanceof Classifier) {
ICompositeNode node = NodeModelUtils.getNode(obj);
INode endID = node.getLastChild().getPreviousSibling();
List<INode> nodes = null;
while (endID instanceof HiddenLeafNode) {
endID = endID.getPreviousSibling();
}
nodes = Collections.<INode>singletonList(endID);
if (endID instanceof ICompositeNode) {
ICompositeNode fullName = (ICompositeNode) endID;
if (obj instanceof AadlPackage) {
nodes = new ArrayList<INode>();
endID = fullName.getLastChild();
while (endID instanceof HiddenLeafNode) {
endID = endID.getPreviousSibling();
}
INode id = fullName.getFirstChild();
while (id instanceof HiddenLeafNode) {
id = id.getNextSibling();
}
if (id != null) {
nodes.add(id);
while (id != endID) {
id = id.getNextSibling();
nodes.add(id);
}
}
} else if (typeName) {
endID = fullName.getFirstChild();
while (endID instanceof HiddenLeafNode) {
endID = endID.getNextSibling();
}
nodes = Collections.<INode>singletonList(endID);
} else {
endID = fullName.getLastChild();
while (endID instanceof HiddenLeafNode) {
endID = endID.getPreviousSibling();
}
nodes = Collections.<INode>singletonList(endID);
}
}
return createRegion(nodes);
} else {
return null;
}
}
use of org.osate.aadl2.ModelUnit in project osate2 by osate.
the class PropertiesValidator method checkPropertySetElementReferenceForPackageProperties.
public void checkPropertySetElementReferenceForPackageProperties(NamedElement pse, Element context) {
if (Aadl2Util.isNull(pse)) {
return;
}
PropertySet referenceNS = (PropertySet) AadlUtil.getContainingTopLevelNamespace(pse);
PackageSection containingPackageSection = EcoreUtil2.getContainerOfType(context, PackageSection.class);
if (containingPackageSection == null) {
AadlPackage aadlPackage = EcoreUtil2.getContainerOfType(context, AadlPackage.class);
EList<ModelUnit> importedPropertySets = null;
PackageSection packageSection = aadlPackage.getPublicSection();
if (packageSection == null) {
packageSection = aadlPackage.getPrivateSection();
}
if (packageSection != null) {
importedPropertySets = packageSection.getImportedUnits();
for (ModelUnit importedPropertySet : importedPropertySets) {
if (importedPropertySet instanceof PropertySet && !importedPropertySet.eIsProxy() && (importedPropertySet == referenceNS || (referenceNS.getQualifiedName().equalsIgnoreCase(importedPropertySet.getQualifiedName())))) {
return;
}
}
}
if (packageSection != null) {
error("The referenced property set '" + referenceNS.getName() + "' of " + (pse instanceof Property ? "property '" : (pse instanceof PropertyType ? "property type '" : "property constant '")) + pse.getName() + "' is not listed in a with clause.", context, null, MISSING_WITH, referenceNS.getName(), EcoreUtil.getURI(referenceNS).toString(), EcoreUtil.getURI(packageSection).toString());
} else {
error("The referenced property set '" + referenceNS.getName() + "' of " + (pse instanceof Property ? "property '" : (pse instanceof PropertyType ? "property type '" : "property constant '")) + pse.getName() + "' is not listed in a with clause.", context, null);
}
}
}
use of org.osate.aadl2.ModelUnit 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.ModelUnit in project osate2 by osate.
the class OrganizeWithHandler method findMissingWiths.
private List<ModelUnit> findMissingWiths(PropertySet propertySet) {
List<ModelUnit> currentWiths = propertySet.getImportedUnits();
List<ModelUnit> missingWiths = new ArrayList<ModelUnit>();
TreeIterator<EObject> packageContents = propertySet.eAllContents();
while (packageContents.hasNext()) {
EObject nextObject = packageContents.next();
EList<EObject> crossReferences = nextObject.eCrossReferences();
for (EObject crossReference : crossReferences) {
EObject container = crossReference.eContainer();
while (container != null) {
if ((container instanceof PropertySet || container instanceof AadlPackage) && (!AadlUtil.isPredeclaredPropertySet(((ModelUnit) container).getName())) && (!((ModelUnit) container).equals(propertySet))) {
if (!currentWiths.contains(container) && !missingWiths.contains(container)) {
missingWiths.add((ModelUnit) container);
}
}
container = container.eContainer();
}
}
}
return missingWiths;
}
use of org.osate.aadl2.ModelUnit in project osate2 by osate.
the class OrganizeWithHandler method organizeWithClauses.
private void organizeWithClauses(PropertySet propSet) {
List<ModelUnit> workingImportedUnits = new ArrayList<ModelUnit>();
for (ModelUnit nextImportedUnit : propSet.getImportedUnits()) {
workingImportedUnits.add(nextImportedUnit);
}
List<ModelUnit> unusedImportedUnits = getUnusedWiths(propSet);
workingImportedUnits.removeAll(unusedImportedUnits);
List<ModelUnit> missingWiths = findMissingWiths(propSet);
workingImportedUnits.addAll(missingWiths);
Collections.sort(workingImportedUnits, new Comparator<ModelUnit>() {
@Override
public int compare(ModelUnit obj1, ModelUnit obj2) {
return obj1.getName().toLowerCase().compareTo(obj2.getName().toLowerCase());
}
});
propSet.getImportedUnits().removeAll(propSet.getImportedUnits());
propSet.getImportedUnits().addAll(workingImportedUnits);
}
Aggregations