/** * Creates a Soy map from a Java map. While this is O(n) in the map's shallow size, the Java * values are converted into Soy values lazily and only once. The keys are converted eagerly. */ private SoyMap newSoyMapFromJavaMap(Map<?, ?> javaMap) { Map<SoyValue, SoyValueProvider> map = Maps.newHashMapWithExpectedSize(javaMap.size()); for (Map.Entry<?, ?> entry : javaMap.entrySet()) { map.put(convert(entry.getKey()).resolve(), convertLazy(entry.getValue())); } return SoyMapImpl.forProviderMap(map); }
@Override public SoyValueProvider apply(SoyGlobalsValue input) { return convert(input.getSoyGlobalValue()); } });
@Override public SoyValueProvider apply(SoyGlobalsValue input) { return convert(input.getSoyGlobalValue()); } });
/** * Creates a Soy map from a Java map. While this is O(n) in the map's shallow size, the Java * values are converted into Soy values lazily and only once. The keys are converted eagerly. */ private SoyMap newSoyMapFromJavaMap(Map<?, ?> javaMap) { ImmutableMap.Builder<SoyValue, SoyValueProvider> builder = ImmutableMap.builder(); for (Map.Entry<?, ?> entry : javaMap.entrySet()) { builder.put(convert(entry.getKey()).resolve(), convertLazy(entry.getValue())); } return SoyMapImpl.forProviderMap(builder.build()); }
private SoyValue doResolve() { Object resolvedValue; try { resolvedValue = accessorMethod.invoke(delegate); } catch (Exception e) { throw new SoyException("Failed to invoke accessor " + accessorMethod.getName() + " on instance of " + delegate.getClass(), e); } return converter.convert(resolvedValue).resolve(); }
@Override public SoyValue computeForJava(List<SoyValue> args) { final Object[] pluginArgs = Lists.transform(args, new Function<SoyValue, Object>() { public Object apply(SoyValue from) { return SoyValueUtils.fromSoyValue(from); } }).toArray(); Object returnValue = soyServerFunction.apply(pluginArgs); return converter.convert(returnValue).resolve(); }
boolean isValidValue = true; try { SoyValue value0 = SoyValueConverter.INSTANCE.convert(valueObj).resolve(); if (!(value0 instanceof PrimitiveData)) { isValidValue = false;
boolean isValidValue = true; try { SoyValue value0 = SoyValueConverter.INSTANCE.convert(valueObj).resolve(); if (!(value0 instanceof PrimitiveData)) { isValidValue = false;
/** * Calls Future.get() and then converts the result to SoyValue. Note that this result can never * return {@code null}, since null converts to {@code NullData.INSTANCE}. */ @Override @Nonnull protected final SoyValue compute() { try { if (!future.isDone()) { futureBlockCallback.get().beforeBlock(); } return SoyValueConverter.INSTANCE.convert(future.get()).resolve(); } catch (ExecutionException e) { throw new SoyFutureException(e.getCause()); } catch (Throwable e) { throw new SoyFutureException(e); } } }
/** * Calls Future.get() and then converts the result to SoyValue. Note that this result can never * return {@code null}, since null converts to {@code NullData.INSTANCE}. */ @Override @Nonnull protected final SoyValue compute() { try { if (!future.isDone()) { futureBlockCallback.get().beforeBlock(); } return SoyValueConverter.INSTANCE.convert(future.get()).resolve(); } catch (ExecutionException e) { throw new SoyFutureException(e.getCause()); } catch (Throwable e) { throw new SoyFutureException(e); } } }
@Override public TofuJavaValue listOf(List<JavaValue> args) { List<SoyValue> values = Lists.transform( args, new Function<JavaValue, SoyValue>() { @Override public SoyValue apply(JavaValue soyArg) { TofuJavaValue tjv = (TofuJavaValue) soyArg; if (!tjv.hasSoyValue()) { throw RenderException.create( "listOf may only be called with the 'arg' parameters to " + "JavaValueFactory methods"); } return tjv.soyValue(); } }); return TofuJavaValue.forSoyValue( SoyValueConverter.INSTANCE.convert(values).resolve(), fn.getSourceLocation()); }
@Override public SoyValueProvider convert(SoyValueConverter converter, Object value) { if (value instanceof Enum) { return new EnumSoyValue((Enum<?>) value); } if (value instanceof SanitizedString) { SanitizedString sanitizedString = (SanitizedString) value; return UnsafeSanitizedContentOrdainer.ordainAsSafe( sanitizedString.getValue(), toContentKind(sanitizedString.getType()) ); } if (value.getClass().isArray()) { int length = Array.getLength(value); List<Object> list = new ArrayList<>(length); for (int i = 0; i < length; i++) { list.add(Array.get(value, i)); } return converter.convert(list); } SoyDataMapper mapper = findMapper(value); if (mapper != null) { //noinspection unchecked Object newValue = mapper.convert(value); if (newValue != value) { return converter.convert(newValue); } } return new JavaBeanSoyDict(accessorResolver, converter, toSupplier(value)); }
private TofuJavaValue wrapInTofuValue(Method method, Object object) { if (object instanceof SoyValue) { return TofuJavaValue.forSoyValue((SoyValue) object, fn.getSourceLocation()); } try { return TofuJavaValue.forSoyValue( SoyValueConverter.INSTANCE.convert(object).resolve(), fn.getSourceLocation()); } catch (SoyDataException e) { throw RenderException.create("Invalid return value from `" + method + "`", e); } }