X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Fsource%2FTextualModuleSource.java;h=7d0e5335281684aac58ea296d1f51bf71875576c;hb=refs%2Fchanges%2F34%2F1534%2F3;hp=9a6f4c97fb07c33689e21885a1a641d4bdcadf01;hpb=74de2d9be56f36e925a0a5818f4b11a766812cff;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/TextualModuleSource.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/TextualModuleSource.java index 9a6f4c97f..7d0e53352 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/TextualModuleSource.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/source/TextualModuleSource.java @@ -2,6 +2,7 @@ package org.simantics.scl.compiler.source; import java.io.IOException; import java.io.Reader; +import java.io.StringReader; import java.util.Arrays; import org.simantics.scl.compiler.compilation.SCLCompiler; @@ -46,14 +47,17 @@ public abstract class TextualModuleSource implements ModuleSource { 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) { @@ -69,7 +73,7 @@ public abstract class TextualModuleSource implements ModuleSource { } } - protected ImportDeclaration[] getBuiltinImports(UpdateListener listener) { + public ImportDeclaration[] getBuiltinImports(UpdateListener listener) { return DEFAULT_IMPORTS; } @@ -83,7 +87,8 @@ public abstract class TextualModuleSource implements ModuleSource { public Failable compileModule(final ModuleRepository environment, final UpdateListener listener, ModuleCompilationOptions options) { SCLCompiler compiler = new SCLCompiler(options, getJavaReferenceValidatorFactory()); try { - compiler.addSource(getSourceReader(listener)); + String source = getSourceText(listener); + compiler.addSource(source); compiler.compile( new EnvironmentFactoryImpl( environment, @@ -93,11 +98,14 @@ public abstract class TextualModuleSource implements ModuleSource { if(compiler.getErrorLog().hasNoErrors()) return new Success(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); } }