use of org.osate.aadl2.PackageSection 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.PackageSection in project osate2 by osate.
the class PrototypesModel method setConstrainingClassifier.
@Override
public void setConstrainingClassifier(final EditablePrototype prototype, final NamedElementOrDescription value) {
modifyPrototype("Set Constraining Classifier", prototype, p -> {
final EObject classifier = value.getResolvedValue(prototype.prototype.eResource().getResourceSet());
if (classifier != null) {
// Import its package if necessary
final AadlPackage pkg = (AadlPackage) p.getElementRoot();
if (classifier instanceof Classifier && ((Classifier) classifier).getNamespace() != null && pkg != null) {
final PackageSection section = pkg.getPublicSection();
final AadlPackage selectedClassifierPkg = (AadlPackage) ((Classifier) classifier).getNamespace().getOwner();
if (selectedClassifierPkg != null && pkg != selectedClassifierPkg) {
AadlImportsUtil.addImportIfNeeded(section, selectedClassifierPkg);
}
}
}
// Update the classifier
if (p instanceof ComponentPrototype) {
((ComponentPrototype) p).setConstrainingClassifier((ComponentClassifier) classifier);
} else if (p instanceof FeatureGroupPrototype) {
((FeatureGroupPrototype) p).setConstrainingFeatureGroupType((FeatureGroupType) classifier);
} else if (p instanceof FeaturePrototype) {
((FeaturePrototype) p).setConstrainingClassifier((ComponentClassifier) classifier);
}
});
}
use of org.osate.aadl2.PackageSection 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.PackageSection 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();
}
use of org.osate.aadl2.PackageSection in project osate2 by osate.
the class PropertiesLinkingService method findClassifier.
/**
* find the classifier taking into account rename aliases
* We do not check whether the referenced package is in the with clause. This is checked separately
* This is a helper method for findFeatureGroupType and findComponentClassifier
* @param context classifier reference context
* @param reference identifying attribute of reference
* @param name name to be resolved
* @return Classifier or null
*/
public Classifier findClassifier(EObject context, EReference reference, String name) {
Namespace scope = AadlUtil.getContainingTopLevelNamespace(context);
EObject e = getIndexedObject(context, reference, name);
if (e != null && e instanceof Classifier && reference.getEReferenceType().isSuperTypeOf(e.eClass())) {
// the result satisfied the expected class
Namespace ns = AadlUtil.getContainingTopLevelNamespace(e);
if (ns instanceof PrivatePackageSection && scope != ns) {
return null;
}
return (Classifier) e;
}
// need to do a local lookup as it was not found in the index.
String packname = null;
String cname = name;
final int idx = name.lastIndexOf("::");
if (idx != -1) {
packname = name.substring(0, idx);
cname = name.substring(idx + 2);
// if rename is not a package rename, but component type rename then all is treated as component ID
if (cname.equalsIgnoreCase("all")) {
return null;
}
}
// NOTE: checking whether the referenced package is imported is done by the validator.
if (context instanceof NamedElement) {
// then stop. Otherwise we have a cycle.
if (((NamedElement) context).getName() == null) {
if (packname == null || scope.getName().equalsIgnoreCase(packname)) {
return null;
}
}
}
if (e == null && scope instanceof PackageSection) {
// the reference is from inside a package section. Lookup by identifier with or without qualification
e = findNamedElementInAadlPackage(packname, cname, scope);
if (e != null && e instanceof Classifier && reference.getEReferenceType().isSuperTypeOf(e.eClass())) {
// the result satisfied the expected class
return (Classifier) e;
}
}
return null;
}
Aggregations