contentKind.isEmpty() ? Optional.<ContentKind>absent() : Optional.of(ContentKind.valueOf(contentKind)); this.callees = ImmutableSet.copyOf(annotation.callees()); this.delCallees = ImmutableSet.copyOf(annotation.delCallees());
contentKind.isEmpty() ? Optional.<ContentKind>absent() : Optional.of(ContentKind.valueOf(contentKind)); this.callees = ImmutableSet.copyOf(annotation.callees()); this.delCallees = ImmutableSet.copyOf(annotation.delCallees());
CompiledMethodBody compile( RenderUnitNode node, ExtraCodeCompiler prefix, ExtraCodeCompiler suffix) { List<Statement> statements = new ArrayList<>(); // Tag the content with the kind if (node.getContentKind() != null) { statements.add( appendableExpression .setSanitizedContentKind(node.getContentKind()) .setSanitizedContentDirectionality( ContentKind.valueOf(node.getContentKind().name()).getDefaultDir()) .toStatement()); } statements.add(prefix.compile(exprCompiler, appendableExpression)); statements.add(visitChildrenInNewScope(node)); statements.add(suffix.compile(exprCompiler, appendableExpression)); statements.add( // needs to go at the beginning but can only be generated after the whole method body. 0, detachState.generateReattachTable()); return CompiledMethodBody.create( Statement.concat(statements), detachState.getNumberOfDetaches()); }
(callee.getContentKind() != null) ? UnsafeSanitizedContentOrdainer.ordainAsSafe( calleeBuilder.toString(), ContentKind.valueOf(callee.getContentKind().name())) : StringData.forValue(calleeBuilder.toString()); for (SoyPrintDirective directive : node.getEscapingDirectives()) {
/** * Generates code to box the expression assuming that it is non-nullable and on the top of the * stack. */ private static void doBox(CodeBuilder adapter, SoyRuntimeType type) { if (type.isKnownSanitizedContent()) { FieldRef.enumReference( ContentKind.valueOf(((SanitizedType) type.soyType()).getContentKind().name())) .accessStaticUnchecked(adapter); MethodRef.ORDAIN_AS_SAFE.invokeUnchecked(adapter); } else if (type.isKnownString()) { MethodRef.STRING_DATA_FOR_VALUE.invokeUnchecked(adapter); } else if (type.isKnownList()) { MethodRef.LIST_IMPL_FOR_PROVIDER_LIST.invokeUnchecked(adapter); } else if (type.isKnownLegacyObjectMap()) { FieldRef.enumReference(RuntimeType.LEGACY_OBJECT_MAP_OR_RECORD).putUnchecked(adapter); MethodRef.DICT_IMPL_FOR_PROVIDER_MAP.invokeUnchecked(adapter); } else if (type.isKnownMap()) { MethodRef.MAP_IMPL_FOR_PROVIDER_MAP.invokeUnchecked(adapter); } else if (type.isKnownProto()) { MethodRef.SOY_PROTO_VALUE_IMPL_CREATE.invokeUnchecked(adapter); } else { throw new IllegalStateException("Can't box soy expression of type " + type); } }
@Override public SanitizedContent.ContentKind render(Appendable out) { TemplateNode template = baseTofu.renderMain( out, templateName, data, ijData, activeDelPackageNames, msgBundle, idRenamingMap, cssRenamingMap, debugSoyTemplateInfo); if (contentKindExplicitlySet || template.getContentKind() != null) { // Enforce the content kind if: // - The caller explicitly set a content kind to validate. // - The template is strict. This avoids accidentally using a text strict template in a // place where HTML was implicitly expected. enforceContentKind(template); } return template.getContentKind() != null ? SanitizedContent.ContentKind.valueOf(template.getContentKind().name()) : null; }
/** * Generates code to box the expression assuming that it is non-nullable and on the top of the * stack. */ private static void doBox(CodeBuilder adapter, SoyRuntimeType type) { if (type.isKnownSanitizedContent()) { FieldRef.enumReference( ContentKind.valueOf(((SanitizedType) type.soyType()).getContentKind().name())) .accessStaticUnchecked(adapter); MethodRef.ORDAIN_AS_SAFE.invokeUnchecked(adapter); } else if (type.isKnownString()) { MethodRef.STRING_DATA_FOR_VALUE.invokeUnchecked(adapter); } else if (type.isKnownListOrUnionOfLists()) { MethodRef.LIST_IMPL_FOR_PROVIDER_LIST.invokeUnchecked(adapter); } else if (type.isKnownLegacyObjectMapOrUnionOfMaps()) { FieldRef.enumReference(RuntimeMapTypeTracker.Type.LEGACY_OBJECT_MAP_OR_RECORD) .putUnchecked(adapter); MethodRef.DICT_IMPL_FOR_PROVIDER_MAP.invokeUnchecked(adapter); } else if (type.isKnownMapOrUnionOfMaps()) { MethodRef.MAP_IMPL_FOR_PROVIDER_MAP.invokeUnchecked(adapter); } else if (type.isKnownProtoOrUnionOfProtos()) { MethodRef.SOY_PROTO_VALUE_CREATE.invokeUnchecked(adapter); } else { throw new IllegalStateException("Can't box soy expression of type " + type); } }
@Override public SanitizedContent.ContentKind render(Appendable out) { TemplateNode template = baseTofu.renderMain( out, templateName, data, ijData, activeDelPackageNames, msgBundle, idRenamingMap, cssRenamingMap, debugSoyTemplateInfo, pluginInstances); if (contentKindExplicitlySet || template.getContentKind() != null) { // Enforce the content kind if: // - The caller explicitly set a content kind to validate. // - The template is strict. This avoids accidentally using a text strict template in a // place where HTML was implicitly expected. enforceContentKind(template); } return template.getContentKind() != null ? SanitizedContent.ContentKind.valueOf(template.getContentKind().name()) : null; }
CompiledMethodBody compile(RenderUnitNode node) { Statement templateBody = visitChildrenInNewScope(node); // Tag the content with the kind if (node.getContentKind() != null) { templateBody = Statement.concat( appendableExpression.setSanitizedContentKind(node.getContentKind()).toStatement(), appendableExpression .setSanitizedContentDirectionality( ContentKind.valueOf(node.getContentKind().name()).getDefaultDir()) .toStatement(), templateBody); } Statement jumpTable = detachState.generateReattachTable(); return CompiledMethodBody.create( Statement.concat(jumpTable, templateBody), detachState.getNumberOfDetaches()); }
private SoyValue renderRenderUnitNode(final RenderUnitNode renderUnitNode) { RenderableThunk thunk = new RenderableThunk() { @Override protected void doRender(Appendable appendable) throws IOException { renderBlock(renderUnitNode, appendable); } }; SanitizedContentKind contentKind = renderUnitNode.getContentKind(); if (contentKind != null) { return LazySanitizedContents.forThunk(thunk, ContentKind.valueOf(contentKind.name())); } else { return StringData.forThunk(thunk); } }
/** * Returns an {@link Expression} that evaluates to the {@link ContentKind} value that is * equivalent to the given {@link SanitizedContentKind}, or null. */ public static Expression constantSanitizedContentKindAsContentKind( @Nullable SanitizedContentKind kind) { return (kind == null) ? BytecodeUtils.constantNull(CONTENT_KIND_TYPE) : FieldRef.enumReference(ContentKind.valueOf(kind.name())).accessor(); }
private static ContentKind fromSanitizedContentKind(SanitizedContentKind kind) { if (kind == null) { return null; } return ContentKind.valueOf(kind.name()); } /**
/** * Returns an {@link Expression} that evaluates to the {@link ContentKind} value that is * equivalent to the given {@link SanitizedContentKind}, or null. */ public static Expression constantSanitizedContentKindAsContentKind( @Nullable SanitizedContentKind kind) { return (kind == null) ? BytecodeUtils.constantNull(CONTENT_KIND_TYPE) : FieldRef.enumReference(ContentKind.valueOf(kind.name())).accessor(); }