99import de .monticore .types3 .TypeCheck3 ;
1010import de .se_rwth .commons .logging .Log ;
1111
12+ import static de .monticore .symbols .basicsymbols .BasicSymbolsMill .BOOLEAN ;
13+
1214/**
1315 * Checks that the preconditions of transitions evaluate to boolean values.
1416 */
1517public class TransitionPreconditionsAreBoolean implements SCTransitions4CodeASTTransitionBodyCoCo {
1618
17- public static final String ERROR_CODE = "0xCC111" ;
19+ public static final String GUARD_NOT_BOOLEAN_ERROR_CODE = "0xCC111" ;
20+
21+ public static final String GUARD_NOT_BOOLEAN_ERROR_MSG = "Expected '%s' but provided '%s'." ;
1822
19- protected static final String MESSAGE = "Guard expressions must be boolean. Your guard expression is of type '%s'." ;
23+ @ Deprecated
24+ public static final String ERROR_CODE = GUARD_NOT_BOOLEAN_ERROR_CODE ;
25+
26+ @ Deprecated
27+ protected static final String MESSAGE = GUARD_NOT_BOOLEAN_ERROR_MSG ;
2028
2129 /**
2230 * Used to extract the type to which the transition precondition evaluates to.
@@ -36,14 +44,18 @@ public TransitionPreconditionsAreBoolean(IDerive typeDeriver) {
3644
3745 @ Override
3846 public void check (ASTTransitionBody node ) {
39- if (node .isPresentPre ()) {
47+ if (node .isPresentPre ()) {
4048 SymTypeExpression preType = TypeCheck3 .typeOf (node .getPre ());
4149 if (preType .isObscureType ()) {
42- Log .debug (String .format ("Coco '%s' is not checked on transition guard expression at %s, because the " +
43- "expression is malformed." , this .getClass ().getSimpleName (), node .get_SourcePositionStart ()), "Cocos" );
44- } else if (!SymTypeRelations .isBoolean (preType )) {
50+ Log .debug (() -> String .format (
51+ "Coco '%s' skipped for transition guard at %s. The type is obscure, an error should already have been logged." ,
52+ this .getClass ().getSimpleName (),
53+ node .get_SourcePositionStart ()),
54+ "Cocos"
55+ );
56+ } else if (!SymTypeRelations .isBoolean (preType )) {
4557 Log .error (
46- String .format (ERROR_CODE + " " + MESSAGE , preType .print ()),
58+ String .format (ERROR_CODE + " " + GUARD_NOT_BOOLEAN_ERROR_MSG , BOOLEAN , preType .print ()),
4759 node .get_SourcePositionStart (), node .get_SourcePositionEnd ()
4860 );
4961 }
0 commit comments