Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c43c699faddff5142dbdd393cf79584b3544d233 (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
/*****************************************************************************
 * Copyright (c) 2012 CEA LIST.
 *
 *    
 * 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:
 *  Vincent Lorenzo (CEA LIST) Vincent.Lorenzo@cea.fr - Initial API and implementation
 *  
 *****************************************************************************/
package org.eclipse.papyrus.infra.emf.compare.diff.check;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.eclipse.emf.compare.diff.engine.IMatchManager;
import org.eclipse.emf.compare.diff.engine.check.AbstractCheck;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.papyrus.infra.emf.compare.diff.utils.PapyrusCompareOptions;

/**
 * 
 * This checker allow to know if differences on a feature should be ignored or not
 * 
 */
public class FeaturesCheck extends AbstractCheck implements IFeaturesCheck {

	/**
	 * The list of the features that should be ignored in the whole diff
	 */
	private final List<EStructuralFeature> ignoreAll;

	/**
	 * the list of the features that should be ignored for some EObject
	 */
	private final Map<EStructuralFeature, List<EObject>> ignoreSomeCase;

	/**
	 * 
	 * Constructor.
	 * 
	 * @param manager
	 * @param options
	 */
	@SuppressWarnings("unchecked")
	//cast on List and Map
	public FeaturesCheck(final IMatchManager manager, final Map<String, Object> options) {
		super(manager);

		if(options != null && options.containsKey(PapyrusCompareOptions.KEY_IGNORE_ALL_CHANGES_ON_FEATURES)) {
			this.ignoreAll = (List<EStructuralFeature>)options.get(PapyrusCompareOptions.KEY_IGNORE_ALL_CHANGES_ON_FEATURES);
		} else {
			this.ignoreAll = Collections.EMPTY_LIST;
		}
		if(options != null && options.containsKey(PapyrusCompareOptions.KEY_IGNORE_CHANGES_ON_FEATURES_FOR)) {
			this.ignoreSomeCase = (Map<EStructuralFeature, List<EObject>>)options.get(PapyrusCompareOptions.KEY_IGNORE_CHANGES_ON_FEATURES_FOR);
		} else {
			this.ignoreSomeCase = Collections.EMPTY_MAP;
		}
	}

	/**
	 * 
	 * Constructor.
	 * 
	 * @param manager
	 */
	public FeaturesCheck(final IMatchManager manager) {
		this(manager, null);
	}

	/**
	 * This method is used to know if a feature should always be ignored
	 * 
	 * @param feature
	 * @return
	 */
	public boolean shouldBeIgnored(final EStructuralFeature feature) {
		return this.ignoreAll.contains(feature);
	}

	/**
	 * This method begins by testing the feature must ALWAYS be ignored using shouldBeIgnored(feature).
	 * If not, we verify is the feature should be ignored in some case, depending on its context
	 * 
	 * 
	 * @param feature
	 * @param context
	 * @return
	 */
	public boolean shouldBeIgnored(final EStructuralFeature feature, final EObject context) {
		if(shouldBeIgnored(feature)) {
			return true;
		}
		final List<EObject> values = this.ignoreSomeCase.get(feature);
		if(values != null) {
			return values.contains(context);
		}
		return false;
	}
}

Back to the top