@SuppressWarnings({"unchecked", "rawtypes"})
 private void setSourceRef(
     DataAssociation association,
     ItemAwareElement value,
     EObject container,
     EStructuralFeature containerFeature) {
   if (association.getSourceRef().size() == 0) {
     if (container != null) {
       if (containerFeature.isMany()) ((List) container.eGet(containerFeature)).add(value);
       else container.eSet(containerFeature, value);
     }
     if (value == null) association.getSourceRef().clear();
     else association.getSourceRef().add(value);
     updateConnectionIfNeeded(association, value);
   } else {
     if (container != null) {
       if (containerFeature.isMany()) ((List) container.eGet(containerFeature)).add(value);
       else container.eSet(containerFeature, value);
     }
     updateConnectionIfNeeded(association, value);
     if (value == null) association.getSourceRef().clear();
     else association.getSourceRef().set(0, value);
     updateConnectionIfNeeded(association, value);
   }
   if (association.getTargetRef() != null) {
     ItemAwareElement targetRef = association.getTargetRef();
     if (value != null) targetRef.setItemSubjectRef(value.getItemSubjectRef());
     else targetRef.setItemSubjectRef(null);
     updateConnectionIfNeeded(association, value);
   }
 }
Exemplo n.º 2
0
 protected String toString(IEObjectRegion region) {
   EObject obj = region.getSemanticElement();
   StringBuilder builder =
       new StringBuilder(Strings.padEnd(toClassWithName(obj), textWidth, ' ') + " ");
   EObject element = region.getGrammarElement();
   if (element instanceof AbstractElement)
     builder.append(grammarToString.apply((AbstractElement) element));
   else if (element instanceof AbstractRule) builder.append(((AbstractRule) element).getName());
   else builder.append(": ERROR: No grammar element.");
   List<String> segments = Lists.newArrayList();
   EObject current = obj;
   while (current.eContainer() != null) {
     EObject container = current.eContainer();
     EStructuralFeature containingFeature = current.eContainingFeature();
     StringBuilder segment = new StringBuilder();
     segment.append(toClassWithName(container));
     segment.append("/");
     segment.append(containingFeature.getName());
     if (containingFeature.isMany()) {
       int index = ((List<?>) container.eGet(containingFeature)).indexOf(current);
       segment.append("[" + index + "]");
     }
     current = container;
     segments.add(segment.toString());
   }
   if (!segments.isEmpty()) {
     builder.append(" path:");
     builder.append(Joiner.on("=").join(segments));
   }
   return builder.toString();
 }
Exemplo n.º 3
0
 public CharSequence assignmentOperator(final EStructuralFeature it) {
   StringConcatenation _builder = new StringConcatenation();
   {
     boolean _isMany = it.isMany();
     if (_isMany) {
       _builder.append("+=");
     } else {
       boolean _and = false;
       EClassifier _eType = it.getEType();
       boolean _isBoolean = Ecore2XtextExtensions.isBoolean(_eType);
       if (!_isBoolean) {
         _and = false;
       } else {
         boolean _isPrefixBooleanFeature = Ecore2XtextExtensions.isPrefixBooleanFeature(it);
         _and = (_isBoolean && _isPrefixBooleanFeature);
       }
       if (_and) {
         _builder.append("?=");
       } else {
         _builder.append("=");
       }
     }
   }
   return _builder;
 }
    UncontrolUpdate(
        EStructuralFeature.Setting setting,
        EObject originalObject,
        CDOID originalProxy,
        URI destinationURI,
        CDOID destinationProxy) {
      super(setting);
      this.originalObject = originalObject;
      this.originalProxy = originalProxy;
      this.destinationURI = destinationURI;
      this.destinationProxy = destinationProxy;

      EStructuralFeature feature = setting.getEStructuralFeature();
      InternalEObject owner = (InternalEObject) setting.getEObject();

      if (!feature.isMany()) {
        index = EStore.NO_INDEX;
      } else {
        // don't go directly to the store because it may have proxies.
        // Use the resolved view in the EObject, instead
        index = ((EList<?>) owner.eGet(feature)).indexOf(originalObject);
        if (index < 0) {
          Activator.log.error(
              "Setting does not include the object being replaced by a proxy.",
              null); //$NON-NLS-1$
        }
      }
    }
Exemplo n.º 5
0
 public static boolean isMany(EClass eClass, String featureName) {
   if (eClass == null || featureName == null) {
     return false;
   }
   EStructuralFeature feature = eClass.getEStructuralFeature(featureName);
   return feature != null && feature.isMany();
 }
Exemplo n.º 6
0
  /**
   * CDO persists the isUnset state of an eObject in the database. The indicator for this is that
   * the feature is null in the revision (see CDOStore.isSet()). When committing a legacy object all
   * values in the instance for native attributes are set with the java default values. So, these
   * values will be stored in the revision and CDO cannot distinguish whether the feature is set or
   * not. This method must ensure that the value will be set to null if the feature is not set.
   */
  public void cdoInternalPreCommit() {
    // We have to set this here because the CDOLegacyAdapter will not be notified when the instance
    // is the target of a
    // single-directional containment reference.
    // If the container is not an legacy Object the system will get no information
    instanceToRevisionContainment();

    InternalCDORevision revision = cdoRevision();
    for (EStructuralFeature feature : classInfo.getAllPersistentFeatures()) {
      if (feature.isUnsettable()) {
        if (!isSetInstanceValue(instance, feature)) {
          if (feature.isMany()) {
            @SuppressWarnings("unchecked")
            InternalEList<Object> list = (InternalEList<Object>) instance.eGet(feature);
            clearEList(list);
          } else {
            revision.set(feature, EStore.NO_INDEX, null);
          }
        } else if (instance.eGet(feature) == null) {
          // Must be single-valued!
          revision.set(feature, EStore.NO_INDEX, CDORevisionData.NIL);
        }
      }
    }
  }
Exemplo n.º 7
0
  public Object get(EStructuralFeature feature, int index) {
    if (feature.isMany()) {
      CDOList list = getList(feature);
      return list.get(index);
    }

    return getValue(feature);
  }
Exemplo n.º 8
0
  public <T> T[] toArray(EStructuralFeature feature, T[] array) {
    if (!feature.isMany()) {
      throw new IllegalStateException("!feature.isMany()");
    }

    CDOList list = getList(feature);
    return list.toArray(array);
  }
Exemplo n.º 9
0
  public Object set(EStructuralFeature feature, int index, Object value) {
    if (feature.isMany()) {
      CDOList list = getList(feature);
      return list.set(index, value);
    }

    return setValue(feature, value);
  }
    @Override
    public void revert() {
      EStructuralFeature feature = setting.getEStructuralFeature();

      if (index >= 0 || !feature.isMany()) {
        InternalEObject owner = (InternalEObject) setting.getEObject();
        store.set(owner, feature, index, CDOUtils.getCDOID(originalObject));
      }
    }
    @Override
    public void apply() {
      EStructuralFeature feature = setting.getEStructuralFeature();

      if ((index >= 0) || !feature.isMany()) {
        InternalEObject owner = (InternalEObject) setting.getEObject();
        store.set(owner, feature, index, proxy);
      }
    }
Exemplo n.º 12
0
    /**
     * @return the result feature delta, or <code>null</code> to indicate an unresolved conflict.
     */
    protected CDOFeatureDelta changedInSourceAndTarget(
        CDOFeatureDelta targetFeatureDelta, CDOFeatureDelta sourceFeatureDelta) {
      EStructuralFeature feature = targetFeatureDelta.getFeature();
      if (feature.isMany()) {
        return changedInSourceAndTargetManyValued(feature, targetFeatureDelta, sourceFeatureDelta);
      }

      return changedInSourceAndTargetSingleValued(feature, targetFeatureDelta, sourceFeatureDelta);
    }
Exemplo n.º 13
0
 public static void eSetOrAdd(
     EObject obj, EStructuralFeature feature, Object value, int newIndex) {
   if (feature.isMany() && value != null) {
     List featureList = ((List) obj.eGet(feature));
     if (newIndex >= 0 && newIndex < featureList.size()) featureList.add(newIndex, value);
     else featureList.add(value);
   } else {
     obj.eSet(feature, value);
   }
 }
Exemplo n.º 14
0
 private void writeEDataType(PrintWriter out, EObject object, EStructuralFeature feature)
     throws SerializerException {
   if (feature.getEAnnotation("derived") != null) {
     out.print(ASTERISK);
   } else if (feature.isMany()) {
     writeList(out, object, feature);
   } else {
     writeObject(out, object, feature);
   }
 }
Exemplo n.º 15
0
 /**
  * Computes the random amount of objects to add to a feature.
  *
  * @param feature the feature to compute the amount of objects for
  * @param random the Random object used to obtain random values
  * @return 1 if the feature is single valued,<br>
  *     a random value from 0 to 10 if the feature is many-valued and has no upper bound,<br>
  *     a random value between the feature's lower and upper bound otherwise
  */
 private static int computeFeatureAmount(EStructuralFeature feature, Random random) {
   if (!feature.isMany()) {
     return 1;
   }
   if (feature.getUpperBound() < feature.getLowerBound()) {
     return random.nextInt(10);
   }
   return feature.getLowerBound()
       + random.nextInt(feature.getUpperBound() - feature.getLowerBound() + 1);
 }
 /**
  * Clears an EObject's feature, that is removes all objects from a many-valued feature. If the
  * target is single-valued, nothing is done.
  *
  * @param eObject the EObject to clear the feature for
  * @param feature the EStructuralFeature that shall be cleared
  */
 protected static void clear(EObject eObject, EStructuralFeature feature) {
   if (eObject.eIsSet(feature)) {
     if (feature.isMany()) {
       ModelGeneratorUtil.removePerCommand(
           eObject, feature, (Collection<?>) eObject.eGet(feature), exceptionLog, ignoreAndLog);
     } else {
       ModelGeneratorUtil.setPerCommand(eObject, feature, null, exceptionLog, ignoreAndLog);
     }
   }
 }
Exemplo n.º 17
0
 /**
  * This basically calls a setter via EMF reflection to set a structural feature.
  *
  * <ul>
  *   <li>If <code>value</code> is a {@link List} of elements, the feature <code>ref</code> must,
  *       of course, also be a list.
  *   <li>If <code>value</code> is a single element, then <code>ref</code> might have multiplicity
  *       <code>1</code> or it might also be a list. In the latter case, <code>value</code> is
  *       added to the list.
  * </ul>
  *
  * @param obj The object which holds the feature to set.
  * @param ref The feature which should be set.
  * @param value The value that should be set.
  * @return <code>true</code>, if the value could be set or <b>if it was already set</b>; <code>
  *     false</code> otherwise.
  */
 @SuppressWarnings("unchecked")
 public static boolean setStructuralFeature(EObject obj, EStructuralFeature ref, Object value) {
   if (!ref.isChangeable()) {
     throw new IllegalArgumentException(
         "Cannot set a non-changeable reference: " + obj.eClass().getName() + "." + ref.getName());
   }
   try {
     if (ref.isMany()) {
       final List<Object> list = (List<Object>) obj.eGet(ref);
       if (value instanceof List) {
         final List<Object> valueList = (List<Object>) value;
         for (final Object listValue : valueList) {
           if (!list.contains(listValue) && !list.add(listValue)) {
             return false;
           }
         }
       } else {
         if (!list.contains(value) && !list.add(value)) {
           return false;
         }
       }
       return true;
     } else {
       if (value instanceof List) {
         final List<Object> valueList = (List<Object>) value;
         if (valueList.size() > 1) {
           throw new IllegalArgumentException(
               "Cannot set a list of values to a non-many feature!");
         } else if (valueList.size() == 1) {
           if (obj.eGet(ref) == null || !obj.eGet(ref).equals(valueList.get(0))) {
             obj.eSet(ref, valueList.get(0));
           }
         } else {
           obj.eSet(ref, null);
         }
       } else {
         if (obj.eGet(ref) == null || !obj.eGet(ref).equals(value)) {
           obj.eSet(ref, value);
         }
       }
       return true;
     }
   } catch (final Exception e) {
     throw new IllegalArgumentException(
         "Could not set value ("
             + value
             + ") to: "
             + obj.eClass().getName()
             + "."
             + ref.getName()
             + " of object "
             + obj,
         e);
   }
 }
Exemplo n.º 18
0
  protected void convertContent(EObject eObject) {
    final Object target = objectMapping.get(eObject);

    final ModelObject<?> modelObject = ModelResolver.getInstance().getModelObject(target);
    for (final EStructuralFeature eStructuralFeature :
        modelObject.eClass().getEAllStructuralFeatures()) {
      if (!eStructuralFeature.isChangeable() || eStructuralFeature.isVolatile()) {
        continue;
      }

      // not set, not convert
      if (!eStructuralFeature.isMany() && !eObject.eIsSet(eStructuralFeature)) {
        continue;
      }

      if (FeatureMapUtil.isFeatureMap(eStructuralFeature)) {
        convertFeatureMap(eObject, modelObject, eStructuralFeature);
      } else if (eStructuralFeature.isMany()) {
        if (eStructuralFeature instanceof EAttribute) {
          final EAttribute eAttribute = (EAttribute) eStructuralFeature;
          convertManyEAttribute(eObject, modelObject, eAttribute);
        } else {
          final EReference eReference = (EReference) eStructuralFeature;
          if (eReference.isContainer()) {
            continue;
          }
          convertManyEReference(eObject, modelObject, eReference);
        }
      } else {
        if (eStructuralFeature instanceof EAttribute) {
          final EAttribute eAttribute = (EAttribute) eStructuralFeature;
          convertSingleEAttribute(eObject, modelObject, eAttribute);
        } else {
          final EReference eReference = (EReference) eStructuralFeature;
          if (eReference.isContainer()) {
            continue;
          }
          convertSingleEReference(eObject, modelObject, eReference);
        }
      }
    }
  }
Exemplo n.º 19
0
 public static void replaceInContainer(final EObject search, final EObject replacement) {
   EObject container = search.eContainer();
   EStructuralFeature f = search.eContainingFeature();
   if (f.isMany()) {
     @SuppressWarnings("unchecked")
     EList<? super EObject> l = (EList<? super EObject>) container.eGet(f);
     l.set(l.indexOf(search), replacement);
   } else {
     container.eSet(f, replacement);
   }
 }
Exemplo n.º 20
0
  /**
   * IMPORTANT: Compile errors in this method might indicate an old version of EMF. Legacy support
   * is only enabled for EMF with fixed bug #247130. These compile errors do not affect native
   * models!
   */
  protected void resolveProxies(EStructuralFeature feature) {
    Object value = getInstanceValue(instance, feature);
    if (value != null) {
      if (feature.isMany()) {
        @SuppressWarnings("unchecked")
        InternalEList<Object> list = (InternalEList<Object>) value;
        int size = list.size();

        boolean deliver = instance.eDeliver();
        if (deliver) {
          instance.eSetDeliver(false);
        }

        for (int i = 0; i < size; i++) {
          Object element = list.get(i);
          if (element instanceof LegacyProxy) {
            CDOID id = ((LegacyProxy) element).getID();
            InternalCDOObject resolved = (InternalCDOObject) viewAndState.view.getObject(id);
            InternalEObject instance = resolved.cdoInternalInstance();

            // TODO LEGACY
            // // TODO Is InternalEList.basicSet() needed???
            // if (list instanceof
            // org.eclipse.emf.ecore.util.DelegatingInternalEList)
            // {
            // list =
            // ((org.eclipse.emf.ecore.util.DelegatingInternalEList)list).getDelegateInternalEList();
            // }

            // if (list instanceof NotifyingListImpl<?>)
            // {
            // ((NotifyingListImpl<Object>)list).basicSet(i, instance, null);
            // }
            // else
            // {
            list.set(i, instance);
            // }
          }
        }

        if (deliver) {
          instance.eSetDeliver(true);
        }
      } else {
        if (value instanceof LegacyProxy) {
          CDOID id = ((LegacyProxy) value).getID();
          InternalCDOObject resolved = (InternalCDOObject) viewAndState.view.getObject(id);
          InternalEObject instance = resolved.cdoInternalInstance();
          setInstanceValue(instance, feature, instance);
        }
      }
    }
  }
    @Override
    public void revert() {
      EStructuralFeature feature = setting.getEStructuralFeature();

      if (index >= 0 || !feature.isMany()) {
        InternalEObject owner = (InternalEObject) setting.getEObject();

        // on reversion, we are processing only references that were external
        // to the unit that was to be re-integrated, so necessarily all
        // references must be set to the original proxies
        store.set(owner, feature, index, originalProxy);
      }
    }
Exemplo n.º 22
0
  /** @since 4.0 */
  public boolean adjustReferences(CDOReferenceAdjuster referenceAdjuster) {
    if (TRACER.isEnabled()) {
      TRACER.format("Adjusting references for revision {0}", this);
    }

    boolean changed = false;

    CDOID id1 =
        (CDOID)
            referenceAdjuster.adjustReference(
                resourceID, CDOContainerFeatureDelta.CONTAINER_FEATURE, CDOFeatureDelta.NO_INDEX);
    if (id1 != resourceID) {
      resourceID = id1;
      changed = true;
    }

    Object id2 =
        referenceAdjuster.adjustReference(
            containerID, CDOContainerFeatureDelta.CONTAINER_FEATURE, CDOFeatureDelta.NO_INDEX);
    if (id2 != containerID) {
      containerID = id2;
      changed = true;
    }

    EStructuralFeature[] features = getAllPersistentFeatures();
    for (int i = 0; i < features.length; i++) {
      EStructuralFeature feature = features[i];
      if (feature instanceof EReference || FeatureMapUtil.isFeatureMap(feature)) {
        if (feature.isMany()) {
          InternalCDOList list = (InternalCDOList) getValueAsList(i);
          if (list != null) {
            changed |= list.adjustReferences(referenceAdjuster, feature);
          }
        } else {
          CDOType type = CDOModelUtil.getType(feature);
          Object oldValue = getValue(i);
          Object newValue =
              type.adjustReferences(referenceAdjuster, oldValue, feature, CDOFeatureDelta.NO_INDEX);
          if (oldValue != newValue) // Just an optimization for NOOP adjusters
          {
            setValue(i, newValue);
            changed = true;
          }
        }
      }
    }

    return changed;
  }
 public Set<QualifiedName> getImportedNames(XtextResource resource) {
   XPackage xPackage = getXPackage(resource);
   String packageName = xPackage.getName();
   List<String> implicitPackageImports = newArrayList(packageName, "java.lang");
   Set<QualifiedName> importedNames = newLinkedHashSet();
   Map<String, QualifiedName> implicitAliases = getImplicitAliases();
   for (INode node : XcoreUtil.importableCrossReferences(xPackage)) {
     CrossReference grammarElement = (CrossReference) node.getGrammarElement();
     EObject container = grammarElement.eContainer();
     if (container instanceof Assignment) {
       String name = node.getText().trim();
       if (name.endsWith("::")) {
         name = name.substring(0, name.length() - 2);
       }
       QualifiedName actualQualifiedName = nameConverter.toQualifiedName(name);
       Assignment assignment = (Assignment) container;
       String feature = assignment.getFeature();
       EObject semanticObject = NodeModelUtils.findActualSemanticObjectFor(node);
       EStructuralFeature eStructuralFeature =
           semanticObject.eClass().getEStructuralFeature(feature);
       if (!eStructuralFeature.isMany()) {
         EObject eCrossReference = (EObject) semanticObject.eGet(eStructuralFeature);
         EObject eContainer = eCrossReference.eContainer();
         if (eContainer != xPackage
             && !(eContainer instanceof XPackage
                 && "xcore.lang".equals(((XPackage) eContainer).getName()))
             && !(eContainer instanceof GenPackage
                 && packageName.equals(((GenPackage) eContainer).getQualifiedPackageName()))
             && !(eCrossReference instanceof JvmDeclaredType
                 && implicitPackageImports.contains(
                     ((JvmDeclaredType) eCrossReference).getPackageName()))) {
           QualifiedName fullyQualifiedName = nameProvider.getFullyQualifiedName(eCrossReference);
           if (fullyQualifiedName != null
               && !actualQualifiedName.equals(fullyQualifiedName)
               && !fullyQualifiedName.equals(implicitAliases.get(name))) {
             importedNames.add(fullyQualifiedName);
           }
         }
       } else {
         throw new RuntimeException("Not expecting multi-valued cross references in these models");
       }
     } else {
       throw new RuntimeException(
           "Expecting all cross references to be part of an assignment in these models");
     }
   }
   return importedNames;
 }
Exemplo n.º 24
0
 /**
  * Detach object from its container so that a child-stealing detection is avoided when attaching
  * to a new container.
  */
 public static void resetContainer(@NonNull EObject eObject) {
   EStructuralFeature eContainingFeature = eObject.eContainingFeature();
   if (eContainingFeature != null) {
     EObject eContainer = eObject.eContainer();
     if (eContainer != null) {
       if (!eContainingFeature.isMany()) {
         eContainer.eSet(eContainingFeature, null);
       } else {
         Object objects = eContainer.eGet(eContainingFeature);
         if (objects instanceof List<?>) {
           ((List<?>) objects).remove(eObject);
         }
       }
     }
   }
 }
    @Override
    public void apply() {
      EStructuralFeature feature = setting.getEStructuralFeature();

      if ((index >= 0) || !feature.isMany()) {
        InternalEObject owner = (InternalEObject) setting.getEObject();

        if ((destinationURI == null) || inUnit(owner, destinationURI)) {
          // direct reference
          store.set(owner, feature, index, CDOUtils.getCDOID(originalObject));
        } else {
          // proxy reference for cross-unit
          store.set(owner, feature, index, destinationProxy);
        }
      }
    }
 @Override
 public double isApplicable(EObject domainObject, VDomainModelReference dmr) {
   final EStructuralFeature feature =
       EMFFormsSpreadsheetValueConverterHelper.getFeature(
           domainObject, dmr, databinding, reportService);
   if (feature == null) {
     return NOT_APPLICABLE;
   }
   if (!EAttribute.class.isInstance(feature)) {
     return NOT_APPLICABLE;
   }
   if (!feature.isMany()) {
     return NOT_APPLICABLE;
   }
   return 0d;
 }
Exemplo n.º 27
0
  /** @since 4.1 */
  public void freeze() {
    flags |= FROZEN_FLAG;

    if (isReadable()) {
      EStructuralFeature[] features = getAllPersistentFeatures();
      for (int i = 0; i < features.length; i++) {
        EStructuralFeature feature = features[i];
        if (feature.isMany()) {
          InternalCDOList list = (InternalCDOList) doGetValue(i);
          if (list != null) {
            list.freeze();
          }
        }
      }
    }
  }
Exemplo n.º 28
0
 private void writeObject(PrintWriter out, EObject object, EStructuralFeature feature)
     throws SerializerException {
   Object ref = object.eGet(feature);
   if (ref == null || (feature.isUnsettable() && !object.eIsSet(feature))) {
     EClassifier type = feature.getEType();
     if (type instanceof EClass) {
       EStructuralFeature structuralFeature = ((EClass) type).getEStructuralFeature(WRAPPED_VALUE);
       if (structuralFeature != null) {
         String name = structuralFeature.getEType().getName();
         if (name.equals(IFC_BOOLEAN)
             || name.equals(IFC_LOGICAL)
             || structuralFeature.getEType() == EcorePackage.eINSTANCE.getEBoolean()) {
           out.print(BOOLEAN_UNDEFINED);
         } else {
           out.print(DOLLAR);
         }
       } else {
         out.print(DOLLAR);
       }
     } else {
       if (type == EcorePackage.eINSTANCE.getEBoolean()) {
         out.print(BOOLEAN_UNDEFINED);
       } else if (feature.isMany()) {
         out.print("()");
       } else {
         out.print(DOLLAR);
       }
     }
   } else {
     if (ref instanceof EObject) {
       writeEmbedded(out, (EObject) ref);
     } else if (feature.getEType() == ECORE_PACKAGE_INSTANCE.getEDouble()) {
       Object stringValue =
           object.eGet(object.eClass().getEStructuralFeature(feature.getName() + "AsString"));
       if (stringValue != null && model.isUseDoubleStrings()) {
         out.print(stringValue);
       } else {
         writePrimitive(out, ref);
       }
     } else {
       writePrimitive(out, ref);
     }
   }
 }
 @SuppressWarnings({"unchecked", "rawtypes"})
 private void setTargetRef(
     DataAssociation association,
     ItemAwareElement value,
     EObject container,
     EStructuralFeature containerFeature) {
   if (container != null) {
     if (containerFeature.isMany()) ((List) container.eGet(containerFeature)).add(value);
     else container.eSet(containerFeature, value);
   }
   updateConnectionIfNeeded(association, value);
   association.setTargetRef(value);
   if (!association.getSourceRef().isEmpty()) {
     ItemAwareElement sourceRef = association.getSourceRef().get(0);
     if (value != null) sourceRef.setItemSubjectRef(value.getItemSubjectRef());
     else sourceRef.setItemSubjectRef(null);
   }
   updateConnectionIfNeeded(association, value);
 }
 @SuppressWarnings("unchecked")
 private void refreshDerivedFeature() {
   logger.trace("[Notify: " + derivedFeature.getName() + "] Derived refresh.");
   try {
     if (source.eNotificationRequired()) {
       if (type == null) {
         type = derivedFeature.getEType();
       }
       if (derivedFeature.isMany()) {
         if (currentValue != null) {
           oldValue = new HashSet<EObject>((Collection<EObject>) currentValue);
         } else {
           oldValue = new HashSet<EObject>();
         }
         currentValue = new HashSet<EObject>();
         Collection<? extends Object> targets =
             (Collection<? extends Object>) source.eGet(derivedFeature);
         int position = 0;
         for (Object target : targets) {
           comprehension.traverseFeature(visitor, source, derivedFeature, target, position++);
         }
         if (currentValue instanceof Collection<?> && oldValue instanceof Collection<?>) {
           ((Collection<?>) oldValue).removeAll((Collection<?>) currentValue);
           if (((Collection<?>) oldValue).size() > 0) {
             sendRemoveManyNotification(source, derivedFeature, oldValue);
           }
         }
       } else {
         Object target = source.eGet(derivedFeature);
         comprehension.traverseFeature(visitor, source, derivedFeature, target, null);
       }
     }
   } catch (Exception ex) {
     logger.error(
         "The derived feature adapter encountered an error in processing the EMF model. "
             + "This happened while maintaining the derived feature "
             + derivedFeature.getName()
             + " of object "
             + source,
         ex);
   }
 }