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

leeonky / test-charm-java / 218

15 Apr 2025 02:45PM UTC coverage: 74.045% (-0.04%) from 74.088%
218

push

circleci

leeonky
Introduce adaptiveList

20 of 21 new or added lines in 3 files covered. (95.24%)

34 existing lines in 11 files now uncovered.

7968 of 10761 relevant lines covered (74.05%)

0.74 hits per line

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

95.63
/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.*;
17

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

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

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

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

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

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

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

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

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

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

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

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

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

133
    public <T> RuntimeContextBuilder registerPropertyAccessor(Class<T> type, PropertyAccessor<? extends T> propertyAccessor) {
134
        propertyAccessors.put(type, propertyAccessor);
1✔
135
        return this;
1✔
136
    }
137

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

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

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

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

160
    public Converter getConverter() {
UNCOV
161
        return converter;
×
162
    }
163

164
    public RuntimeContextBuilder setConverter(Converter converter) {
UNCOV
165
        this.converter = converter;
×
UNCOV
166
        return this;
×
167
    }
168

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

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

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

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

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

200
    public CheckerSet checkerSetForMatching() {
201
        return checkerSetForMatching;
1✔
202
    }
203

204
    public CheckerSet checkerSetForEqualing() {
205
        return checkerSetForEqualing;
1✔
206
    }
207

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

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

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

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

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

236
            @Override
237
            protected TextAttribute attribute(TextAttribute attribute) {
UNCOV
238
                return formatter.attribute(attribute);
×
239
            }
240

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

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

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

258
    public <T> RuntimeContextBuilder registerMetaProperty(Class<T> type, Object name, RuntimeHandler<MetaData<T>> function) {
259
        localMetaProperties.computeIfAbsent(type, k -> new HashMap<>()).put(name, cast(function));
1✔
260
        return this;
1✔
261
    }
262

263
    public <T> RuntimeContextBuilder registerMetaPropertyPattern(Class<T> type, String name, RuntimeHandler<MetaData<T>> function) {
264
        localMetaPropertyPatterns.computeIfAbsent(type, k -> new HashMap<>()).put(Pattern.compile(name), cast(function));
1✔
265
        return this;
1✔
266
    }
267

268
    public <T> RuntimeContextBuilder registerDataRemark(Class<T> type, RuntimeHandler<RemarkData<T>> action) {
269
        remarks.put(type, cast(action));
1✔
270
        return this;
1✔
271
    }
272

273
    public <T> RuntimeContextBuilder registerExclamation(Class<T> type, RuntimeHandler<RuntimeData<T>> action) {
274
        exclamations.put(type, cast(action));
1✔
275
        return this;
1✔
276
    }
277

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

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

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

296
    public void setMaxDumpingObjectSize(int maxDumpingObjectSize) {
UNCOV
297
        this.maxDumpingObjectSize = maxDumpingObjectSize;
×
UNCOV
298
    }
×
299

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

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

310
    public Features features() {
311
        return features;
1✔
312
    }
313

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

318
        public Features features() {
319
            return features;
1✔
320
        }
321

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

327
        public Data<?> getThis() {
328
            return stack.getFirst();
1✔
329
        }
330

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

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

344
        public <T> Set<?> findPropertyReaderNames(Data<T> data) {
345
            return getObjectPropertyAccessor(data.instance()).getPropertyNames(data);
1✔
346
        }
347

348
        @SuppressWarnings("unchecked")
349
        private <T> PropertyAccessor<T> getObjectPropertyAccessor(T instance) {
350
            return (PropertyAccessor<T>) propertyAccessors.tryGetData(instance)
1✔
351
                    .orElseGet(() -> new JavaClassPropertyAccessor<>(BeanClass.createFrom(instance)));
1✔
352
        }
353

354
        @SuppressWarnings("unchecked")
355
        public <T> Boolean isNull(T instance) {
356
            return propertyAccessors.tryGetData(instance).map(f -> ((PropertyAccessor<T>) f).isNull(instance))
1✔
357
                    .orElseGet(() -> Objects.equals(instance, null));
1✔
358
        }
359

360
        public <T> Data<?> accessProperty(Data<T> data, Object propertyChain) {
361
            return getObjectPropertyAccessor(data.instance()).getData(data, propertyChain, this);
1✔
362
        }
363

364
        public DALCollection<Object> createCollection(Object instance) {
365
            return dALCollectionFactories.tryGetData(instance).map(factory -> factory.create(instance))
1✔
366
                    .orElseGet(() -> new CollectionDALCollection<>(toStream(instance).collect(toList())));
1✔
367
        }
368

369
        public boolean isRegisteredList(Object instance) {
370
            return dALCollectionFactories.tryGetData(instance).map(f -> f.isList(instance)).orElse(false);
1✔
371
        }
372

373
        public Converter getConverter() {
374
            return converter;
1✔
375
        }
376

377
        public Optional<BeanClass<?>> schemaType(String schema, boolean isList) {
378
            return Optional.ofNullable(schemas.get(schema)).map(s ->
1✔
379
                    isList ? BeanClass.create(Array.newInstance(s.getType(), 0).getClass()) : s);
1✔
380
        }
381

382
        public <T> Data<T> data(T instance) {
383
            return data(instance, SchemaType.create(null));
1✔
384
        }
385

386
        public <T> Data<T> data(T instance, SchemaType schema) {
387
            return new Data<>(instance, this, schema);
1✔
388
        }
389

390
        public <N> Data<N> lazy(ThrowingSupplier<N> supplier, SchemaType schemaType) {
391
            try {
392
                return new Data<>(supplier.get(), this, schemaType);
1✔
393
            } catch (Throwable e) {
1✔
394
                return new Data<N>(null, this, schemaType) {
1✔
395
                    @Override
396
                    public N instance() {
UNCOV
397
                        return sneakyThrow(buildUserRuntimeException(e));
×
398
                    }
399
                };
400
            }
401
        }
402

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

409
        public void appendPartialPropertyReference(Data<?> data, Object symbol) {
410
            fetchPartialProperties(data).map(partialProperties -> partialProperties.appendPartialProperties(symbol));
1✔
411
        }
1✔
412

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

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

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

432
        public NumberType getNumberType() {
433
            return numberType;
1✔
434
        }
435

436
        public Optional<Object> getImplicitObject(Object obj) {
437
            return objectImplicitMapper.tryGetData(obj).map(mapper -> mapper.apply(obj));
1✔
438
        }
439

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

444
        public RuntimeHandler<MetaData<?>> fetchGlobalMetaFunction(MetaData<?> metaData) {
445
            return metaProperties.computeIfAbsent(metaData.name(), k -> {
1✔
446
                throw illegalOp2(format("Meta property `%s` not found", metaData.name()));
1✔
447
            });
448
        }
449

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

464
        public Optional<RuntimeHandler<MetaData<?>>> fetchSuperMetaFunction(MetaData<?> metaData) {
465
            return metaFunctionsByType(metaData)
1✔
466
                    .filter(e -> !metaData.calledBy(e.getKey()))
1✔
467
                    .map(e -> {
1✔
468
                        metaData.addCallType(e.getKey());
1✔
469
                        return e.getValue().get(metaData.name());
1✔
470
                    }).filter(Objects::nonNull).findFirst();
1✔
471
        }
472

473
        private Stream<Map.Entry<Class<?>, Map<Object, RuntimeHandler<MetaData<?>>>>> metaFunctionsByType(MetaData<?> metaData) {
474
            return localMetaProperties.entrySet().stream().filter(e -> metaData.isInstance(e.getKey()));
1✔
475
        }
476

477
        private Stream<Map.Entry<Class<?>, Map<Pattern, RuntimeHandler<MetaData<?>>>>> metaFunctionPatternsByType(MetaData<?> metaData) {
478
            return localMetaPropertyPatterns.entrySet().stream().filter(e -> metaData.isInstance(e.getKey()));
1✔
479
        }
480

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

490
        public Checker fetchEqualsChecker(Data<?> expected, Data<?> actual) {
491
            return checkerSetForEqualing.fetch(expected, actual);
1✔
492
        }
493

494
        public Checker fetchMatchingChecker(Data<?> expected, Data<?> actual) {
495
            return checkerSetForMatching.fetch(expected, actual);
1✔
496
        }
497

498
        @SuppressWarnings("unchecked")
499
        public <T> Dumper<T> fetchDumper(Data<T> data) {
500
            return dumperFactories.tryGetData(data.instance()).map(factory -> ((DumperFactory<T>) factory).apply(data)).orElseGet(() -> {
1✔
501
                if (data.isNull())
1✔
502
                    return (_data, dumpingContext) -> dumpingContext.append("null");
1✔
503
                if (data.isList())
1✔
504
                    return (Dumper<T>) Dumper.LIST_DUMPER;
1✔
505
                if (data.instance() != null && data.instance().getClass().isEnum())
1✔
506
                    return (Dumper<T>) Dumper.VALUE_DUMPER;
1✔
507
                return (Dumper<T>) Dumper.MAP_DUMPER;
1✔
508
            });
509
        }
510

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

515
        public int maxDumpingObjectSize() {
516
            return maxDumpingObjectSize;
1✔
517
        }
518

519
        public boolean hookError(String expression, Throwable error) {
520
            return errorHook.handle(getThis(), expression, error);
1✔
521
        }
522

523
        public Data<?> invokeMetaProperty(DALNode inputNode, Data<?> inputData, Object symbolName) {
524
            MetaData<?> metaData = new MetaData<>(inputNode, inputData, symbolName, this);
1✔
525
            return fetchLocalMetaFunction(metaData).orElseGet(() -> fetchGlobalMetaFunction(metaData)).handleData(metaData);
1✔
526
        }
527

528
        public Data<?> invokeDataRemark(RemarkData<?> remarkData) {
529
            Object value = remarkData.data().value();
1✔
530
            return remarks.tryGetData(value)
1✔
531
                    .orElseThrow(() -> illegalOperation("Not implement operator () of " + getClassName(value)))
1✔
532
                    .handleData(remarkData);
1✔
533
        }
534

535
        public Data<?> invokeExclamations(ExclamationData<?> exclamationData) {
536
            Object value = exclamationData.data().value();
1✔
537
            return exclamations.tryGetData(value)
1✔
538
                    .orElseThrow(() -> illegalOp2(format("Not implement operator %s of %s",
1✔
539
                            exclamationData.label(), Classes.getClassName(value))))
1✔
540
                    .handleData(exclamationData);
1✔
541
        }
542

543
        @SuppressWarnings("unchecked")
544
        public Data<?> calculate(Data<?> v1, DALOperator opt, Data<?> v2) {
545
            for (Operation operation : operations.get(opt.overrideType()))
1✔
546
                if (operation.match(v1, opt, v2, this))
1✔
547
                    return operation.operateData(v1, opt, v2, this);
1✔
548
            throw illegalOperation(format("No operation `%s` between '%s' and '%s'", opt.overrideType(),
1✔
549
                    getClassName(v1.instance()), getClassName(v2.instance())));
1✔
550
        }
551

552
        public PrintStream warningOutput() {
553
            return warning;
1✔
554
        }
555

556
        public BiFunction<Object, List<Object>, List<Object>> fetchCurryingMethodArgRange(Method method) {
557
            return curryingMethodArgRanges.get(method);
1✔
558
        }
559

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

568
        @SuppressWarnings("unchecked")
569
        public Comparable<?> transformComparable(Object object) {
570
            return customSorters.tryGetData(object).map(f -> f.apply(object)).orElseGet(() -> (Comparable) object);
1✔
571
        }
572
    }
573
}
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