]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/FileModuleSource.java
Added a function to read the module source text
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / source / FileModuleSource.java
1 package org.simantics.scl.compiler.source;
2
3 import java.io.File;
4 import java.io.FileInputStream;
5 import java.io.IOException;
6 import java.io.InputStream;
7
8 import org.simantics.scl.compiler.internal.codegen.types.JavaReferenceValidator;
9 import org.simantics.scl.compiler.internal.codegen.types.RuntimeJavaReferenceValidator;
10 import org.simantics.scl.compiler.module.ImportDeclaration;
11 import org.simantics.scl.compiler.module.repository.UpdateListener;
12
13 public class FileModuleSource extends EncodedTextualModuleSource {
14     
15     private final ClassLoader classLoader;
16     private final File path;
17     private final ImportDeclaration[] builtinImports;
18    
19     public FileModuleSource(String moduleName, ClassLoader classLoader,
20             File path, ImportDeclaration[] builtinImports) {
21         super(moduleName);
22         this.classLoader = classLoader;
23         this.path = path;
24         this.builtinImports = builtinImports;
25     }
26
27     @Override
28     protected InputStream getSourceStream(UpdateListener listener)
29             throws IOException {
30         return new FileInputStream(path);
31     }
32
33     @Override
34     protected JavaReferenceValidator<?, ?, ?, ?> getJavaReferenceValidator() {
35         return new RuntimeJavaReferenceValidator(classLoader);
36     }
37     
38     @Override
39     public ImportDeclaration[] getBuiltinImports(UpdateListener listener) {
40         return builtinImports;
41     }
42 }