Search in sources :

Example 1 with EObjectResolvingEList

use of org.eclipse.emf.ecore.util.EObjectResolvingEList in project BIMserver by opensourceBIM.

the class IfcPrinter method printMap.

@SuppressWarnings("unchecked")
public void printMap(Map<Long, EObject> map) {
    for (Long key : map.keySet()) {
        EObject object = map.get(key);
        System.out.println("#" + key + " " + object.eClass().getName());
        for (EAttribute attribute : object.eClass().getEAllAttributes()) {
            System.out.println("\t" + attribute.getName() + "(" + attribute.getEType().getName() + "): " + object.eGet(attribute));
        }
        for (EReference reference : object.eClass().getEAllReferences()) {
            System.out.println("\t" + reference.getName() + "(" + reference.getEReferenceType().getName() + "): ");
            if (object.eGet(reference) instanceof EObjectResolvingEList) {
                EObjectResolvingEList<EObject> referencedObjectList = (EObjectResolvingEList<EObject>) object.eGet(reference);
                if (referencedObjectList != null && referencedObjectList.size() > 0) {
                    if (reference.getEReferenceType().getEStructuralFeature("wrappedValue") != null) {
                        for (Object obj : referencedObjectList) {
                            Object wrappedValue = ((EObject) obj).eGet(reference.getEReferenceType().getEStructuralFeature("wrappedValue"));
                            System.out.println(wrappedValue.toString());
                            if (referencedObjectList.get(referencedObjectList.size() - 1) != obj) {
                                System.out.println();
                                System.out.println("\t" + reference.getName() + "(" + reference.getEReferenceType().getName() + "): ");
                            }
                        }
                    } else {
                        for (Object obj : referencedObjectList) {
                            if (obj != null) {
                                System.out.println("=> ");
                            }
                        }
                    }
                }
            } else if (reference.getEReferenceType().getEStructuralFeature("wrappedValue") != null) {
            // EObject object2 = (EObject)object.eGet(reference);
            // if (object2 != null) {
            // Object wrappedValue = object2.eGet(reference.getEReferenceType().getEStructuralFeature("wrappedValue"));
            // Logger.log(wrappedValue);
            // }
            } else {
                if (object.eGet(reference) != null) {
                    System.out.println("=>");
                } else {
                    System.out.println("null");
                }
            }
            System.out.println();
        }
    }
}
Also used : EAttribute(org.eclipse.emf.ecore.EAttribute) EObjectResolvingEList(org.eclipse.emf.ecore.util.EObjectResolvingEList) EObject(org.eclipse.emf.ecore.EObject) EObject(org.eclipse.emf.ecore.EObject) EReference(org.eclipse.emf.ecore.EReference)

Example 2 with EObjectResolvingEList

use of org.eclipse.emf.ecore.util.EObjectResolvingEList in project dsl-devkit by dsldevkit.

the class AbstractScopingTest method getCrossReferencedObject.

/**
 * Returns the referenced {@link EObject} pointed to by the cross reference.
 * <p>
 * <em>Note</em>: For implicit item traversal to work, a custom implementation must be provided by overriding this method.
 * </p>
 *
 * @param sourceTag
 *          the source tag
 * @param traverseImplicitItems
 *          If target of a reference is an implicit item and this parameter is set to true, the test will get and compare the original object from which this
 *          implicit item was created.
 * @param crossReference
 *          Cross reference to be resolved, must not be {@code null}
 * @return the referenced {@link EObject}, must not be {@code null}
 */
protected EObject getCrossReferencedObject(final int sourceTag, final boolean traverseImplicitItems, final CrossReference crossReference) {
    EObject context = getObjectForTag(sourceTag);
    if (crossReference == null) {
        // $NON-NLS-1$
        throw new IllegalArgumentException(NLS.bind("Cross reference on object ''{0}'' could not be resolved.", context.toString()));
    }
    // We only handle references in assignments
    Assignment assignment = EObjectUtil.eContainer(crossReference, Assignment.class);
    EObject sourceObject = null;
    String featureName = assignment.getFeature();
    EReference reference = (EReference) context.eClass().getEStructuralFeature(featureName);
    if (reference.isMany()) {
        Object featureValue = context.eGet(reference, false);
        // $NON-NLS-1$
        assertTrue("List must be of type EObjectResolvingEList", featureValue instanceof EObjectResolvingEList);
        @SuppressWarnings("unchecked") EObjectResolvingEList<? extends EObject> objects = (EObjectResolvingEList<? extends EObject>) context.eGet(reference, false);
        if (objects.size() == 1) {
            sourceObject = EcoreUtil.resolve(objects.get(0), context);
        } else {
            // TODO DSL-166: Handle this case when needed for tests.
            // $NON-NLS-1$
            fail("Multiple references not supported yet");
        }
    } else {
        sourceObject = (EObject) context.eGet(reference, true);
    }
    // $NON-NLS-1$
    assertNotNull("Bad test. Referenced object is null.", sourceObject);
    return sourceObject;
}
Also used : Assignment(org.eclipse.xtext.Assignment) EObjectResolvingEList(org.eclipse.emf.ecore.util.EObjectResolvingEList) EObject(org.eclipse.emf.ecore.EObject) EObject(org.eclipse.emf.ecore.EObject) EReference(org.eclipse.emf.ecore.EReference)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)2 EReference (org.eclipse.emf.ecore.EReference)2 EObjectResolvingEList (org.eclipse.emf.ecore.util.EObjectResolvingEList)2 EAttribute (org.eclipse.emf.ecore.EAttribute)1 Assignment (org.eclipse.xtext.Assignment)1