Search in sources :

Example 1 with Setting

use of org.eclipse.emf.ecore.EStructuralFeature.Setting in project xtext-core by eclipse.

the class XtextValidator method checkExternalPackage.

protected void checkExternalPackage(ReferencedMetamodel metamodelReference, String importURI) {
    EPackage referencedPackage = metamodelReference.getEPackage();
    if (referencedPackage.eIsProxy() || isRuntime(metamodelReference))
        return;
    if (isRegisteredPackage(referencedPackage)) {
        addIssue("The imported package is not on the classpath of this project which may lead to follow-up errors.", metamodelReference, XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE, INVALID_PACKAGE_REFERENCE_NOT_ON_CLASSPATH, importURI);
        return;
    }
    if (!importURI.equals(referencedPackage.getNsURI())) {
        IResourceDescriptions descriptions = resourceDescriptionsProvider.getResourceDescriptions(metamodelReference.eResource());
        Iterable<IEObjectDescription> packagesInIndex = descriptions.getExportedObjects(EcorePackage.Literals.EPACKAGE, QualifiedName.create(referencedPackage.getNsURI()), false);
        if (!Iterables.isEmpty(packagesInIndex)) {
            addIssue("Packages should be imported by their namespace URI.", metamodelReference, XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE, INVALID_PACKAGE_REFERENCE_EXTERNAL, referencedPackage.getNsURI());
        } else if (!ClasspathUriUtil.isClasspathUri(URI.createURI(importURI))) {
            addIssue("The imported package is not on the classpath of this project which may lead to follow-up errors.", metamodelReference, XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE, INVALID_PACKAGE_REFERENCE_NOT_ON_CLASSPATH, importURI);
            return;
        } else {
            return;
        }
    }
    Map<EObject, Collection<Setting>> allReferences = EcoreUtil.CrossReferencer.find(Collections.singletonList(referencedPackage));
    Set<Object> allReferencedInstances = Sets.newHashSet();
    for (Setting setting : Iterables.concat(allReferences.values())) {
        Object referenced = setting.get(true);
        if (allReferencedInstances.add(referenced) && referenced instanceof EObject) {
            EPackage transitive = EcoreUtil2.getContainerOfType((EObject) referenced, EPackage.class);
            if (isRegisteredPackage(transitive)) {
                if (referenced instanceof EDataType)
                    continue;
                if (referenced == EcorePackage.Literals.EOBJECT)
                    continue;
                IResourceDescriptions descriptions = resourceDescriptionsProvider.getResourceDescriptions(metamodelReference.eResource());
                Iterable<IEObjectDescription> packagesInIndex = descriptions.getExportedObjects(EcorePackage.Literals.EPACKAGE, QualifiedName.create(importURI), false);
                if (!Iterables.isEmpty(packagesInIndex)) {
                    if (setting.getEObject().eResource().getURI().isPlatformResource())
                        addIssue("The imported package refers to elements in the package registry instead of using the instances from the workspace", metamodelReference, XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE, INVALID_PACKAGE_REFERENCE_EXTERNAL, referencedPackage.getNsURI());
                    else
                        addIssue("The imported package refers to elements in the package registry instead of using the instances from the workspace", metamodelReference, XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE, INVALID_PACKAGE_REFERENCE_EXTERNAL);
                    return;
                } else {
                    addIssue("The imported package refers to elements that are not on the classpath of this project. The package '" + transitive.getNsURI() + "' was loaded from the registry.", metamodelReference, XtextPackage.Literals.ABSTRACT_METAMODEL_DECLARATION__EPACKAGE, INVALID_PACKAGE_REFERENCE_NOT_ON_CLASSPATH, referencedPackage.getNsURI());
                    return;
                }
            }
        }
    }
}
Also used : EDataType(org.eclipse.emf.ecore.EDataType) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) EObject(org.eclipse.emf.ecore.EObject) Setting(org.eclipse.emf.ecore.EStructuralFeature.Setting) Collection(java.util.Collection) EObject(org.eclipse.emf.ecore.EObject) EPackage(org.eclipse.emf.ecore.EPackage) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription)

Example 2 with Setting

use of org.eclipse.emf.ecore.EStructuralFeature.Setting in project InformationSystem by ObeoNetwork.

the class TypesServices method getAllReferencingStructuredTypes.

private Collection<StructuredType> getAllReferencingStructuredTypes(StructuredType referencedType) {
    Collection<StructuredType> referencingTypes = new HashSet<StructuredType>();
    Session session = new EObjectQuery(referencedType).getSession();
    Collection<Setting> inverseReferences = null;
    ECrossReferenceAdapter xReferencer = null;
    if (session != null) {
        xReferencer = session.getSemanticCrossReferencer();
    }
    if (xReferencer != null) {
        inverseReferences = xReferencer.getInverseReferences(referencedType);
    } else {
        if (referencedType.eResource() != null && referencedType.eResource().getResourceSet() != null) {
            inverseReferences = UsageCrossReferencer.find(referencedType, referencedType.eResource().getResourceSet());
        }
    }
    if (inverseReferences != null) {
        for (Setting setting : inverseReferences) {
            if (setting.getEObject() instanceof StructuredType && setting.getEStructuralFeature() == EnvironmentPackage.Literals.STRUCTURED_TYPE__SUPERTYPE) {
                referencingTypes.add((StructuredType) setting.getEObject());
            } else if (setting.getEObject() instanceof Reference && setting.getEStructuralFeature() == EnvironmentPackage.Literals.REFERENCE__REFERENCED_TYPE) {
                referencingTypes.add(((Reference) setting.getEObject()).getContainingType());
            }
        }
    }
    return referencingTypes;
}
Also used : EObjectQuery(org.eclipse.sirius.business.api.query.EObjectQuery) ECrossReferenceAdapter(org.eclipse.emf.ecore.util.ECrossReferenceAdapter) Reference(org.obeonetwork.dsl.environment.Reference) Setting(org.eclipse.emf.ecore.EStructuralFeature.Setting) StructuredType(org.obeonetwork.dsl.environment.StructuredType) HashSet(java.util.HashSet) Session(org.eclipse.sirius.business.api.session.Session)

Example 3 with Setting

use of org.eclipse.emf.ecore.EStructuralFeature.Setting in project InformationSystem by ObeoNetwork.

the class DBindingEditorCreationDescriptionImpl method getMappings.

/**
 * {@inheritDoc}
 *
 * @see org.eclipse.sirius.viewpoint.description.tool.impl.RepresentationCreationDescriptionImpl#getMappings()
 * @generated NOT
 */
@Override
public EList<RepresentationElementMapping> getMappings() {
    if (this.eResource() == null) {
        throw new UnsupportedOperationException();
    }
    ECrossReferenceAdapter crossReferencer = ECrossReferenceAdapter.getCrossReferenceAdapter(this.eResource().getResourceSet());
    if (crossReferencer == null) {
        throw new UnsupportedOperationException();
    }
    final List<RepresentationElementMapping> mappings = new LinkedList<RepresentationElementMapping>();
    final Collection<Setting> settings = crossReferencer.getInverseReferences(this, true);
    for (final Setting setting : settings) {
        final EObject eReferencer = setting.getEObject();
        final EStructuralFeature eFeature = setting.getEStructuralFeature();
        if (eReferencer instanceof RepresentationElementMapping && eFeature.equals(org.eclipse.sirius.viewpoint.description.DescriptionPackage.eINSTANCE.getRepresentationElementMapping_DetailDescriptions())) {
            mappings.add((RepresentationElementMapping) eReferencer);
        }
    }
    return new BasicEList<RepresentationElementMapping>(mappings);
}
Also used : ECrossReferenceAdapter(org.eclipse.emf.ecore.util.ECrossReferenceAdapter) RepresentationElementMapping(org.eclipse.sirius.viewpoint.description.RepresentationElementMapping) Setting(org.eclipse.emf.ecore.EStructuralFeature.Setting) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) BasicEList(org.eclipse.emf.common.util.BasicEList) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) LinkedList(java.util.LinkedList)

Example 4 with Setting

use of org.eclipse.emf.ecore.EStructuralFeature.Setting in project InformationSystem by ObeoNetwork.

the class EntityToMLD method getPointingReferencesForIndexCreation.

private Collection<Reference> getPointingReferencesForIndexCreation(Entity entity) {
    @SuppressWarnings("serial") Collection<Setting> settings = new EcoreUtil.UsageCrossReferencer(entity.eResource().getResourceSet()) {

        @Override
        protected boolean crossReference(EObject eObject, EReference eReference, EObject crossReferencedEObject) {
            return super.crossReference(eObject, eReference, crossReferencedEObject) && eReference == EnvironmentPackage.Literals.REFERENCE__REFERENCED_TYPE;
        }

        @Override
        protected boolean containment(EObject eObject) {
            return (eObject instanceof Reference || eObject instanceof Entity || eObject instanceof Namespace || eObject instanceof Root || eObject instanceof org.obeonetwork.dsl.overview.Root);
        }

        public Collection<Setting> findUsage(EObject object) {
            return super.findUsage(object);
        }
    }.findUsage(entity);
    Collection<Reference> references = new ArrayList<Reference>();
    for (Setting setting : settings) {
        if (setting.getEObject() instanceof Reference) {
            Reference reference = (Reference) setting.getEObject();
            if (shouldCreateFKInTarget(reference)) {
                references.add(reference);
            }
        }
    }
    return references;
}
Also used : Entity(org.obeonetwork.dsl.entity.Entity) Root(org.obeonetwork.dsl.entity.Root) Reference(org.obeonetwork.dsl.environment.Reference) EReference(org.eclipse.emf.ecore.EReference) Setting(org.eclipse.emf.ecore.EStructuralFeature.Setting) ArrayList(java.util.ArrayList) Namespace(org.obeonetwork.dsl.environment.Namespace) EObject(org.eclipse.emf.ecore.EObject) Collection(java.util.Collection) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) EReference(org.eclipse.emf.ecore.EReference)

Example 5 with Setting

use of org.eclipse.emf.ecore.EStructuralFeature.Setting in project InformationSystem by ObeoNetwork.

the class ImporterUtil method getReferencingElements.

public static Collection<ReferenceData> getReferencingElements(Collection<EObject> elements, Session session) {
    Collection<ReferenceData> referencesData = new ArrayList<ReferenceData>();
    Collection<EObject> allElements = getAllElementsWithChildren(elements);
    for (EObject element : allElements) {
        Collection<Setting> inverseReferences = session.getSemanticCrossReferencer().getInverseReferences(element, true);
        for (Setting setting : inverseReferences) {
            referencesData.add(new ReferenceData(element, setting));
        }
    }
    return referencesData;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) Setting(org.eclipse.emf.ecore.EStructuralFeature.Setting) ArrayList(java.util.ArrayList)

Aggregations

Setting (org.eclipse.emf.ecore.EStructuralFeature.Setting)16 EObject (org.eclipse.emf.ecore.EObject)11 ArrayList (java.util.ArrayList)7 Resource (org.eclipse.emf.ecore.resource.Resource)7 EReference (org.eclipse.emf.ecore.EReference)5 Collection (java.util.Collection)4 ECrossReferenceAdapter (org.eclipse.emf.ecore.util.ECrossReferenceAdapter)4 System (org.obeonetwork.graal.System)4 GraalUsageCrossReferencer (org.obeonetwork.graal.util.GraalUsageCrossReferencer)4 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 EDataType (org.eclipse.emf.ecore.EDataType)2 EPackage (org.eclipse.emf.ecore.EPackage)2 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2 Session (org.eclipse.sirius.business.api.session.Session)2 Reference (org.obeonetwork.dsl.environment.Reference)2 Requirement (org.obeonetwork.dsl.requirement.Requirement)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URL (java.net.URL)1