public abstract static class CodeChunk.WithValue extends CodeChunk
Expressions represent values. Sequences of statements can represent a value (for example, if the first statement declares a variable and subsequent statements update the variable's state), but they are not required to.
Chunks representing values are required in certain contexts (for example, the right-hand
side of an assignment).
CodeChunk.Generator, CodeChunk.RequiresCollector, CodeChunk.WithValueEMPTY_OBJECT_LITERAL, LITERAL_EMPTY_STRING, LITERAL_FALSE, LITERAL_NULL, LITERAL_TRUE| Modifier and Type | Method and Description |
|---|---|
CodeChunk.WithValue |
and(CodeChunk.WithValue rhs,
CodeChunk.Generator codeGenerator)
Returns a code chunk representing the logical and (
&&) of this chunk with the given
chunk. |
CodeChunk.WithValue |
assign(CodeChunk.WithValue rhs) |
CodeChunk.WithValue |
bracketAccess(CodeChunk.WithValue arg) |
CodeChunk.WithValue |
call(CodeChunk.WithValue... args) |
CodeChunk.WithValue |
call(Iterable<? extends CodeChunk.WithValue> args) |
CodeChunk.WithValue |
divideBy(CodeChunk.WithValue rhs) |
CodeChunk.WithValue |
dotAccess(String identifier)
Takes in a String identifier for convenience, since that's what most use cases need.
|
CodeChunk.WithValue |
doubleEquals(CodeChunk.WithValue rhs) |
CodeChunk.WithValue |
doubleEqualsNull() |
CodeChunk.WithValue |
doubleNotEquals(CodeChunk.WithValue rhs) |
abstract com.google.common.collect.ImmutableList<CodeChunk> |
initialStatements()
Returns the initial statements associated with this value.
|
CodeChunk.WithValue |
instanceof_(CodeChunk.WithValue identifier) |
boolean |
isCheap()
Returns
true if the expression represented by this code chunk is so trivial that it
isn't worth storing it in a temporary if it needs to be referenced multiple times. |
CodeChunk.WithValue |
minus(CodeChunk.WithValue rhs) |
CodeChunk.WithValue |
op(Operator op,
CodeChunk.WithValue rhs) |
CodeChunk.WithValue |
or(CodeChunk.WithValue rhs,
CodeChunk.Generator codeGenerator)
Returns a code chunk representing the logical or (
||) of this chunk with the given
chunk. |
CodeChunk.WithValue |
plus(CodeChunk.WithValue rhs) |
CodeChunk.WithValue |
plusEquals(CodeChunk.WithValue rhs) |
abstract JsExpr |
singleExprOrName()
If this chunk can be represented as a single expression, returns that expression.
|
CodeChunk.WithValue |
times(CodeChunk.WithValue rhs) |
CodeChunk.WithValue |
tripleEquals(CodeChunk.WithValue rhs) |
CodeChunk.WithValue |
withInitialStatement(CodeChunk initialStatement)
Convenience method for
withInitialStatements(ImmutableList.of(statement)). |
CodeChunk.WithValue |
withInitialStatements(Iterable<? extends CodeChunk> initialStatements)
Returns a chunk whose output expression is the same as this chunk's, but which includes the
given initial statements.
|
arrayLiteral, assertExpr, assertExprAndCollectRequires, assign, collectRequires, dontTrustPrecedenceOf, dottedIdNoRequire, forLoop, forLoop, fromExpr, function, getCode, getStatementsForInsertingIntoForeignCodeAtIndent, id, ifExpression, ifStatement, mapLiteral, new_, not, number, number, operation, regexLiteral, return_, statements, statements, stringLiteral, switch_, throw_, treatRawStringAsStatementLegacyOnlypublic final CodeChunk.WithValue plus(CodeChunk.WithValue rhs)
public final CodeChunk.WithValue minus(CodeChunk.WithValue rhs)
public final CodeChunk.WithValue plusEquals(CodeChunk.WithValue rhs)
public final CodeChunk.WithValue doubleEquals(CodeChunk.WithValue rhs)
public final CodeChunk.WithValue doubleNotEquals(CodeChunk.WithValue rhs)
public final CodeChunk.WithValue tripleEquals(CodeChunk.WithValue rhs)
public final CodeChunk.WithValue doubleEqualsNull()
public final CodeChunk.WithValue times(CodeChunk.WithValue rhs)
public final CodeChunk.WithValue divideBy(CodeChunk.WithValue rhs)
public final CodeChunk.WithValue and(CodeChunk.WithValue rhs, CodeChunk.Generator codeGenerator)
&&) of this chunk with the given
chunk.codeGenerator - Required in case temporary variables need to be allocated for
short-circuiting behavior (rhs should be evaluated only if the current chunk
evaluates as true).public final CodeChunk.WithValue or(CodeChunk.WithValue rhs, CodeChunk.Generator codeGenerator)
||) of this chunk with the given
chunk.codeGenerator - Required in case temporary variables need to be allocated for
short-circuiting behavior (rhs should be evaluated only if the current chunk
evaluates as false).public final CodeChunk.WithValue op(Operator op, CodeChunk.WithValue rhs)
public final CodeChunk.WithValue dotAccess(String identifier)
public final CodeChunk.WithValue bracketAccess(CodeChunk.WithValue arg)
public final CodeChunk.WithValue call(CodeChunk.WithValue... args)
public final CodeChunk.WithValue call(Iterable<? extends CodeChunk.WithValue> args)
public final CodeChunk.WithValue instanceof_(CodeChunk.WithValue identifier)
public final CodeChunk.WithValue assign(CodeChunk.WithValue rhs)
public final CodeChunk.WithValue withInitialStatements(Iterable<? extends CodeChunk> initialStatements)
This method is designed for interoperability with parts of the JS codegen system that do
not understand code chunks. For example, when applying plugin functions, TranslateExprNodeVisitor.visitFunctionNode(com.google.template.soy.exprtree.FunctionNode) needs to
downgrade the plugin arguments from CodeChunk.WithValues to JsExprs for the plugin
API to process. The result (a JsExpr) needs to be upgraded back to a CodeChunk.WithValue that
includes the initial statements from the original arguments.
public final CodeChunk.WithValue withInitialStatement(CodeChunk initialStatement)
withInitialStatements(ImmutableList.of(statement)).public abstract JsExpr singleExprOrName()
initial statements.
This method should rarely be used, but is needed when interoperating with parts of the
codegen system that do not yet understand CodeChunks (e.g. SoyJsSrcFunction).
public abstract com.google.common.collect.ImmutableList<CodeChunk> initialStatements()
TODO(b/33382980): If we have this method, why do we need doFormatInitialStatements? should doFormatInitialStatements be implemented in terms of this method? is this method supposed to contain all initial statements? even from conditional branches?
public boolean isCheap()
true if the expression represented by this code chunk is so trivial that it
isn't worth storing it in a temporary if it needs to be referenced multiple times.
The default is false, only certain special code chunks return true.