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