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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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;
}
}
|