/** * Converts a Java object into an equivalent SoyValueProvider. * * @param obj The object to convert. * @return An equivalent SoyValueProvider. * @throws SoyDataException If the given object cannot be converted. */ @Nonnull public SoyValueProvider convert(@Nullable Object obj) { SoyValueProvider convertedPrimitive = convertCheap(obj); if (convertedPrimitive != null) { return convertedPrimitive; } return convertNonPrimitive(obj); }
@Override public SoyValue apply(Map<String, ?> input) { return newDictFromMap(input); } });
@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) { 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); }
/** * Creates a SoyList from a Java Iterable. * * <p>Values are converted into Soy types lazily and only once. * * @param items The collection of Java values * @return A new SoyList initialized from the given Java Collection. */ private SoyList newListFromIterable(Iterable<?> items) { // Create a list backed by a Java list which has eagerly converted each value into a lazy // value provider. Specifically, the list iteration is done eagerly so that the lazy value // provider can cache its value. ImmutableList.Builder<SoyValueProvider> builder = ImmutableList.builder(); for (Object item : items) { builder.add(convertLazy(item)); } return ListImpl.forProviderList(builder.build()); }
/** * Returns a SoyValueProvider corresponding to a Java object, but doesn't perform any work until * resolve() is called. */ private SoyValueProvider convertLazy(@Nullable final Object obj) { SoyValueProvider convertedPrimitive = convertCheap(obj); if (convertedPrimitive != null) { return convertedPrimitive; } else { return new SoyAbstractCachingValueProvider() { @Override protected SoyValue compute() { return convertNonPrimitive(obj).resolve(); } @Override public RenderResult status() { return RenderResult.done(); } }; } }
@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()); }
/** * Creates a SoyList from a Java Iterable. * * <p>Values are converted into Soy types lazily and only once. * * @param items The collection of Java values * @return A new SoyList initialized from the given Java Collection. */ private SoyList newListFromIterable(Iterable<?> items) { // Create a list backed by a Java list which has eagerly converted each value into a lazy // value provider. Specifically, the list iteration is done eagerly so that the lazy value // provider can cache its value. ImmutableList.Builder<SoyValueProvider> builder = ImmutableList.builder(); for (Object item : items) { builder.add(convertLazy(item)); } return ListImpl.forProviderList(builder.build()); }
/** * Returns a SoyValueProvider corresponding to a Java object, but doesn't perform any work until * resolve() is called. */ private SoyValueProvider convertLazy(@Nullable final Object obj) { SoyValueProvider convertedPrimitive = convertCheap(obj); if (convertedPrimitive != null) { return convertedPrimitive; } else { return new SoyAbstractCachingValueProvider() { @Override protected SoyValue compute() { return convertNonPrimitive(obj).resolve(); } @Override public RenderResult status() { return RenderResult.done(); } }; } }
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 Renderer setData(Map<String, ?> data) { this.data = (data == null) ? null : SoyValueConverter.INSTANCE.newDictFromMap(data); return this; }
/** * Converts a Java object into an equivalent SoyValueProvider. * * @param obj The object to convert. * @return An equivalent SoyValueProvider. * @throws SoyDataException If the given object cannot be converted. */ @Nonnull public SoyValueProvider convert(@Nullable Object obj) { SoyValueProvider convertedPrimitive = convertCheap(obj); if (convertedPrimitive != null) { return convertedPrimitive; } return convertNonPrimitive(obj); }
/** * Creates a Soy dictionary from a Java string map. While this is O(n) in the map's shallow size, * the Java values are converted into Soy values lazily and only once. */ public SoyDict newDictFromMap(Map<String, ?> javaStringMap) { // Create a dictionary backed by a map which has eagerly converted each value into a lazy // value provider. Specifically, the map iteration is done eagerly so that the lazy value // provider can cache its value. ImmutableMap.Builder<String, SoyValueProvider> builder = ImmutableMap.builder(); for (Map.Entry<String, ?> entry : javaStringMap.entrySet()) { builder.put(entry.getKey(), convertLazy(entry.getValue())); } return DictImpl.forProviderMap( builder.build(), // This Java map could represent a Soy legacy_object_map, a Soy map, or a Soy record. // We don't know which until one of the SoyMap, SoyLegacyObjectMap, or SoyRecord methods // is invoked on it. RuntimeMapTypeTracker.Type.UNKNOWN); }
@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(); }
@Override public Renderer setIjData(Map<String, ?> ijData) { this.ijData = (ijData == null) ? null : SoyValueConverter.INSTANCE.newDictFromMap(ijData); return this; }
/** * Creates a Soy dictionary from a Java string map. While this is O(n) in the map's shallow size, * the Java values are converted into Soy values lazily and only once. */ public SoyDict newDictFromMap(Map<String, ?> javaStringMap) { // Create a dictionary backed by a map which has eagerly converted each value into a lazy // value provider. Specifically, the map iteration is done eagerly so that the lazy value // provider can cache its value. ImmutableMap.Builder<String, SoyValueProvider> builder = ImmutableMap.builder(); for (Map.Entry<String, ?> entry : javaStringMap.entrySet()) { builder.put(entry.getKey(), convertLazy(entry.getValue())); } return DictImpl.forProviderMap( builder.build(), // This Java map could represent a Soy legacy_object_map, a Soy map, or a Soy record. // We don't know which until one of the SoyMap, SoyLegacyObjectMap, or SoyRecord methods // is invoked on it. RuntimeType.UNKNOWN); }
boolean isValidValue = true; try { SoyValue value0 = SoyValueConverter.INSTANCE.convert(valueObj).resolve(); if (!(value0 instanceof PrimitiveData)) { isValidValue = false;
@Override public SoyValue apply(Map<String, ?> input) { return newDictFromMap(input); } });
boolean isValidValue = true; try { SoyValue value0 = SoyValueConverter.INSTANCE.convert(valueObj).resolve(); if (!(value0 instanceof PrimitiveData)) { isValidValue = false;