Skip to main content
summaryrefslogtreecommitdiffstats
blob: 2d92680e9dfed71b9509ed51ea26cf53b121ed75 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*******************************************************************************
 * Copyright (c) 2016-2017, Thales Global Services S.A.S.
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *   Abel Hegedus, Tamas Borbas, Balazs Grill, Peter Lunk, Daniel Segesdi (IncQuery Labs Ltd.) - initial API and implementation
 *******************************************************************************/
package org.eclipse.emf.diffmerge.patch.runtime.modelaccess

import org.eclipse.emf.common.util.EList
import org.eclipse.emf.ecore.EClass
import org.eclipse.emf.ecore.EObject
import org.eclipse.emf.ecore.EStructuralFeature
import org.eclipse.emf.ecore.util.EcoreUtil

class SimpleReflectiveEMFModelAccess extends AbstractEMFModleAccess {
  override protected doCreate(EClass type) {
    val eObject = type.EPackage.EFactoryInstance.create(type)
    return eObject
  }

  override protected doAdd(EObject container, EStructuralFeature feature, Object element) {
    if(feature.isMany) {
      val featureValueList = container.eGet(feature) as EList
      featureValueList.add(element)
    } else {
      container.eSet(feature, element)
    }
  }

  override protected doAdd(EObject container, EStructuralFeature feature, Object element, int index) {
    val featureValue = container.eGet(feature) as EList
    featureValue.add(index, element)
  }

  override protected doChangeIndex(EObject container, EStructuralFeature feature, Object element, int index) {
    val featureValue = container.eGet(feature) as EList
    featureValue.move(index, element)
  }

  override protected doRemove(EObject element) {
    EcoreUtil.remove(element)
  }

  override protected doRemove(EObject container, EStructuralFeature feature, Object element) {
    if(feature.isMany) {
      val featureValueList = container.eGet(feature) as EList
      featureValueList.remove(element)
    } else {
      container.eUnset(feature)
    }
  }

  override protected doRemove(EObject container, EStructuralFeature feature, int index) {
    val featureValueList = container.eGet(feature) as EList
    featureValueList.remove(index)
  }
}

Back to the top