com.google.clearsilver.jsilver.compiler
Class TemplateTranslator

java.lang.Object
  extended by com.google.clearsilver.jsilver.syntax.analysis.AnalysisAdapter
      extended by com.google.clearsilver.jsilver.syntax.analysis.DepthFirstAdapter
          extended by com.google.clearsilver.jsilver.compiler.TemplateTranslator
All Implemented Interfaces:
Analysis, Switch

public class TemplateTranslator
extends DepthFirstAdapter

Translates a JSilver AST into compilable Java code. This executes much faster than the interpreter.

See Also:
TemplateCompiler

Field Summary
static JavaExpression CONTEXT
           
static JavaExpression DATA
           
static JavaExpression DATA_CONTEXT
           
static JavaExpression NULL
           
static JavaExpression RESOURCE_LOADER
           
static JavaExpression TEMPLATE_LOADER
           
static JavaExpression THIS_TEMPLATE
           
 
Constructor Summary
TemplateTranslator(String packageName, String className, Writer output, boolean propagateEscapeStatus)
           
 
Method Summary
 void caseAAltCommand(AAltCommand node)
          <?cs alt:someValue > ...
 void caseAAutoescapeCommand(AAutoescapeCommand node)
          A fake command injected by AutoEscaper.
 void caseACallCommand(ACallCommand node)
          <?cs call:someMacro(x,y) command.
 void caseADataCommand(ADataCommand node)
          Chunk of data (i.e.
 void caseADefCommand(ADefCommand node)
          <?cs def:someMacro(x,y) > ...
 void caseAEachCommand(AEachCommand node)
          <?cs each:x=Stuff > ...
 void caseAEscapeCommand(AEscapeCommand node)
          <?cs escape:'html' > command.
 void caseAEvarCommand(AEvarCommand node)
          <?cs evar:blah > command.
 void caseAHardIncludeCommand(AHardIncludeCommand node)
          <?cs include!'somefile.cs' > command.
 void caseAHardLincludeCommand(AHardLincludeCommand node)
          <?cs linclude:'somefile.cs' > command.
 void caseAIfCommand(AIfCommand node)
          <?cs if:blah > ...
 void caseAIncludeCommand(AIncludeCommand node)
          <?cs include:'somefile.cs' > command.
 void caseALincludeCommand(ALincludeCommand node)
          <?cs linclude:'somefile.cs' > command.
 void caseALoopCommand(ALoopCommand node)
          <?cs loop:0,10 > ...
 void caseALoopIncCommand(ALoopIncCommand node)
          <?cs loop:0,10,2 > ...
 void caseALoopToCommand(ALoopToCommand node)
          <?cs loop:10 > ...
 void caseALvarCommand(ALvarCommand node)
          <?cs lvar:blah > command.
 void caseANameCommand(ANameCommand node)
          <?cs name:blah > command.
 void caseASetCommand(ASetCommand node)
          <?cs set:x='y' > command.
 void caseAUvarCommand(AUvarCommand node)
          <?cs uvar:blah > expression.
 void caseAVarCommand(AVarCommand node)
          <?cs var:blah > expression.
 void caseAWithCommand(AWithCommand node)
          <?cs with:x=Something > ...
 void caseStart(Start node)
           
 void caseTCsOpen(TCsOpen node)
          Every time a <cs token is found, grab the line and column and call context.setCurrentPosition() so this is captured for stack traces.
 
Methods inherited from class com.google.clearsilver.jsilver.syntax.analysis.DepthFirstAdapter
caseAAddExpression, caseAAndExpression, caseACommaExpression, caseACommentCommand, caseAContentTypeCommand, caseACsOpenPosition, caseADecimalExpression, caseADecNumberVariable, caseADescendVariable, caseADivideExpression, caseAEqExpression, caseAExistsExpression, caseAExpandVariable, caseAFunctionExpression, caseAGteExpression, caseAGtExpression, caseAHexExpression, caseAHexNumberVariable, caseAInlineCommand, caseALteExpression, caseALtExpression, caseAModuloExpression, caseAMultipleCommand, caseAMultiplyExpression, caseANameVariable, caseANeExpression, caseANegativeExpression, caseANoopCommand, caseANoopExpression, caseANotExpression, caseANumericAddExpression, caseANumericEqExpression, caseANumericExpression, caseANumericNeExpression, caseAOrExpression, caseASequenceExpression, caseAStringExpression, caseASubtractExpression, caseAVariableExpression, defaultIn, defaultOut, inAAddExpression, inAAltCommand, inAAndExpression, inAAutoescapeCommand, inACallCommand, inACommaExpression, inACommentCommand, inAContentTypeCommand, inACsOpenPosition, inADataCommand, inADecimalExpression, inADecNumberVariable, inADefCommand, inADescendVariable, inADivideExpression, inAEachCommand, inAEqExpression, inAEscapeCommand, inAEvarCommand, inAExistsExpression, inAExpandVariable, inAFunctionExpression, inAGteExpression, inAGtExpression, inAHardIncludeCommand, inAHardLincludeCommand, inAHexExpression, inAHexNumberVariable, inAIfCommand, inAIncludeCommand, inAInlineCommand, inALincludeCommand, inALoopCommand, inALoopIncCommand, inALoopToCommand, inALteExpression, inALtExpression, inALvarCommand, inAModuloExpression, inAMultipleCommand, inAMultiplyExpression, inANameCommand, inANameVariable, inANeExpression, inANegativeExpression, inANoopCommand, inANoopExpression, inANotExpression, inANumericAddExpression, inANumericEqExpression, inANumericExpression, inANumericNeExpression, inAOrExpression, inASequenceExpression, inASetCommand, inAStringExpression, inASubtractExpression, inAUvarCommand, inAVarCommand, inAVariableExpression, inAWithCommand, inStart, outAAddExpression, outAAltCommand, outAAndExpression, outAAutoescapeCommand, outACallCommand, outACommaExpression, outACommentCommand, outAContentTypeCommand, outACsOpenPosition, outADataCommand, outADecimalExpression, outADecNumberVariable, outADefCommand, outADescendVariable, outADivideExpression, outAEachCommand, outAEqExpression, outAEscapeCommand, outAEvarCommand, outAExistsExpression, outAExpandVariable, outAFunctionExpression, outAGteExpression, outAGtExpression, outAHardIncludeCommand, outAHardLincludeCommand, outAHexExpression, outAHexNumberVariable, outAIfCommand, outAIncludeCommand, outAInlineCommand, outALincludeCommand, outALoopCommand, outALoopIncCommand, outALoopToCommand, outALteExpression, outALtExpression, outALvarCommand, outAModuloExpression, outAMultipleCommand, outAMultiplyExpression, outANameCommand, outANameVariable, outANeExpression, outANegativeExpression, outANoopCommand, outANoopExpression, outANotExpression, outANumericAddExpression, outANumericEqExpression, outANumericExpression, outANumericNeExpression, outAOrExpression, outASequenceExpression, outASetCommand, outAStringExpression, outASubtractExpression, outAUvarCommand, outAVarCommand, outAVariableExpression, outAWithCommand, outStart
 
Methods inherited from class com.google.clearsilver.jsilver.syntax.analysis.AnalysisAdapter
caseEOF, caseTAlt, caseTAnd, caseTArgWhitespace, caseTAssignment, caseTAutoescape, caseTBang, caseTBracketClose, caseTBracketOpen, caseTCall, caseTComma, caseTCommandDelimiter, caseTComment, caseTCommentStart, caseTContentType, caseTCsClose, caseTData, caseTDecNumber, caseTDef, caseTDollar, caseTDot, caseTEach, caseTElse, caseTElseIf, caseTEq, caseTEscape, caseTEvar, caseTGt, caseTGte, caseTHardDelimiter, caseTHash, caseTHexNumber, caseTIf, caseTInclude, caseTInline, caseTLinclude, caseTLoop, caseTLt, caseTLte, caseTLvar, caseTMinus, caseTName, caseTNe, caseTOr, caseTParenClose, caseTParenOpen, caseTPercent, caseTPlus, caseTQuestion, caseTSet, caseTSlash, caseTStar, caseTString, caseTUvar, caseTVar, caseTWith, caseTWord, defaultCase, getIn, getOut, setIn, setOut
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATA

public static final JavaExpression DATA

CONTEXT

public static final JavaExpression CONTEXT

DATA_CONTEXT

public static final JavaExpression DATA_CONTEXT

NULL

public static final JavaExpression NULL

RESOURCE_LOADER

public static final JavaExpression RESOURCE_LOADER

TEMPLATE_LOADER

public static final JavaExpression TEMPLATE_LOADER

THIS_TEMPLATE

public static final JavaExpression THIS_TEMPLATE
Constructor Detail

TemplateTranslator

public TemplateTranslator(String packageName,
                          String className,
                          Writer output,
                          boolean propagateEscapeStatus)
Method Detail

caseStart

public void caseStart(Start node)
Specified by:
caseStart in interface Analysis
Overrides:
caseStart in class DepthFirstAdapter

caseADataCommand

public void caseADataCommand(ADataCommand node)
Chunk of data (i.e. not a CS command).

Specified by:
caseADataCommand in interface Analysis
Overrides:
caseADataCommand in class DepthFirstAdapter

caseAVarCommand

public void caseAVarCommand(AVarCommand node)
<?cs var:blah > expression. Evaluate as string and write output, using default escaping.

Specified by:
caseAVarCommand in interface Analysis
Overrides:
caseAVarCommand in class DepthFirstAdapter

caseAUvarCommand

public void caseAUvarCommand(AUvarCommand node)
<?cs uvar:blah > expression. Evaluate as string and write output, but don't escape.

Specified by:
caseAUvarCommand in interface Analysis
Overrides:
caseAUvarCommand in class DepthFirstAdapter

caseASetCommand

public void caseASetCommand(ASetCommand node)
<?cs set:x='y' > command.

Specified by:
caseASetCommand in interface Analysis
Overrides:
caseASetCommand in class DepthFirstAdapter

caseANameCommand

public void caseANameCommand(ANameCommand node)
<?cs name:blah > command. Writes out the name of the original variable referred to by a given node.

Specified by:
caseANameCommand in interface Analysis
Overrides:
caseANameCommand in class DepthFirstAdapter

caseAIfCommand

public void caseAIfCommand(AIfCommand node)
<?cs if:blah > ... <?cs else > ... <?cs /if > command.

Specified by:
caseAIfCommand in interface Analysis
Overrides:
caseAIfCommand in class DepthFirstAdapter

caseAEachCommand

public void caseAEachCommand(AEachCommand node)
<?cs each:x=Stuff > ... <?cs /each > command. Loops over child items of a data node.

Specified by:
caseAEachCommand in interface Analysis
Overrides:
caseAEachCommand in class DepthFirstAdapter

caseAWithCommand

public void caseAWithCommand(AWithCommand node)
<?cs with:x=Something > ... <?cs /with > command. Aliases a value within a specific scope.

Specified by:
caseAWithCommand in interface Analysis
Overrides:
caseAWithCommand in class DepthFirstAdapter

caseALoopToCommand

public void caseALoopToCommand(ALoopToCommand node)
<?cs loop:10 > ... <?cs /loop > command. Loops over a range of numbers, starting at zero.

Specified by:
caseALoopToCommand in interface Analysis
Overrides:
caseALoopToCommand in class DepthFirstAdapter

caseALoopCommand

public void caseALoopCommand(ALoopCommand node)
<?cs loop:0,10 > ... <?cs /loop > command. Loops over a range of numbers.

Specified by:
caseALoopCommand in interface Analysis
Overrides:
caseALoopCommand in class DepthFirstAdapter

caseALoopIncCommand

public void caseALoopIncCommand(ALoopIncCommand node)
<?cs loop:0,10,2 > ... <?cs /loop > command. Loops over a range of numbers, with a specific increment.

Specified by:
caseALoopIncCommand in interface Analysis
Overrides:
caseALoopIncCommand in class DepthFirstAdapter

caseAAltCommand

public void caseAAltCommand(AAltCommand node)
<?cs alt:someValue > ... <?cs /alt > command. If value exists, write it, otherwise write the body of the command.

Specified by:
caseAAltCommand in interface Analysis
Overrides:
caseAAltCommand in class DepthFirstAdapter

caseAEscapeCommand

public void caseAEscapeCommand(AEscapeCommand node)
<?cs escape:'html' > command. Changes default escaping function.

Specified by:
caseAEscapeCommand in interface Analysis
Overrides:
caseAEscapeCommand in class DepthFirstAdapter

caseAAutoescapeCommand

public void caseAAutoescapeCommand(AAutoescapeCommand node)
A fake command injected by AutoEscaper. AutoEscaper determines the html context in which an include or lvar or evar command is called and stores this context in the AAutoescapeCommand node. This function loads the include or lvar template in this stored context.

Specified by:
caseAAutoescapeCommand in interface Analysis
Overrides:
caseAAutoescapeCommand in class DepthFirstAdapter

caseAHardLincludeCommand

public void caseAHardLincludeCommand(AHardLincludeCommand node)
<?cs linclude:'somefile.cs' > command. Lazily includes another template (at render time). Throw an error if file does not exist.

Specified by:
caseAHardLincludeCommand in interface Analysis
Overrides:
caseAHardLincludeCommand in class DepthFirstAdapter

caseALincludeCommand

public void caseALincludeCommand(ALincludeCommand node)
<?cs linclude:'somefile.cs' > command. Lazily includes another template (at render time). Silently ignore if the included file does not exist.

Specified by:
caseALincludeCommand in interface Analysis
Overrides:
caseALincludeCommand in class DepthFirstAdapter

caseAHardIncludeCommand

public void caseAHardIncludeCommand(AHardIncludeCommand node)
<?cs include!'somefile.cs' > command. Throw an error if file does not exist.

Specified by:
caseAHardIncludeCommand in interface Analysis
Overrides:
caseAHardIncludeCommand in class DepthFirstAdapter

caseAIncludeCommand

public void caseAIncludeCommand(AIncludeCommand node)
<?cs include:'somefile.cs' > command. Silently ignore if the included file does not exist.

Specified by:
caseAIncludeCommand in interface Analysis
Overrides:
caseAIncludeCommand in class DepthFirstAdapter

caseALvarCommand

public void caseALvarCommand(ALvarCommand node)
<?cs lvar:blah > command. Evaluate expression and execute commands within.

Specified by:
caseALvarCommand in interface Analysis
Overrides:
caseALvarCommand in class DepthFirstAdapter

caseAEvarCommand

public void caseAEvarCommand(AEvarCommand node)
<?cs evar:blah > command. Evaluate expression and execute commands within.

Specified by:
caseAEvarCommand in interface Analysis
Overrides:
caseAEvarCommand in class DepthFirstAdapter

caseADefCommand

public void caseADefCommand(ADefCommand node)
<?cs def:someMacro(x,y) > ... <?cs /def > command. Define a macro (available for the remainder of the context).

Specified by:
caseADefCommand in interface Analysis
Overrides:
caseADefCommand in class DepthFirstAdapter

caseACallCommand

public void caseACallCommand(ACallCommand node)
<?cs call:someMacro(x,y) command. Call a macro.

Specified by:
caseACallCommand in interface Analysis
Overrides:
caseACallCommand in class DepthFirstAdapter

caseTCsOpen

public void caseTCsOpen(TCsOpen node)
Every time a <cs token is found, grab the line and column and call context.setCurrentPosition() so this is captured for stack traces.

Specified by:
caseTCsOpen in interface Analysis
Overrides:
caseTCsOpen in class AnalysisAdapter


Copyright © 2010-2012 Google. All Rights Reserved.