Search in sources :

Example 66 with EReference

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

the class PartialSerializer method findRegion.

protected IAstRegion findRegion(IEObjectRegion owner, FeatureChange change) {
    EStructuralFeature feature = change.getFeature();
    if (feature instanceof EReference && ((EReference) feature).isContainment()) {
        ITextRegionAccess access = owner.getTextRegionAccess();
        EObject oldValue = change.getReferenceValue();
        if (oldValue != null) {
            return access.regionForEObject(oldValue);
        }
        EObject value = (EObject) owner.getSemanticElement().eGet(feature);
        if (value != null) {
            return access.regionForEObject(value);
        }
        return null;
    } else {
        return owner.getRegionFor().feature(feature);
    }
}
Also used : ITextRegionAccess(org.eclipse.xtext.formatting2.regionaccess.ITextRegionAccess) EObject(org.eclipse.emf.ecore.EObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EReference(org.eclipse.emf.ecore.EReference)

Example 67 with EReference

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

the class ReferenceUpdater method createUpdatableReference.

protected IUpdatableReference createUpdatableReference(ISemanticRegion current) {
    EReference ref = (EReference) current.getContainingFeature();
    CrossReference crossRef = GrammarUtil.containingCrossReference(current.getGrammarElement());
    EObject owner = current.getContainingRegion().getSemanticElement();
    Object value = owner.eGet(ref);
    if (value instanceof List<?>) {
        List<?> targets = (List<?>) value;
        int i = current.getIndexInContainingFeature();
        EObject t = (EObject) targets.get(i);
        if (t != null && !t.eIsProxy()) {
            return new UpdatableReference(owner, ref, i, t, crossRef, current);
        }
    } else if (value instanceof EObject) {
        EObject t = (EObject) value;
        if (!t.eIsProxy()) {
            return new UpdatableReference(owner, ref, -1, t, crossRef, current);
        }
    } else {
        throw new IllegalStateException();
    }
    return null;
}
Also used : IUpdatableReference(org.eclipse.xtext.ide.serializer.hooks.IUpdatableReference) EObject(org.eclipse.emf.ecore.EObject) CrossReference(org.eclipse.xtext.CrossReference) EObject(org.eclipse.emf.ecore.EObject) List(java.util.List) EReference(org.eclipse.emf.ecore.EReference)

Example 68 with EReference

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

the class ResourceLifecycleManager method openAndApplyReferences.

public Resource openAndApplyReferences(ResourceSet resourceSet, RelatedResource toLoad) {
    Resource resource = resourceSet.getResource(toLoad.getUri(), true);
    for (IReferenceSnapshot desc : toLoad.outgoingReferences) {
        EObject source = resource.getEObject(desc.getSourceEObjectUri().fragment());
        EObject target = desc.getTarget().getObject();
        EReference reference = desc.getEReference();
        if (reference.isMany()) {
            @SuppressWarnings("unchecked") List<Object> list = (EList<Object>) source.eGet(reference, false);
            list.set(desc.getIndexInList(), target);
        } else {
            source.eSet(reference, target);
        }
    }
    return resource;
}
Also used : EList(org.eclipse.emf.common.util.EList) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) RelatedResource(org.eclipse.xtext.ide.serializer.impl.RelatedResourcesProvider.RelatedResource) EObject(org.eclipse.emf.ecore.EObject) IReferenceSnapshot(org.eclipse.xtext.ide.serializer.hooks.IReferenceSnapshot) EReference(org.eclipse.emf.ecore.EReference)

Example 69 with EReference

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

the class EcoreUtil2Test method testGetAllReferencedObjects.

@Test
public void testGetAllReferencedObjects() {
    EClass a = createEClass("a");
    EClass b = createEClass("b");
    EPackage pack = EcoreFactory.eINSTANCE.createEPackage();
    pack.setName("empty");
    pack.setNsPrefix("empty");
    pack.setNsURI("empty");
    pack.getEClassifiers().add(a);
    pack.getEClassifiers().add(b);
    EReference ref = EcoreFactory.eINSTANCE.createEReference();
    a.getEStructuralFeatures().add(ref);
    ref.setUpperBound(1);
    ref.setEType(b);
    EObject objA = pack.getEFactoryInstance().create(a);
    EObject objB = pack.getEFactoryInstance().create(b);
    List<EObject> res = EcoreUtil2.getAllReferencedObjects(objA, ref);
    assertNotNull(res);
    assertTrue(res.isEmpty());
    res = EcoreUtil2.getAllReferencedObjects(objA, ref);
    assertNotNull(res);
    objA.eSet(ref, objB);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EObject(org.eclipse.emf.ecore.EObject) EReference(org.eclipse.emf.ecore.EReference) EPackage(org.eclipse.emf.ecore.EPackage) Test(org.junit.Test)

Example 70 with EReference

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

the class EcoreUtil2Test method testExternalFormOfEReferenceNoNPE.

/**
 * This test assumes that an EPackage with indexed references is no longer available.
 */
@Test
public void testExternalFormOfEReferenceNoNPE() throws Exception {
    EReference reference = EcorePackage.Literals.EATTRIBUTE__EATTRIBUTE_TYPE;
    URI uri = EcoreUtil.getURI(reference);
    String externalForm = uri.toString();
    EReference foundReference = EcoreUtil2.getEReferenceFromExternalForm(EPackage.Registry.INSTANCE, externalForm);
    assertSame(reference, foundReference);
    String brokenExternalFrom = makeInvalid(externalForm);
    assertNull(EcoreUtil2.getEReferenceFromExternalForm(EPackage.Registry.INSTANCE, brokenExternalFrom));
    String shortExternalForm = EcoreUtil2.toExternalForm(reference);
    foundReference = EcoreUtil2.getEReferenceFromExternalForm(EPackage.Registry.INSTANCE, shortExternalForm);
    assertSame(reference, foundReference);
    String brokenShortExternalFrom = makeInvalid(shortExternalForm);
    assertNull(EcoreUtil2.getEReferenceFromExternalForm(EPackage.Registry.INSTANCE, brokenShortExternalFrom));
    brokenShortExternalFrom = shortExternalForm.replace('A', 'a');
    assertNull(EcoreUtil2.getEReferenceFromExternalForm(EPackage.Registry.INSTANCE, brokenShortExternalFrom));
}
Also used : URI(org.eclipse.emf.common.util.URI) EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Aggregations

EReference (org.eclipse.emf.ecore.EReference)229 EObject (org.eclipse.emf.ecore.EObject)118 EClass (org.eclipse.emf.ecore.EClass)58 List (java.util.List)52 ArrayList (java.util.ArrayList)48 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)37 Test (org.junit.Test)31 EAttribute (org.eclipse.emf.ecore.EAttribute)29 PalladioSelectEObjectDialog (org.palladiosimulator.editors.commons.dialogs.selection.PalladioSelectEObjectDialog)28 EClassifier (org.eclipse.emf.ecore.EClassifier)21 Resource (org.eclipse.emf.ecore.resource.Resource)21 IdEObject (org.bimserver.emf.IdEObject)18 EList (org.eclipse.emf.common.util.EList)17 IScope (org.eclipse.xtext.scoping.IScope)15 HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)14 InternalEObject (org.eclipse.emf.ecore.InternalEObject)14 URI (org.eclipse.emf.common.util.URI)13 EPackage (org.eclipse.emf.ecore.EPackage)12 AbstractEList (org.eclipse.emf.common.util.AbstractEList)10 CrossReference (org.eclipse.xtext.CrossReference)10