code stringlengths 73 34.1k | label stringclasses 1
value |
|---|---|
public T setId(int id) {
Preconditions.checkState(this.id == null);
this.id = id;
return (T) this;
} | java |
public T setSoyDoc(String soyDoc, SourceLocation soyDocLocation) {
Preconditions.checkState(this.soyDoc == null);
Preconditions.checkState(cmdText != null);
int paramOffset = soyDoc.indexOf("@param");
if (paramOffset != -1) {
errorReporter.report(
new RawTextNode(-1, soyDoc, soyDocLocati... | java |
public T addParams(Iterable<? extends TemplateParam> newParams) {
Set<String> seenParamKeys = new HashSet<>();
if (this.params == null) {
this.params = ImmutableList.copyOf(newParams);
} else {
for (TemplateParam oldParam : this.params) {
seenParamKeys.add(oldParam.name());
}
... | java |
public static <T extends Node> ImmutableList<T> getAllNodesOfType(
Node rootSoyNode, final Class<T> classObject) {
return getAllMatchingNodesOfType(rootSoyNode, classObject, arg -> true);
} | java |
private static <T extends Node> ImmutableList<T> getAllMatchingNodesOfType(
Node rootSoyNode, final Class<T> classObject, final Predicate<T> filter) {
final ImmutableList.Builder<T> matchedNodesBuilder = ImmutableList.builder();
// optimization to avoid navigating into expr trees if we can't possibly matc... | java |
public static <R> void execOnAllV2Exprs(
SoyNode node, final AbstractNodeVisitor<ExprNode, R> exprNodeVisitor) {
visitAllNodes(
node,
new NodeVisitor<Node, VisitDirective>() {
@Override
public VisitDirective exec(Node node) {
if (node instanceof ExprHolderNode) ... | java |
public static boolean checkCloseTagClosesOptional(TagName closeTag, TagName optionalOpenTag) {
// TODO(b/120994894): Replace this with checkArgument() when HtmlTagEntry can be replaced.
if (!optionalOpenTag.isStatic() || !optionalOpenTag.isDefinitelyOptional()) {
return false;
}
if (!closeTag.isSt... | java |
public static boolean checkOpenTagClosesOptional(TagName openTag, TagName optionalOpenTag) {
checkArgument(optionalOpenTag.isDefinitelyOptional(), "Open tag is not optional.");
if (!(openTag.isStatic() && optionalOpenTag.isStatic())) {
return false;
}
String optionalTagName = optionalOpenTag.getSt... | java |
public SwitchBuilder addCase(Expression caseLabel, Statement body) {
clauses.add(new Switch.CaseClause(ImmutableList.of(caseLabel), body));
return this;
} | java |
public ExprNode valueAsExpr(ErrorReporter reporter) {
checkState(value == null);
if (valueExprList.size() > 1) {
reporter.report(
valueExprList.get(1).getSourceLocation(), EXPECTED_A_SINGLE_EXPRESSION, key.identifier());
// Return the first expr to avoid an NPE in CallNode ctor.
retu... | java |
public static List<String> genNoncollidingBaseNamesForExprs(
List<ExprNode> exprNodes, String fallbackBaseName, ErrorReporter errorReporter) {
int numExprs = exprNodes.size();
// --- Compute candidate base names for each expression. ---
List<List<String>> candidateBaseNameLists = Lists.newArrayListW... | java |
@CheckReturnValue
public Expression build(CodeChunk.Generator codeGenerator) {
ImmutableList<IfThenPair<Expression>> pairs = conditions.build();
Expression ternary = tryCreateTernary(pairs);
if (ternary != null) {
return ternary;
}
// Otherwise we need to introduce a temporary and assign to ... | java |
void addBasic(Token token) {
if (basicStart == -1) {
basicStart = buffer.length();
basicStartOfWhitespace = -1;
basicHasNewline = false;
}
switch (token.kind) {
case SoyFileParserConstants.TOKEN_WS:
if (token.image.indexOf('\r') != -1 || token.image.indexOf('\n') != -1) {
... | java |
private void append(Token token, String content) {
if (content.isEmpty()) {
throw new IllegalStateException(
String.format(
"shouldn't append empty content: %s @ %s",
SoyFileParserConstants.tokenImage[token.kind], Tokens.createSrcLoc(fileName, token)));
}
// add a... | java |
public static String javaClassNameFromSoyTemplateName(String soyTemplate) {
checkArgument(
BaseUtils.isDottedIdentifier(soyTemplate), "%s is not a valid template name.", soyTemplate);
return CLASS_PREFIX + soyTemplate;
} | java |
public static String javaFileName(String soyNamespace, String fileName) {
checkArgument(
BaseUtils.isDottedIdentifier(soyNamespace),
"%s is not a valid soy namspace name.",
soyNamespace);
return (CLASS_PREFIX + soyNamespace).replace('.', '/') + '/' + fileName;
} | java |
public static void rewriteStackTrace(Throwable throwable) {
StackTraceElement[] stack = throwable.getStackTrace();
for (int i = 0; i < stack.length; i++) {
StackTraceElement curr = stack[i];
if (curr.getClassName().startsWith(CLASS_PREFIX)) {
stack[i] =
new StackTraceElement(
... | java |
private static String translateVar(SoyToJsVariableMappings variableMappings, Matcher matcher) {
Preconditions.checkArgument(matcher.matches());
String firstPart = matcher.group(1);
StringBuilder exprTextSb = new StringBuilder();
// ------ Translate the first key, which may be a variable or a data key ... | java |
public String typeExprForRecordMember(boolean isOptional) {
if (typeExpressions.size() > 1 || isOptional) {
// needs parens
return "("
+ typeExpr()
+ (isOptional && !typeExpressions.contains("undefined") ? "|undefined" : "")
+ ")";
}
return typeExpr();
} | java |
public static DictImpl forProviderMap(
Map<String, ? extends SoyValueProvider> providerMap, RuntimeMapTypeTracker.Type mapType) {
return new DictImpl(providerMap, mapType);
} | java |
private StackTraceElement[] concatWithJavaStackTrace(StackTraceElement[] javaStackTrace) {
if (soyStackTrace.isEmpty()) {
return javaStackTrace;
}
StackTraceElement[] finalStackTrace =
new StackTraceElement[soyStackTrace.size() + javaStackTrace.length];
soyStackTrace.toArray(finalStackTra... | java |
public void put(Object... data) {
// TODO: Perhaps change to only convert varargs to Map, and do put(Map) elsewhere.
if (data.length % 2 != 0) {
throw new SoyDataException(
"Varargs to put(...) must have an even number of arguments (key-value pairs).");
}
for (int i = 0; i < data.length... | java |
public void remove(String keyStr) {
List<String> keys = split(keyStr, '.');
int numKeys = keys.size();
CollectionData collectionData = this;
for (int i = 0; i <= numKeys - 2; ++i) {
SoyData soyData = collectionData.getSingle(keys.get(i));
if (!(soyData instanceof CollectionData)) {
... | java |
private static List<String> split(String str, char delim) {
List<String> result = Lists.newArrayList();
int currPartStart = 0;
while (true) {
int currPartEnd = str.indexOf(delim, currPartStart);
if (currPartEnd == -1) {
result.add(str.substring(currPartStart));
break;
} e... | java |
public static boolean isNumericPrimitive(SoyType type) {
SoyType.Kind kind = type.getKind();
if (NUMERIC_PRIMITIVES.contains(kind)) {
return true;
}
return type.isAssignableFrom(NUMBER_TYPE) || NUMBER_TYPE.isAssignableFrom(type);
} | java |
public static SoyType tryRemoveNull(SoyType soyType) {
if (soyType == NullType.getInstance()) {
return NullType.getInstance();
}
return removeNull(soyType);
} | java |
public static SoyType computeLowestCommonType(
SoyTypeRegistry typeRegistry, SoyType t0, SoyType t1) {
if (t0 == ErrorType.getInstance() || t1 == ErrorType.getInstance()) {
return ErrorType.getInstance();
}
if (t0.isAssignableFrom(t1)) {
return t0;
} else if (t1.isAssignableFrom(t0)) {... | java |
public static SoyType computeLowestCommonType(
SoyTypeRegistry typeRegistry, Collection<SoyType> types) {
SoyType result = null;
for (SoyType type : types) {
result = (result == null) ? type : computeLowestCommonType(typeRegistry, result, type);
}
return result;
} | java |
public static Optional<SoyType> computeLowestCommonTypeArithmetic(SoyType t0, SoyType t1) {
// If either of the types is an error type, return the error type
if (t0.getKind() == Kind.ERROR || t1.getKind() == Kind.ERROR) {
return Optional.of(ErrorType.getInstance());
}
// If either of the types isn... | java |
Statement detachForCall(final Expression callRender) {
checkArgument(callRender.resultType().equals(RENDER_RESULT_TYPE));
final Label reattachRender = new Label();
final SaveRestoreState saveRestoreState = variables.saveRestoreState();
// We pass NULL statement for the restore logic since we handle that... | java |
Statement generateReattachTable() {
final Expression readField = stateField.accessor(thisExpr);
final Statement defaultCase =
Statement.throwExpression(MethodRef.RUNTIME_UNEXPECTED_STATE_ERROR.invoke(readField));
return new Statement() {
@Override
protected void doGen(final CodeBuilder a... | java |
private int addState(Label reattachPoint, Statement restore) {
ReattachState create = ReattachState.create(reattachPoint, restore);
reattaches.add(create);
int state = reattaches.size() - 1; // the index of the ReattachState in the list
return state;
} | java |
private boolean shouldProtect(Expression operand, OperandPosition operandPosition) {
if (operand instanceof Operation) {
Operation operation = (Operation) operand;
return operation.precedence() < this.precedence()
|| (operation.precedence() == this.precedence()
&& operandPosition... | java |
public static SimplifyVisitor create(
IdGenerator idGenerator, ImmutableList<SoyFileNode> sourceFiles) {
return new SimplifyVisitor(
idGenerator, sourceFiles, new SimplifyExprVisitor(), new PreevalVisitorFactory());
} | java |
@VisibleForTesting
static String buildMsgContentStrForMsgIdComputation(
ImmutableList<SoyMsgPart> msgParts, boolean doUseBracedPhs) {
msgParts = IcuSyntaxUtils.convertMsgPartsToEmbeddedIcuSyntax(msgParts);
StringBuilder msgStrSb = new StringBuilder();
for (SoyMsgPart msgPart : msgParts) {
... | java |
private static String formatParseExceptionDetails(
String errorToken, List<String> expectedTokens) {
// quotes/normalize the expected tokens before rendering, just in case after normalization some
// can be deduplicated.
ImmutableSet.Builder<String> normalizedTokensBuilder = ImmutableSet.builder();
... | java |
private static void maybeMarkBadProtoAccess(ExprNode expr, SoyValue value) {
if (value instanceof SoyProtoValue) {
((SoyProtoValue) value).setAccessLocationKey(expr.getSourceLocation());
}
} | java |
private static boolean isNullOrUndefinedBase(SoyValue base) {
return base == null
|| base instanceof NullData
|| base instanceof UndefinedData
|| base == NullSafetySentinel.INSTANCE;
} | java |
@Override
protected void visitFieldAccessNode(FieldAccessNode node) {
// simplify children first
visitChildren(node);
ExprNode baseExpr = node.getChild(0);
if (baseExpr instanceof RecordLiteralNode) {
RecordLiteralNode recordLiteral = (RecordLiteralNode) baseExpr;
for (int i = 0; i < recor... | java |
private void attemptPreeval(ExprNode node) {
// Note that we need to catch RenderException because preevaluation may fail, e.g. when
// (a) the expression uses a bidi function that needs bidiGlobalDir to be in scope, but the
// apiCallScope is not currently active,
// (b) the expression uses an ext... | java |
static SoyValue getConstantOrNull(ExprNode expr) {
switch (expr.getKind()) {
case NULL_NODE:
return NullData.INSTANCE;
case BOOLEAN_NODE:
return BooleanData.forValue(((BooleanNode) expr).getValue());
case INTEGER_NODE:
return IntegerData.forValue(((IntegerNode) expr).getVa... | java |
public static <T> T visitField(FieldDescriptor fieldDescriptor, FieldVisitor<T> visitor) {
// NOTE: map fields are technically repeated, so check isMap first.
if (fieldDescriptor.isMapField()) {
List<FieldDescriptor> mapFields = fieldDescriptor.getMessageType().getFields();
checkState(mapFields.size... | java |
static JbcSrcJavaValue error(Expression expr, JbcSrcValueErrorReporter reporter) {
return new JbcSrcJavaValue(
expr,
/* method= */ null,
/* allowedType= */ null,
/* constantNull= */ false,
/* error= */ true,
reporter);
} | java |
static JbcSrcJavaValue of(Expression expr, JbcSrcValueErrorReporter reporter) {
if (expr instanceof SoyExpression) {
return new JbcSrcJavaValue(
expr,
/* method= */ null,
/* allowedType= */ ((SoyExpression) expr).soyType(),
/* constantNull= */ false,
/* error=... | java |
static JbcSrcJavaValue of(Expression expr, Method method, JbcSrcValueErrorReporter reporter) {
checkNotNull(method);
if (expr instanceof SoyExpression) {
return new JbcSrcJavaValue(
expr,
method,
/* allowedType= */ ((SoyExpression) expr).soyType(),
/* constantNull= ... | java |
static JbcSrcJavaValue of(
SoyExpression expr, SoyType allowedType, JbcSrcValueErrorReporter reporter) {
return new JbcSrcJavaValue(
expr,
/* method= */ null,
checkNotNull(allowedType),
/* constantNull= */ false,
/* error= */ false,
reporter);
} | java |
public static Class<?> classFromAsmType(Type type) {
Optional<Class<?>> maybeClass = objectTypeToClassCache.getUnchecked(type);
if (!maybeClass.isPresent()) {
throw new IllegalArgumentException("Could not load: " + type);
}
return maybeClass.get();
} | java |
public static Expression numericConversion(final Expression expr, final Type to) {
if (to.equals(expr.resultType())) {
return expr;
}
if (!isNumericPrimitive(to) || !isNumericPrimitive(expr.resultType())) {
throw new IllegalArgumentException("Cannot convert from " + expr.resultType() + " to " + ... | java |
public static Expression compare(
final int comparisonOpcode, final Expression left, final Expression right) {
checkArgument(
left.resultType().equals(right.resultType()),
"left and right must have matching types, found %s and %s",
left.resultType(),
right.resultType());
ch... | java |
public static Expression logicalNot(final Expression baseExpr) {
baseExpr.checkAssignableTo(Type.BOOLEAN_TYPE);
checkArgument(baseExpr.resultType().equals(Type.BOOLEAN_TYPE), "not a boolean expression");
return new Expression(Type.BOOLEAN_TYPE, baseExpr.features()) {
@Override
protected void doG... | java |
private static Expression doEqualsString(SoyExpression stringExpr, SoyExpression other) {
// This is compatible with SharedRuntime.compareString, which interestingly makes == break
// transitivity. See b/21461181
SoyRuntimeType otherRuntimeType = other.soyRuntimeType();
if (otherRuntimeType.isKnownStri... | java |
public PyFunctionExprBuilder setUnpackedKwargs(PyExpr mapping) {
if (unpackedKwargs != null) {
throw new UnsupportedOperationException("Only one kwarg unpacking allowed per expression.");
}
StringBuilder expr = new StringBuilder("**");
if (mapping.getPrecedence() < Integer.MAX_VALUE) {
expr.... | java |
public String build() {
StringBuilder sb = new StringBuilder(funcName + "(");
// Join args and kwargs into simple strings.
String args =
argList.stream()
.map(PyExpr::getText)
.filter(Objects::nonNull)
.collect(Collectors.joining(", "));
String kwargs =
... | java |
protected RenderVisitor createHelperInstance(Appendable outputBuf, SoyRecord data) {
return new RenderVisitor(
evalVisitorFactory,
outputBuf,
basicTemplates,
deltemplates,
data,
ijData,
activeDelPackageSelector,
msgBundle,
xidRenamingMap,
... | java |
private void renderTemplate(TemplateNode template, Predicate<String> paramsToTypeCheck) {
env = Environment.create(template, data, ijData);
checkStrictParamTypes(template, paramsToTypeCheck);
visitChildren(template);
env = null; // unpin for gc
} | java |
private SoyValue eval(ExprNode expr, SoyNode node) {
if (expr == null) {
throw RenderException.create("Cannot evaluate expression in V1 syntax.")
.addStackTraceElement(node);
}
// Lazily initialize evalVisitor.
if (evalVisitor == null) {
evalVisitor =
evalVisitorFactory... | java |
static void append(Appendable outputBuf, CharSequence cs) {
try {
outputBuf.append(cs);
} catch (IOException e) {
throw new RuntimeException(e);
}
} | java |
static void append(Appendable outputBuf, SoyValue value, SoyNode node) {
try {
value.render(outputBuf);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (RenderException e) {
throw e.addStackTraceElement(node);
}
} | java |
private SoyValue applyDirective(
SoyPrintDirective directive, SoyValue value, List<SoyValue> args, SoyNode node) {
// Get directive.
if (!(directive instanceof SoyJavaPrintDirective)) {
throw RenderException.createWithSource(
"Failed to find Soy print directive with name '"
... | java |
private void checkValueType(TemplateParam param, SoyValue value, TemplateNode node) {
if (!TofuTypeChecks.isInstance(param.type(), value, node.getSourceLocation())) {
// should this be a soydataexception?
throw RenderException.createWithSource(
"Parameter type mismatch: attempt to bind value '... | java |
public String getDescriptorExpression() {
// We only need to import the outermost descriptor.
Descriptor descriptor = typeDescriptor;
while (descriptor.getContainingType() != null) {
descriptor = descriptor.getContainingType();
}
return JavaQualifiedNames.getQualifiedName(descriptor) + ".getDe... | java |
public String getNameForBackend(SoyBackendKind backend) {
switch (backend) {
case JS_SRC:
// The 'proto' prefix is JSPB-specific. If we ever support some other
// JavaScript proto implementation, we'll need some way to determine which
// proto implementation the user wants to use at th... | java |
@Override
protected void visitHtmlAttributeNode(HtmlAttributeNode node) {
// Skip attributes that do not have a value.
if (!node.hasValue()) {
return;
}
SourceLocation insertionLocation = node.getSourceLocation();
for (FunctionNode function : SoyTreeUtils.getAllNodesOfType(node, FunctionNode... | java |
public static SanitizedContent ordainAsSafe(String value, ContentKind kind) {
return ordainAsSafe(value, kind, kind.getDefaultDir());
} | java |
private void findProtoTypesRecurse(SoyType type, SortedSet<String> protoTypes) {
switch (type.getKind()) {
case PROTO:
protoTypes.add(((SoyProtoType) type).getDescriptorExpression());
break;
case PROTO_ENUM:
protoTypes.add(((SoyProtoEnumType) type).getDescriptorExpression());
... | java |
private static String buildTemplateNameForJavadoc(
SoyFileNode currSoyFile, TemplateMetadata template) {
StringBuilder resultSb = new StringBuilder();
if (template.getSourceLocation().getFilePath().equals(currSoyFile.getFilePath())
&& template.getTemplateKind() != TemplateMetadata.Kind.DELTEMPLA... | java |
private static void appendImmutableList(
IndentedLinesBuilder ilb, String typeParamSnippet, Collection<String> itemSnippets) {
appendListOrSetHelper(ilb, "ImmutableList." + typeParamSnippet + "of", itemSnippets);
} | java |
private static void appendImmutableMap(
IndentedLinesBuilder ilb, String typeParamSnippet, Map<String, String> entrySnippetPairs) {
if (entrySnippetPairs.isEmpty()) {
ilb.appendLineStart("ImmutableMap.", typeParamSnippet, "of()");
} else {
ilb.appendLine("ImmutableMap.", typeParamSnippet, "bu... | java |
static Environment create(TemplateNode template, SoyRecord data, SoyRecord ijData) {
return new Impl(template, data, ijData);
} | java |
public static Iterable<CrossLanguageStringXform> getAllEscapers() {
// This list is hard coded but is checked by unittests for the contextual auto-escaper.
return ImmutableList.of(
EscapeHtml.INSTANCE,
NormalizeHtml.INSTANCE,
EscapeHtmlNospace.INSTANCE,
NormalizeHtmlNospace.INSTA... | java |
public static Statement returnExpression(final Expression expression) {
// TODO(lukes): it would be nice to do a checkType operation here to make sure that expression
// is compatible with the return type of the method, but i don't know how to get that
// information here (reasonably). So it is the caller'... | java |
public static Statement throwExpression(final Expression expression) {
expression.checkAssignableTo(THROWABLE_TYPE);
return new Statement() {
@Override
protected void doGen(CodeBuilder adapter) {
expression.gen(adapter);
adapter.throwException();
}
};
} | java |
public static Statement concat(final Iterable<? extends Statement> statements) {
checkNotNull(statements);
return new Statement() {
@Override
protected void doGen(CodeBuilder adapter) {
for (Statement statement : statements) {
statement.gen(adapter);
}
}
};
} | java |
public final Statement labelStart(final Label label) {
return new Statement() {
@Override
protected void doGen(CodeBuilder adapter) {
adapter.mark(label);
Statement.this.gen(adapter);
}
};
} | java |
final Expression then(final Expression expression) {
return new Expression(expression.resultType(), expression.features()) {
@Override
protected void doGen(CodeBuilder adapter) {
Statement.this.gen(adapter);
expression.gen(adapter);
}
};
} | java |
public Future<?> future() {
Future<?> f = future;
if (f == null) {
throw new IllegalStateException(
"Result.future() can only be called if type() is DETACH, type was: " + type);
}
return f;
} | java |
public void write(T instance, ClassVisitor visitor) {
doWrite(instance, visitor.visitAnnotation(typeDescriptor, isRuntimeVisible));
} | java |
private static <T extends Annotation> FieldWriter annotationFieldWriter(
final String name, final AnnotationRef<T> ref) {
return new FieldWriter() {
@Override
public void write(AnnotationVisitor visitor, Object value) {
ref.doWrite(ref.annType.cast(value), visitor.visitAnnotation(name, ref... | java |
private static FieldWriter simpleFieldWriter(final String name) {
return new FieldWriter() {
@Override
public void write(AnnotationVisitor visitor, Object value) {
visitor.visit(name, value);
}
};
} | java |
private static FieldWriter simpleArrayFieldWriter(final String name) {
return new FieldWriter() {
@Override
public void write(AnnotationVisitor visitor, Object value) {
int len = Array.getLength(value);
AnnotationVisitor arrayVisitor = visitor.visitArray(name);
for (int i = 0; i ... | java |
private static <T extends Annotation> FieldWriter annotationArrayFieldWriter(
final String name, final AnnotationRef<T> ref) {
return new FieldWriter() {
@Override
public void write(AnnotationVisitor visitor, Object value) {
int len = Array.getLength(value);
AnnotationVisitor array... | java |
public static LocalVariable createThisVar(TypeInfo owner, Label start, Label end) {
return new LocalVariable("this", owner.type(), 0, start, end, Feature.NON_NULLABLE);
} | java |
public void tableEntry(CodeBuilder mv) {
mv.visitLocalVariable(
variableName(),
resultType().getDescriptor(),
null, // no generic signature
start(),
end(),
index());
} | java |
private Statement store(final Expression expr, final Optional<Label> firstVarInstruction) {
expr.checkAssignableTo(resultType());
return new Statement() {
@Override
protected void doGen(CodeBuilder adapter) {
expr.gen(adapter);
if (firstVarInstruction.isPresent()) {
adapter... | java |
public static SoyValue resolveSoyValueProvider(SoyValueProvider provider) {
SoyValue value = provider.resolve();
return handleTofuNull(value);
} | java |
public static SoyString checkSoyString(Object o) {
// if it isn't a sanitized content we don't want to warn and if it isn't a soystring we should
// always fail.
if (o instanceof SoyString
&& o instanceof SanitizedContent
&& ((SanitizedContent) o).getContentKind() != ContentKind.TEXT
... | java |
public static SoyValue callLegacySoyFunction(
LegacyFunctionAdapter fnAdapter, List<SoyValue> args) {
for (int i = 0; i < args.size(); i++) {
if (args.get(i) == null) {
args.set(i, NullData.INSTANCE);
}
}
return handleTofuNull(fnAdapter.computeForJava(args));
} | java |
public static SoyValue applyPrintDirective(
SoyJavaPrintDirective directive, SoyValue value, List<SoyValue> args) {
value = value == null ? NullData.INSTANCE : value;
for (int i = 0; i < args.size(); i++) {
if (args.get(i) == null) {
args.set(i, NullData.INSTANCE);
}
}
return d... | java |
public static CompiledTemplate applyEscapers(
CompiledTemplate delegate, ImmutableList<SoyJavaPrintDirective> directives) {
ContentKind kind = delegate.kind();
if (canSkipEscaping(directives, kind)) {
return delegate;
}
return new EscapedCompiledTemplate(delegate, directives, kind);
} | java |
PyStringExpr getPyExpr() {
if (this.msgNode.isPlrselMsg()) {
return this.msgNode.isPluralMsg() ? pyFuncForPluralMsg() : pyFuncForSelectMsg();
} else {
return this.msgNode.isRawTextMsg() ? pyFuncForRawTextMsg() : pyFuncForGeneralMsg();
}
} | java |
private Map<PyExpr, PyExpr> collectVarNameListAndToPyExprMap() {
Map<PyExpr, PyExpr> nodePyVarToPyExprMap = new LinkedHashMap<>();
for (Map.Entry<String, MsgSubstUnitNode> entry : msgNode.getVarNameToRepNodeMap().entrySet()) {
MsgSubstUnitNode substUnitNode = entry.getValue();
PyExpr substPyExpr = n... | java |
Expression genCodeForParamAccess(String paramName, VarDefn varDefn) {
Expression source = OPT_DATA;
if (varDefn.isInjected()) {
// Special case for csp_nonce. It is created by the compiler itself, and users should not need
// to set it. So, instead of generating opt_ij_data.csp_nonce, we generate op... | java |
@Override
protected Expression visitVarRefNode(VarRefNode node) {
Expression translation = variableMappings.maybeGet(node.getName());
if (translation != null) {
// Case 1: In-scope local var.
return translation;
} else {
// Case 2: Data reference.
return genCodeForParamAccess(node.... | java |
NullSafeAccumulator dotAccess(FieldAccess access, boolean nullSafe) {
if (access instanceof ProtoCall) {
ProtoCall protoCall = (ProtoCall) access;
Expression maybeUnpack = protoCall.unpackFunction();
if (maybeUnpack != null) {
Preconditions.checkState(
unpackFunction == null, "... | java |
NullSafeAccumulator bracketAccess(Expression arg, boolean nullSafe) {
chain.add(new Bracket(arg, nullSafe));
// With a bracket access we no longer need to unpack the entire list, just a singular object.
accessType = AccessType.SINGULAR;
return this;
} | java |
Expression result(CodeChunk.Generator codeGenerator) {
Expression accessChain = buildAccessChain(base, codeGenerator, chain.iterator());
if (unpackFunction == null) {
return accessChain;
} else {
return accessType.unpackResult(accessChain, unpackFunction);
}
} | java |
private static Expression buildAccessChain(
Expression base, CodeChunk.Generator generator, Iterator<ChainAccess> chain) {
if (!chain.hasNext()) {
return base; // base case
}
ChainAccess link = chain.next();
if (link.nullSafe) {
if (!base.isCheap()) {
base = generator.declarati... | java |
public static boolean isRtlLanguage(String locale) {
try {
return UScript.isRightToLeft(
UCharacter.getPropertyValueEnum(
UProperty.SCRIPT, ULocale.addLikelySubtags(new ULocale(locale)).getScript()));
} catch (IllegalArgumentException e) {
return false;
}
} | java |
public List<String> genJsSrc(
SoyFileSetNode soyTree,
TemplateRegistry registry,
SoyIncrementalDomSrcOptions options,
ErrorReporter errorReporter) {
SoyJsSrcOptions incrementalJSSrcOptions = options.toJsSrcOptions();
BidiGlobalDir bidiGlobalDir =
SoyBidiUtils.decodeBidiGlobalDi... | java |
public static SanitizedContent serializeObject(Gson gson, Object obj) {
return ordainJson(gson.toJson(obj));
} | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.