diff options
author | 2024-06-30 20:23:02 +0200 | |
---|---|---|
committer | 2024-06-30 20:37:27 +0200 | |
commit | 57f9177f3717984b873c3c1d43c42472800e476a (patch) | |
tree | 266af6ab96daaed62e5fb0cb190765e5c899499f /subprojects/language/src/main/java/tools | |
parent | refactor(language): computed constraint symbol (diff) | |
download | refinery-57f9177f3717984b873c3c1d43c42472800e476a.tar.gz refinery-57f9177f3717984b873c3c1d43c42472800e476a.tar.zst refinery-57f9177f3717984b873c3c1d43c42472800e476a.zip |
feat(language): computed value validation
Diffstat (limited to 'subprojects/language/src/main/java/tools')
3 files changed, 23 insertions, 1 deletions
diff --git a/subprojects/language/src/main/java/tools/refinery/language/resource/ProblemResourceDescriptionStrategy.java b/subprojects/language/src/main/java/tools/refinery/language/resource/ProblemResourceDescriptionStrategy.java index 505c7787..cad98d50 100644 --- a/subprojects/language/src/main/java/tools/refinery/language/resource/ProblemResourceDescriptionStrategy.java +++ b/subprojects/language/src/main/java/tools/refinery/language/resource/ProblemResourceDescriptionStrategy.java | |||
@@ -46,6 +46,8 @@ public class ProblemResourceDescriptionStrategy extends DefaultResourceDescripti | |||
46 | public static final String MODULE_KIND = DATA_PREFIX + "MODULE_KIND"; | 46 | public static final String MODULE_KIND = DATA_PREFIX + "MODULE_KIND"; |
47 | public static final String COLOR_RELATION = DATA_PREFIX + "COLOR_RELATION"; | 47 | public static final String COLOR_RELATION = DATA_PREFIX + "COLOR_RELATION"; |
48 | public static final String COLOR_RELATION_TRUE = "true"; | 48 | public static final String COLOR_RELATION_TRUE = "true"; |
49 | public static final String COMPUTED_VALUE = DATA_PREFIX + "COMPUTED_VALUE"; | ||
50 | public static final String COMPUTED_VALUE_TRUE = "true"; | ||
49 | 51 | ||
50 | @Inject | 52 | @Inject |
51 | private IQualifiedNameConverter qualifiedNameConverter; | 53 | private IQualifiedNameConverter qualifiedNameConverter; |
@@ -160,9 +162,12 @@ public class ProblemResourceDescriptionStrategy extends DefaultResourceDescripti | |||
160 | } else if (eObject instanceof AggregatorDeclaration) { | 162 | } else if (eObject instanceof AggregatorDeclaration) { |
161 | builder.put(SHADOWING_KEY, SHADOWING_KEY_AGGREGATOR); | 163 | builder.put(SHADOWING_KEY, SHADOWING_KEY_AGGREGATOR); |
162 | } | 164 | } |
163 | if (eObject instanceof PredicateDefinition predicateDefinition && predicateDefinition.isError()) { | 165 | if (ProblemUtil.isError(eObject)) { |
164 | builder.put(ERROR_PREDICATE, ERROR_PREDICATE_TRUE); | 166 | builder.put(ERROR_PREDICATE, ERROR_PREDICATE_TRUE); |
165 | } | 167 | } |
168 | if (ProblemUtil.isComputedValue(eObject)) { | ||
169 | builder.put(COMPUTED_VALUE, COMPUTED_VALUE_TRUE); | ||
170 | } | ||
166 | var documentationMap = documentationCommentParser.parseDocumentation(eObject); | 171 | var documentationMap = documentationCommentParser.parseDocumentation(eObject); |
167 | builder.putAll(documentationMap); | 172 | builder.putAll(documentationMap); |
168 | return builder.build(); | 173 | return builder.build(); |
diff --git a/subprojects/language/src/main/java/tools/refinery/language/utils/ProblemUtil.java b/subprojects/language/src/main/java/tools/refinery/language/utils/ProblemUtil.java index e1820261..7e7de681 100644 --- a/subprojects/language/src/main/java/tools/refinery/language/utils/ProblemUtil.java +++ b/subprojects/language/src/main/java/tools/refinery/language/utils/ProblemUtil.java | |||
@@ -53,6 +53,10 @@ public final class ProblemUtil { | |||
53 | return eObject instanceof PredicateDefinition predicateDefinition && predicateDefinition.isError(); | 53 | return eObject instanceof PredicateDefinition predicateDefinition && predicateDefinition.isError(); |
54 | } | 54 | } |
55 | 55 | ||
56 | public static boolean isComputedValue(EObject eObject) { | ||
57 | return eObject instanceof PredicateDefinition predicateDefinition && !predicateDefinition.getBodies().isEmpty(); | ||
58 | } | ||
59 | |||
56 | public static boolean isAtomNode(Node node) { | 60 | public static boolean isAtomNode(Node node) { |
57 | var containingFeature = node.eContainingFeature(); | 61 | var containingFeature = node.eContainingFeature(); |
58 | if (containingFeature == ProblemPackage.Literals.NODE_DECLARATION__NODES) { | 62 | if (containingFeature == ProblemPackage.Literals.NODE_DECLARATION__NODES) { |
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 63c8631c..7114b693 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,6 +49,7 @@ public class ProblemValidator extends AbstractProblemValidator { | |||
49 | public static final String INVALID_MODALITY_ISSUE = ISSUE_PREFIX + "INVALID_MODALITY"; | 49 | public static final String INVALID_MODALITY_ISSUE = ISSUE_PREFIX + "INVALID_MODALITY"; |
50 | public static final String INVALID_RULE_ISSUE = ISSUE_PREFIX + "INVALID_RULE"; | 50 | public static final String INVALID_RULE_ISSUE = ISSUE_PREFIX + "INVALID_RULE"; |
51 | public static final String INVALID_TRANSITIVE_CLOSURE_ISSUE = ISSUE_PREFIX + "INVALID_TRANSITIVE_CLOSURE"; | 51 | public static final String INVALID_TRANSITIVE_CLOSURE_ISSUE = ISSUE_PREFIX + "INVALID_TRANSITIVE_CLOSURE"; |
52 | public static final String INVALID_COMPUTED_VALUE_ISSUE = ISSUE_PREFIX + "INVALID_COMPUTED_VALUE"; | ||
52 | public static final String UNSUPPORTED_ASSERTION_ISSUE = ISSUE_PREFIX + "UNSUPPORTED_ASSERTION"; | 53 | public static final String UNSUPPORTED_ASSERTION_ISSUE = ISSUE_PREFIX + "UNSUPPORTED_ASSERTION"; |
53 | public static final String UNKNOWN_EXPRESSION_ISSUE = ISSUE_PREFIX + "UNKNOWN_EXPRESSION"; | 54 | public static final String UNKNOWN_EXPRESSION_ISSUE = ISSUE_PREFIX + "UNKNOWN_EXPRESSION"; |
54 | public static final String INVALID_ASSIGNMENT_ISSUE = ISSUE_PREFIX + "INVALID_ASSIGNMENT"; | 55 | public static final String INVALID_ASSIGNMENT_ISSUE = ISSUE_PREFIX + "INVALID_ASSIGNMENT"; |
@@ -425,6 +426,18 @@ public class ProblemValidator extends AbstractProblemValidator { | |||
425 | acceptError(message, atom, ProblemPackage.Literals.ATOM__TRANSITIVE_CLOSURE, 0, | 426 | acceptError(message, atom, ProblemPackage.Literals.ATOM__TRANSITIVE_CLOSURE, 0, |
426 | INVALID_TRANSITIVE_CLOSURE_ISSUE); | 427 | INVALID_TRANSITIVE_CLOSURE_ISSUE); |
427 | } | 428 | } |
429 | if (atom.isComputed()) { | ||
430 | var target = atom.getRelation(); | ||
431 | if (target != null && !target.eIsProxy() && !ProblemUtil.isComputedValue(target)) { | ||
432 | var message = "Relation '%s' has no computed value.".formatted(target.getName()); | ||
433 | acceptError(message, atom, ProblemPackage.Literals.ATOM__COMPUTED, 0, INVALID_COMPUTED_VALUE_ISSUE); | ||
434 | } | ||
435 | var definitionContext = EcoreUtil2.getContainerOfType(atom, ParametricDefinition.class); | ||
436 | if (!(definitionContext instanceof RuleDefinition)) { | ||
437 | var message = "Computed value references may only appear in rule definitions."; | ||
438 | acceptError(message, atom, ProblemPackage.Literals.ATOM__COMPUTED, 0, INVALID_COMPUTED_VALUE_ISSUE); | ||
439 | } | ||
440 | } | ||
428 | } | 441 | } |
429 | 442 | ||
430 | @Check | 443 | @Check |