Search in sources :

Example 1 with ModelUnit

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;
    }
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) AadlPackage(org.osate.aadl2.AadlPackage) ModelUnit(org.osate.aadl2.ModelUnit) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) Classifier(org.osate.aadl2.Classifier) HiddenLeafNode(org.eclipse.xtext.nodemodel.impl.HiddenLeafNode)

Example 2 with ModelUnit

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);
        }
    }
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) PackageSection(org.osate.aadl2.PackageSection) ModelUnit(org.osate.aadl2.ModelUnit) PropertySet(org.osate.aadl2.PropertySet) PropertyType(org.osate.aadl2.PropertyType) ArraySizeProperty(org.osate.aadl2.ArraySizeProperty) Property(org.osate.aadl2.Property)

Example 3 with ModelUnit

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();
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) XtextResource(org.eclipse.xtext.resource.XtextResource) TargetURIs(org.eclipse.xtext.findReferences.TargetURIs) PropertyType(org.osate.aadl2.PropertyType) URI(org.eclipse.emf.common.util.URI) Aadl2LocationInFile(org.osate.xtext.aadl2.util.Aadl2LocationInFile) EObject(org.eclipse.emf.ecore.EObject) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Property(org.osate.aadl2.Property) EReference(org.eclipse.emf.ecore.EReference) IReferenceDescription(org.eclipse.xtext.resource.IReferenceDescription) ComponentType(org.osate.aadl2.ComponentType) BadLocationException(org.eclipse.jface.text.BadLocationException) PropertyConstant(org.osate.aadl2.PropertyConstant) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IReferenceFinder(org.eclipse.xtext.findReferences.IReferenceFinder) ITextRegion(org.eclipse.xtext.util.ITextRegion) ModelUnit(org.osate.aadl2.ModelUnit) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap) NamedElement(org.osate.aadl2.NamedElement) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument)

Example 4 with ModelUnit

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;
}
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 5 with ModelUnit

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

Aggregations

ModelUnit (org.osate.aadl2.ModelUnit)17 AadlPackage (org.osate.aadl2.AadlPackage)8 ArrayList (java.util.ArrayList)6 IFile (org.eclipse.core.resources.IFile)6 EObject (org.eclipse.emf.ecore.EObject)6 PropertySet (org.osate.aadl2.PropertySet)6 BasicEList (org.eclipse.emf.common.util.BasicEList)5 Element (org.osate.aadl2.Element)5 List (java.util.List)3 URI (org.eclipse.emf.common.util.URI)3 INode (org.eclipse.xtext.nodemodel.INode)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 EList (org.eclipse.emf.common.util.EList)2 EClass (org.eclipse.emf.ecore.EClass)2 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)2 HiddenLeafNode (org.eclipse.xtext.nodemodel.impl.HiddenLeafNode)2 org.osate.aadl2 (org.osate.aadl2)2 ComponentImplementation (org.osate.aadl2.ComponentImplementation)2 Property (org.osate.aadl2.Property)2