com.google.caja.render
Class Indenter

java.lang.Object
  extended by com.google.caja.render.Indenter

 class Indenter
extends java.lang.Object

Wraps a list of tokens and provides operations that may replace whitespace tokens in that list.


Field Summary
(package private)  boolean breakAfterComment
          Whether to break after a comment.
(package private)  int[] match
          Maps indices of brackets ("(", ")", etc.) in tokens to the corresponding open or close bracket.
(package private)  boolean[] parenthetical
          For each token in tokens, true if the closest containing pair of brackets are parentheses.
(package private)  java.util.List<java.lang.String> tokens
          The token list.
 
Constructor Summary
Indenter(java.util.List<java.lang.String> tokens, boolean breakAfterComment)
           
 
Method Summary
(package private)  void breakLines()
          Change space tokens into newlines when a single line contains too many tokens or when a line is normally broken at that token.
(package private)  void indent(int lineLengthLimit)
          Called once all the line-breaks are present to introduce indentation by looking at the stack of open bracketed blocks.
private  boolean isShortRun(int start, int end)
           
private static java.lang.String makeIndent(int nSpaces)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tokens

final java.util.List<java.lang.String> tokens
The token list. Modified in place.


match

final int[] match
Maps indices of brackets ("(", ")", etc.) in tokens to the corresponding open or close bracket.

For each token in tokens, the corresponding element in this list is -1 if token is not a bracket, or the index of the close/open bracket token that ends/starts the run of tokens started/opened by token.

For example, for the code f(a[i]), tokens is ["f", "(", "a", "[", "i", "]", ")"], and match[1] == 6 && match[6] == 1 as the outer parentheses match up, match[3] == 5 && match[5] == 3 as the inner parentheses match up. and all the other elements in match are -1.


parenthetical

final boolean[] parenthetical
For each token in tokens, true if the closest containing pair of brackets are parentheses. If token is a bracket, then the corresponding element of parenthetical is true iff token is a parenthesis.

For example, for the code f(a[i]), tokens is ["f", "(", "a", "[", "i", "]", ")"], and parenthetical is [false, true, true, false, false, false, true]


breakAfterComment

final boolean breakAfterComment
Whether to break after a comment.

Constructor Detail

Indenter

Indenter(java.util.List<java.lang.String> tokens,
         boolean breakAfterComment)
Method Detail

breakLines

void breakLines()
Change space tokens into newlines when a single line contains too many tokens or when a line is normally broken at that token.

This does not need to worry about inserting newlines into restricted productions since the superclass will convert to spaces any newlines that would appear in a restricted context.


indent

void indent(int lineLengthLimit)
Called once all the line-breaks are present to introduce indentation by looking at the stack of open bracketed blocks. Turns newline tokens in tokens into newlines followed by runs of spaces.


isShortRun

private boolean isShortRun(int start,
                           int end)

makeIndent

private static java.lang.String makeIndent(int nSpaces)


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