Skip to main content
summaryrefslogtreecommitdiffstats
blob: ad6114e8c140281939f8d4a8cd19b90e663c1cae (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*******************************************************************************
 * Copyright (c) 2017 Thales Global Services S.A.S.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Abel Hegedus (IncQuery Labs Ltd.) - initial API and implementation
 *******************************************************************************/
package org.eclipse.emf.diffmerge.patch.persistence.emf.transform

import org.apache.log4j.Logger
import org.eclipse.emf.diffmerge.patch.AbstractModelPatchEntry
import org.eclipse.emf.diffmerge.patch.AttributeEntry
import org.eclipse.emf.diffmerge.patch.ElementEntry
import org.eclipse.emf.diffmerge.patch.ReferenceEntry
import org.eclipse.emf.diffmerge.patch.StructuralFeatureEntry
import org.eclipse.emf.diffmerge.patch.api.BaseModelPatchMetadata
import org.eclipse.emf.diffmerge.patch.api.ChangeDirection
import org.eclipse.emf.diffmerge.patch.api.Identifiable
import org.eclipse.emf.diffmerge.patch.api.ModelPatch
import org.eclipse.emf.diffmerge.patch.api.ModelPatchEntry
import org.eclipse.emf.diffmerge.patch.persistence.emf.emodelpatch.EAttributeEntry
import org.eclipse.emf.diffmerge.patch.persistence.emf.emodelpatch.EChangeDirection
import org.eclipse.emf.diffmerge.patch.persistence.emf.emodelpatch.EElementEntry
import org.eclipse.emf.diffmerge.patch.persistence.emf.emodelpatch.EIdentifiable
import org.eclipse.emf.diffmerge.patch.persistence.emf.emodelpatch.EModelPatch
import org.eclipse.emf.diffmerge.patch.persistence.emf.emodelpatch.EModelPatchEMFMetadata
import org.eclipse.emf.diffmerge.patch.persistence.emf.emodelpatch.EModelPatchEntry
import org.eclipse.emf.diffmerge.patch.persistence.emf.emodelpatch.EModelPatchMetadata
import org.eclipse.emf.diffmerge.patch.persistence.emf.emodelpatch.EReferenceEntry
import org.eclipse.emf.diffmerge.patch.persistence.emf.emodelpatch.EStructuralFeatureEntry
import org.eclipse.emf.diffmerge.patch.runtime.EMFModelPatchMetadata

class EModelPatchToPOJO {

  val EModelPatch source
  val ModelPatch target
  val Logger logger

  new(EModelPatch source, ModelPatch target, Logger logger) {
    this.source = source
    this.target = target
    this.logger = logger

  }

  def transform(){
    source.metadata.transformElement

    source.entries.filter(EModelPatchEntry).forEach[
      it.transformElement
    ]
  }

  protected def void transformElement(EModelPatchMetadata emetadata) {
    val metadata = if(emetadata instanceof EModelPatchEMFMetadata
    ){
      new EMFModelPatchMetadata => [
        modelUriList += emetadata.modelUris
        usedNamespaceUris += emetadata.usedNamespaceUris
      ]
    } else {
      new BaseModelPatchMetadata
    }
    metadata => [
      author = emetadata.author
      createdAt = emetadata.createdAt
      description = emetadata.description
      input = emetadata.input
    ]
    target.metadata = metadata
    return
  }

  protected def void transformElement(EModelPatchEntry entry) {
    val eentry = entry.transformEntry
    target.entries.add(eentry)
    return
  }

  protected def dispatch ModelPatchEntry transformEntry(EElementEntry entry) {
    new ElementEntry => [
      entry.transformAbstractEntryFeatures(it)
      type = entry.type.toIdentifiable
    ]
  }

  protected def dispatch ModelPatchEntry transformEntry(EAttributeEntry entry) {
    new AttributeEntry => [
      entry.transformStructuralFeatureEntryFeatures(it)
      value = entry.value
    ]
  }

  protected def dispatch ModelPatchEntry transformEntry(EReferenceEntry entry) {
    new ReferenceEntry => [
      entry.transformStructuralFeatureEntryFeatures(it)
      target = entry.target.toIdentifiable
    ]
  }

  protected def transformAbstractEntryFeatures(EModelPatchEntry eentry, AbstractModelPatchEntry entry) {
      entry.direction = eentry.direction.transformDirection
      entry.context = eentry.context.toIdentifiable
  }

  protected def transformStructuralFeatureEntryFeatures(EStructuralFeatureEntry eentry, StructuralFeatureEntry entry) {
      eentry.transformAbstractEntryFeatures(entry)
      entry.feature = eentry.feature.toIdentifiable
  }

  protected def toIdentifiable(EIdentifiable eidentifiable) {
    new Identifiable(eidentifiable.targetIdentifier)
  }

  protected def transformDirection(EChangeDirection direction) {
    return switch direction {
      case ADD: ChangeDirection.ADD
      case REMOVE: ChangeDirection.REMOVE
    }
  }

}

Back to the top