summaryrefslogtreecommitdiffstats
path: root/rba.tool.editor/src/rba/tool/editor/validation/validators/ValidatorUtils.xtend
diff options
context:
space:
mode:
authorKenji Hosokawa <khosokawa@jp.adit-jv.com>2021-08-03 18:42:39 +0900
committerKenji Hosokawa <khosokawa@jp.adit-jv.com>2021-08-06 19:32:38 +0900
commitbe4f78978faba3d3ceb88df02a7f93a2e09ff1e0 (patch)
tree1f3f1a96251ac4f655c8a96fc33d5d4ee779cd06 /rba.tool.editor/src/rba/tool/editor/validation/validators/ValidatorUtils.xtend
parent71ca7c6cab863767ef30c8bd05b2bbfda8731cb5 (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/ValidatorUtils.xtend')
-rw-r--r--rba.tool.editor/src/rba/tool/editor/validation/validators/ValidatorUtils.xtend109
1 files changed, 109 insertions, 0 deletions
diff --git a/rba.tool.editor/src/rba/tool/editor/validation/validators/ValidatorUtils.xtend b/rba.tool.editor/src/rba/tool/editor/validation/validators/ValidatorUtils.xtend
new file mode 100644
index 0000000..2416be7
--- /dev/null
+++ b/rba.tool.editor/src/rba/tool/editor/validation/validators/ValidatorUtils.xtend
@@ -0,0 +1,109 @@
+package rba.tool.editor.validation.validators
+
+import java.util.List
+import java.util.function.Consumer
+import rba.core.Expression
+import rba.core.ExpressionType
+import rba.tool.editor.messages.Messages
+import rba.core.Allocatable
+import rba.core.RBACorePackage
+import rba.core.Content
+import rba.view.RBAViewPackage
+import rba.view.Area
+import rba.view.ViewContent
+
+
+class ValidatorUtils {
+
+ def public static boolean isContent(Expression operand) {
+ return (operand.type != ExpressionType.CONTENT && operand.type != ExpressionType.SOUND);
+ }
+ def private static String getModelType(Object obj) {
+ return obj.class.simpleName.replaceAll("Impl", "");
+ }
+
+ /** @return true: Check passed. false: Error occurs. */
+ def public static boolean mustHaveVisibility(Allocatable model, Consumer<String> handling) {
+ if (!model.eIsSet(RBACorePackage.eINSTANCE.allocatable_Visibility)) {
+ handling.accept(String.format(Messages.VISIBILITY_IS_REQUIRED, getModelType(model), model.name));
+ return false;
+ }
+ return true;
+ }
+
+ /** @return true: Check passed. false: Error occurs. */
+ def public static boolean mustHaveZorder(Area model, Consumer<String> handling) {
+ if (!model.eIsSet(RBAViewPackage.eINSTANCE.area_Zorder)) {
+ handling.accept(String.format(Messages.ZORDER_IS_REQUIRED, getModelType(model), model.name));
+ return false;
+ }
+ return true;
+ }
+
+ /** @return true: Check passed. false: Error occurs. */
+ def public static boolean mustHaveLeastOneSize(Area model, Consumer<String> handling) {
+ if (model.size.empty) {
+ handling.accept(String.format(Messages.HAS_AT_LEAST_ONE_SIZE, getModelType(model), model.name));
+ return false;
+ }
+ return true;
+ }
+
+ /** @return true: Check passed. false: Error occurs. */
+ def public static boolean mustHaveLeastOneSize(ViewContent model, Consumer<String> handling) {
+ if (model.size.empty) {
+ handling.accept(String.format(Messages.HAS_AT_LEAST_ONE_SIZE, getModelType(model), model.name));
+ return false;
+ }
+ return true;
+ }
+
+ /** @return true: Check passed. false: Error occurs. */
+ def public static boolean mustHaveLeastOneState(Content model, Consumer<String> handling) {
+ if (model.states.empty) {
+ handling.accept(String.format(Messages.HAS_AT_LEAST_ONE_STATE, getModelType(model), model.name));
+ return false;
+ }
+ return true;
+ }
+
+ /** @return true: Check passed. false: Error occurs. */
+ def public static boolean mustHaveLeastOneAllocatable(Content model, Consumer<String> handling) {
+ if (model.allocatable.empty) {
+ handling.accept(String.format(Messages.ALLOCATABLE_SIZE, getModelType(model), model.name));
+ return false;
+ }
+ return true;
+ }
+
+ /** @return true: Check passed. false: Error occurs. */
+ def public static boolean operandSizeMustBeOne(List<Expression> operands, String operatorName,
+ Consumer<String> handling) {
+ if (operands.size != 1) {
+ handling.accept(String.format(Messages.OPERAND_SIZE_ONE, operatorName));
+ return false;
+ }
+ return true;
+ }
+
+ /** @return true: Check passed. false: Find an error. */
+ def public static boolean operandSizeMustBeTwo(List<Expression> operands, String operatorName,
+ Consumer<String> handling) {
+ if (operands.size != 2) {
+ handling.accept(String.format(Messages.OPERAND_SIZE_TWO, operatorName));
+ return false;
+ }
+ return true;
+ }
+
+ /** @return true: Check passed. false: Error occurs. */
+ def public static boolean firstOperandMustBeContent(Expression firstOperand, String operatorName,
+ Consumer<String> handling) {
+ if (isContent(firstOperand)) {
+ handling.accept(String.format(Messages.FIRST_OPERAND_MUST_CONTENT, operatorName));
+ return false;
+ }
+ return true;
+ }
+
+}