use of org.osate.aadl2.PropertySet in project osate2 by osate.
the class OrganizeWithHandler method execute.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public Object execute(ExecutionEvent event) throws org.eclipse.core.commands.ExecutionException {
IWorkbench wb = PlatformUI.getWorkbench();
IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
IWorkbenchPage page = win.getActivePage();
IEditorPart activeEditor = page.getActiveEditor();
if (activeEditor == null) {
return null;
}
XtextEditor xtextEditor = (XtextEditor) activeEditor.getAdapter(XtextEditor.class);
if (xtextEditor != null) {
IXtextDocument iXTextDoc = xtextEditor.getDocument();
iXTextDoc.modify(new IUnitOfWork.Void() {
@Override
public void process(Object state) throws Exception {
EObject rootObject = ((Resource) state).getContents().get(0);
if (rootObject instanceof AadlPackage) {
AadlPackage pkg = (AadlPackage) rootObject;
List<PackageSection> pkgSections = new ArrayList<PackageSection>();
if (pkg.getOwnedPublicSection() != null) {
pkgSections.add(pkg.getOwnedPublicSection());
}
if (pkg.getOwnedPrivateSection() != null) {
pkgSections.add(pkg.getOwnedPrivateSection());
}
for (PackageSection pkgSection : pkgSections) {
organizeWithClauses(pkgSection);
}
} else if (rootObject instanceof PropertySet) {
PropertySet propSet = (PropertySet) rootObject;
organizeWithClauses(propSet);
}
}
});
}
return null;
}
use of org.osate.aadl2.PropertySet 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.PropertySet 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);
}
use of org.osate.aadl2.PropertySet 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.PropertySet in project osate2 by osate.
the class AadlElementContentProvider method getChildren.
@Override
public Object[] getChildren(Object parentElement) {
Stream<EObject> children;
final ResourceSetImpl resourceSet = new ResourceSetImpl();
if (parentElement instanceof IFile) {
String path = ((IFile) parentElement).getFullPath().toString();
URI uri = URI.createPlatformResourceURI(path, true);
Resource resource = resourceSet.getResource(uri, true);
children = resource.getContents().stream();
} else if (parentElement instanceof ContributedAadlStorage) {
URI uri = ((ContributedAadlStorage) parentElement).getUri();
Resource resource = resourceSet.getResource(uri, true);
children = resource.getContents().stream();
} else {
EObjectURIWrapper wrapper = (EObjectURIWrapper) parentElement;
EObject eObject = resourceSet.getEObject(wrapper.getUri(), true);
if (eObject instanceof AadlPackage || eObject instanceof PropertySet || eObject instanceof ComponentInstance) {
children = eObject.eContents().stream().filter(element -> !(element instanceof SystemOperationMode || element instanceof PropertyAssociation));
} else if (eObject instanceof PackageSection) {
children = eObject.eContents().stream().filter(element -> element instanceof Classifier || element instanceof AnnexLibrary);
} else if (eObject instanceof Classifier) {
children = eObject.eContents().stream().filter(element -> element instanceof ClassifierFeature || element instanceof PropertyAssociation);
} else {
children = Stream.empty();
}
}
final EObjectURIWrapper.Factory factory = new EObjectURIWrapper.Factory(UiUtil.getModelElementLabelProvider());
// Issue 2430: limit the number of children to 150
return children.limit(150).map(element -> factory.createWrapperFor(element)).toArray();
}
Aggregations