diff options
author | 2021-08-03 18:42:39 +0900 | |
---|---|---|
committer | 2021-08-06 19:32:38 +0900 | |
commit | be4f78978faba3d3ceb88df02a7f93a2e09ff1e0 (patch) | |
tree | 1f3f1a96251ac4f655c8a96fc33d5d4ee779cd06 /rba.tool.editor/src/rba/tool/editor/validation/validators/PlusOperatorValidator.xtend | |
parent | 71ca7c6cab863767ef30c8bd05b2bbfda8731cb5 (diff) |
Initial commit
Bug-AGL: SPEC-4033
Signed-off-by: Kenji Hosokawa <khosokawa@jp.adit-jv.com>
Diffstat (limited to 'rba.tool.editor/src/rba/tool/editor/validation/validators/PlusOperatorValidator.xtend')
-rw-r--r-- | rba.tool.editor/src/rba/tool/editor/validation/validators/PlusOperatorValidator.xtend | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/rba.tool.editor/src/rba/tool/editor/validation/validators/PlusOperatorValidator.xtend b/rba.tool.editor/src/rba/tool/editor/validation/validators/PlusOperatorValidator.xtend new file mode 100644 index 0000000..b98e8f5 --- /dev/null +++ b/rba.tool.editor/src/rba/tool/editor/validation/validators/PlusOperatorValidator.xtend @@ -0,0 +1,47 @@ +package rba.tool.editor.validation.validators + +import org.eclipse.xtext.validation.Check +import org.eclipse.xtext.validation.EValidatorRegistrar +import rba.core.ComparisonOperator +import rba.core.ExpressionType +import rba.core.PlusOperator +import rba.core.RBACorePackage +import rba.tool.editor.messages.Messages +import rba.tool.editor.validation.AbstractRBAModelValidator + +class PlusOperatorValidator extends AbstractRBAModelValidator { + + private String PLUS_OPERAND_SIZE = Messages.PLUS_OPERAND_SIZE; + + private String PLUS_OPERAND_TYPE = Messages.PLUS_OPERAND_TYPE; + + private String PLUS_OPERAND_TYPE_NOT_OPERATOR = Messages.PLUS_OPERAND_TYPE_NOT_OPERATOR; + + override register(EValidatorRegistrar registrar) { + // not needed for classes used as ComposedCheck + } + + @Check(FAST) + def checkPlusOperatorFast(PlusOperator plusOperator) { + if (plusOperator.operand.size < 2) { + error(PLUS_OPERAND_SIZE, RBACorePackage.Literals.OPERATOR__OPERAND) + return; + } + } + + @Check(NORMAL) + def checkPlusOperatorNormal(PlusOperator plusOperator) { + for (var i = 0; i < plusOperator.operand.size; i++) { + var operand = plusOperator.operand.get(i) + if (operand instanceof ComparisonOperator) { + error(PLUS_OPERAND_TYPE_NOT_OPERATOR, RBACorePackage.Literals.OPERATOR__OPERAND, i, null) + return; + } + + if (operand.type != ExpressionType.VALUE) { + error(PLUS_OPERAND_TYPE, RBACorePackage.Literals.OPERATOR__OPERAND, i, null) + return; + } + } + } +} |