• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

leeonky / test-charm-java / 212

14 Apr 2025 05:15AM UTC coverage: 74.088% (-0.1%) from 74.209%
212

push

circleci

leeonky
Update version

7957 of 10740 relevant lines covered (74.09%)

0.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.24
/DAL-java/src/main/java/com/github/leeonky/dal/runtime/RuntimeContextBuilder.java
1
package com.github.leeonky.dal.runtime;
2

3
import com.github.leeonky.dal.ast.node.DALNode;
4
import com.github.leeonky.dal.ast.opt.DALOperator;
5
import com.github.leeonky.dal.format.Formatter;
6
import com.github.leeonky.dal.runtime.checker.Checker;
7
import com.github.leeonky.dal.runtime.checker.CheckerSet;
8
import com.github.leeonky.dal.runtime.inspector.Dumper;
9
import com.github.leeonky.dal.runtime.inspector.DumperFactory;
10
import com.github.leeonky.dal.runtime.schema.Expect;
11
import com.github.leeonky.dal.type.ExtensionName;
12
import com.github.leeonky.dal.type.InputCode;
13
import com.github.leeonky.dal.type.Schema;
14
import com.github.leeonky.interpreter.RuntimeContext;
15
import com.github.leeonky.interpreter.SyntaxException;
16
import com.github.leeonky.util.BeanClass;
17
import com.github.leeonky.util.Classes;
18
import com.github.leeonky.util.Converter;
19
import com.github.leeonky.util.NumberType;
20

21
import java.io.PrintStream;
22
import java.lang.reflect.Array;
23
import java.lang.reflect.Method;
24
import java.lang.reflect.Modifier;
25
import java.util.*;
26
import java.util.function.*;
27
import java.util.regex.Pattern;
28
import java.util.stream.Collectors;
29
import java.util.stream.Stream;
30

31
import static com.github.leeonky.dal.runtime.CurryingMethod.createCurryingMethod;
32
import static com.github.leeonky.dal.runtime.DalException.throwUserRuntimeException;
33
import static com.github.leeonky.dal.runtime.ExpressionException.illegalOp2;
34
import static com.github.leeonky.dal.runtime.ExpressionException.illegalOperation;
35
import static com.github.leeonky.dal.runtime.schema.Actual.actual;
36
import static com.github.leeonky.dal.runtime.schema.Verification.expect;
37
import static com.github.leeonky.util.Classes.getClassName;
38
import static com.github.leeonky.util.Classes.named;
39
import static com.github.leeonky.util.CollectionHelper.toStream;
40
import static java.lang.String.format;
41
import static java.lang.reflect.Modifier.STATIC;
42
import static java.util.Arrays.stream;
43
import static java.util.Collections.emptySet;
44
import static java.util.Optional.of;
45
import static java.util.stream.Collectors.joining;
46
import static java.util.stream.Collectors.toList;
47

48
public class RuntimeContextBuilder {
1✔
49
    private final ClassKeyMap<PropertyAccessor<Object>> propertyAccessors = new ClassKeyMap<>();
1✔
50
    private final ClassKeyMap<DALCollectionFactory<Object, Object>> dALCollectionFactories = new ClassKeyMap<>();
1✔
51
    private final ClassKeyMap<Function<Object, Object>> objectImplicitMapper = new ClassKeyMap<>();
1✔
52
    private final ClassKeyMap<Function<Object, Comparable<?>>> customSorters = new ClassKeyMap<>();
1✔
53
    private final Map<String, ConstructorViaSchema> valueConstructors = new LinkedHashMap<>();
1✔
54
    private final Map<String, BeanClass<?>> schemas = new HashMap<>();
1✔
55
    private final Set<Method> extensionMethods = new HashSet<>();
1✔
56
    private final Map<Object, Function<MetaData, Object>> metaProperties = new HashMap<>();
1✔
57
    private final ClassKeyMap<Function<RemarkData, Data>> remarks = new ClassKeyMap<>();
1✔
58
    private final ClassKeyMap<Function<RuntimeData, Data>> exclamations = new ClassKeyMap<>();
1✔
59
    private final List<UserLiteralRule> userDefinedLiterals = new ArrayList<>();
1✔
60
    private final NumberType numberType = new NumberType();
1✔
61
    private final Map<Method, BiFunction<Object, List<Object>, List<Object>>> curryingMethodArgRanges = new HashMap<>();
1✔
62
    private final Map<String, TextFormatter<?, ?>> textFormatterMap = new LinkedHashMap<>();
1✔
63
    private final Map<Operators, LinkedList<Operation>> operations = new HashMap<>();
1✔
64
    private Converter converter = Converter.getInstance();
1✔
65
    private final ClassKeyMap<DumperFactory> dumperFactories = new ClassKeyMap<>();
1✔
66
    private final CheckerSet checkerSetForMatching = new CheckerSet(CheckerSet::defaultMatching);
1✔
67
    private final CheckerSet checkerSetForEqualing = new CheckerSet(CheckerSet::defaultEqualing);
1✔
68
    private int maxDumpingLineSize = 2000;
1✔
69
    private int maxDumpingObjectSize = 255;
1✔
70
    private ErrorHook errorHook = (i, code, e) -> false;
1✔
71
    private final Map<Class<?>, Map<Object, Function<MetaData, Object>>> localMetaProperties
1✔
72
            = new TreeMap<>(Classes::compareByExtends);
73
    private final Map<Class<?>, Map<Pattern, Function<MetaData, Object>>> localMetaPropertyPatterns
1✔
74
            = new TreeMap<>(Classes::compareByExtends);
75
    private PrintStream warning = System.err;
1✔
76
    private final Features features = new Features();
1✔
77
    private Consumer<Data> returnHook = x -> {
1✔
78
    };
1✔
79

80
    public RuntimeContextBuilder registerMetaProperty(Object property, Function<MetaData, Object> function) {
81
        metaProperties.put(property, function);
1✔
82
        return this;
1✔
83
    }
84

85
    public RuntimeContextBuilder registerTextFormatter(String name, TextFormatter<?, ?> formatter) {
86
        textFormatterMap.put(name, formatter);
1✔
87
        return this;
1✔
88
    }
89

90
    public DALRuntimeContext build(Object inputValue) {
91
        return build(() -> inputValue, null);
1✔
92
    }
93

94
    public DALRuntimeContext build(InputCode<?> inputSupplier) {
95
        return build(inputSupplier, null);
1✔
96
    }
97

98
    public DALRuntimeContext build(InputCode<?> inputSupplier, Class<?> rootSchema) {
99
        if (inputSupplier == null)
1✔
100
            return new DALRuntimeContext(() -> null, rootSchema);
1✔
101
        return new DALRuntimeContext(inputSupplier, rootSchema);
1✔
102
    }
103

104
    public RuntimeContextBuilder registerValueFormat(Formatter<?, ?> formatter) {
105
        return registerValueFormat(formatter.getFormatterName(), formatter);
1✔
106
    }
107

108
    @SuppressWarnings("unchecked")
109
    public RuntimeContextBuilder registerValueFormat(String name, Formatter<?, ?> formatter) {
110
        valueConstructors.put(name, (o, c) -> ((Formatter<Object, ?>) formatter).transform(o.instance()));
1✔
111
        return this;
1✔
112
    }
113

114
    public RuntimeContextBuilder registerSchema(Class<? extends Schema> schema) {
115
        return registerSchema(NameStrategy.SIMPLE_NAME, schema);
1✔
116
    }
117

118
    @SuppressWarnings("unchecked")
119
    public RuntimeContextBuilder registerSchema(String name, Class<? extends Schema> schema) {
120
        schemas.put(name, BeanClass.create(schema));
1✔
121
        return registerSchema(name, (data, context) ->
1✔
122
                expect(new Expect(BeanClass.create((Class) schema), null)).verify(context, actual(data)));
1✔
123
    }
124

125
    public RuntimeContextBuilder registerSchema(String name, BiFunction<Data, DALRuntimeContext, Boolean> predicate) {
126
        valueConstructors.put(name, (o, context) -> {
1✔
127
            if (predicate.apply(o, context))
1✔
128
                return o.instance();
1✔
129
            throw new IllegalTypeException();
×
130
        });
131
        return this;
1✔
132
    }
133

134
    @SuppressWarnings("unchecked")
135
    public <T> RuntimeContextBuilder registerPropertyAccessor(Class<T> type, PropertyAccessor<? extends T> propertyAccessor) {
136
        propertyAccessors.put(type, (PropertyAccessor<Object>) propertyAccessor);
1✔
137
        return this;
1✔
138
    }
139

140
    @SuppressWarnings("unchecked")
141
    public <T, E> RuntimeContextBuilder registerDALCollectionFactory(Class<T> type, DALCollectionFactory<T, E> DALCollectionFactory) {
142
        dALCollectionFactories.put(type, (DALCollectionFactory<Object, Object>) DALCollectionFactory);
1✔
143
        return this;
1✔
144
    }
145

146
    public RuntimeContextBuilder registerSchema(NameStrategy nameStrategy, Class<? extends Schema> schema) {
147
        return registerSchema(nameStrategy.toName(schema), schema);
1✔
148
    }
149

150
    public RuntimeContextBuilder registerStaticMethodExtension(Class<?> staticMethodExtensionClass) {
151
        Stream.of(staticMethodExtensionClass.getMethods()).filter(method -> method.getParameterCount() >= 1
1✔
152
                && (STATIC & method.getModifiers()) != 0).forEach(extensionMethods::add);
1✔
153
        return this;
1✔
154
    }
155

156
    @SuppressWarnings("unchecked")
157
    public <T> RuntimeContextBuilder registerImplicitData(Class<T> type, Function<T, Object> mapper) {
158
        objectImplicitMapper.put(type, (Function) mapper);
1✔
159
        return this;
1✔
160
    }
161

162
    public Converter getConverter() {
163
        return converter;
×
164
    }
165

166
    public RuntimeContextBuilder setConverter(Converter converter) {
167
        this.converter = converter;
×
168
        return this;
×
169
    }
170

171
    public RuntimeContextBuilder registerUserDefinedLiterals(UserLiteralRule rule) {
172
        userDefinedLiterals.add(rule);
1✔
173
        return this;
1✔
174
    }
175

176
    public RuntimeContextBuilder registerCurryingMethodAvailableParameters(Method method, BiFunction<Object,
177
            List<Object>, List<Object>> range) {
178
        curryingMethodArgRanges.put(method, range);
1✔
179
        return this;
1✔
180
    }
181

182
    private Set<Method> methodToCurrying(Class<?> type, Object methodName) {
183
        return Stream.of(stream(type.getMethods()).filter(method -> !Modifier.isStatic(method.getModifiers()))
1✔
184
                                .filter(method -> method.getName().equals(methodName)),
1✔
185
                        staticMethodsToCurrying(type, methodName, Object::equals),
1✔
186
                        staticMethodsToCurrying(type, methodName, Class::isAssignableFrom))
1✔
187
                .flatMap(Function.identity()).collect(Collectors.toCollection(LinkedHashSet::new));
1✔
188
    }
189

190
    private Stream<Method> staticMethodsToCurrying(Class<?> type, Object property,
191
                                                   BiPredicate<Class<?>, Class<?>> condition) {
192
        return extensionMethods.stream()
1✔
193
                .filter(method -> staticExtensionMethodName(method).equals(property))
1✔
194
                .filter(method -> condition.test(method.getParameters()[0].getType(), type));
1✔
195
    }
196

197
    private static String staticExtensionMethodName(Method method) {
198
        ExtensionName extensionName = method.getAnnotation(ExtensionName.class);
1✔
199
        return extensionName != null ? extensionName.value() : method.getName();
1✔
200
    }
201

202
    public CheckerSet checkerSetForMatching() {
203
        return checkerSetForMatching;
1✔
204
    }
205

206
    public CheckerSet checkerSetForEqualing() {
207
        return checkerSetForEqualing;
1✔
208
    }
209

210
    public RuntimeContextBuilder registerDumper(Class<?> type, DumperFactory factory) {
211
        dumperFactories.put(type, factory);
1✔
212
        return this;
1✔
213
    }
214

215
    public void setMaxDumpingLineSize(int size) {
216
        maxDumpingLineSize = size;
1✔
217
    }
1✔
218

219
    public <T> RuntimeContextBuilder registerErrorHook(ErrorHook hook) {
220
        errorHook = Objects.requireNonNull(hook);
1✔
221
        return this;
1✔
222
    }
223

224
    public void mergeTextFormatter(String name, String other, String... others) {
225
        TextFormatter formatter = textFormatterMap.get(other);
1✔
226
        for (String o : others)
1✔
227
            formatter = formatter.merge(textFormatterMap.get(o));
1✔
228
        registerTextFormatter(name, delegateFormatter(formatter, "Merged from " + other + " " + String.join(" ", others)));
1✔
229
    }
1✔
230

231
    private TextFormatter delegateFormatter(TextFormatter formatter, final String description) {
232
        return new TextFormatter() {
1✔
233
            @Override
234
            protected Object format(Object content, TextAttribute attribute, DALRuntimeContext context) {
235
                return formatter.format(content, attribute, context);
×
236
            }
237

238
            @Override
239
            protected TextAttribute attribute(TextAttribute attribute) {
240
                return formatter.attribute(attribute);
×
241
            }
242

243
            @Override
244
            public Class<?> returnType() {
245
                return formatter.returnType();
1✔
246
            }
247

248
            @Override
249
            public Class<?> acceptType() {
250
                return formatter.acceptType();
1✔
251
            }
252

253
            @Override
254
            public String description() {
255
                return description;
1✔
256
            }
257
        };
258
    }
259

260
    public RuntimeContextBuilder registerMetaProperty(Class<?> type, Object name, Function<MetaData, Object> function) {
261
        localMetaProperties.computeIfAbsent(type, k -> new HashMap<>()).put(name, function);
1✔
262
        return this;
1✔
263
    }
264

265
    public RuntimeContextBuilder registerMetaPropertyPattern(Class<?> type, String name, Function<MetaData, Object> function) {
266
        localMetaPropertyPatterns.computeIfAbsent(type, k -> new HashMap<>()).put(Pattern.compile(name), function);
1✔
267
        return this;
1✔
268
    }
269

270
    public RuntimeContextBuilder registerDataRemark(Class<?> type, Function<RemarkData, Data> action) {
271
        remarks.put(type, action);
1✔
272
        return this;
1✔
273
    }
274

275
    public RuntimeContextBuilder registerExclamation(Class<?> type, Function<RuntimeData, Data> action) {
276
        exclamations.put(type, action);
1✔
277
        return this;
1✔
278
    }
279

280
    public RuntimeContextBuilder registerOperator(Operators operator, Operation operation) {
281
        operations.computeIfAbsent(operator, o -> new LinkedList<>()).addFirst(operation);
1✔
282
        return this;
1✔
283
    }
284

285
    @SuppressWarnings("unchecked")
286
    public <T> RuntimeContextBuilder registerCustomSorter(Class<T> type, Function<T, Comparable<?>> sorter) {
287
        customSorters.put(type, (Function<Object, Comparable<?>>) sorter);
1✔
288
        return this;
1✔
289
    }
290

291
    public BeanClass<?> schemaType(String schema) {
292
        BeanClass<?> type = schemas.get(schema);
1✔
293
        if (type != null)
1✔
294
            return type;
1✔
295
        throw new IllegalStateException(format("Unknown schema '%s'", schema));
×
296
    }
297

298
    public void setMaxDumpingObjectSize(int maxDumpingObjectSize) {
299
        this.maxDumpingObjectSize = maxDumpingObjectSize;
×
300
    }
×
301

302
    public RuntimeContextBuilder setWarningOutput(PrintStream printStream) {
303
        warning = printStream;
1✔
304
        return this;
1✔
305
    }
306

307
    public RuntimeContextBuilder registerReturnHook(Consumer<Data> hook) {
308
        returnHook = returnHook.andThen(hook);
1✔
309
        return this;
1✔
310
    }
311

312
    public Features features() {
313
        return features;
1✔
314
    }
315

316
    public class DALRuntimeContext implements RuntimeContext {
317
        private final LinkedList<Data> stack = new LinkedList<>();
1✔
318
        private final Map<Data, PartialPropertyStack> partialPropertyStacks;
319

320
        public Features features() {
321
            return features;
1✔
322
        }
323

324
        public DALRuntimeContext(InputCode<?> supplier, Class<?> schema) {
1✔
325
            stack.push(Data.lazy(supplier, this, SchemaType.create(schema == null ? null : BeanClass.create(schema))));
1✔
326
            partialPropertyStacks = new HashMap<>();
1✔
327
        }
1✔
328

329
        public Data getThis() {
330
            return stack.getFirst();
1✔
331
        }
332

333
        public <T> T pushAndExecute(Data data, Supplier<T> supplier) {
334
            try {
335
                stack.push(data);
1✔
336
                return supplier.get();
1✔
337
            } finally {
338
                returnHook.accept(stack.pop());
1✔
339
            }
340
        }
341

342
        public Optional<ConstructorViaSchema> searchValueConstructor(String type) {
343
            return Optional.ofNullable(valueConstructors.get(type));
1✔
344
        }
345

346
        public Set<?> findPropertyReaderNames(Object instance) {
347
            return getObjectPropertyAccessor(instance).getPropertyNames(instance);
1✔
348
        }
349

350
        private PropertyAccessor<Object> getObjectPropertyAccessor(Object instance) {
351
            return propertyAccessors.tryGetData(instance)
1✔
352
                    .orElseGet(() -> new JavaClassPropertyAccessor<>(BeanClass.createFrom(instance)));
1✔
353
        }
354

355
        public Boolean isNull(Object instance) {
356
            return propertyAccessors.tryGetData(instance).map(f -> f.isNull(instance))
1✔
357
                    .orElseGet(() -> Objects.equals(instance, null));
1✔
358
        }
359

360
        public Object getPropertyValue(Data data, Object property) {
361
            try {
362
                return getObjectPropertyAccessor(data.instance()).getValueByData(data, property);
1✔
363
            } catch (InvalidPropertyException e) {
1✔
364
                try {
365
                    return currying(data.instance(), property).orElseThrow(() -> e).resolve();
1✔
366
                } catch (Throwable e1) {
1✔
367
                    return throwUserRuntimeException(e1);
×
368
                }
369
            } catch (Throwable e) {
1✔
370
                return throwUserRuntimeException(e);
×
371
            }
372
        }
373

374
        public DALCollection<Object> createCollection(Object instance) {
375
            return dALCollectionFactories.tryGetData(instance).map(factory -> factory.create(instance))
1✔
376
                    .orElseGet(() -> new CollectionDALCollection<>(toStream(instance).collect(toList())));
1✔
377
        }
378

379
        public boolean isRegisteredList(Object instance) {
380
            return dALCollectionFactories.tryGetData(instance).map(f -> f.isList(instance)).orElse(false);
1✔
381
        }
382

383
        public Converter getConverter() {
384
            return converter;
1✔
385
        }
386

387
        public Optional<BeanClass<?>> schemaType(String schema, boolean isList) {
388
            return Optional.ofNullable(schemas.get(schema)).map(s ->
1✔
389
                    isList ? BeanClass.create(Array.newInstance(s.getType(), 0).getClass()) : s);
1✔
390
        }
391

392
        public Data data(Object instance) {
393
            return data(instance, null);
1✔
394
        }
395

396
        public Data data(Object instance, BeanClass<?> schemaType) {
397
            return new Data(instance, this, SchemaType.create(schemaType));
1✔
398
        }
399

400
        public Optional<Result> takeUserDefinedLiteral(String token) {
401
            return userDefinedLiterals.stream().map(userLiteralRule -> userLiteralRule.compile(token))
1✔
402
                    .filter(Result::hasResult)
1✔
403
                    .findFirst();
1✔
404
        }
405

406
        public void appendPartialPropertyReference(Data data, Object symbol) {
407
            fetchPartialProperties(data).map(partialProperties -> partialProperties.appendPartialProperties(symbol));
1✔
408
        }
1✔
409

410
        private Optional<PartialProperties> fetchPartialProperties(Data data) {
411
            return partialPropertyStacks.values().stream().map(partialPropertyStack ->
1✔
412
                    partialPropertyStack.fetchPartialProperties(data)).filter(Objects::nonNull).findFirst();
1✔
413
        }
414

415
        public void initPartialPropertyStack(Data instance, Object prefix, Data partial) {
416
            partialPropertyStacks.computeIfAbsent(instance, _key -> fetchPartialProperties(instance)
1✔
417
                    .map(partialProperties -> partialProperties.partialPropertyStack)
1✔
418
                    .orElseGet(PartialPropertyStack::new)).setupPartialProperties(prefix, partial);
1✔
419
        }
1✔
420

421
        public Set<String> collectPartialProperties(Data instance) {
422
            PartialPropertyStack partialPropertyStack = partialPropertyStacks.get(instance);
1✔
423
            if (partialPropertyStack != null)
1✔
424
                return partialPropertyStack.collectPartialProperties(instance);
1✔
425
            return fetchPartialProperties(instance).map(partialProperties ->
1✔
426
                    partialProperties.partialPropertyStack.collectPartialProperties(instance)).orElse(emptySet());
1✔
427
        }
428

429
        public NumberType getNumberType() {
430
            return numberType;
1✔
431
        }
432

433
        public Optional<Object> getImplicitObject(Object obj) {
434
            return objectImplicitMapper.tryGetData(obj).map(mapper -> mapper.apply(obj));
1✔
435
        }
436

437
        public Set<Method> methodToCurrying(Class<?> type, Object methodName) {
438
            return RuntimeContextBuilder.this.methodToCurrying(type, methodName);
1✔
439
        }
440

441
        public Function<MetaData, Object> fetchGlobalMetaFunction(MetaData metaData) {
442
            return metaProperties.computeIfAbsent(metaData.name(), k -> {
1✔
443
                throw illegalOp2(format("Meta property `%s` not found", metaData.name()));
1✔
444
            });
445
        }
446

447
        private Optional<Function<MetaData, Object>> fetchLocalMetaFunction(MetaData metaData) {
448
            return Stream.concat(metaFunctionsByType(metaData).map(e -> {
1✔
449
                        metaData.addCallType(e.getKey());
1✔
450
                        return e.getValue().get(metaData.name());
1✔
451
                    }), metaFunctionPatternsByType(metaData).map(e -> {
1✔
452
                        metaData.addCallType(e.getKey());
1✔
453
                        return e.getValue().entrySet()
1✔
454
                                .stream().filter(entry -> entry.getKey().matcher(metaData.name().toString()).matches())
1✔
455
                                .map(Map.Entry::getValue)
1✔
456
                                .findFirst().orElse(null);
1✔
457
                    })).filter(Objects::nonNull)
1✔
458
                    .findFirst();
1✔
459
        }
460

461
        public Optional<Function<MetaData, Object>> fetchSuperMetaFunction(MetaData metaData) {
462
            return metaFunctionsByType(metaData)
1✔
463
                    .filter(e -> !metaData.calledBy(e.getKey()))
1✔
464
                    .map(e -> {
1✔
465
                        metaData.addCallType(e.getKey());
1✔
466
                        return e.getValue().get(metaData.name());
1✔
467
                    }).filter(Objects::nonNull).findFirst();
1✔
468
        }
469

470
        private Stream<Map.Entry<Class<?>, Map<Object, Function<MetaData, Object>>>> metaFunctionsByType(MetaData metaData) {
471
            return localMetaProperties.entrySet().stream().filter(e -> metaData.isInstance(e.getKey()));
1✔
472
        }
473

474
        private Stream<Map.Entry<Class<?>, Map<Pattern, Function<MetaData, Object>>>> metaFunctionPatternsByType(MetaData metaData) {
475
            return localMetaPropertyPatterns.entrySet().stream().filter(e -> metaData.isInstance(e.getKey()));
1✔
476
        }
477

478
        @SuppressWarnings("unchecked")
479
        public <T> TextFormatter<String, T> fetchFormatter(String name, int position) {
480
            return (TextFormatter<String, T>) textFormatterMap.computeIfAbsent(name, attribute -> {
1✔
481
                throw new SyntaxException(format("Invalid text formatter `%s`, all supported formatters are:\n%s",
1✔
482
                        attribute, textFormatterMap.entrySet().stream().map(e -> format("  %s:\n    %s",
1✔
483
                                e.getKey(), e.getValue().fullDescription())).collect(joining("\n"))), position);
1✔
484
            });
485
        }
486

487
        public Checker fetchEqualsChecker(Data expected, Data actual) {
488
            return checkerSetForEqualing.fetch(expected, actual);
1✔
489
        }
490

491
        public Checker fetchMatchingChecker(Data expected, Data actual) {
492
            return checkerSetForMatching.fetch(expected, actual);
1✔
493
        }
494

495
        public Dumper fetchDumper(Data data) {
496
            return dumperFactories.tryGetData(data.instance()).map(factory -> factory.apply(data)).orElseGet(() -> {
1✔
497
                if (data.isNull())
1✔
498
                    return (_data, dumpingContext) -> dumpingContext.append("null");
1✔
499
                if (data.isList())
1✔
500
                    return Dumper.LIST_DUMPER;
1✔
501
                if (data.instance() != null && data.instance().getClass().isEnum())
1✔
502
                    return Dumper.VALUE_DUMPER;
1✔
503
                return Dumper.MAP_DUMPER;
1✔
504
            });
505
        }
506

507
        public int maxDumpingLineCount() {
508
            return maxDumpingLineSize;
1✔
509
        }
510

511
        public int maxDumpingObjectSize() {
512
            return maxDumpingObjectSize;
1✔
513
        }
514

515
        public boolean hookError(String expression, Throwable error) {
516
            return errorHook.handle(getThis(), expression, error);
1✔
517
        }
518

519
        public Data invokeMetaProperty(DALNode inputNode, Data inputData, Object symbolName) {
520
            MetaData metaData = new MetaData(inputNode, inputData, symbolName, this);
1✔
521
            return data(fetchLocalMetaFunction(metaData).orElseGet(() -> fetchGlobalMetaFunction(metaData)).apply(metaData));
1✔
522
        }
523

524
        public Data invokeDataRemark(RemarkData remarkData) {
525
            Object instance = remarkData.data().instance();
1✔
526
            return remarks.tryGetData(instance)
1✔
527
                    .orElseThrow(() -> illegalOperation("Not implement operator () of " + getClassName(instance)))
1✔
528
                    .apply(remarkData);
1✔
529
        }
530

531
        public Data invokeExclamations(ExclamationData exclamationData) {
532
            Object instance = exclamationData.data().instance();
1✔
533
            return exclamations.tryGetData(instance)
1✔
534
                    .orElseThrow(() -> illegalOp2(format("Not implement operator %s of %s",
1✔
535
                            exclamationData.label(), Classes.getClassName(instance))))
1✔
536
                    .apply(exclamationData);
1✔
537
        }
538

539
        public Data calculate(Data v1, DALOperator opt, Data v2) {
540
            for (Operation operation : operations.get(opt.overrideType()))
1✔
541
                if (operation.match(v1, opt, v2, this))
1✔
542
                    return operation.operateData(v1, opt, v2, this);
1✔
543
            throw illegalOperation(format("No operation `%s` between '%s' and '%s'", opt.overrideType(),
1✔
544
                    getClassName(v1.instance()), getClassName(v2.instance())));
1✔
545
        }
546

547
        public PrintStream warningOutput() {
548
            return warning;
1✔
549
        }
550

551
        public BiFunction<Object, List<Object>, List<Object>> fetchCurryingMethodArgRange(Method method) {
552
            return curryingMethodArgRanges.get(method);
1✔
553
        }
554

555
        public Optional<CurryingMethod> currying(Object instance, Object property) {
556
            List<InstanceCurryingMethod> methods = methodToCurrying(named(instance.getClass()), property).stream()
1✔
557
                    .map(method -> createCurryingMethod(instance, method, getConverter(), this)).collect(toList());
1✔
558
            if (!methods.isEmpty())
1✔
559
                return of(new CurryingMethodGroup(methods, null));
1✔
560
            return getImplicitObject(instance).flatMap(obj -> currying(obj, property));
1✔
561
        }
562

563
        @SuppressWarnings("unchecked")
564
        public Comparable<?> transformComparable(Object object) {
565
            return customSorters.tryGetData(object).map(f -> f.apply(object)).orElseGet(() -> (Comparable) object);
1✔
566
        }
567
    }
568
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc