@Override public int size(InternalEObject object, EStructuralFeature feature) { if (feature instanceof EReference) { EReference eReference = (EReference) feature; final Map<Object, Object> cache = pCore.getActiveCache(); if (!(eReference.getEType() instanceof EClass)) { return super.size(object, feature); } PersistentEObject neoEObject = NeoEObjectAdapterFactoryImpl.getAdapter(object, PersistentEObject.class); NeoEMFIndexedCacheKey key = new NeoEMFIndexedCacheKey(neoEObject.id().toString(), eReference, -2); if (cache.containsKey(key)) { pCore.hit(); ; int cachedSize = (int) cache.get(key); if (cachedSize == -1) { return 0; } else { return cachedSize; } } else { pCore.miss(); ; return super.size(object, feature); } } return super.size(object, feature); }
/** {@inheritDoc} Overridden for debugging purposes. */ @Override protected Predicate<Method> getPredicate(EObject context, EReference reference) { String methodName = "scope_" + reference.getEContainingClass().getName() + "_" + reference.getName(); // System.out.println(methodName + " ctx " + context.eClass().getName()); return PolymorphicDispatcher.Predicates.forName(methodName, 2); }
public void cdoInternalPostDetach(boolean remote) { if (remote) { setInstanceContainer(null, eContainerFeatureID()); setInstanceResource(null); return; } // This loop adjusts the opposite wrapper objects to support dangling references. See // Bugzilla_251263_Test InternalCDORevision revision = cdoRevision(); for (EReference reference : classInfo.getAllPersistentReferences()) { if (!reference.isContainer() && classInfo.hasPersistentOpposite(reference)) { if (reference.isMany()) { EReference oppositeReference = reference.getEOpposite(); int size = revision.size(reference); for (int i = 0; i < size; i++) { EObject object = (EObject) getValueFromRevision(reference, i); adjustPersistentOppositeReference(this, object, oppositeReference); } } else { EObject oppositeObject = (EObject) instance.eGet(reference); if (oppositeObject != null) { EReference oppositeReference = reference.getEOpposite(); adjustPersistentOppositeReference(this, oppositeObject, oppositeReference); } } } } }
public static List<EClass> filterByContainmentFeature( Collection<EClass> eClasses, MappingEntry mappingEntry) { EClass superType = null; if (mappingEntry instanceof NodeMapping) { NodeReference nodeReference = (NodeReference) mappingEntry.eContainer(); if (nodeReference != null) { EReference modelReference = nodeReference.getChildrenFeature() != null ? nodeReference.getChildrenFeature() : nodeReference.getContainmentFeature(); if (modelReference != null) { superType = modelReference.getEReferenceType(); } } } else if (mappingEntry instanceof LinkMapping) { if (((LinkMapping) mappingEntry).getContainmentFeature() != null) { superType = ((LinkMapping) mappingEntry).getContainmentFeature().getEReferenceType(); } } return sort( getConcreteEClasses( getSubtypesOf( filterValidEObjectsFrom(eClasses, mappingEntry.eResource().getResourceSet()), superType))); }
@Override public boolean canDelete(IDeleteContext context) { // Participant bands in a ChoreographyTask only be "deleted" (from the model) // if there are no other references to the participant; but they can be "removed" // (from the ChoreographyTask's participantRef list) at any time. // @see RemoveChoreographyParticipantFeature PictogramElement pe = context.getPictogramElement(); if (ChoreographyUtil.isChoreographyParticipantBand(pe)) { int referenceCount = 0; Participant participant = BusinessObjectUtil.getFirstElementOfType(pe, Participant.class); Definitions definitions = ModelUtil.getDefinitions(participant); TreeIterator<EObject> iter = definitions.eAllContents(); while (iter.hasNext()) { EObject o = iter.next(); for (EReference reference : o.eClass().getEAllReferences()) { if (!reference.isContainment() && !(o instanceof DiagramElement)) { if (reference.isMany()) { List list = (List) o.eGet(reference); for (Object referencedObject : list) { if (referencedObject == participant) ++referenceCount; } } else { Object referencedObject = o.eGet(reference); if (referencedObject == participant) ++referenceCount; } } } } return referenceCount <= 1; } return true; }
/** * @see * org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, * org.eclipse.core.runtime.IAdaptable) * @param arg0 * @param arg1 * @return * @throws ExecutionException */ @SuppressWarnings("unchecked") @Override protected CommandResult doExecuteWithResult(IProgressMonitor arg0, IAdaptable arg1) throws ExecutionException { Object createdElement = elementAdapter.getAdapter(EObject.class); if (createdElement instanceof EObject) { EObject eObjectCreatedElement = (EObject) createdElement; for (IGraphicalEditPart parent : graphicalParent) { EObject eObjectSourceReference = parent.resolveSemanticElement(); AbstractContainerNodeDescriptor desc = GroupContainmentRegistry.getContainerDescriptor(parent); List<EReference> refs = desc.getReferenceFor(eObjectCreatedElement.eClass()); for (EReference ref : refs) { if (ref != null && ref.isMany()) { Collection<EObject> collection = (Collection<EObject>) eObjectSourceReference.eGet(ref); if (!collection.contains(eObjectCreatedElement)) { collection.add(eObjectCreatedElement); } } else if (ref != null && !ref.isMany()) { eObjectSourceReference.eSet(ref, eObjectCreatedElement); } } } } return CommandResult.newOKCommandResult(); }
protected void clearReference(EObject obj, EReference ref) { if (!ref.isContainment() && !ref.isContainer() && !ref.isDerived() && ref.isChangeable() && !ref.isTransient()) obj.eUnset(ref); }
private void fillEReference(EObject eObject, JsonNode root, Resource resource) { final EClass eClass = eObject.eClass(); for (Iterator<Entry<String, JsonNode>> it = root.getFields(); it.hasNext(); ) { Entry<String, JsonNode> field = it.next(); String key = field.getKey(); JsonNode value = field.getValue(); EReference reference = getEReference(eClass, key); if (reference != null && !reference.isContainment() && !reference.isDerived() && !reference.isTransient()) { if (value.isArray()) { for (Iterator<JsonNode> itEl = value.getElements(); itEl.hasNext(); ) { JsonNode current = itEl.next(); createProxyReference(eObject, root, current, reference, resource); } } else { createProxyReference(eObject, root, value, reference, resource); } } } for (EObject content : eObject.eContents()) { if (processed.containsKey(content)) fillEReference(content, processed.get(content), resource); } }
private void init() { BasicEList<EStructuralFeature> contains = new UniqueEList<EStructuralFeature>(this.size); BasicEList<EStructuralFeature> crossRefs = new UniqueEList<EStructuralFeature>(this.size); for (int i = 0; i < this.size; ++i) { EStructuralFeature eFeature = (EStructuralFeature) this.data[i]; if (eFeature instanceof EReference) { EReference eReference = (EReference) eFeature; if (eReference.isContainment()) { contains.add(eReference); } else if (!eReference.isContainer()) { crossRefs.add(eReference); } } } contains.shrink(); crossRefs.shrink(); this.containments = new EStructuralFeature[contains.size()]; this.crossReferences = new EStructuralFeature[crossRefs.size()]; int i = 0; for (EStructuralFeature feature : contains) { this.containments[i++] = feature; } i = 0; for (EStructuralFeature feature : crossRefs) { this.crossReferences[i++] = feature; } }
private void createContainment( EObject eObject, EReference reference, JsonNode root, JsonNode node, Resource resource) { if (node.isArray()) { if (reference.isMany()) { @SuppressWarnings("unchecked") EList<EObject> values = (EList<EObject>) eObject.eGet(reference); for (Iterator<JsonNode> it = node.getElements(); it.hasNext(); ) { JsonNode current = it.next(); EObject contained = createContainedObject(reference, root, current, resource); if (contained != null) values.add(contained); } } else if (node.getElements().hasNext()) { JsonNode current = node.getElements().next(); EObject contained = createContainedObject(reference, root, current, resource); if (contained != null) eObject.eSet(reference, contained); } } else { EObject contained = createContainedObject(reference, root, node, resource); if (reference.isMany()) { @SuppressWarnings("unchecked") EList<EObject> values = (EList<EObject>) eObject.eGet(reference); if (contained != null) values.add(contained); } else { if (contained != null) eObject.eSet(reference, contained); } } }
private void setContainmentLink(EObject eObject) { if (eObject.eContainer() != null) { EObject eContainer = eObject.eContainer(); EReference eReference = eObject.eContainmentFeature(); int position = eReference.isMany() ? position = getContainmentPosition(eContainer, eObject) : 0; addLink(eContainer, eObject, eReference, position); } }
private void update( EReference ref, EObject eParentObj, EObject eObj, EObject eRef, EObject eDef) { if (eObj != null && eObj instanceof DataPointComponent) { eDef = ChartDefaultValueUtil.getPercentileDataPointDefObj( (DataPointComponent) eObj, (DataPointComponent) eDef); } update(ref.getEReferenceType(), ref.getName(), eParentObj, eObj, eRef, eDef); }
private static void getNsURI(StringBuilder s, EObject element) { if (element instanceof org.eclipse.ocl.examples.pivot.Package) { String nsURI = ((org.eclipse.ocl.examples.pivot.Package) element).getNsURI(); if (nsURI != null) { s.append(nsURI); return; } } else if (element instanceof EPackage) { String nsURI = ((EPackage) element).getNsURI(); if (nsURI != null) { s.append(nsURI); return; } } EObject eContainer = element.eContainer(); if (eContainer instanceof org.eclipse.ocl.examples.pivot.Package) { String nsURI = ((org.eclipse.ocl.examples.pivot.Package) element).getNsURI(); if (nsURI != null) { s.append(nsURI); s.append("#/"); } else { getNsURI(s, eContainer); } } else if (eContainer instanceof EPackage) { String nsURI = ((EPackage) element).getNsURI(); if (nsURI != null) { s.append(nsURI); s.append("#/"); } else { getNsURI(s, eContainer); } } else if (eContainer == null) { String name = null; if (element instanceof org.eclipse.ocl.examples.pivot.Package) { name = ((org.eclipse.ocl.examples.pivot.Package) element).getName(); } else if (element instanceof EPackage) { name = ((EPackage) element).getName(); } if (name == null) { name = "$null$"; } s.append(name); return; } else { getNsURI(s, eContainer); } EReference eFeature = element.eContainmentFeature(); s.append("@"); s.append(eFeature.getName()); if (eFeature.isMany()) { int index = ((List<?>) eContainer.eGet(element.eContainingFeature())).indexOf(element); s.append("."); s.append(index); } }
/** * Convenient implementation of the {@link #getLinkElements(InternalProject, EObject, EReference)} * method to use the {@link ItemPropertyDescriptor} to get all object of an object. * * @param project the project the call is from * @param modelElement {@link EObject} to add the {@link EReference} to * @param eReference the {@link EReference} to add * @return {@link Iterator} of {@link EObject} that can be linked */ @Override public Iterator<EObject> getLinkElements( InternalProject project, EObject modelElement, EReference eReference) { final EClass elementClass = modelElement.eClass(); EClassifier type = EcoreUtil.getReifiedType(elementClass, eReference.getEGenericType()).getEClassifier(); if (type == null) { type = eReference.getEType(); } return ItemPropertyDescriptor.getReachableObjectsOfType(modelElement, type).iterator(); }
private static void checkObject( EObject expected, EObject actual, Set<EStructuralFeature> excludeFeatures, Set<EObject> visited) { if (expected == null) { assertThat(actual, is(nullValue())); return; } if (visited.contains(expected)) return; visited.add(expected); assertThat( "Actual instance for type '" + expected.eClass().getName() + "' must not be null", actual, is(notNullValue())); for (EAttribute attribute : expected.eClass().getEAllAttributes()) { if (!excludeFeatures.contains(attribute)) assertThat( "Attribute '" + attribute.getName() + "' on class '" + expected.eClass().getName() + "' did not match", actual.eGet(attribute), is(expected.eGet(attribute))); } for (EReference reference : expected.eClass().getEAllReferences()) { if (excludeFeatures.contains(reference)) continue; if (reference.isMany()) { @SuppressWarnings("unchecked") EList<EObject> expectedObjects = (EList<EObject>) expected.eGet(reference); @SuppressWarnings("unchecked") EList<EObject> actualObjects = (EList<EObject>) actual.eGet(reference); assertThat( "Reference size for '" + reference.getName() + "' does not match", actualObjects.size(), is(expectedObjects.size())); for (int i = 0; i < expectedObjects.size(); i++) checkObject(expectedObjects.get(i), actualObjects.get(i), excludeFeatures, visited); } else checkObject( (EObject) expected.eGet(reference), (EObject) actual.eGet(reference), excludeFeatures, visited); } }
public void findLocalReferences( Set<? extends EObject> targets, IAcceptor<IReferenceDescription> acceptor, Predicate<IReferenceDescription> filter, IProgressMonitor monitor) { if (monitor != null && monitor.isCanceled()) return; if (targets != null && !targets.isEmpty()) { Set<Resource> targetResources = new HashSet<Resource>(); for (EObject target : targets) { targetResources.add(target.eResource()); } Map<EObject, Collection<Setting>> targetResourceInternalCrossRefs = CrossReferencer.find(targetResources); Map<EObject, URI> exportedElementsMap = null; SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.ReferenceQuery_monitor, targets.size()); for (EObject target : targets) { Collection<Setting> crossRefSettings = targetResourceInternalCrossRefs.get(target); if (crossRefSettings != null) { SubMonitor subSubMonitor = subMonitor.newChild(crossRefSettings.size()); for (Setting crossRefSetting : crossRefSettings) { if (subSubMonitor.isCanceled()) return; EObject source = crossRefSetting.getEObject(); if (crossRefSetting.getEStructuralFeature() instanceof EReference) { EReference reference = (EReference) crossRefSetting.getEStructuralFeature(); int index = 0; if (reference.isMany()) { List<?> values = (List<?>) source.eGet(reference); for (int i = 0; i < values.size(); ++i) { if (target == values.get(i)) { index = i; break; } } } if (exportedElementsMap == null) exportedElementsMap = createExportedElementsMap(target.eResource()); IReferenceDescription localReferenceDescription = new DefaultReferenceDescription( source, target, reference, index, findClosestExportedContainerURI(source, exportedElementsMap)); if (filter == null || filter.apply(localReferenceDescription)) acceptor.accept(localReferenceDescription); } subSubMonitor.worked(1); } } } } }
/** * Returns all valid references for an EObject. This excludes container/containment references. A * reference is valid if it is neither derived nor volatile and if it is changeable and either * many-valued or not already set. * * @param eObject the EObject to get references for * @param exceptionLog the current log of exceptions * @param ignoreAndLog should exceptions be ignored and added to <code>exceptionLog</code>? * @return all valid references as a list */ public static List<EReference> getValidReferences( EObject eObject, Set<RuntimeException> exceptionLog, boolean ignoreAndLog) { List<EReference> result = new LinkedList<EReference>(); for (EReference reference : eObject.eClass().getEAllReferences()) { if (!reference.isContainer() && !reference.isContainment() && isValid(reference, eObject, exceptionLog, ignoreAndLog) && (reference.isMany() || !eObject.eIsSet(reference))) { result.add(reference); } } return result; }
public static Collection<EReference> getEReferences( Collection<EReference> eReferences, boolean containmentOnly) { if (!containmentOnly) { return eReferences; } for (Iterator<EReference> it = eReferences.iterator(); it.hasNext(); ) { EReference nextReference = it.next(); if (nextReference != null && !nextReference.isContainment()) { it.remove(); } } return eReferences; }
void resolve(EObject object, EReference reference, EObject proxy) { EReference opposite = reference.getEOpposite(); if (opposite != null) { if (opposite.isMany()) { InternalEList<?> list = (InternalEList<?>) object.eGet(opposite, false); int index = list.basicIndexOf(proxy); if (index >= 0) { list.get(index); // resolve just this index } } else { object.eGet(opposite, true); // resolve the scalar reference } } }
public void resolveFuzzy( String identifier, org.eclipse.emf.ecore.EObject container, org.eclipse.emf.ecore.EReference reference, int position, org.emftext.language.office.resource.office.IOfficeReferenceResolveResult< org.eclipse.emf.ecore.EObject> result) { if (container == null) { return; } if (org.emftext.language.office.OfficePackage.eINSTANCE.getEmployee().isInstance(container)) { OfficeFuzzyResolveResult<org.emftext.language.office.Office> frr = new OfficeFuzzyResolveResult<org.emftext.language.office.Office>(result); String referenceName = reference.getName(); org.eclipse.emf.ecore.EStructuralFeature feature = container.eClass().getEStructuralFeature(referenceName); if (feature != null && feature instanceof org.eclipse.emf.ecore.EReference && referenceName != null && referenceName.equals("worksIn")) { employeeWorksInReferenceResolver.resolve( identifier, (org.emftext.language.office.Employee) container, (org.eclipse.emf.ecore.EReference) feature, position, true, frr); } } if (org.emftext.language.office.OfficePackage.eINSTANCE.getEmployee().isInstance(container)) { OfficeFuzzyResolveResult<org.emftext.language.office.Employee> frr = new OfficeFuzzyResolveResult<org.emftext.language.office.Employee>(result); String referenceName = reference.getName(); org.eclipse.emf.ecore.EStructuralFeature feature = container.eClass().getEStructuralFeature(referenceName); if (feature != null && feature instanceof org.eclipse.emf.ecore.EReference && referenceName != null && referenceName.equals("worksWith")) { employeeWorksWithReferenceResolver.resolve( identifier, (org.emftext.language.office.Employee) container, (org.eclipse.emf.ecore.EReference) feature, position, true, frr); } } }
@Before public void before() { ePackage = FACTORY.createEPackage(); ePackage.setName("Package"); eClass0 = FACTORY.createEClass(); eClass0.setName("EClass0"); ePackage.getEClassifiers().add(eClass0); eClass1 = FACTORY.createEClass(); eClass1.setName("EClass1"); ePackage.getEClassifiers().add(eClass1); singleRef = FACTORY.createEReference(); singleRef.setName("singleRef"); singleRef.setUpperBound(1); singleRef.setEType(eClass1); singleRef.setContainment(true); eClass0.getEStructuralFeatures().add(singleRef); multiRef = FACTORY.createEReference(); multiRef.setName("multiRef"); multiRef.setUpperBound(-1); multiRef.setEType(eClass0); multiRef.setContainment(true); eClass1.getEStructuralFeatures().add(multiRef); }
public static Collection<EReference> getEReferencesOfType( Collection<EReference> references, EClass referenceType) { Collection<EReference> result = getValidEStructuralFeatures(references); if (referenceType == null) { return result; } for (Iterator<EReference> it = result.iterator(); it.hasNext(); ) { EReference nextFeature = it.next(); if (nextFeature != null && !nextFeature.getEReferenceType().isSuperTypeOf(referenceType)) { it.remove(); } } return result; }
protected < ContainerType extends org.eclipse.emf.ecore.EObject, ReferenceType extends org.eclipse.emf.ecore.EObject> void registerContextDependentProxy( final ASPM.resource.ASPM.mopp.ASPMContextDependentURIFragmentFactory< ContainerType, ReferenceType> factory, final ContainerType container, final org.eclipse.emf.ecore.EReference reference, final String id, final org.eclipse.emf.ecore.EObject proxy) { final int position; if (reference.isMany()) { position = ((java.util.List<?>) container.eGet(reference)).size(); } else { position = -1; } postParseCommands.add( new ASPM.resource.ASPM.IASPMCommand<ASPM.resource.ASPM.IASPMTextResource>() { public boolean execute(ASPM.resource.ASPM.IASPMTextResource resource) { if (resource == null) { // the resource can be null if the parser is used for code completion return true; } resource.registerContextDependentProxy( factory, container, reference, id, proxy, position); return true; } }); }
private void addLink( EObject sourceEObject, EObject targetEObject, EReference eReference, int targetPosition) { Object_ sourceObject = map.getObject(sourceEObject); Object_ targetObject = map.getObject(targetEObject); Association association = getFUMLAssociation(eReference); if (hasOppositeReference(eReference) && haveProcessedAsOpposite(eReference, sourceObject, targetObject, association)) { return; } // Setup target property end LinkCreationData linkData = new LinkCreationData(sourceObject, targetObject, association); LinkEndCreationData targetEndData = linkData.createLinkEndCreationData(); targetEndData.setEnd(getTargetPropertyEnd(eReference, association)); linkData.setTargetEndData(targetEndData); linkData.setTargetPosition(targetPosition); // Setup source property end LinkEndCreationData sourceEndData = linkData.createLinkEndCreationData(); if (hasOppositeReference(eReference)) { EReference oppositeReference = eReference.getEOpposite(); sourceEndData.setEnd(getTargetPropertyEnd(oppositeReference, association)); int sourcePosition = getPosition(targetEObject, oppositeReference, sourceEObject); linkData.setSourcePosition(sourcePosition); addProcessedOpposite(sourceEndData); } else { sourceEndData.setEnd(getSourcePropertyEnd(eReference, association)); } linkData.setSourceEndData(sourceEndData); Link link = linkData.createNewLink(); map.addExtensionalValue(link); // link.addTo(locus); locus.add(link); }
private void handleMultipleResults() { org.eclipse.emf.common.util.EList<org.eclipse.emf.ecore.EObject> list = null; Object temp = container.eGet(reference); if (temp instanceof org.eclipse.emf.common.util.EList<?>) { list = org.emftext.sdk.concretesyntax.resource.cs.util.CsCastUtil.cast(temp); } boolean first = true; for (org.emftext.sdk.concretesyntax.resource.cs.ICsReferenceMapping<ReferenceType> mapping : result.getMappings()) { if (first) { first = false; } else if (list != null) { addResultToList(mapping, proxy, list); } else { new org.emftext.sdk.concretesyntax.resource.cs.util.CsRuntimeUtil() .logError( container.eClass().getName() + "." + reference.getName() + " has multiplicity 1 but was resolved to multiple elements", null); } } }
/** * Sets or adds to a reference for an EObject with any generated instance of <code>referenceClass * </code> using SetCommand/AddCommand. If the reference is not required, <code>random</code> * decides whether the reference is set or how many EObjects are added to it. * * @param eObject the EObject to set the reference for * @param referenceClass the EClass all referenced EObject shall be instances of * @param reference the reference to set * @param random the Random-object that randomizes EObjects and their amount * @param exceptionLog the current log of exceptions * @param ignoreAndLog should exceptions be ignored and added to <code>exceptionLog</code>? * @param allEObjects all existing EObjects mapped to their EClass * @see #addPerCommand(EObject, EStructuralFeature, Collection, Set, boolean) * @see #addPerCommand(EObject, EStructuralFeature, Object, Set, boolean) * @see #setPerCommand(EObject, EStructuralFeature, Object, Set, boolean) */ public static void setReference( EObject eObject, EClass referenceClass, EReference reference, Random random, Set<RuntimeException> exceptionLog, boolean ignoreAndLog, Map<EClass, List<EObject>> allEObjects) { List<EObject> possibleReferenceObjects = allEObjects.get(referenceClass); Collections.shuffle(possibleReferenceObjects, random); if (!possibleReferenceObjects.isEmpty()) { int index = 0; if (reference.isMany()) { int numberOfReferences = computeFeatureAmount(reference, random); for (int i = 0; i < numberOfReferences; i++) { ModelGeneratorUtil.addPerCommand( eObject, reference, possibleReferenceObjects.get(index), exceptionLog, ignoreAndLog); // ensures every EObject is set at most once if (++index == possibleReferenceObjects.size()) { break; } } // Change of referencing // Delete reference.isRequired() in order to set 0..1 references // } else if (reference.isRequired() || random.nextBoolean()){ } else if (random.nextBoolean()) { ModelGeneratorUtil.setPerCommand( eObject, reference, possibleReferenceObjects.get(index), exceptionLog, ignoreAndLog); } } }
protected void computeReferencedJvmTypeHighlighting( IHighlightedPositionAcceptor acceptor, EObject referencer, CancelIndicator cancelIndicator) { for (EReference reference : referencer.eClass().getEAllReferences()) { EClass referencedType = reference.getEReferenceType(); if (EcoreUtil2.isAssignableFrom(TypesPackage.Literals.JVM_TYPE, referencedType)) { List<EObject> referencedObjects = EcoreUtil2.getAllReferencedObjects(referencer, reference); if (referencedObjects.size() > 0) operationCanceledManager.checkCanceled(cancelIndicator); for (EObject referencedObject : referencedObjects) { EObject resolvedReferencedObject = EcoreUtil.resolve(referencedObject, referencer); if (resolvedReferencedObject != null && !resolvedReferencedObject.eIsProxy()) { highlightReferenceJvmType(acceptor, referencer, reference, resolvedReferencedObject); } } } } }
/** * Returns a list that holds the opposite elements of the given reference for the given owner. The * opposite elements are those of type E that have the reference to owner. * * <p>The collection corresponding to opposite in the following picture is returned, for given * owner and reference. * * <pre> * <b>opposite</b> reference * E ----------------------------- owner * </pre> * * reference has to be a key of the map observedRefToOpposite. * * @param <E> * @param <E> The type of the elements in the collection. * @param dataClass The class of the elements in the collection. * @param owner The object whose list is retrieved. * @param reference The reference whose opposite reference is retrieved. * @return The opposite of reference for owner. */ public <E> List<E> getOppositeList( Class<E> dataClass, InternalEObject owner, EReference reference) { EReference opposite = observedRefToOpposite.get(reference); if (opposite == null) throw new IllegalArgumentException( "This reference is not observed by this adapter: " + reference.toString()); EObjectEList<E> result = new EObjectEList<E>(dataClass, owner, opposite.getFeatureID()); for (Setting cur : getNonNavigableInverseReferences(owner, false)) { if (cur.getEStructuralFeature().equals(reference)) result.add(dataClass.cast(cur.getEObject())); } return result; }
private void adjustPersistentOppositeReference( InternalCDOObject cdoObject, EObject oppositeObject, EReference oppositeReference) { InternalCDOObject oppositeCDOObject = (InternalCDOObject) CDOUtil.getCDOObject(oppositeObject); if (oppositeCDOObject != null) { InternalCDOView view = oppositeCDOObject.cdoView(); if (view != null) { CDOStore store = viewAndState.view.getStore(); if (store != null) { if (oppositeReference.isMany()) { EObject eObject = oppositeCDOObject.cdoInternalInstance(); @SuppressWarnings("unchecked") EList<Object> list = (EList<Object>) eObject.eGet(oppositeReference); int index = list.indexOf(instance); if (index != EStore.NO_INDEX && !store.isEmpty(oppositeCDOObject, oppositeReference)) { store.set(oppositeCDOObject, oppositeReference, index, cdoObject); } } else { store.set(oppositeCDOObject, oppositeReference, 0, cdoObject); } } } } }
/** * Converts the value of an EReference with isMany==false, the value is converted to a Object and * set in the correct feature in the model managed object. * * @param eObject the eObject from which the value is read * @param modelObject the Object in which the value is to be set * @param eReference the eReference which is converted */ protected void convertSingleEReference( final EObject eObject, final ModelObject<?> modelObject, final EReference eReference) { // bidirectional one-to-many are always set from the many side to preserve the order final EObject value = (EObject) eObject.eGet(eReference); if (!eReference.isMany() && value != null && eReference.getEOpposite() != null && eReference.getEOpposite().isMany()) { return; } if (value == null) { modelObject.eSet(eReference, null); } else { modelObject.eSet(eReference, createTarget(value)); } }