Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 091aa7bbf2ed648092438bc59a9c56765fd20352 (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
package org.eclipse.papyrus.uml.xtext.integration.validation;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.validation.AbstractModelConstraint;
import org.eclipse.emf.validation.EMFEventType;
import org.eclipse.emf.validation.IValidationContext;
import org.eclipse.papyrus.uml.xtext.integration.InvalidStringUtil;
import org.eclipse.uml2.uml.Element;

/**
 * Creates an error if a model element has an annotation. If an annotation exist
 * the xtext string couldn't be parsed and is out of sync with the UML model.
 * 
 * 
 * @author Markus M�hlbrandt
 * 
 */
public class ExistsAnnotationConstraint extends AbstractModelConstraint {

	@Override
	public IStatus validate(IValidationContext ctx) {
		EObject eObj = ctx.getTarget();
		EMFEventType eType = ctx.getEventType();
		String text = null;
		// In the case of batch mode.
		if (eType == EMFEventType.NULL) {
			if (eObj instanceof Element) {
				Element element = (Element) eObj;
				text = InvalidStringUtil.getTextualRepresentation(element);
			}

			if (text != null && !"".equals(text)) { //$NON-NLS-1$
				return ctx.createFailureStatus(eObj.eClass().getName());
			}
		}
		return ctx.createSuccessStatus();
	}

}

Back to the top