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

leeonky / test-charm-java / 227

21 Apr 2025 03:32PM UTC coverage: 71.06% (-3.0%) from 74.052%
227

push

circleci

leeonky
Refactor UI test

6 of 15 new or added lines in 5 files covered. (40.0%)

42 existing lines in 11 files now uncovered.

6858 of 9651 relevant lines covered (71.06%)

0.71 hits per line

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

95.65
/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.value()));
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.value();
1✔
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() {
161
        return converter;
×
162
    }
163

164
    public RuntimeContextBuilder setConverter(Converter converter) {
165
        this.converter = converter;
×
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())
1✔
182
                                .filter(method -> !Modifier.isStatic(method.getModifiers()) && !method.isBridge())
1✔
183
                                .filter(method -> method.getName().equals(methodName)),
1✔
184
                        staticMethodsToCurrying(type, methodName, Object::equals),
1✔
185
                        staticMethodsToCurrying(type, methodName, Class::isAssignableFrom))
1✔
186
                .flatMap(Function.identity()).collect(Collectors.toCollection(LinkedHashSet::new));
1✔
187
    }
188

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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