From be4f78978faba3d3ceb88df02a7f93a2e09ff1e0 Mon Sep 17 00:00:00 2001 From: Kenji Hosokawa Date: Tue, 3 Aug 2021 18:42:39 +0900 Subject: Initial commit Bug-AGL: SPEC-4033 Signed-off-by: Kenji Hosokawa --- .../validation/validators/ValidatorUtils.xtend | 109 +++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 rba.tool.editor/src/rba/tool/editor/validation/validators/ValidatorUtils.xtend (limited to 'rba.tool.editor/src/rba/tool/editor/validation/validators/ValidatorUtils.xtend') 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 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 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 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 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 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 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 operands, String operatorName, + Consumer 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 operands, String operatorName, + Consumer 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 handling) { + if (isContent(firstOperand)) { + handling.accept(String.format(Messages.FIRST_OPERAND_MUST_CONTENT, operatorName)); + return false; + } + return true; + } + +} -- cgit 1.2.3-korg