import java.io.IOException;
import java.io.Reader;
+import java.io.StringReader;
import java.util.Arrays;
import org.simantics.scl.compiler.compilation.SCLCompiler;
import org.simantics.scl.compiler.errors.Failure;
import org.simantics.scl.compiler.errors.Success;
import org.simantics.scl.compiler.internal.codegen.types.JavaReferenceValidator;
+import org.simantics.scl.compiler.internal.codegen.types.JavaReferenceValidatorFactory;
import org.simantics.scl.compiler.internal.codegen.types.RuntimeJavaReferenceValidator;
import org.simantics.scl.compiler.module.ImportDeclaration;
import org.simantics.scl.compiler.module.Module;
return getClass().getClassLoader();
}
- protected abstract Reader getSourceReader(UpdateListener listener) throws IOException;
+ protected Reader getSourceReader(UpdateListener listener) throws IOException {
+ return new StringReader(getSourceText(listener));
+ }
+
protected JavaReferenceValidator<?, ?, ?, ?> getJavaReferenceValidator() {
return new RuntimeJavaReferenceValidator(getClassLoader());
}
public String getSourceText(UpdateListener listener) throws IOException {
Reader reader = getSourceReader(listener);
- char[] buffer = new char[65536];
+ char[] buffer = new char[4096];
int pos = 0;
try {
while(true) {
}
}
- protected ImportDeclaration[] getBuiltinImports(UpdateListener listener) {
+ public ImportDeclaration[] getBuiltinImports(UpdateListener listener) {
return DEFAULT_IMPORTS;
}
@SuppressWarnings("unchecked")
@Override
public Failable<Module> compileModule(final ModuleRepository environment, final UpdateListener listener, ModuleCompilationOptions options) {
- SCLCompiler compiler = new SCLCompiler(options);
+ SCLCompiler compiler = new SCLCompiler(options, getJavaReferenceValidatorFactory());
try {
- compiler.addSource(getSourceReader(listener));
+ String source = getSourceText(listener);
+ compiler.addSource(source);
compiler.compile(
new EnvironmentFactoryImpl(
environment,
getBuiltinImports(listener),
listener),
- moduleName,
- getJavaReferenceValidator());
- if(compiler.getErrorLog().isEmpty())
+ moduleName);
+ if(compiler.getErrorLog().hasNoErrors())
return new Success<Module>(compiler.getModule());
else {
- LOGGER.error("While compiling " + getModuleName() + ":");
- LOGGER.error(CompilationErrorFormatter.toString(getSourceReader(null), compiler.getErrorLog().getErrors()));
+ if(options == null || !options.silent)
+ LOGGER.error("While compiling " + getModuleName() + ":\n " +
+ CompilationErrorFormatter.toString(getSourceReader(null), compiler.getErrorLog().getErrors()).replaceAll("\n", "\n "));
return new Failure(compiler.getErrorLog().getErrors());
}
} catch (IOException e) {
+ if(options == null || !options.silent)
+ LOGGER.error("Compilation of module " + moduleName + " failed.", e);
return new Failure(e);
}
}
+ public JavaReferenceValidatorFactory getJavaReferenceValidatorFactory() {
+ return new JavaReferenceValidatorFactory() {
+
+ @Override
+ public JavaReferenceValidator<Object, Object, Object, Object> getJavaReferenceValidator(String context) {
+ return (JavaReferenceValidator<Object, Object, Object, Object>)TextualModuleSource.this.getJavaReferenceValidator();
+ }
+
+ @Override
+ public JavaReferenceValidator<Object, Object, Object, Object> getDefaultJavaReferenceValidator() {
+ return (JavaReferenceValidator<Object, Object, Object, Object>)TextualModuleSource.this.getJavaReferenceValidator();
+ }
+ };
+ }
+
@Override
public double getPriority() {
return priority;