Search in sources :

Example 6 with PackageSection

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;
}
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 PackageSection

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);
        }
    });
}
Also used : FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) AadlPackage(org.osate.aadl2.AadlPackage) FeaturePrototype(org.osate.aadl2.FeaturePrototype) PackageSection(org.osate.aadl2.PackageSection) EObject(org.eclipse.emf.ecore.EObject) FeatureGroupType(org.osate.aadl2.FeatureGroupType) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) ComponentPrototype(org.osate.aadl2.ComponentPrototype)

Example 8 with PackageSection

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;
}
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 9 with PackageSection

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

Example 10 with PackageSection

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;
}
Also used : PackageSection(org.osate.aadl2.PackageSection) PrivatePackageSection(org.osate.aadl2.PrivatePackageSection) PublicPackageSection(org.osate.aadl2.PublicPackageSection) EObject(org.eclipse.emf.ecore.EObject) Classifier(org.osate.aadl2.Classifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) PrivatePackageSection(org.osate.aadl2.PrivatePackageSection) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement) NamedElement(org.osate.aadl2.NamedElement) Namespace(org.osate.aadl2.Namespace)

Aggregations

PackageSection (org.osate.aadl2.PackageSection)23 AadlPackage (org.osate.aadl2.AadlPackage)18 Classifier (org.osate.aadl2.Classifier)13 PropertySet (org.osate.aadl2.PropertySet)9 EObject (org.eclipse.emf.ecore.EObject)8 NamedElement (org.osate.aadl2.NamedElement)8 ComponentClassifier (org.osate.aadl2.ComponentClassifier)6 ModelUnit (org.osate.aadl2.ModelUnit)6 ClassifierFeature (org.osate.aadl2.ClassifierFeature)4 ComponentType (org.osate.aadl2.ComponentType)4 PrivatePackageSection (org.osate.aadl2.PrivatePackageSection)4 Property (org.osate.aadl2.Property)4 ArrayList (java.util.ArrayList)3 Resource (org.eclipse.emf.ecore.resource.Resource)3 AnnexLibrary (org.osate.aadl2.AnnexLibrary)3 ComponentImplementation (org.osate.aadl2.ComponentImplementation)3 PropertyType (org.osate.aadl2.PropertyType)3 PublicPackageSection (org.osate.aadl2.PublicPackageSection)3 QualifiedNamedElement (org.osate.ba.declarative.QualifiedNamedElement)3 Stream (java.util.stream.Stream)2