diff options
author | 2024-06-28 18:58:50 +0200 | |
---|---|---|
committer | 2024-06-28 18:58:50 +0200 | |
commit | 2e8a2f6a80fbd974ad877aeee4ef76b740831311 (patch) | |
tree | 21aa932352a94ca0a811e60e474ab8e57cc84d4d /subprojects/language-web/src | |
parent | refactor(reasoning): fix Sonar warnings (diff) | |
download | refinery-2e8a2f6a80fbd974ad877aeee4ef76b740831311.tar.gz refinery-2e8a2f6a80fbd974ad877aeee4ef76b740831311.tar.zst refinery-2e8a2f6a80fbd974ad877aeee4ef76b740831311.zip |
refactor: show semantics even if propagation fails
Diffstat (limited to 'subprojects/language-web/src')
-rw-r--r-- | subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsInternalErrorResult.java | 9 | ||||
-rw-r--r-- | subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsIssuesResult.java | 13 | ||||
-rw-r--r-- | subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsModelResult.java (renamed from subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsSuccessResult.java) | 5 | ||||
-rw-r--r-- | subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsResult.java | 22 | ||||
-rw-r--r-- | subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsService.java | 15 | ||||
-rw-r--r-- | subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsWorker.java | 13 |
6 files changed, 39 insertions, 38 deletions
diff --git a/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsInternalErrorResult.java b/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsInternalErrorResult.java deleted file mode 100644 index ff592e93..00000000 --- a/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsInternalErrorResult.java +++ /dev/null | |||
@@ -1,9 +0,0 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.language.web.semantics; | ||
7 | |||
8 | public record SemanticsInternalErrorResult(String error) implements SemanticsResult { | ||
9 | } | ||
diff --git a/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsIssuesResult.java b/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsIssuesResult.java deleted file mode 100644 index 644bd179..00000000 --- a/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsIssuesResult.java +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.language.web.semantics; | ||
7 | |||
8 | import org.eclipse.xtext.web.server.validation.ValidationResult; | ||
9 | |||
10 | import java.util.List; | ||
11 | |||
12 | public record SemanticsIssuesResult(List<ValidationResult.Issue> issues) implements SemanticsResult { | ||
13 | } | ||
diff --git a/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsSuccessResult.java b/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsModelResult.java index f26fa2b2..b0ec58c3 100644 --- a/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsSuccessResult.java +++ b/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsModelResult.java | |||
@@ -11,6 +11,7 @@ import tools.refinery.language.web.semantics.metadata.RelationMetadata; | |||
11 | 11 | ||
12 | import java.util.List; | 12 | import java.util.List; |
13 | 13 | ||
14 | public record SemanticsSuccessResult(List<NodeMetadata> nodes, List<RelationMetadata> relations, | 14 | public record SemanticsModelResult(List<NodeMetadata> nodes, List<RelationMetadata> relations, |
15 | JsonObject partialInterpretation) implements SemanticsResult { | 15 | JsonObject partialInterpretation) { |
16 | public static SemanticsModelResult EMPTY = new SemanticsModelResult(List.of(), List.of(), new JsonObject()); | ||
16 | } | 17 | } |
diff --git a/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsResult.java b/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsResult.java index a2e19a2f..16f25309 100644 --- a/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsResult.java +++ b/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsResult.java | |||
@@ -6,7 +6,25 @@ | |||
6 | package tools.refinery.language.web.semantics; | 6 | package tools.refinery.language.web.semantics; |
7 | 7 | ||
8 | import org.eclipse.xtext.web.server.IServiceResult; | 8 | import org.eclipse.xtext.web.server.IServiceResult; |
9 | import org.eclipse.xtext.web.server.validation.ValidationResult; | ||
9 | 10 | ||
10 | public sealed interface SemanticsResult extends IServiceResult permits SemanticsSuccessResult, | 11 | import java.util.List; |
11 | SemanticsInternalErrorResult, SemanticsIssuesResult { | 12 | |
13 | public record SemanticsResult(SemanticsModelResult model, String error, | ||
14 | List<ValidationResult.Issue> issues) implements IServiceResult { | ||
15 | public SemanticsResult(SemanticsModelResult model) { | ||
16 | this(model, null, List.of()); | ||
17 | } | ||
18 | |||
19 | public SemanticsResult(String error) { | ||
20 | this(null, error, List.of()); | ||
21 | } | ||
22 | |||
23 | public SemanticsResult(SemanticsModelResult model, String error) { | ||
24 | this(model, error, List.of()); | ||
25 | } | ||
26 | |||
27 | public SemanticsResult(List<ValidationResult.Issue> issues) { | ||
28 | this(null, null, issues); | ||
29 | } | ||
12 | } | 30 | } |
diff --git a/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsService.java b/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsService.java index 331ef84b..f6b723fe 100644 --- a/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsService.java +++ b/subprojects/language-web/src/main/java/tools/refinery/language/web/semantics/SemanticsService.java | |||
@@ -5,7 +5,6 @@ | |||
5 | */ | 5 | */ |
6 | package tools.refinery.language.web.semantics; | 6 | package tools.refinery.language.web.semantics; |
7 | 7 | ||
8 | import com.google.gson.JsonObject; | ||
9 | import com.google.inject.Inject; | 8 | import com.google.inject.Inject; |
10 | import com.google.inject.Provider; | 9 | import com.google.inject.Provider; |
11 | import com.google.inject.Singleton; | 10 | import com.google.inject.Singleton; |
@@ -21,9 +20,11 @@ import org.slf4j.LoggerFactory; | |||
21 | import tools.refinery.language.model.problem.Problem; | 20 | import tools.refinery.language.model.problem.Problem; |
22 | import tools.refinery.language.web.xtext.server.push.PushWebDocument; | 21 | import tools.refinery.language.web.xtext.server.push.PushWebDocument; |
23 | 22 | ||
24 | import java.util.List; | ||
25 | import java.util.Optional; | 23 | import java.util.Optional; |
26 | import java.util.concurrent.*; | 24 | import java.util.concurrent.ExecutionException; |
25 | import java.util.concurrent.ExecutorService; | ||
26 | import java.util.concurrent.TimeUnit; | ||
27 | import java.util.concurrent.TimeoutException; | ||
27 | import java.util.concurrent.atomic.AtomicBoolean; | 28 | import java.util.concurrent.atomic.AtomicBoolean; |
28 | 29 | ||
29 | @Singleton | 30 | @Singleton |
@@ -74,7 +75,7 @@ public class SemanticsService extends AbstractCachedService<SemanticsResult> { | |||
74 | } | 75 | } |
75 | var problem = getProblem(doc); | 76 | var problem = getProblem(doc); |
76 | if (problem == null) { | 77 | if (problem == null) { |
77 | return new SemanticsSuccessResult(List.of(), List.of(), new JsonObject()); | 78 | return new SemanticsResult(SemanticsModelResult.EMPTY); |
78 | } | 79 | } |
79 | var worker = workerProvider.get(); | 80 | var worker = workerProvider.get(); |
80 | worker.setProblem(problem, cancelIndicator); | 81 | worker.setProblem(problem, cancelIndicator); |
@@ -101,14 +102,14 @@ public class SemanticsService extends AbstractCachedService<SemanticsResult> { | |||
101 | if (message == null) { | 102 | if (message == null) { |
102 | message = "Partial interpretation error"; | 103 | message = "Partial interpretation error"; |
103 | } | 104 | } |
104 | return new SemanticsInternalErrorResult(message); | 105 | return new SemanticsResult(message); |
105 | } catch (TimeoutException e) { | 106 | } catch (TimeoutException e) { |
106 | future.cancel(true); | 107 | future.cancel(true); |
107 | if (!warmedUpCurrently) { | 108 | if (!warmedUpCurrently) { |
108 | warmedUp.set(true); | 109 | warmedUp.set(true); |
109 | } | 110 | } |
110 | LOG.trace("Semantics service timeout", e); | 111 | LOG.trace("Semantics service timeout", e); |
111 | return new SemanticsInternalErrorResult("Partial interpretation timed out"); | 112 | return new SemanticsResult("Partial interpretation timed out"); |
112 | } | 113 | } |
113 | if (LOG.isTraceEnabled()) { | 114 | if (LOG.isTraceEnabled()) { |
114 | long end = System.currentTimeMillis(); | 115 | long end = System.currentTimeMillis(); |
@@ -133,7 +134,7 @@ public class SemanticsService extends AbstractCachedService<SemanticsResult> { | |||
133 | if (contents.isEmpty()) { | 134 | if (contents.isEmpty()) { |
134 | return null; | 135 | return null; |
135 | } | 136 | } |
136 | var model = contents.get(0); | 137 | var model = contents.getFirst(); |
137 | if (!(model instanceof Problem problem)) { | 138 | if (!(model instanceof Problem problem)) { |
138 | return null; | 139 | return null; |
139 | } | 140 | } |
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 fed3c8a3..32791960 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 | |||
@@ -21,6 +21,7 @@ import tools.refinery.language.model.problem.Problem; | |||
21 | import tools.refinery.language.web.semantics.metadata.MetadataCreator; | 21 | import tools.refinery.language.web.semantics.metadata.MetadataCreator; |
22 | import tools.refinery.language.semantics.TracedException; | 22 | import tools.refinery.language.semantics.TracedException; |
23 | import tools.refinery.store.reasoning.literal.Concreteness; | 23 | import tools.refinery.store.reasoning.literal.Concreteness; |
24 | import tools.refinery.store.reasoning.seed.PropagatedModel; | ||
24 | import tools.refinery.store.reasoning.translator.TranslationException; | 25 | import tools.refinery.store.reasoning.translator.TranslationException; |
25 | import tools.refinery.store.util.CancellationToken; | 26 | import tools.refinery.store.util.CancellationToken; |
26 | 27 | ||
@@ -63,9 +64,9 @@ class SemanticsWorker implements Callable<SemanticsResult> { | |||
63 | cancellationToken.checkCancelled(); | 64 | cancellationToken.checkCancelled(); |
64 | ModelSemantics semantics; | 65 | ModelSemantics semantics; |
65 | try { | 66 | try { |
66 | semantics = semanticsFactory.cancellationToken(cancellationToken).createSemantics(problem); | 67 | semantics = semanticsFactory.cancellationToken(cancellationToken).tryCreateSemantics(problem); |
67 | } catch (TranslationException e) { | 68 | } catch (TranslationException e) { |
68 | return new SemanticsInternalErrorResult(e.getMessage()); | 69 | return new SemanticsResult(e.getMessage()); |
69 | } catch (TracedException e) { | 70 | } catch (TracedException e) { |
70 | var cause = e.getCause(); | 71 | var cause = e.getCause(); |
71 | // Suppress the type of the cause exception. | 72 | // Suppress the type of the cause exception. |
@@ -79,12 +80,14 @@ class SemanticsWorker implements Callable<SemanticsResult> { | |||
79 | var relationsMetadata = metadataCreator.getRelationsMetadata(); | 80 | var relationsMetadata = metadataCreator.getRelationsMetadata(); |
80 | cancellationToken.checkCancelled(); | 81 | cancellationToken.checkCancelled(); |
81 | var partialInterpretation = partialInterpretation2Json.getPartialInterpretation(semantics, cancellationToken); | 82 | var partialInterpretation = partialInterpretation2Json.getPartialInterpretation(semantics, cancellationToken); |
82 | return new SemanticsSuccessResult(nodesMetadata, relationsMetadata, partialInterpretation); | 83 | var modelResult = new SemanticsModelResult(nodesMetadata, relationsMetadata, partialInterpretation); |
84 | var error = semantics.isRejected() ? PropagatedModel.PROPAGATION_FAILED_MESSAGE : null; | ||
85 | return new SemanticsResult(modelResult, error); | ||
83 | } | 86 | } |
84 | 87 | ||
85 | private SemanticsResult getTracedErrorResult(EObject sourceElement, String message) { | 88 | private SemanticsResult getTracedErrorResult(EObject sourceElement, String message) { |
86 | if (sourceElement == null || !problem.eResource().equals(sourceElement.eResource())) { | 89 | if (sourceElement == null || !problem.eResource().equals(sourceElement.eResource())) { |
87 | return new SemanticsInternalErrorResult(message); | 90 | return new SemanticsResult(message); |
88 | } | 91 | } |
89 | var diagnostic = new FeatureBasedDiagnostic(Diagnostic.ERROR, message, sourceElement, null, 0, | 92 | var diagnostic = new FeatureBasedDiagnostic(Diagnostic.ERROR, message, sourceElement, null, 0, |
90 | CheckType.EXPENSIVE, DIAGNOSTIC_ID); | 93 | CheckType.EXPENSIVE, DIAGNOSTIC_ID); |
@@ -94,6 +97,6 @@ class SemanticsWorker implements Callable<SemanticsResult> { | |||
94 | .map(issue -> new ValidationResult.Issue(issue.getMessage(), "error", issue.getLineNumber(), | 97 | .map(issue -> new ValidationResult.Issue(issue.getMessage(), "error", issue.getLineNumber(), |
95 | issue.getColumn(), issue.getOffset(), issue.getLength())) | 98 | issue.getColumn(), issue.getOffset(), issue.getLength())) |
96 | .toList(); | 99 | .toList(); |
97 | return new SemanticsIssuesResult(issues); | 100 | return new SemanticsResult(issues); |
98 | } | 101 | } |
99 | } | 102 | } |