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/IfStatementValidator.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/IfStatementValidator.xtend')
-rw-r--r-- | rba.tool.editor/src/rba/tool/editor/validation/validators/IfStatementValidator.xtend | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/rba.tool.editor/src/rba/tool/editor/validation/validators/IfStatementValidator.xtend b/rba.tool.editor/src/rba/tool/editor/validation/validators/IfStatementValidator.xtend new file mode 100644 index 0000000..2eefb6b --- /dev/null +++ b/rba.tool.editor/src/rba/tool/editor/validation/validators/IfStatementValidator.xtend @@ -0,0 +1,44 @@ +package rba.tool.editor.validation.validators + +import org.eclipse.xtext.validation.Check +import org.eclipse.xtext.validation.EValidatorRegistrar +import rba.core.ExpressionType +import rba.core.IfStatement +import rba.core.RBACorePackage +import rba.tool.editor.messages.Messages +import rba.tool.editor.validation.AbstractRBAModelValidator + +/** + * This class contains custom validation rules. + * + * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#validation + */ +class IfStatementValidator extends AbstractRBAModelValidator { + + private String CONDITION_BOOLEAN_TYPE_CHECK = Messages.CONDITION_BOOLEAN_TYPE_CHECK; + + private String CONDITION_TPYE_EQUAL_CHECK = Messages.CONDITION_TPYE_EQUAL_CHECK; + + override register(EValidatorRegistrar registrar) { + // not needed for classes used as ComposedCheck + } + + @Check(NORMAL) + def checkIfStatement(IfStatement ifStatement) { + if (ifStatement.condition.type !== ExpressionType.BOOLEAN) { + error(CONDITION_BOOLEAN_TYPE_CHECK, RBACorePackage.Literals.IF_STATEMENT__CONDITION); + return; + } + if (!isExpressionTypeEquals(ifStatement.thenExpression.type, ifStatement.elseExpression.type)) { + error(CONDITION_TPYE_EQUAL_CHECK, RBACorePackage.Literals.IF_STATEMENT__ELSE_EXPRESSION); + return; + } + } + + def boolean isExpressionTypeEquals(ExpressionType type1, ExpressionType type2) { + if (type1 === type2) { + return true; + } + return false + } +} |