Search in sources :

Example 6 with PropertySet

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;
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) AadlPackage(org.osate.aadl2.AadlPackage) PackageSection(org.osate.aadl2.PackageSection) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) Resource(org.eclipse.emf.ecore.resource.Resource) IEditorPart(org.eclipse.ui.IEditorPart) IWorkbench(org.eclipse.ui.IWorkbench) IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) EObject(org.eclipse.emf.ecore.EObject) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) PropertySet(org.osate.aadl2.PropertySet) EObject(org.eclipse.emf.ecore.EObject) EList(org.eclipse.emf.common.util.EList) ArrayList(java.util.ArrayList) List(java.util.List) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Example 7 with PropertySet

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;
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) ModelUnit(org.osate.aadl2.ModelUnit) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) PropertySet(org.osate.aadl2.PropertySet)

Example 8 with PropertySet

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);
}
Also used : ModelUnit(org.osate.aadl2.ModelUnit) ArrayList(java.util.ArrayList)

Example 9 with PropertySet

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;
}
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 10 with PropertySet

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();
}
Also used : ComponentInstance(org.osate.aadl2.instance.ComponentInstance) URI(org.eclipse.emf.common.util.URI) PackageSection(org.osate.aadl2.PackageSection) EObject(org.eclipse.emf.ecore.EObject) AadlPackage(org.osate.aadl2.AadlPackage) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) PropertySet(org.osate.aadl2.PropertySet) UiUtil(org.osate.ui.UiUtil) PropertyAssociation(org.osate.aadl2.PropertyAssociation) Stream(java.util.stream.Stream) Classifier(org.osate.aadl2.Classifier) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) Resource(org.eclipse.emf.ecore.resource.Resource) IFile(org.eclipse.core.resources.IFile) ClassifierFeature(org.osate.aadl2.ClassifierFeature) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) AnnexLibrary(org.osate.aadl2.AnnexLibrary) EObjectURIWrapper(org.osate.aadl2.modelsupport.EObjectURIWrapper) ContributedAadlStorage(org.osate.xtext.aadl2.ui.resource.ContributedAadlStorage) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) IFile(org.eclipse.core.resources.IFile) AadlPackage(org.osate.aadl2.AadlPackage) PropertyAssociation(org.osate.aadl2.PropertyAssociation) PackageSection(org.osate.aadl2.PackageSection) Resource(org.eclipse.emf.ecore.resource.Resource) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) Classifier(org.osate.aadl2.Classifier) URI(org.eclipse.emf.common.util.URI) ClassifierFeature(org.osate.aadl2.ClassifierFeature) ContributedAadlStorage(org.osate.xtext.aadl2.ui.resource.ContributedAadlStorage) EObject(org.eclipse.emf.ecore.EObject) EObjectURIWrapper(org.osate.aadl2.modelsupport.EObjectURIWrapper) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) PropertySet(org.osate.aadl2.PropertySet) AnnexLibrary(org.osate.aadl2.AnnexLibrary)

Aggregations

PropertySet (org.osate.aadl2.PropertySet)23 AadlPackage (org.osate.aadl2.AadlPackage)15 EObject (org.eclipse.emf.ecore.EObject)10 ArrayList (java.util.ArrayList)8 Property (org.osate.aadl2.Property)8 Classifier (org.osate.aadl2.Classifier)7 Element (org.osate.aadl2.Element)7 ModelUnit (org.osate.aadl2.ModelUnit)7 EList (org.eclipse.emf.common.util.EList)6 PropertyAssociation (org.osate.aadl2.PropertyAssociation)6 List (java.util.List)5 NamedElement (org.osate.aadl2.NamedElement)5 Resource (org.eclipse.emf.ecore.resource.Resource)4 AnnexLibrary (org.osate.aadl2.AnnexLibrary)4 ComponentClassifier (org.osate.aadl2.ComponentClassifier)4 PackageSection (org.osate.aadl2.PackageSection)4 PropertyConstant (org.osate.aadl2.PropertyConstant)4 PropertyType (org.osate.aadl2.PropertyType)4 Stream (java.util.stream.Stream)3 URI (org.eclipse.emf.common.util.URI)3