diff options
author | 2024-07-06 18:53:23 +0200 | |
---|---|---|
committer | 2024-07-06 19:36:17 +0200 | |
commit | a9ddf62be6b5ef6cbb9bff15981aab530f948106 (patch) | |
tree | 4657c42f0507b1942ace7df881c89baecabd6efc /subprojects/language/src/main/java/tools | |
parent | refactor(frontend): fix React warnings (diff) | |
download | refinery-a9ddf62be6b5ef6cbb9bff15981aab530f948106.tar.gz refinery-a9ddf62be6b5ef6cbb9bff15981aab530f948106.tar.zst refinery-a9ddf62be6b5ef6cbb9bff15981aab530f948106.zip |
feat(semantics): implicit rule preconditions
Diffstat (limited to 'subprojects/language/src/main/java/tools')
-rw-r--r-- | subprojects/language/src/main/java/tools/refinery/language/validation/ProblemValidator.java | 25 |
1 files changed, 5 insertions, 20 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 8d64933f..aef1e71d 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 | |||
@@ -454,33 +454,17 @@ public class ProblemValidator extends AbstractProblemValidator { | |||
454 | for (var consequent : consequents) { | 454 | for (var consequent : consequents) { |
455 | countRuleParameterUsages(consequent, useCounts); | 455 | countRuleParameterUsages(consequent, useCounts); |
456 | } | 456 | } |
457 | var isError = ruleDefinition.getKind() == RuleKind.PROPAGATION; | ||
458 | int consequentCount = consequents.size(); | 457 | int consequentCount = consequents.size(); |
459 | for (var entry : useCounts.entrySet()) { | 458 | for (var entry : useCounts.entrySet()) { |
460 | if (entry.getValue() < consequentCount) { | 459 | if (entry.getValue() < consequentCount) { |
461 | var parameter = entry.getKey(); | 460 | var parameter = entry.getKey(); |
462 | var message = "Unused rule parameter '%s'.".formatted(parameter.getName()); | 461 | var message = "Unused rule parameter '%s'.".formatted(parameter.getName()); |
463 | if (isError) { | 462 | acceptWarning(message, parameter, ProblemPackage.Literals.NAMED_ELEMENT__NAME, 0, |
464 | acceptError(message, parameter, ProblemPackage.Literals.NAMED_ELEMENT__NAME, 0, UNUSED_PARAMETER); | 463 | UNUSED_PARAMETER); |
465 | } else { | ||
466 | acceptWarning(message, parameter, ProblemPackage.Literals.NAMED_ELEMENT__NAME, 0, | ||
467 | UNUSED_PARAMETER); | ||
468 | } | ||
469 | } | 464 | } |
470 | } | 465 | } |
471 | } | 466 | } |
472 | 467 | ||
473 | @Check | ||
474 | public void checkPropagationRuleConsequent(Consequent consequent) { | ||
475 | var rule = EcoreUtil2.getContainerOfType(consequent, RuleDefinition.class); | ||
476 | if (rule == null || rule.getKind() != RuleKind.PROPAGATION) { | ||
477 | return; | ||
478 | } | ||
479 | if (consequent.getActions().size() > 1) { | ||
480 | acceptError("Propagation rules must have exactly one action.", consequent, null, 0, INVALID_RULE_ISSUE); | ||
481 | } | ||
482 | } | ||
483 | |||
484 | private static void countRuleParameterUsages(Consequent consequent, Map<Parameter, Integer> useCounts) { | 468 | private static void countRuleParameterUsages(Consequent consequent, Map<Parameter, Integer> useCounts) { |
485 | var usedParameters = new HashSet<Parameter>(); | 469 | var usedParameters = new HashSet<Parameter>(); |
486 | for (var action : consequent.getActions()) { | 470 | for (var action : consequent.getActions()) { |
@@ -489,14 +473,15 @@ public class ProblemValidator extends AbstractProblemValidator { | |||
489 | } | 473 | } |
490 | } | 474 | } |
491 | for (var usedParameter : usedParameters) { | 475 | for (var usedParameter : usedParameters) { |
492 | useCounts.compute(usedParameter, (ignored, value) -> value == null ? 0 : value + 1); | 476 | useCounts.compute(usedParameter, (ignored, value) -> value == null ? null : value + 1); |
493 | } | 477 | } |
494 | } | 478 | } |
495 | 479 | ||
496 | private static void collectUsedParameters(AssertionAction assertionAction, HashSet<Parameter> usedParameters) { | 480 | private static void collectUsedParameters(AssertionAction assertionAction, HashSet<Parameter> usedParameters) { |
497 | for (var argument : assertionAction.getArguments()) { | 481 | for (var argument : assertionAction.getArguments()) { |
498 | if (argument instanceof NodeAssertionArgument nodeAssertionArgument && | 482 | if (argument instanceof NodeAssertionArgument nodeAssertionArgument && |
499 | nodeAssertionArgument.getNode() instanceof Parameter usedParameter) { | 483 | nodeAssertionArgument.getNode() instanceof Parameter usedParameter && |
484 | !usedParameter.eIsProxy()) { | ||
500 | usedParameters.add(usedParameter); | 485 | usedParameters.add(usedParameter); |
501 | } | 486 | } |
502 | } | 487 | } |