Skip to main content
summaryrefslogtreecommitdiffstats
blob: be472166a41bd8c089eca81449c9e6407c326a68 (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
/*******************************************************************************
 * 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, Peter Lunk, Daniel Segesdi (IncQuery Labs Ltd.) - initial API and implementation
 *******************************************************************************/
package org.eclipse.emf.diffmerge.patch.api.filters

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.IModelPatchEntryFilter
import org.eclipse.emf.diffmerge.patch.api.ModelPatchEntry
import org.eclipse.emf.diffmerge.patch.api.ModelPatchEntryProperty
import org.eclipse.xtend.lib.annotations.Accessors

import static com.google.common.base.Preconditions.*

class EntryPropertyFilter implements IModelPatchEntryFilter {
  @Accessors(PUBLIC_GETTER)
  private ModelPatchEntryProperty filteredProperty
  @Accessors(PUBLIC_GETTER)
  private String filteredValue

  new(ModelPatchEntryProperty filteredProperty, String filteredValue) {
    checkNotNull(filteredProperty)
    checkNotNull(filteredValue)
    this.filteredProperty = filteredProperty
    this.filteredValue = filteredValue
  }

  override isEntryFiltered(ModelPatchEntry entry) {
    var boolean result = false
    switch(filteredProperty) {
      case CONTEXT: {
        result = filteredValue==entry.context.identifier
      }
      case FEATURE: {
        if(entry instanceof StructuralFeatureEntry) {
          result = filteredValue==entry.feature.identifier
        }
      }
      case TARGET: {
        if(entry instanceof ReferenceEntry) {
          result = filteredValue==entry.target.identifier
        }
      }
      case TYPE: {
        if(entry instanceof ElementEntry) {
          result = filteredValue==entry.type.identifier
        }
      }
      case VALUE: {
        if(entry instanceof AttributeEntry) {
          result = filteredValue==entry.value
        }
      }
    }
    return result
  }

}

Back to the top