Search in sources :

Example 16 with ModelUnit

use of org.osate.aadl2.ModelUnit in project osate2 by osate.

the class ModelLoadingAdapter method getAdapter.

/**
 * XXX: Notice - the methods dealing with EMF Index operations has been moved to the EMFIndexRetrieval Class in org.osate.xtext.aadl2.properties.util
 */
/*
	 * * Usage: ModelUnit target = (ModelUnit)Platform.getAdapterManager().getAdapter(f, ModelUnit.class);
	 */
@Override
public Object getAdapter(Object adaptableObject, Class adapterType) {
    if (adapterType == ModelUnit.class || adapterType == Element.class || adapterType == InstanceObject.class || adapterType == SystemInstance.class) {
        if (adaptableObject instanceof ISelection) {
            final ISelection sel = (ISelection) adaptableObject;
            if (!(sel instanceof IStructuredSelection)) {
                return null;
            }
            final IStructuredSelection selection = (IStructuredSelection) sel;
            if (!(selection.getFirstElement() instanceof IFile)) {
                return null;
            }
            adaptableObject = selection.getFirstElement();
        }
        if (adaptableObject instanceof IFile) {
            final IFile file = (IFile) adaptableObject;
            String ext = file.getFileExtension();
            if (ext == null) {
                return null;
            }
            if (ext.toLowerCase().equals(FileNameConstants.SOURCE_FILE_EXT)) {
                ModelUnit model;
                ResourceSet resourceSet = new ResourceSetImpl();
                String sp = file.getFullPath().toString();
                Resource resource = resourceSet.getResource(URI.createPlatformResourceURI(sp, false), true);
                if (!resource.getContents().isEmpty()) {
                    model = (ModelUnit) resource.getContents().get(0);
                } else {
                    model = null;
                }
                return model;
            } else if (ext.toLowerCase().equals("aaxl2")) {
                SystemInstance model;
                ResourceSet resourceSet = new ResourceSetImpl();
                String sp = file.getFullPath().toString();
                Resource resource = resourceSet.getResource(URI.createPlatformResourceURI(sp, false), true);
                if (!resource.getContents().isEmpty()) {
                    model = (SystemInstance) resource.getContents().get(0);
                } else {
                    model = null;
                }
                return model;
            }
        }
    }
    return null;
}
Also used : IFile(org.eclipse.core.resources.IFile) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) SystemInstance(org.osate.aadl2.instance.SystemInstance) ModelUnit(org.osate.aadl2.ModelUnit) Element(org.osate.aadl2.Element) ISelection(org.eclipse.jface.viewers.ISelection) Resource(org.eclipse.emf.ecore.resource.Resource) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet)

Example 17 with ModelUnit

use of org.osate.aadl2.ModelUnit in project osate2 by osate.

the class PropertiesLinkingDiagnosticMessageProvider method getUnresolvedProxyMessage.

@Override
public DiagnosticMessage getUnresolvedProxyMessage(ILinkingDiagnosticContext context) {
    EClass referenceType = context.getReference().getEReferenceType();
    String targetName = null;
    if (Aadl2Package.eINSTANCE.getAbstractNamedValue() == referenceType) {
        targetName = "Property Constant, Property Definition, Enumeration or Unit literal";
        String msg = "Couldn't resolve reference to " + targetName + " '" + context.getLinkText() + "'." + " For classifier references use classifier( <ref> ).";
        return new DiagnosticMessage(msg, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC);
    }
    boolean suppressError = false;
    if (Aadl2Package.eINSTANCE.getProperty() == referenceType) {
        boolean showWarningInstead = false;
        if (context.getLinkText().indexOf("::") > 0) {
            // get preferences ~ same as org.osate.ui.utils.PropertySetModel
            String[] ignoredPerPreference = getIgnoredPropertySetPreference();
            showWarningInstead = getIgnoredPropertySetAlertPreference();
            // FIXME - should process property set name only
            for (String propSetName : context.getLinkText().split("::")) {
                if (!suppressError) {
                    // check against preference
                    for (String pref : ignoredPerPreference) {
                        if (pref.equalsIgnoreCase(propSetName)) {
                            suppressError = true;
                            break;
                        }
                    }
                }
            }
        }
        String msg = "Couldn't resolve reference to property definition '" + context.getLinkText() + "'." + (context.getLinkText().indexOf("::") < 0 ? " Property set name may be missing." : "");
        if (suppressError) {
            if (showWarningInstead) {
                return new DiagnosticMessage(msg, Severity.WARNING, Diagnostic.LINKING_DIAGNOSTIC);
            } else {
                return null;
            }
        } else {
            return new DiagnosticMessage(msg, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC);
        }
    }
    if (Aadl2Package.eINSTANCE.getPropertyType() == referenceType) {
        String msg = "Couldn't resolve reference to property type '" + context.getLinkText() + "'." + (context.getLinkText().indexOf("::") < 0 ? " Property set name may be missing." : "");
        return new DiagnosticMessage(msg, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC);
    }
    if (Aadl2Package.eINSTANCE.getPropertyConstant() == referenceType) {
        String msg = "Couldn't resolve reference to property constant '" + context.getLinkText() + "'." + (context.getLinkText().indexOf("::") < 0 ? " Property set name may be missing." : "");
        return new DiagnosticMessage(msg, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC);
    }
    if (Aadl2Package.eINSTANCE.getNamedElement() == referenceType) {
        EObject obj = context.getContext();
        if (obj instanceof ContainmentPathElement) {
            Subcomponent sub = AadlUtil.getContainingSubcomponent(obj);
            INode node = NodeModelUtils.findActualNodeFor(obj);
            String name = NodeModelUtils.getTokenText(node);
            if (sub != null && !(obj.eContainer() instanceof ContainmentPathElement)) {
                String msg = "Could not find path element " + name + " in subcomponent " + sub.getName();
                return new DiagnosticMessage(msg, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC);
            }
        }
        String msg = "Couldn't resolve reference to '" + context.getLinkText() + "'.";
        return new DiagnosticMessage(msg, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC);
    }
    if (Aadl2Package.eINSTANCE.getMode() == referenceType) {
        EObject cxt = context.getContext();
        PropertyAssociation pa = AadlUtil.getContainingPropertyAssociation(cxt);
        boolean iscontainedPA = (pa != null && !pa.getAppliesTos().isEmpty());
        String msg = "Couldn't resolve reference to mode '" + context.getLinkText() + "'";
        if (iscontainedPA) {
            EList<ContainedNamedElement> appl = pa.getAppliesTos();
            ContainedNamedElement path = appl.get(appl.size() - 1);
            msg = msg + " in applies to '" + Aadl2Util.getPrintablePathName(path) + "'.";
        } else {
            msg = msg + ".";
        }
        return new DiagnosticMessage(msg, Severity.ERROR, Diagnostic.LINKING_DIAGNOSTIC);
    }
    DiagnosticMessage msg = super.getUnresolvedProxyMessage(context);
    if (referenceType.getName().equals("ModelUnit")) {
        // check against preference
        for (String inIgnoredPrefList : getIgnoredPropertySetPreference()) {
            if (inIgnoredPrefList.equalsIgnoreCase(context.getLinkText())) {
                return new DiagnosticMessage(context.getLinkText() + " property set is missing. Install additional plug-ins that have this property set", Severity.WARNING, Diagnostic.LINKING_DIAGNOSTIC);
            }
        }
    }
    return msg;
}
Also used : EClass(org.eclipse.emf.ecore.EClass) DiagnosticMessage(org.eclipse.xtext.diagnostics.DiagnosticMessage) INode(org.eclipse.xtext.nodemodel.INode) PropertyAssociation(org.osate.aadl2.PropertyAssociation) EObject(org.eclipse.emf.ecore.EObject) Subcomponent(org.osate.aadl2.Subcomponent) ContainmentPathElement(org.osate.aadl2.ContainmentPathElement) ContainedNamedElement(org.osate.aadl2.ContainedNamedElement)

Example 18 with ModelUnit

use of org.osate.aadl2.ModelUnit in project osate2 by osate.

the class OrganizeWithHandler method findMissingWiths.

private List<ModelUnit> findMissingWiths(PackageSection pkgSection) {
    List<ModelUnit> currentWiths = pkgSection.getImportedUnits();
    List<ModelUnit> missingWiths = new ArrayList<ModelUnit>();
    TreeIterator<EObject> packageContents = pkgSection.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(pkgSection.eContainer()))) {
                    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 19 with ModelUnit

use of org.osate.aadl2.ModelUnit in project osate2 by osate.

the class OrganizeWithHandler method organizeWithClauses.

private void organizeWithClauses(PackageSection pkgSection) {
    List<ModelUnit> workingImportedUnits = new ArrayList<ModelUnit>();
    for (ModelUnit nextImportedUnit : pkgSection.getImportedUnits()) {
        workingImportedUnits.add(nextImportedUnit);
    }
    List<ModelUnit> unusedImportedUnits = getUnusedWiths(pkgSection);
    workingImportedUnits.removeAll(unusedImportedUnits);
    List<ModelUnit> missingWiths = findMissingWiths(pkgSection);
    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());
        }
    });
    pkgSection.getImportedUnits().removeAll(pkgSection.getImportedUnits());
    pkgSection.getImportedUnits().addAll(workingImportedUnits);
}
Also used : ModelUnit(org.osate.aadl2.ModelUnit) ArrayList(java.util.ArrayList)

Example 20 with ModelUnit

use of org.osate.aadl2.ModelUnit in project AGREE by loonwerks.

the class AgreeFileUtil method collectResourceFiles.

/**
 * Recursive function to recursively collect all referenced files of the current resource.
 * @param resource - The resource representing the file.
 * @param files - Set of resource path/file names.
 * @throws Exception
 */
private static void collectResourceFiles(Resource resource, Set<IFile> files) throws Exception {
    final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    URI uri = resource.getURI();
    IFile file = workspaceRoot.getFile(new Path(uri.toPlatformString(true)));
    if (uri.segment(0).equals("plugin")) {
        // We're going to ignore these
        return;
    } else if (!file.isAccessible() || !file.exists()) {
        throw new Exception("Unable to access file " + file.getName() + ".");
    } else {
        files.add(file);
    }
    // Get the resources that are referred to (via the 'with' statement)
    EList<EObject> resourceContents = resource.getContents();
    for (EObject eObj : resourceContents) {
        if (eObj instanceof AadlPackage) {
            AadlPackage aadlPackage = (AadlPackage) eObj;
            // Resources included in the public section
            if (aadlPackage.getOwnedPublicSection() != null) {
                final EList<ModelUnit> importedUnits = aadlPackage.getPublicSection().getImportedUnits();
                for (ModelUnit mUnit : importedUnits) {
                    IFile resourceFile = workspaceRoot.getFile(new Path(mUnit.eResource().getURI().toPlatformString(true)));
                    if (!files.contains(resourceFile)) {
                        collectResourceFiles(mUnit.eResource(), files);
                    }
                }
            }
            // Resources included in the private section
            if (aadlPackage.getOwnedPrivateSection() != null) {
                final EList<ModelUnit> importedUnits = aadlPackage.getPrivateSection().getImportedUnits();
                for (ModelUnit mUnit : importedUnits) {
                    IFile resourceFile = workspaceRoot.getFile(new Path(mUnit.eResource().getURI().toPlatformString(true)));
                    if (!files.contains(resourceFile)) {
                        collectResourceFiles(mUnit.eResource(), files);
                    }
                }
            }
        }
    }
    return;
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) AadlPackage(org.osate.aadl2.AadlPackage) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) EObject(org.eclipse.emf.ecore.EObject) ModelUnit(org.osate.aadl2.ModelUnit) URI(org.eclipse.emf.common.util.URI) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

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