Refine search
public String render(Locale locale, int lineWidth) { StringWriter out = new StringWriter(); STWriter wr = new AutoIndentWriter(out); wr.setLineWidth(lineWidth); write(wr, locale); return out.toString(); }
protected void indent(STWriter out, InstanceScope scope, int strIndex) { String indent = scope.st.impl.strings[strIndex]; if ( debug ) { int start = out.index(); // track char we're about to write EvalExprEvent e = new IndentEvent(scope, start, start + indent.length() - 1, getExprStartChar(scope), getExprStopChar(scope)); trackDebugEvent(scope, e); } out.pushIndentation(indent); }
protected int writePOJO(STWriter out, Object o, String[] options) throws IOException { String formatString = null; if ( options!=null ) formatString = options[Option.FORMAT.ordinal()]; AttributeRenderer r = group.getAttributeRenderer(o.getClass()); String v; if ( r!=null ) v = r.toString(o, formatString, locale); else v = o.toString(); int n; if ( options!=null && options[Option.WRAP.ordinal()]!=null ) { n = out.write(v, options[Option.WRAP.ordinal()]); } else { n = out.write(v); } return n; }
public List<InterpEvent> getEvents(Locale locale, int lineWidth) { StringWriter out = new StringWriter(); STWriter wr = new AutoIndentWriter(out); wr.setLineWidth(lineWidth); Interpreter interp = new Interpreter(groupThatCreatedThisInstance, locale, true); interp.exec(wr, this); // render and track events return interp.getEvents(); }
protected int _exec(STWriter out, ST self) { int start = out.index(); // track char we're about to write int prevOpcode = 0; int n = 0; // how many char we write out st = self.groupThatCreatedThisInstance.getEmbeddedInstanceOf(this, self, ip, name); ip += Bytecode.OPND_SIZE_IN_BYTES; name = (String)operands[sp-nargs]; st = self.groupThatCreatedThisInstance.getEmbeddedInstanceOf(this, self, ip, name); storeArgs(self, nargs, st); sp -= nargs; st = self.groupThatCreatedThisInstance.getEmbeddedInstanceOf(this, self, ip, name); break; case Bytecode.INSTR_DEDENT : out.popIndentation(); break; case Bytecode.INSTR_NEWLINE : nwline>0 ) out.write(Misc.newline); int stop = out.index() - 1; EvalTemplateEvent e = new EvalTemplateEvent(currentScope, start, stop); trackDebugEvent(self, e);
public void write(ST code, String fileName) throws IOException { //long start = System.currentTimeMillis(); Writer w = tool.getOutputFile(grammar, fileName); // Write the output to a StringWriter STWriter wr = new AutoIndentWriter(w); wr.setLineWidth(lineWidth); code.write(wr); w.close(); //long stop = System.currentTimeMillis(); //System.out.println("render time for "+fileName+": "+(int)(stop-start)+"ms"); }
Object[] options) int start = out.index(); // track char we're about to write out.pushAnchorPoint(); out.popAnchorPoint(); start, out.index() - 1, getExprStartChar(scope), getExprStopChar(scope));
/** Write out an expression result that doesn't use expression options. * E.g., {@code <name>} */ protected int writeObjectNoOptions(STWriter out, InstanceScope scope, Object o) { int start = out.index(); // track char we're about to write int n = writeObject(out, scope, o, null); if ( debug ) { EvalExprEvent e = new EvalExprEvent(scope, start, out.index() - 1, getExprStartChar(scope), getExprStopChar(scope)); trackDebugEvent(scope, e); } return n; }
protected int writeIterator(STWriter out, InstanceScope scope, Object o, String[] options) throws IOException { if ( o==null ) return 0; int n = 0; Iterator<?> it = (Iterator<?>)o; String separator = null; if ( options!=null ) separator = options[Option.SEPARATOR.ordinal()]; boolean seenAValue = false; while ( it.hasNext() ) { Object iterValue = it.next(); // Emit separator if we're beyond first value boolean needSeparator = seenAValue && separator!=null && // we have a separator and (iterValue!=null || // either we have a value options[Option.NULL.ordinal()]!=null); // or no value but null option if ( needSeparator ) n += out.writeSeparator(separator); int nw = writeObject(out, scope, iterValue, options); if ( nw > 0 ) seenAValue = true; n += nw; } return n; }
out.writeWrap(options[Option.WRAP.ordinal()]);
public List<InterpEvent> getEvents(Locale locale, int lineWidth) { StringWriter out = new StringWriter(); STWriter wr = new AutoIndentWriter(out); wr.setLineWidth(lineWidth); Interpreter interp = new Interpreter(groupThatCreatedThisInstance, locale, true); InstanceScope scope = new InstanceScope(null, this); interp.exec(wr, scope); // render and track events return interp.getEvents(); }
protected int _exec(STWriter out, InstanceScope scope) { final ST self = scope.st; int start = out.index(); // track char we're about to write int prevOpcode = 0; int n = 0; // how many char we write out st = self.groupThatCreatedThisInstance.getEmbeddedInstanceOf(this, scope, name); ip += Bytecode.OPND_SIZE_IN_BYTES; name = (String)operands[sp-nargs]; st = self.groupThatCreatedThisInstance.getEmbeddedInstanceOf(this, scope, name); storeArgs(scope, nargs, st); sp -= nargs; st = self.groupThatCreatedThisInstance.getEmbeddedInstanceOf(this, scope, name); break; case Bytecode.INSTR_DEDENT : out.popIndentation(); break; case Bytecode.INSTR_NEWLINE : nwline>0 ) out.write(Misc.newline); int stop = out.index() - 1; EvalTemplateEvent e = new EvalTemplateEvent(scope, start, stop); trackDebugEvent(scope, e);
public void write(ST code, String fileName) throws IOException { //long start = System.currentTimeMillis(); Writer w = tool.getOutputFile(grammar, fileName); // Write the output to a StringWriter STWriter wr = new AutoIndentWriter(w); wr.setLineWidth(lineWidth); code.write(wr); w.close(); //long stop = System.currentTimeMillis(); //System.out.println("render time for "+fileName+": "+(int)(stop-start)+"ms"); }
Object[] options) int start = out.index(); // track char we're about to write out.pushAnchorPoint(); out.popAnchorPoint(); start, out.index() - 1, getExprStartChar(scope), getExprStopChar(scope));
/** Write out an expression result that doesn't use expression options. * E.g., {@code <name>} */ protected int writeObjectNoOptions(STWriter out, InstanceScope scope, Object o) { int start = out.index(); // track char we're about to write int n = writeObject(out, scope, o, null); if ( debug ) { EvalExprEvent e = new EvalExprEvent(scope, start, out.index() - 1, getExprStartChar(scope), getExprStopChar(scope)); trackDebugEvent(scope, e); } return n; }
protected int writeIterator(STWriter out, InstanceScope scope, Object o, String[] options) throws IOException { if ( o==null ) return 0; int n = 0; Iterator<?> it = (Iterator<?>)o; String separator = null; if ( options!=null ) separator = options[Option.SEPARATOR.ordinal()]; boolean seenAValue = false; while ( it.hasNext() ) { Object iterValue = it.next(); // Emit separator if we're beyond first value boolean needSeparator = seenAValue && separator!=null && // we have a separator and (iterValue!=null || // either we have a value options[Option.NULL.ordinal()]!=null); // or no value but null option if ( needSeparator ) n += out.writeSeparator(separator); int nw = writeObject(out, scope, iterValue, options); if ( nw > 0 ) seenAValue = true; n += nw; } return n; }
out.writeWrap(options[Option.WRAP.ordinal()]);
public String render(Locale locale, int lineWidth) { StringWriter out = new StringWriter(); STWriter wr = new AutoIndentWriter(out); wr.setLineWidth(lineWidth); write(wr, locale); return out.toString(); }
public List<InterpEvent> getEvents(Locale locale, int lineWidth) { StringWriter out = new StringWriter(); STWriter wr = new AutoIndentWriter(out); wr.setLineWidth(lineWidth); Interpreter interp = new Interpreter(groupThatCreatedThisInstance, locale, true); InstanceScope scope = new InstanceScope(null, this); interp.exec(wr, scope); // render and track events return interp.getEvents(); }
protected int _exec(STWriter out, InstanceScope scope) { final ST self = scope.st; int start = out.index(); // track char we're about to write int prevOpcode = 0; int n = 0; // how many char we write out st = self.groupThatCreatedThisInstance.getEmbeddedInstanceOf(this, scope, name); ip += Bytecode.OPND_SIZE_IN_BYTES; name = (String)operands[sp-nargs]; st = self.groupThatCreatedThisInstance.getEmbeddedInstanceOf(this, scope, name); storeArgs(scope, nargs, st); sp -= nargs; st = self.groupThatCreatedThisInstance.getEmbeddedInstanceOf(this, scope, name); break; case Bytecode.INSTR_DEDENT : out.popIndentation(); break; case Bytecode.INSTR_NEWLINE : nwline>0 ) out.write(Misc.newline); int stop = out.index() - 1; EvalTemplateEvent e = new EvalTemplateEvent(scope, start, stop); trackDebugEvent(scope, e);