diff options
author | 2024-05-17 18:40:14 +0200 | |
---|---|---|
committer | 2024-05-26 17:22:32 +0200 | |
commit | 8faf73a84b51d94ee4d8cc49dbbf9ff82898f436 (patch) | |
tree | 5fe4657c90b0158ea843e0492486b0de5aa7ab3c /subprojects/language/src/main/java/tools | |
parent | feat(language): rule validation (diff) | |
download | refinery-8faf73a84b51d94ee4d8cc49dbbf9ff82898f436.tar.gz refinery-8faf73a84b51d94ee4d8cc49dbbf9ff82898f436.tar.zst refinery-8faf73a84b51d94ee4d8cc49dbbf9ff82898f436.zip |
refactor(language): merge Assertion and AssertionAction
Diffstat (limited to 'subprojects/language/src/main/java/tools')
4 files changed, 22 insertions, 23 deletions
diff --git a/subprojects/language/src/main/java/tools/refinery/language/formatting2/ProblemFormatter.java b/subprojects/language/src/main/java/tools/refinery/language/formatting2/ProblemFormatter.java index d6ece1ea..c6fca89a 100644 --- a/subprojects/language/src/main/java/tools/refinery/language/formatting2/ProblemFormatter.java +++ b/subprojects/language/src/main/java/tools/refinery/language/formatting2/ProblemFormatter.java | |||
@@ -35,7 +35,7 @@ public class ProblemFormatter extends AbstractJavaFormatter { | |||
35 | surroundNewLines(doc, assertion, this::singleNewLine); | 35 | surroundNewLines(doc, assertion, this::singleNewLine); |
36 | var region = regionFor(assertion); | 36 | var region = regionFor(assertion); |
37 | doc.append(region.feature(ProblemPackage.Literals.ASSERTION__DEFAULT), this::oneSpace); | 37 | doc.append(region.feature(ProblemPackage.Literals.ASSERTION__DEFAULT), this::oneSpace); |
38 | doc.append(region.feature(ProblemPackage.Literals.ASSERTION__RELATION), this::noSpace); | 38 | doc.append(region.feature(ProblemPackage.Literals.ABSTRACT_ASSERTION__RELATION), this::noSpace); |
39 | formatParenthesizedList(region, doc); | 39 | formatParenthesizedList(region, doc); |
40 | for (var argument : assertion.getArguments()) { | 40 | for (var argument : assertion.getArguments()) { |
41 | doc.format(argument); | 41 | doc.format(argument); |
diff --git a/subprojects/language/src/main/java/tools/refinery/language/serializer/PreferShortAssertionsProblemSemanticSequencer.java b/subprojects/language/src/main/java/tools/refinery/language/serializer/PreferShortAssertionsProblemSemanticSequencer.java index 3432b2d8..225bf49d 100644 --- a/subprojects/language/src/main/java/tools/refinery/language/serializer/PreferShortAssertionsProblemSemanticSequencer.java +++ b/subprojects/language/src/main/java/tools/refinery/language/serializer/PreferShortAssertionsProblemSemanticSequencer.java | |||
@@ -12,9 +12,11 @@ import org.eclipse.xtext.serializer.sequencer.ITransientValueService.ValueTransi | |||
12 | import tools.refinery.language.model.problem.Assertion; | 12 | import tools.refinery.language.model.problem.Assertion; |
13 | import tools.refinery.language.model.problem.LogicConstant; | 13 | import tools.refinery.language.model.problem.LogicConstant; |
14 | import tools.refinery.language.model.problem.LogicValue; | 14 | import tools.refinery.language.model.problem.LogicValue; |
15 | import tools.refinery.language.model.problem.ProblemPackage; | ||
16 | import tools.refinery.language.services.ProblemGrammarAccess; | 15 | import tools.refinery.language.services.ProblemGrammarAccess; |
17 | 16 | ||
17 | import static tools.refinery.language.model.problem.ProblemPackage.Literals.ABSTRACT_ASSERTION__ARGUMENTS; | ||
18 | import static tools.refinery.language.model.problem.ProblemPackage.Literals.ABSTRACT_ASSERTION__RELATION; | ||
19 | |||
18 | public class PreferShortAssertionsProblemSemanticSequencer extends ProblemSemanticSequencer { | 20 | public class PreferShortAssertionsProblemSemanticSequencer extends ProblemSemanticSequencer { |
19 | @Inject | 21 | @Inject |
20 | private ProblemGrammarAccess grammarAccess; | 22 | private ProblemGrammarAccess grammarAccess; |
@@ -27,13 +29,13 @@ public class PreferShortAssertionsProblemSemanticSequencer extends ProblemSemant | |||
27 | return; | 29 | return; |
28 | } | 30 | } |
29 | if (errorAcceptor != null) { | 31 | if (errorAcceptor != null) { |
30 | if (transientValues.isValueTransient(semanticObject, ProblemPackage.Literals.ASSERTION__RELATION) == ValueTransient.YES) { | 32 | if (transientValues.isValueTransient(semanticObject, ABSTRACT_ASSERTION__RELATION) == ValueTransient.YES) { |
31 | errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, | 33 | errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, |
32 | ProblemPackage.Literals.ASSERTION__RELATION)); | 34 | ABSTRACT_ASSERTION__RELATION)); |
33 | } | 35 | } |
34 | if (transientValues.isListTransient(semanticObject, ProblemPackage.Literals.ASSERTION__ARGUMENTS) == ListTransient.YES) { | 36 | if (transientValues.isListTransient(semanticObject, ABSTRACT_ASSERTION__ARGUMENTS) == ListTransient.YES) { |
35 | errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, | 37 | errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, |
36 | ProblemPackage.Literals.ASSERTION__ARGUMENTS)); | 38 | ABSTRACT_ASSERTION__ARGUMENTS)); |
37 | } | 39 | } |
38 | } | 40 | } |
39 | var feeder = createSequencerFeeder(context, semanticObject); | 41 | var feeder = createSequencerFeeder(context, semanticObject); |
diff --git a/subprojects/language/src/main/java/tools/refinery/language/typesystem/TypedModule.java b/subprojects/language/src/main/java/tools/refinery/language/typesystem/TypedModule.java index 0b252c09..63815506 100644 --- a/subprojects/language/src/main/java/tools/refinery/language/typesystem/TypedModule.java +++ b/subprojects/language/src/main/java/tools/refinery/language/typesystem/TypedModule.java | |||
@@ -8,7 +8,6 @@ package tools.refinery.language.typesystem; | |||
8 | import com.google.inject.Inject; | 8 | import com.google.inject.Inject; |
9 | import org.eclipse.emf.common.util.Diagnostic; | 9 | import org.eclipse.emf.common.util.Diagnostic; |
10 | import org.eclipse.emf.ecore.EObject; | 10 | import org.eclipse.emf.ecore.EObject; |
11 | import org.eclipse.emf.ecore.EReference; | ||
12 | import org.eclipse.emf.ecore.EStructuralFeature; | 11 | import org.eclipse.emf.ecore.EStructuralFeature; |
13 | import org.eclipse.xtext.validation.CheckType; | 12 | import org.eclipse.xtext.validation.CheckType; |
14 | import org.eclipse.xtext.validation.FeatureBasedDiagnostic; | 13 | import org.eclipse.xtext.validation.FeatureBasedDiagnostic; |
@@ -97,17 +96,17 @@ public class TypedModule { | |||
97 | } | 96 | } |
98 | 97 | ||
99 | private void checkTypes(Assertion assertion) { | 98 | private void checkTypes(Assertion assertion) { |
100 | var relation = assertion.getRelation(); | 99 | checkAssertionValueType(assertion); |
101 | var value = assertion.getValue(); | 100 | checkNodeAssertionArgumentTypes(assertion, false); |
102 | checkAssertion(assertion, relation, value, ProblemPackage.Literals.ASSERTION__RELATION); | ||
103 | checkNodeAssertionArgumentTypes(assertion.getArguments(), false); | ||
104 | } | 101 | } |
105 | 102 | ||
106 | private void checkAssertion(EObject assertion, Relation relation, Expr value, EReference relationReference) { | 103 | private void checkAssertionValueType(AbstractAssertion assertion) { |
104 | var relation = assertion.getRelation(); | ||
107 | if (relation == null) { | 105 | if (relation == null) { |
108 | return; | 106 | return; |
109 | } | 107 | } |
110 | var type = signatureProvider.getSignature(relation).resultType(); | 108 | var type = signatureProvider.getSignature(relation).resultType(); |
109 | var value = assertion.getValue(); | ||
111 | if (type == ExprType.LITERAL) { | 110 | if (type == ExprType.LITERAL) { |
112 | if (value == null) { | 111 | if (value == null) { |
113 | return; | 112 | return; |
@@ -117,14 +116,14 @@ public class TypedModule { | |||
117 | } | 116 | } |
118 | if (value == null) { | 117 | if (value == null) { |
119 | var message = "Assertion value of type %s is required.".formatted(type); | 118 | var message = "Assertion value of type %s is required.".formatted(type); |
120 | error(message, assertion, relationReference, 0, ProblemValidator.TYPE_ERROR); | 119 | error(message, assertion, ProblemPackage.Literals.ABSTRACT_ASSERTION__VALUE, 0, |
120 | ProblemValidator.TYPE_ERROR); | ||
121 | } | 121 | } |
122 | expectType(value, type); | 122 | expectType(value, type); |
123 | } | 123 | } |
124 | 124 | ||
125 | private void checkNodeAssertionArgumentTypes(Collection<AssertionArgument> assertionArguments, | 125 | private void checkNodeAssertionArgumentTypes(AbstractAssertion assertion, boolean allowVariables) { |
126 | boolean allowVariables) { | 126 | for (var argument : assertion.getArguments()) { |
127 | for (var argument : assertionArguments) { | ||
128 | if (argument instanceof NodeAssertionArgument nodeAssertionArgument) { | 127 | if (argument instanceof NodeAssertionArgument nodeAssertionArgument) { |
129 | checkNodeAssertionArgumentType(nodeAssertionArgument, allowVariables); | 128 | checkNodeAssertionArgumentType(nodeAssertionArgument, allowVariables); |
130 | } | 129 | } |
@@ -150,10 +149,8 @@ public class TypedModule { | |||
150 | } | 149 | } |
151 | 150 | ||
152 | private void checkTypes(AssertionAction assertionAction) { | 151 | private void checkTypes(AssertionAction assertionAction) { |
153 | var relation = assertionAction.getRelation(); | 152 | checkAssertionValueType(assertionAction); |
154 | var value = assertionAction.getValue(); | 153 | checkNodeAssertionArgumentTypes(assertionAction, true); |
155 | checkAssertion(assertionAction, relation, value, ProblemPackage.Literals.ASSERTION_ACTION__RELATION); | ||
156 | checkNodeAssertionArgumentTypes(assertionAction.getArguments(), true); | ||
157 | } | 154 | } |
158 | 155 | ||
159 | public List<FeatureBasedDiagnostic> getDiagnostics() { | 156 | public List<FeatureBasedDiagnostic> getDiagnostics() { |
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 7046d4c6..0285c0c8 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 | |||
@@ -382,16 +382,16 @@ public class ProblemValidator extends AbstractProblemValidator { | |||
382 | } | 382 | } |
383 | 383 | ||
384 | @Check | 384 | @Check |
385 | public void checkAssertion(Assertion assertion) { | 385 | public void checkAssertion(AbstractAssertion assertion) { |
386 | var relation = assertion.getRelation(); | 386 | var relation = assertion.getRelation(); |
387 | if (relation instanceof DatatypeDeclaration) { | 387 | if (relation instanceof DatatypeDeclaration) { |
388 | var message = "Assertions for data types are not supported."; | 388 | var message = "Assertions for data types are not supported."; |
389 | acceptError(message, assertion, ProblemPackage.Literals.ASSERTION__RELATION, 0, | 389 | acceptError(message, assertion, ProblemPackage.Literals.ABSTRACT_ASSERTION__RELATION, 0, |
390 | UNSUPPORTED_ASSERTION_ISSUE); | 390 | UNSUPPORTED_ASSERTION_ISSUE); |
391 | return; | 391 | return; |
392 | } | 392 | } |
393 | int argumentCount = assertion.getArguments().size(); | 393 | int argumentCount = assertion.getArguments().size(); |
394 | checkArity(assertion, ProblemPackage.Literals.ASSERTION__RELATION, argumentCount); | 394 | checkArity(assertion, ProblemPackage.Literals.ABSTRACT_ASSERTION__RELATION, argumentCount); |
395 | } | 395 | } |
396 | 396 | ||
397 | @Check | 397 | @Check |