diff options
author | 2024-05-17 18:30:58 +0200 | |
---|---|---|
committer | 2024-05-26 17:22:32 +0200 | |
commit | 2a70f0ec9ea7d5e292abac87b344f4bc8091096e (patch) | |
tree | 569f2c78a9857600733a174c7424315b7ea07d45 /subprojects/language/src/main/java/tools | |
parent | feat: type checking for rules (diff) | |
download | refinery-2a70f0ec9ea7d5e292abac87b344f4bc8091096e.tar.gz refinery-2a70f0ec9ea7d5e292abac87b344f4bc8091096e.tar.zst refinery-2a70f0ec9ea7d5e292abac87b344f4bc8091096e.zip |
feat(language): rule validation
Diffstat (limited to 'subprojects/language/src/main/java/tools')
-rw-r--r-- | subprojects/language/src/main/java/tools/refinery/language/validation/ProblemValidator.java | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/subprojects/language/src/main/java/tools/refinery/language/validation/ProblemValidator.java b/subprojects/language/src/main/java/tools/refinery/language/validation/ProblemValidator.java index c49718ab..7046d4c6 100644 --- a/subprojects/language/src/main/java/tools/refinery/language/validation/ProblemValidator.java +++ b/subprojects/language/src/main/java/tools/refinery/language/validation/ProblemValidator.java | |||
@@ -49,8 +49,9 @@ public class ProblemValidator extends AbstractProblemValidator { | |||
49 | public static final String INVALID_SUPERTYPE_ISSUE = ISSUE_PREFIX + "INVALID_SUPERTYPE"; | 49 | public static final String INVALID_SUPERTYPE_ISSUE = ISSUE_PREFIX + "INVALID_SUPERTYPE"; |
50 | public static final String INVALID_REFERENCE_TYPE_ISSUE = ISSUE_PREFIX + "INVALID_REFERENCE_TYPE"; | 50 | public static final String INVALID_REFERENCE_TYPE_ISSUE = ISSUE_PREFIX + "INVALID_REFERENCE_TYPE"; |
51 | public static final String INVALID_ARITY_ISSUE = ISSUE_PREFIX + "INVALID_ARITY"; | 51 | public static final String INVALID_ARITY_ISSUE = ISSUE_PREFIX + "INVALID_ARITY"; |
52 | public static final String INVALID_MODALITY_ISSUE = ISSUE_PREFIX + "INVALID_MODALITY"; | ||
53 | public static final String INVALID_RULE_ISSUE = ISSUE_PREFIX + "INVALID_RULE"; | ||
52 | public static final String INVALID_TRANSITIVE_CLOSURE_ISSUE = ISSUE_PREFIX + "INVALID_TRANSITIVE_CLOSURE"; | 54 | public static final String INVALID_TRANSITIVE_CLOSURE_ISSUE = ISSUE_PREFIX + "INVALID_TRANSITIVE_CLOSURE"; |
53 | public static final String INVALID_VALUE_ISSUE = ISSUE_PREFIX + "INVALID_VALUE"; | ||
54 | public static final String UNSUPPORTED_ASSERTION_ISSUE = ISSUE_PREFIX + "UNSUPPORTED_ASSERTION"; | 55 | public static final String UNSUPPORTED_ASSERTION_ISSUE = ISSUE_PREFIX + "UNSUPPORTED_ASSERTION"; |
55 | public static final String UNKNOWN_EXPRESSION_ISSUE = ISSUE_PREFIX + "UNKNOWN_EXPRESSION"; | 56 | public static final String UNKNOWN_EXPRESSION_ISSUE = ISSUE_PREFIX + "UNKNOWN_EXPRESSION"; |
56 | public static final String INVALID_ASSIGNMENT_ISSUE = ISSUE_PREFIX + "INVALID_ASSIGNMENT"; | 57 | public static final String INVALID_ASSIGNMENT_ISSUE = ISSUE_PREFIX + "INVALID_ASSIGNMENT"; |
@@ -336,8 +337,24 @@ public class ProblemValidator extends AbstractProblemValidator { | |||
336 | } | 337 | } |
337 | 338 | ||
338 | @Check | 339 | @Check |
339 | public void checkParameterType(Parameter parameter) { | 340 | public void checkParameter(Parameter parameter) { |
340 | checkArity(parameter, ProblemPackage.Literals.PARAMETER__PARAMETER_TYPE, 1); | 341 | checkArity(parameter, ProblemPackage.Literals.PARAMETER__PARAMETER_TYPE, 1); |
342 | var parametricDefinition = EcoreUtil2.getContainerOfType(parameter, ParametricDefinition.class); | ||
343 | if (parametricDefinition instanceof RuleDefinition) { | ||
344 | if (parameter.getParameterType() != null && parameter.getModality() == Modality.NONE) { | ||
345 | acceptError("Parameter type modality must be specified.", parameter, | ||
346 | ProblemPackage.Literals.PARAMETER__PARAMETER_TYPE, 0, INVALID_MODALITY_ISSUE); | ||
347 | } | ||
348 | } else { | ||
349 | if (parameter.getConcreteness() != Concreteness.PARTIAL || parameter.getModality() != Modality.NONE) { | ||
350 | acceptError("Modal parameter types are only supported in rule definitions.", parameter, null, 0, | ||
351 | INVALID_MODALITY_ISSUE); | ||
352 | } | ||
353 | if (parameter.getBinding() != ParameterBinding.SINGLE) { | ||
354 | acceptError("Parameter binding annotations are only supported in rule definitions.", parameter, | ||
355 | ProblemPackage.PARAMETER__BINDING, 0, INVALID_MODALITY_ISSUE); | ||
356 | } | ||
357 | } | ||
341 | } | 358 | } |
342 | 359 | ||
343 | @Check | 360 | @Check |
@@ -353,6 +370,18 @@ public class ProblemValidator extends AbstractProblemValidator { | |||
353 | } | 370 | } |
354 | 371 | ||
355 | @Check | 372 | @Check |
373 | public void checkRuleDefinition(RuleDefinition ruleDefinition) { | ||
374 | if (ruleDefinition.getKind() != RuleKind.REFINEMENT && ruleDefinition.getPreconditions().isEmpty()) { | ||
375 | acceptError("Decision and propagation rules must have at least one precondition.", ruleDefinition, | ||
376 | ProblemPackage.Literals.NAMED_ELEMENT__NAME, 0, INVALID_RULE_ISSUE); | ||
377 | } | ||
378 | if (ruleDefinition.getConsequents().size() != 1) { | ||
379 | acceptError("Rules must have exactly one consequent.", ruleDefinition, | ||
380 | ProblemPackage.Literals.NAMED_ELEMENT__NAME, 0, INVALID_RULE_ISSUE); | ||
381 | } | ||
382 | } | ||
383 | |||
384 | @Check | ||
356 | public void checkAssertion(Assertion assertion) { | 385 | public void checkAssertion(Assertion assertion) { |
357 | var relation = assertion.getRelation(); | 386 | var relation = assertion.getRelation(); |
358 | if (relation instanceof DatatypeDeclaration) { | 387 | if (relation instanceof DatatypeDeclaration) { |