public Value precompile(Value value, Context context, FunctionManager manager) { Value compiled = staticPreCompile(value, context, manager); return null != compiled ? compiled : compile(value, context); }
public static FunctionBinding valueOf(@NonNull String name, @NonNull String args, Context context, @NonNull FunctionManager manager) { Function function = manager.get(name); String[] tokens = FUNCTION_ARGS_DELIMITER.split(args); Value[] arguments = new Value[tokens.length]; String token; Value resolved; for (int i = 0; i < tokens.length; i++) { token = tokens[i].trim(); if (!token.isEmpty() && token.charAt(0) == '\'') { token = token.substring(1, token.length() - 1); resolved = new Primitive(token); } else { resolved = AttributeProcessor.staticPreCompile(new Primitive(token), context, manager); } arguments[i] = resolved != null ? resolved : new Primitive(token); } return new FunctionBinding(function, arguments); }
@Nullable public static Value staticPreCompile(Value value, Context context, FunctionManager manager) { Value compiled = null; if (value.isPrimitive()) { compiled = staticPreCompile(value.getAsPrimitive(), context, manager); } else if (value.isObject()) { compiled = staticPreCompile(value.getAsObject(), context, manager); } else if (value.isBinding() || value.isResource() || value.isAttributeResource() || value.isStyleResource()) { return value; } return compiled; }
public Map<String, Value> readData(JsonReader in) throws IOException { JsonToken peek = in.peek(); if (peek == JsonToken.NULL) { in.nextNull(); return new HashMap<>(); } if (peek != JsonToken.BEGIN_OBJECT) { throw new JsonSyntaxException("data must be a Map<String, String>."); } Map<String, Value> data = new LinkedHashMap<>(); in.beginObject(); while (in.hasNext()) { JsonReaderInternalAccess.INSTANCE.promoteNameToValue(in); String key = in.nextString(); Value value = VALUE_TYPE_ADAPTER.read(in); Value compiled = AttributeProcessor.staticPreCompile(value, context, PROTEUS_INSTANCE_HOLDER.getProteus().functions); if (compiled != null) { value = compiled; } Value replaced = data.put(key, value); if (replaced != null) { throw new JsonSyntaxException("duplicate key: " + key); } } in.endObject(); return data; } }
public static Value staticCompile(@Nullable Value value, Context context) { if (null == value || !value.isPrimitive()) { return Dimension.ZERO; } if (value.isDimension()) { return value; } Value precompiled = AttributeProcessor.staticPreCompile(value.getAsPrimitive(), context, null); if (null != precompiled) { return precompiled; } return Dimension.valueOf(value.getAsString()); }
public static Value staticCompile(@Nullable Value value, Context context) { if (null == value) { return Color.Int.BLACK; } if (value.isColor()) { return value; } else if (value.isObject()) { return Color.valueOf(value.getAsObject(), context); } else if (value.isPrimitive()) { Value precompiled = AttributeProcessor.staticPreCompile(value.getAsPrimitive(), context, null); if (null != precompiled) { return precompiled; } return Color.valueOf(value.getAsString(), Color.Int.BLACK); } else { return Color.Int.BLACK; } }
public static Value staticCompile(@Nullable Value value, Context context) { if (null == value) { return DrawableValue.ColorValue.BLACK; } if (value.isDrawable()) { return value; } else if (value.isPrimitive()) { Value precompiled = AttributeProcessor.staticPreCompile(value.getAsPrimitive(), context, null); if (null != precompiled) { return precompiled; } return DrawableValue.valueOf(value.getAsString(), context); } else if (value.isObject()) { return DrawableValue.valueOf(value.getAsObject(), context); } else { return DrawableValue.ColorValue.BLACK; } }