public final class BytecodeUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static org.objectweb.asm.Type |
ARRAY_LIST_TYPE |
static org.objectweb.asm.commons.Method |
CLASS_INIT |
static org.objectweb.asm.Type |
CLOSEABLE_TYPE |
static org.objectweb.asm.Type |
COMPILED_TEMPLATE_TYPE |
static org.objectweb.asm.Type |
CONTENT_KIND_TYPE |
static org.objectweb.asm.Type |
DIR_TYPE |
static org.objectweb.asm.Type |
ILLEGAL_STATE_EXCEPTION_TYPE |
static org.objectweb.asm.Type |
INTEGER_DATA_TYPE |
static org.objectweb.asm.Type |
LINKED_HASH_MAP_TYPE |
static org.objectweb.asm.Type |
LIST_TYPE |
static org.objectweb.asm.Type |
LOGGING_ADVISING_APPENDABLE_TYPE |
static org.objectweb.asm.Type |
LOGGING_ADVISING_BUILDER_TYPE |
static org.objectweb.asm.Type |
MAP_ENTRY_TYPE |
static org.objectweb.asm.Type |
MAP_TYPE |
static org.objectweb.asm.Type |
MESSAGE_TYPE |
static org.objectweb.asm.Type |
NULL_POINTER_EXCEPTION_TYPE |
static org.objectweb.asm.commons.Method |
NULLARY_INIT |
static TypeInfo |
OBJECT |
static org.objectweb.asm.Type |
RENDER_CONTEXT_TYPE |
static org.objectweb.asm.Type |
RENDER_RESULT_TYPE |
static org.objectweb.asm.Type |
SANITIZED_CONTENT_TYPE |
static org.objectweb.asm.Type |
SOY_LEGACY_OBJECT_MAP_TYPE |
static org.objectweb.asm.Type |
SOY_LIST_TYPE |
static org.objectweb.asm.Type |
SOY_MAP_TYPE |
static org.objectweb.asm.Type |
SOY_PROTO_VALUE_IMPL_TYPE |
static org.objectweb.asm.Type |
SOY_RECORD_TYPE |
static org.objectweb.asm.Type |
SOY_VALUE_PROVIDER_TYPE |
static org.objectweb.asm.Type |
SOY_VALUE_TYPE |
static org.objectweb.asm.Type |
STRING_TYPE |
static org.objectweb.asm.Type |
THROWABLE_TYPE |
| Modifier and Type | Method and Description |
|---|---|
static Expression |
asImmutableList(Iterable<? extends Expression> items)
Returns an expression that returns a new
ImmutableList containing the given items. |
static Expression |
asList(Iterable<? extends Expression> items)
Returns an expression that returns a new
ArrayList containing all the given items. |
static Class<?> |
classFromAsmType(org.objectweb.asm.Type type)
Returns the runtime class represented by the given type.
|
static Expression |
compare(int comparisonOpcode,
Expression left,
Expression right)
Compares the two primitive valued expressions using the provided comparison operation.
|
static Expression |
compareSoyEquals(SoyExpression left,
SoyExpression right)
Compares two
SoyExpressions for equality using soy == semantics. |
static Expression |
constant(boolean value)
Returns an
Expression that can load the given boolean constant. |
static Expression |
constant(char value)
Returns an
Expression that can load the given char constant. |
static Expression |
constant(Dir dir)
Returns an
Expression that evaluates to the given Dir, or null. |
static Expression |
constant(double value)
Returns an
Expression that can load the given double constant. |
static Expression |
constant(int value)
Returns an
Expression that can load the given int constant. |
static Expression |
constant(long value)
Returns an
Expression that can load the given long constant. |
static Expression |
constant(SanitizedContent.ContentKind kind)
Returns an
Expression that evaluates to the given ContentKind, or null. |
static Expression |
constant(String value)
Returns an
Expression that can load the given String constant. |
static Expression |
constant(String value,
ClassFieldManager manager)
Returns an
Expression that can load the given String constant. |
static Expression |
constantNull(org.objectweb.asm.Type type)
Returns an
Expression with the given type that always returns null. |
static Expression |
constantSanitizedContentKindAsContentKind(SanitizedContentKind kind)
Returns an
Expression that evaluates to the SanitizedContent.ContentKind value that is
equivalent to the given SanitizedContentKind, or null. |
static void |
defineDefaultConstructor(org.objectweb.asm.ClassVisitor cv,
TypeInfo ownerType)
Generates a default nullary public constructor for the given type on the
ClassVisitor. |
static Expression |
firstNonNull(Expression left,
Expression right)
Returns an expression that evaluates to
left if left is non null, and evaluates to
right otherwise. |
static boolean |
isDefinitelyAssignableFrom(org.objectweb.asm.Type left,
org.objectweb.asm.Type right)
Returns
true if left is definitely assignable from right. |
static boolean |
isPossiblyAssignableFrom(org.objectweb.asm.Type left,
org.objectweb.asm.Type right)
Returns
true if left is possibly assignable from right. |
static boolean |
isPrimitive(org.objectweb.asm.Type type)
Returns
true if Type is a primitive type. |
static Expression |
logicalAnd(Expression... expressions)
Implements the short circuiting logical and (
&&) operator over the list of boolean
expressions. |
static Expression |
logicalAnd(List<? extends Expression> expressions)
Implements the short circuiting logical and (
&&) operator over the list of boolean
expressions. |
static Expression |
logicalNot(Expression baseExpr)
Returns an expression that evaluates to the logical negation of the given boolean valued
expression.
|
static Expression |
logicalOr(Expression... expressions)
Implements the short circuiting logical or (
||) operator over the list of boolean
expressions. |
static Expression |
logicalOr(List<? extends Expression> expressions)
Implements the short circuiting logical or (
||) operator over the list of boolean
expressions. |
static Expression |
newLinkedHashMap(Iterable<? extends Expression> keys,
Iterable<? extends Expression> values)
Returns an expression that returns a new
LinkedHashMap containing all the given
entries. |
static void |
nullCoalesce(CodeBuilder builder,
org.objectweb.asm.Label nullExit)
Outputs bytecode that will test the item at the top of the stack for null, and branch to
nullExit if it is null. |
static Expression |
numericConversion(Expression expr,
org.objectweb.asm.Type to)
Returns an expression that does a numeric conversion cast from the given expression to the
given type.
|
static Expression |
ternary(Expression condition,
Expression trueBranch,
Expression falseBranch)
Returns an expression that evaluates equivalently to a java ternary expression:
condition ? left : right |
static org.objectweb.asm.Type |
unboxUnchecked(CodeBuilder cb,
SoyRuntimeType soyType,
Class<?> asType)
Outputs bytecode that unboxes the current top element of the stack as
asType. |
public static final TypeInfo OBJECT
public static final org.objectweb.asm.Type LOGGING_ADVISING_APPENDABLE_TYPE
public static final org.objectweb.asm.Type LOGGING_ADVISING_BUILDER_TYPE
public static final org.objectweb.asm.Type ARRAY_LIST_TYPE
public static final org.objectweb.asm.Type COMPILED_TEMPLATE_TYPE
public static final org.objectweb.asm.Type CONTENT_KIND_TYPE
public static final org.objectweb.asm.Type CLOSEABLE_TYPE
public static final org.objectweb.asm.Type DIR_TYPE
public static final org.objectweb.asm.Type INTEGER_DATA_TYPE
public static final org.objectweb.asm.Type LINKED_HASH_MAP_TYPE
public static final org.objectweb.asm.Type LIST_TYPE
public static final org.objectweb.asm.Type MAP_TYPE
public static final org.objectweb.asm.Type MAP_ENTRY_TYPE
public static final org.objectweb.asm.Type MESSAGE_TYPE
public static final org.objectweb.asm.Type NULL_POINTER_EXCEPTION_TYPE
public static final org.objectweb.asm.Type RENDER_CONTEXT_TYPE
public static final org.objectweb.asm.Type RENDER_RESULT_TYPE
public static final org.objectweb.asm.Type SANITIZED_CONTENT_TYPE
public static final org.objectweb.asm.Type SOY_LIST_TYPE
public static final org.objectweb.asm.Type SOY_LEGACY_OBJECT_MAP_TYPE
public static final org.objectweb.asm.Type SOY_MAP_TYPE
public static final org.objectweb.asm.Type SOY_PROTO_VALUE_IMPL_TYPE
public static final org.objectweb.asm.Type SOY_RECORD_TYPE
public static final org.objectweb.asm.Type SOY_VALUE_TYPE
public static final org.objectweb.asm.Type SOY_VALUE_PROVIDER_TYPE
public static final org.objectweb.asm.Type STRING_TYPE
public static final org.objectweb.asm.Type THROWABLE_TYPE
public static final org.objectweb.asm.Type ILLEGAL_STATE_EXCEPTION_TYPE
public static final org.objectweb.asm.commons.Method CLASS_INIT
public static final org.objectweb.asm.commons.Method NULLARY_INIT
public static boolean isPossiblyAssignableFrom(org.objectweb.asm.Type left,
org.objectweb.asm.Type right)
true if left is possibly assignable from right.
Analogous to right instanceof left.
public static boolean isDefinitelyAssignableFrom(org.objectweb.asm.Type left,
org.objectweb.asm.Type right)
true if left is definitely assignable from right.
Analogous to right instanceof left.
public static Class<?> classFromAsmType(org.objectweb.asm.Type type)
IllegalArgumentException - if the class cannot be found. It is expected that this method
will only be called for types that have a runtime on the compilers classpath.public static Expression constant(boolean value)
Expression that can load the given boolean constant.public static Expression constant(int value)
Expression that can load the given int constant.public static Expression constant(char value)
Expression that can load the given char constant.public static Expression constant(long value)
Expression that can load the given long constant.public static Expression constant(double value)
Expression that can load the given double constant.public static Expression constant(String value)
Expression that can load the given String constant.public static Expression constant(String value, ClassFieldManager manager)
Expression that can load the given String constant.
Unlike constant(String) this can handle strings larger than 65K bytes.
public static Expression constant(@Nullable SanitizedContent.ContentKind kind)
Expression that evaluates to the given ContentKind, or null.public static Expression constantSanitizedContentKindAsContentKind(@Nullable SanitizedContentKind kind)
Expression that evaluates to the SanitizedContent.ContentKind value that is
equivalent to the given SanitizedContentKind, or null.public static Expression constant(@Nullable Dir dir)
Expression that evaluates to the given Dir, or null.public static Expression constantNull(org.objectweb.asm.Type type)
Expression with the given type that always returns null.public static Expression numericConversion(Expression expr, org.objectweb.asm.Type to)
IllegalArgumentException - if either the expression or the target type is not a numeric
primitivepublic static boolean isPrimitive(org.objectweb.asm.Type type)
true if Type is a primitive type.public static void defineDefaultConstructor(org.objectweb.asm.ClassVisitor cv,
TypeInfo ownerType)
ClassVisitor.
For java classes this is normally generated by the compiler and looks like:
public Foo() {
super();
}
public static Expression compare(int comparisonOpcode, Expression left, Expression right)
public static Expression logicalNot(Expression baseExpr)
public static Expression compareSoyEquals(SoyExpression left, SoyExpression right)
SoyExpressions for equality using soy == semantics.public static Expression firstNonNull(Expression left, Expression right)
left if left is non null, and evaluates to
right otherwise.public static Expression ternary(Expression condition, Expression trueBranch, Expression falseBranch)
condition ? left : rightpublic static Expression logicalOr(Expression... expressions)
||) operator over the list of boolean
expressions.public static Expression logicalOr(List<? extends Expression> expressions)
||) operator over the list of boolean
expressions.public static Expression logicalAnd(Expression... expressions)
&&) operator over the list of boolean
expressions.public static Expression logicalAnd(List<? extends Expression> expressions)
&&) operator over the list of boolean
expressions.public static Expression asImmutableList(Iterable<? extends Expression> items)
ImmutableList containing the given items.
NOTE: ImmutableList rejects null elements.
public static Expression asList(Iterable<? extends Expression> items)
ArrayList containing all the given items.public static void nullCoalesce(CodeBuilder builder, org.objectweb.asm.Label nullExit)
nullExit if it is null. At nullSafeExit there will be a null value at the top
of the stack.public static org.objectweb.asm.Type unboxUnchecked(CodeBuilder cb, SoyRuntimeType soyType, Class<?> asType)
asType. Top of
stack must not be null.
Always prefer using SoyExpression.unboxAs(java.lang.Class<?>) over this method, whenever possible.
Guarantees: * Bytecode output will not change stack height * Output will only change the top element, and nothing below that
public static Expression newLinkedHashMap(Iterable<? extends Expression> keys, Iterable<? extends Expression> values)
LinkedHashMap containing all the given
entries.