summaryrefslogtreecommitdiffstats
path: root/rba.tool.editor/src/rba/tool/editor/validation/validators/ContentValueValidator.xtend
blob: fc97945e7b5e2a4ca76ac817d1776ece6089524c (plain)
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
package rba.tool.editor.validation.validators

import org.eclipse.xtext.validation.Check
import org.eclipse.xtext.validation.EValidatorRegistrar
import rba.core.ContentValue
import rba.core.ExpressionType
import rba.core.RBACorePackage
import rba.tool.editor.messages.Messages
import rba.tool.editor.validation.AbstractRBAModelValidator

class ContentValueValidator extends AbstractRBAModelValidator {

	private String CONTENTVALUE_SIZE = Messages.CONTENTVALUE_SIZE;

	private String CONTENTVALUE_TYPE = Messages.CONTENTVALUE_TYPE;

	override register(EValidatorRegistrar registrar) {
		// not needed for classes used as ComposedCheck
	}

	@Check(NORMAL)
	def checkContentValue(ContentValue contentValue) {
		if (contentValue.operand.size > 1) {
			error(CONTENTVALUE_SIZE, RBACorePackage.Literals.OPERATOR__OPERAND)
			return;
		}
		for (operand : contentValue.operand) {
			if (operand.type != ExpressionType.AREA && operand.type != ExpressionType.ZONE) {
				error(CONTENTVALUE_TYPE, RBACorePackage.Literals.OPERATOR__OPERAND)
				return;
			}
		}
	}
}