Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d4b89cd1106d3e20af935080c5ca667311846846 (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
/*****************************************************************************
 * Copyright (c) 2011 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
 *
 *****************************************************************************/
package org.eclipse.papyrus.uml.service.types.matcher;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.emf.type.core.IElementMatcher;
import org.eclipse.papyrus.uml.service.types.element.UMLElementTypes;
import org.eclipse.papyrus.uml.service.types.utils.ElementUtil;
import org.eclipse.uml2.uml.Association;
import org.eclipse.uml2.uml.Element;

/**
 * <pre>
 * Test if current {@link Association} has the UML nature.
 * This nature is used to:
 * - distinguish between UML and SysML expected behavior for {@link Association}.
 * - decide whether and {@link Association} can be dropped and used in a specific diagram.
 * - select the property view to use.
 *
 * Existing Associations (created in previous Papyrus version and which have no nature set)
 * are treated as UML Associations.
 * </pre>
 */
public class AssociationMatcher implements IElementMatcher {

	public boolean matches(EObject eObject) {

		boolean isMatch = false;

		if (eObject instanceof Association) {

			Association association = (Association) eObject;
			if (hasValidNature(association) || hasNoNature(association)) {
				isMatch = true;
			}
		}

		return isMatch;
	}

	private boolean hasValidNature(Element element) {
		return ElementUtil.hasNature(element, UMLElementTypes.UML_NATURE);
	}

	private boolean hasNoNature(Element element) {
		String nature = ElementUtil.getNature(element);
		return nature == null || "".equals(nature);
	}
}

Back to the top