diff options
Diffstat (limited to 'subprojects/language-web/src')
-rw-r--r-- | subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsWorker.java | 67 |
1 files changed, 44 insertions, 23 deletions
diff --git a/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsWorker.java b/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsWorker.java index 4ec11bb9..c6485309 100644 --- a/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsWorker.java +++ b/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsWorker.java | |||
@@ -8,6 +8,7 @@ package tools.refinery.language.web.semantics; | |||
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.EStructuralFeature; | ||
11 | import org.eclipse.xtext.service.OperationCanceledManager; | 12 | import org.eclipse.xtext.service.OperationCanceledManager; |
12 | import org.eclipse.xtext.util.CancelIndicator; | 13 | import org.eclipse.xtext.util.CancelIndicator; |
13 | import org.eclipse.xtext.validation.CheckType; | 14 | import org.eclipse.xtext.validation.CheckType; |
@@ -18,11 +19,14 @@ import org.eclipse.xtext.web.server.validation.ValidationResult; | |||
18 | import tools.refinery.generator.ModelSemantics; | 19 | import tools.refinery.generator.ModelSemantics; |
19 | import tools.refinery.generator.ModelSemanticsFactory; | 20 | import tools.refinery.generator.ModelSemanticsFactory; |
20 | import tools.refinery.language.model.problem.Problem; | 21 | import tools.refinery.language.model.problem.Problem; |
22 | import tools.refinery.language.model.problem.ProblemPackage; | ||
21 | import tools.refinery.language.model.problem.ScopeDeclaration; | 23 | import tools.refinery.language.model.problem.ScopeDeclaration; |
24 | import tools.refinery.language.semantics.ProblemTrace; | ||
22 | import tools.refinery.language.semantics.TracedException; | 25 | import tools.refinery.language.semantics.TracedException; |
23 | import tools.refinery.language.web.semantics.metadata.MetadataCreator; | 26 | import tools.refinery.language.web.semantics.metadata.MetadataCreator; |
24 | import tools.refinery.store.dse.propagation.PropagationRejectedResult; | 27 | import tools.refinery.store.dse.propagation.PropagationRejectedResult; |
25 | import tools.refinery.store.dse.propagation.PropagationResult; | 28 | import tools.refinery.store.dse.propagation.PropagationResult; |
29 | import tools.refinery.store.dse.transition.Rule; | ||
26 | import tools.refinery.store.reasoning.literal.Concreteness; | 30 | import tools.refinery.store.reasoning.literal.Concreteness; |
27 | import tools.refinery.store.reasoning.scope.ScopePropagator; | 31 | import tools.refinery.store.reasoning.scope.ScopePropagator; |
28 | import tools.refinery.store.reasoning.translator.TranslationException; | 32 | import tools.refinery.store.reasoning.translator.TranslationException; |
@@ -79,18 +83,31 @@ class SemanticsWorker implements Callable<SemanticsResult> { | |||
79 | } | 83 | } |
80 | cancellationToken.checkCancelled(); | 84 | cancellationToken.checkCancelled(); |
81 | var modelResult = createSemanticsModelResult(semantics); | 85 | var modelResult = createSemanticsModelResult(semantics); |
82 | return createSemanticsResult(modelResult, semantics.getPropagationResult()); | 86 | return createSemanticsResult(modelResult, semantics.getProblemTrace(), semantics.getPropagationResult()); |
83 | } | 87 | } |
84 | 88 | ||
85 | |||
86 | private SemanticsResult getTracedErrorResult(EObject sourceElement, String message) { | 89 | private SemanticsResult getTracedErrorResult(EObject sourceElement, String message) { |
90 | var diagnostics = getTracedDiagnostics(sourceElement, null, message); | ||
91 | return getSemanticsResultWithDiagnostics(null, message, diagnostics); | ||
92 | } | ||
93 | |||
94 | private List<FeatureBasedDiagnostic> getTracedDiagnostics( | ||
95 | EObject sourceElement, EStructuralFeature feature, String message) { | ||
87 | if (sourceElement == null || !problem.eResource().equals(sourceElement.eResource())) { | 96 | if (sourceElement == null || !problem.eResource().equals(sourceElement.eResource())) { |
88 | return new SemanticsResult(message); | 97 | return List.of(); |
89 | } | 98 | } |
90 | var diagnostic = new FeatureBasedDiagnostic(Diagnostic.ERROR, message, sourceElement, null, 0, | 99 | var diagnostic = new FeatureBasedDiagnostic(Diagnostic.ERROR, message, sourceElement, feature, 0, |
91 | CheckType.EXPENSIVE, DIAGNOSTIC_ID); | 100 | CheckType.EXPENSIVE, DIAGNOSTIC_ID); |
92 | var issues = convertIssues(List.of(diagnostic)); | 101 | return List.of(diagnostic); |
93 | return new SemanticsResult(issues); | 102 | } |
103 | |||
104 | private SemanticsResult getSemanticsResultWithDiagnostics( | ||
105 | SemanticsModelResult modelResult, String message, List<FeatureBasedDiagnostic> diagnostics) { | ||
106 | if (diagnostics.isEmpty()) { | ||
107 | return new SemanticsResult(modelResult, message); | ||
108 | } | ||
109 | var issues = convertIssues(diagnostics); | ||
110 | return new SemanticsResult(modelResult, issues); | ||
94 | } | 111 | } |
95 | 112 | ||
96 | private List<ValidationResult.Issue> convertIssues(List<FeatureBasedDiagnostic> diagnostics) { | 113 | private List<ValidationResult.Issue> convertIssues(List<FeatureBasedDiagnostic> diagnostics) { |
@@ -114,26 +131,30 @@ class SemanticsWorker implements Callable<SemanticsResult> { | |||
114 | return new SemanticsModelResult(nodesMetadata, relationsMetadata, partialInterpretation); | 131 | return new SemanticsModelResult(nodesMetadata, relationsMetadata, partialInterpretation); |
115 | } | 132 | } |
116 | 133 | ||
117 | private SemanticsResult createSemanticsResult(SemanticsModelResult modelResult, | 134 | private SemanticsResult createSemanticsResult( |
118 | PropagationResult propagationResult) { | 135 | SemanticsModelResult modelResult, ProblemTrace trace, PropagationResult propagationResult) { |
119 | if (!(propagationResult instanceof PropagationRejectedResult rejectedResult)) { | 136 | if (!(propagationResult instanceof PropagationRejectedResult rejectedResult)) { |
120 | return new SemanticsResult(modelResult); | 137 | return new SemanticsResult(modelResult); |
121 | } | 138 | } |
122 | var message = rejectedResult.formatMessage(); | 139 | var message = rejectedResult.formatMessage(); |
123 | if (!(rejectedResult.reason() instanceof ScopePropagator)) { | 140 | List<FeatureBasedDiagnostic> diagnostics = switch (rejectedResult.reason()) { |
124 | return new SemanticsResult(modelResult, message); | 141 | case ScopePropagator ignored -> getScopePropagatorDiagnostics(message); |
125 | } | 142 | case Rule rule -> getRuleDiagnostics(rule, trace, message); |
126 | var diagnostics = new ArrayList<FeatureBasedDiagnostic>(); | 143 | default -> List.of(); |
127 | for (var statement : problem.getStatements()) { | 144 | }; |
128 | if (statement instanceof ScopeDeclaration scopeDeclaration) { | 145 | return getSemanticsResultWithDiagnostics(modelResult, message, diagnostics); |
129 | diagnostics.add(new FeatureBasedDiagnostic(Diagnostic.ERROR, message, scopeDeclaration, null, 0, | 146 | } |
130 | CheckType.EXPENSIVE, DIAGNOSTIC_ID)); | 147 | |
131 | } | 148 | private List<FeatureBasedDiagnostic> getScopePropagatorDiagnostics(String message) { |
132 | } | 149 | return problem.getStatements().stream() |
133 | if (diagnostics.isEmpty()) { | 150 | .filter(ScopeDeclaration.class::isInstance) |
134 | return new SemanticsResult(modelResult, message); | 151 | .map(eObject -> new FeatureBasedDiagnostic(Diagnostic.ERROR, message, eObject, null, 0, |
135 | } | 152 | CheckType.EXPENSIVE, DIAGNOSTIC_ID)) |
136 | var issues = convertIssues(diagnostics); | 153 | .toList(); |
137 | return new SemanticsResult(modelResult, issues); | 154 | } |
155 | |||
156 | private List<FeatureBasedDiagnostic> getRuleDiagnostics(Rule rule, ProblemTrace trace, String message) { | ||
157 | var ruleDefinition = trace.getRuleDefinition(rule); | ||
158 | return getTracedDiagnostics(ruleDefinition, ProblemPackage.Literals.NAMED_ELEMENT__NAME, message); | ||
138 | } | 159 | } |
139 | } | 160 | } |