Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b8081af3e8d5c505e719733cb93675c1a94d6bd4 (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
/*******************************************************************************
 * 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:
 *    Nicolas Bros (Mia-Software) - Bug 375054 - Add validation warning for overlay on EClass
 *******************************************************************************/
package org.eclipse.emf.facet.custom.sdk.core.internal.validation;

import java.util.Arrays;
import java.util.List;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.facet.custom.metamodel.v0_2_0.custom.EClassCustomization;
import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.DerivedTypedElement;
import org.eclipse.emf.facet.efacet.metamodel.v0_2_0.efacet.FacetOperation;
import org.eclipse.emf.validation.AbstractModelConstraint;
import org.eclipse.emf.validation.IValidationContext;

/**
 * Creates a warning if a {@link FacetOperation} defined in an {@link EClassCustomization} overrides (i.e. customizes)
 * an overlay operation.
 */
public class AvoidEClassOverlayConstraint extends AbstractModelConstraint {

	private static final List<String> OVERLAY_OPS = Arrays.asList(
			"platform:/plugin/org.eclipse.emf.facet.custom.ui/resources/customproperties.efacet#//CustomizedEObject/topLeftOverlay", //$NON-NLS-1$
			"platform:/plugin/org.eclipse.emf.facet.custom.ui/resources/customproperties.efacet#//CustomizedEObject/topMiddleOverlay", //$NON-NLS-1$
			"platform:/plugin/org.eclipse.emf.facet.custom.ui/resources/customproperties.efacet#//CustomizedEObject/topRightOverlay", //$NON-NLS-1$
			"platform:/plugin/org.eclipse.emf.facet.custom.ui/resources/customproperties.efacet#//CustomizedEObject/bottomLeftOverlay", //$NON-NLS-1$
			"platform:/plugin/org.eclipse.emf.facet.custom.ui/resources/customproperties.efacet#//CustomizedEObject/bottomMiddleOverlay", //$NON-NLS-1$
			"platform:/plugin/org.eclipse.emf.facet.custom.ui/resources/customproperties.efacet#//CustomizedEObject/bottomRightOverlay" //$NON-NLS-1$
	);

	@Override
	public IStatus validate(final IValidationContext ctx) {
		IStatus result = ctx.createSuccessStatus();
		final EObject target = ctx.getTarget();
		if (target instanceof FacetOperation) {
			final FacetOperation facetOperation = (FacetOperation) target;
			final DerivedTypedElement override = facetOperation.getOverride();
			final URI overrideURI = EcoreUtil.getURI(override);
			if (facetOperation.eContainer() instanceof EClassCustomization
					&& AvoidEClassOverlayConstraint.OVERLAY_OPS.contains(overrideURI.toString())) {
				result = ctx.createFailureStatus();
			}
		}
		return result;
	}

}

Back to the top