com.google.caja.render
Class SideBySideRenderer

java.lang.Object
  extended by com.google.caja.render.SideBySideRenderer
All Implemented Interfaces:
TokenConsumer
Direct Known Subclasses:
TabularSideBySideRenderer

public abstract class SideBySideRenderer
extends java.lang.Object
implements TokenConsumer

Renders rewritten source code interleaved with the original. E.g. // Rewritten by cajoler. muckWith( IMPORTS___.muckWith( document.forms[0]) IMPORTS___.document.forms[0]);

Author:
mikesamuel@gmail.com

Nested Class Summary
private static class SideBySideRenderer.Chunk
           
 
Field Summary
private  java.util.List<SideBySideRenderer.Chunk> chunks
          Chunks of original source.
private  FilePosition chunkStart
           
private  FilePosition lastPos
           
private  FilePosition mark
           
private  java.util.Map<InputSource,java.lang.Integer> maxLineSeen
           
private  java.util.Map<InputSource,java.lang.String[]> originalSourceLines
           
private  java.lang.StringBuilder renderedBuf
           
private  TokenConsumer renderer
           
 
Constructor Summary
SideBySideRenderer(java.util.Map<InputSource,? extends java.lang.CharSequence> originalSource)
           
 
Method Summary
 void consume(java.lang.String text)
          Receives tokens from rendered parse trees.
private  void emitLine()
           
protected abstract  void emitLine(FilePosition startOfLine, java.lang.String original, java.lang.String rendered)
          Called when rendered tokens have been processed for a line of original source.
private  int lastLineNo(InputSource src)
           
protected abstract  TokenConsumer makeRenderer(java.lang.StringBuilder renderedSrc)
           
 void mark(FilePosition pos)
          Marks tokens consumed before the next call as falling in this range of file positions.
 void noMoreTokens()
          Called when no more tokens are available.
private  java.lang.String originalSourceSnippet(InputSource src, int startLine, int endLine)
           
private static java.util.List<Pair<java.lang.String,java.lang.Integer>> splitChunks(java.lang.String renderedSrc)
           
protected  void switchSource(InputSource previous, InputSource next)
          Called when we render a token from a different source than previously.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

originalSourceLines

private final java.util.Map<InputSource,java.lang.String[]> originalSourceLines

maxLineSeen

private final java.util.Map<InputSource,java.lang.Integer> maxLineSeen

renderer

private final TokenConsumer renderer

lastPos

private FilePosition lastPos

mark

private FilePosition mark

chunkStart

private FilePosition chunkStart

chunks

private final java.util.List<SideBySideRenderer.Chunk> chunks
Chunks of original source.


renderedBuf

private java.lang.StringBuilder renderedBuf
Constructor Detail

SideBySideRenderer

public SideBySideRenderer(java.util.Map<InputSource,? extends java.lang.CharSequence> originalSource)
Method Detail

emitLine

protected abstract void emitLine(FilePosition startOfLine,
                                 java.lang.String original,
                                 java.lang.String rendered)
Called when rendered tokens have been processed for a line of original source.

Parameters:
startOfLine - a file position into the original source code.
original - zero or more lines of original source code.
rendered - one or more lines of rendered source code.

switchSource

protected void switchSource(InputSource previous,
                            InputSource next)
Called when we render a token from a different source than previously. This method does nothing, but may be overridden.

Parameters:
previous - the source from which the last rendered token came.
next - the source from which the next rendered token will come, unless switchSource is called again before consume(java.lang.String).

makeRenderer

protected abstract TokenConsumer makeRenderer(java.lang.StringBuilder renderedSrc)

mark

public void mark(FilePosition pos)
Description copied from interface: TokenConsumer
Marks tokens consumed before the next call as falling in this range of file positions.

Specified by:
mark in interface TokenConsumer
Parameters:
pos - null indicates don't know.

consume

public void consume(java.lang.String text)
Description copied from interface: TokenConsumer
Receives tokens from rendered parse trees.

Specified by:
consume in interface TokenConsumer

noMoreTokens

public void noMoreTokens()
Description copied from interface: TokenConsumer
Called when no more tokens are available.

Specified by:
noMoreTokens in interface TokenConsumer

emitLine

private void emitLine()

splitChunks

private static java.util.List<Pair<java.lang.String,java.lang.Integer>> splitChunks(java.lang.String renderedSrc)

originalSourceSnippet

private java.lang.String originalSourceSnippet(InputSource src,
                                               int startLine,
                                               int endLine)

lastLineNo

private int lastLineNo(InputSource src)


Copyright (C) 2008 Google Inc.
Licensed under the Apache License, Version 2.0