aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2023-12-22 02:19:19 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2023-12-22 02:19:19 +0100
commitbc6951e94776d18b12736f9e7638f5a49cbb49a0 (patch)
treefd3fafa5779063443ba9d6d96aa55f71888f7d64
parentfeat: state-based store for cross references (diff)
downloadrefinery-bc6951e94776d18b12736f9e7638f5a49cbb49a0.tar.gz
refinery-bc6951e94776d18b12736f9e7638f5a49cbb49a0.tar.zst
refinery-bc6951e94776d18b12736f9e7638f5a49cbb49a0.zip
refactor(language): use file extension provider
-rw-r--r--subprojects/generator/src/main/java/tools/refinery/generator/ProblemLoader.java13
1 files changed, 11 insertions, 2 deletions
diff --git a/subprojects/generator/src/main/java/tools/refinery/generator/ProblemLoader.java b/subprojects/generator/src/main/java/tools/refinery/generator/ProblemLoader.java
index 29f80714..2d93a5ad 100644
--- a/subprojects/generator/src/main/java/tools/refinery/generator/ProblemLoader.java
+++ b/subprojects/generator/src/main/java/tools/refinery/generator/ProblemLoader.java
@@ -10,6 +10,7 @@ import com.google.inject.Provider;
10import org.eclipse.emf.common.util.URI; 10import org.eclipse.emf.common.util.URI;
11import org.eclipse.emf.ecore.resource.Resource; 11import org.eclipse.emf.ecore.resource.Resource;
12import org.eclipse.xtext.diagnostics.Severity; 12import org.eclipse.xtext.diagnostics.Severity;
13import org.eclipse.xtext.resource.FileExtensionProvider;
13import org.eclipse.xtext.resource.IResourceFactory; 14import org.eclipse.xtext.resource.IResourceFactory;
14import org.eclipse.xtext.resource.XtextResourceSet; 15import org.eclipse.xtext.resource.XtextResourceSet;
15import org.eclipse.xtext.util.LazyStringInputStream; 16import org.eclipse.xtext.util.LazyStringInputStream;
@@ -24,6 +25,8 @@ import java.io.InputStream;
24import java.util.Map; 25import java.util.Map;
25 26
26public class ProblemLoader { 27public class ProblemLoader {
28 private String fileExtension;
29
27 @Inject 30 @Inject
28 private Provider<XtextResourceSet> resourceSetProvider; 31 private Provider<XtextResourceSet> resourceSetProvider;
29 32
@@ -35,6 +38,11 @@ public class ProblemLoader {
35 38
36 private CancellationToken cancellationToken = CancellationToken.NONE; 39 private CancellationToken cancellationToken = CancellationToken.NONE;
37 40
41 @Inject
42 public void setFileExtensionProvider(FileExtensionProvider fileExtensionProvider) {
43 this.fileExtension = fileExtensionProvider.getPrimaryFileExtension();
44 }
45
38 public ProblemLoader cancellationToken(CancellationToken cancellationToken) { 46 public ProblemLoader cancellationToken(CancellationToken cancellationToken) {
39 this.cancellationToken = cancellationToken; 47 this.cancellationToken = cancellationToken;
40 return this; 48 return this;
@@ -48,7 +56,8 @@ public class ProblemLoader {
48 56
49 public Problem loadStream(InputStream inputStream) throws IOException { 57 public Problem loadStream(InputStream inputStream) throws IOException {
50 var resourceSet = resourceSetProvider.get(); 58 var resourceSet = resourceSetProvider.get();
51 var resource = resourceFactory.createResource(URI.createFileURI("__synthetic.problem")); 59 var uri = URI.createFileURI("__synthetic." + fileExtension);
60 var resource = resourceFactory.createResource(uri);
52 resourceSet.getResources().add(resource); 61 resourceSet.getResources().add(resource);
53 resource.load(inputStream, Map.of()); 62 resource.load(inputStream, Map.of());
54 return loadResource(resource); 63 return loadResource(resource);
@@ -82,7 +91,7 @@ public class ProblemLoader {
82 if (!errors.isEmpty()) { 91 if (!errors.isEmpty()) {
83 throw new ValidationErrorsException(resource.getURI(), errors); 92 throw new ValidationErrorsException(resource.getURI(), errors);
84 } 93 }
85 if (resource.getContents().isEmpty() || !(resource.getContents().get(0) instanceof Problem problem)) { 94 if (resource.getContents().isEmpty() || !(resource.getContents().getFirst() instanceof Problem problem)) {
86 throw new IllegalArgumentException("Model generation problem not found in resource " + resource.getURI()); 95 throw new IllegalArgumentException("Model generation problem not found in resource " + resource.getURI());
87 } 96 }
88 return problem; 97 return problem;