Mercurial Hosting > nabble
diff src/nabble/naml/compiler/TemplatePrintWriter.java @ 0:7ecd1a4ef557
add content
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 21 Mar 2019 19:15:52 -0600 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/nabble/naml/compiler/TemplatePrintWriter.java Thu Mar 21 19:15:52 2019 -0600 @@ -0,0 +1,38 @@ +package nabble.naml.compiler; + +import java.io.Writer; + + +public class TemplatePrintWriter extends PrintWriter { + + public static final TemplatePrintWriter NULL = new TemplatePrintWriter( new Writer() { + public void write(char[] cbuf,int off,int len) {} + public void flush() {} + public void close() {} + } ); + + public TemplatePrintWriter(Writer out) { + super(out); + } + + public void print(Object obj) { + if( obj == null ) + throw new NamlNullPointerException("null written to stream"); + if( obj instanceof BlockWrapper ) { + ((BlockWrapper)obj).printTo(this); + } else { + super.print(obj); + } + } + + public void print(String s) { + if( s == null ) + throw new NamlNullPointerException("null written to stream"); + super.print(s); + } + + public void print(Boolean b) { + throw new RuntimeException("no Booleans allowed, use boolean instead"); + } + +}