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

leeonky / test-charm-java / 290

08 Sep 2025 03:25PM UTC coverage: 74.312% (-0.003%) from 74.315%
290

push

circleci

leeonky
Introduce PropertyWriterDecorator

10 of 25 new or added lines in 6 files covered. (40.0%)

20 existing lines in 10 files now uncovered.

8155 of 10974 relevant lines covered (74.31%)

0.74 hits per line

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

95.71
/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.DALException.buildUserRuntimeException;
29
import static com.github.leeonky.dal.runtime.ExpressionException.illegalOp2;
30
import static com.github.leeonky.dal.runtime.ExpressionException.illegalOperation;
31
import static com.github.leeonky.dal.runtime.schema.Actual.actual;
32
import static com.github.leeonky.dal.runtime.schema.Verification.expect;
33
import static com.github.leeonky.util.Classes.getClassName;
34
import static com.github.leeonky.util.Classes.named;
35
import static com.github.leeonky.util.CollectionHelper.toStream;
36
import static com.github.leeonky.util.Sneaky.cast;
37
import static com.github.leeonky.util.Sneaky.sneakyThrow;
38
import static java.lang.String.format;
39
import static java.lang.reflect.Modifier.STATIC;
40
import static java.util.Arrays.stream;
41
import static java.util.Collections.emptySet;
42
import static java.util.Optional.of;
43
import static java.util.stream.Collectors.joining;
44
import static java.util.stream.Collectors.toList;
45

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

158
    public Converter getConverter() {
159
        return converter;
×
160
    }
161

162
    public RuntimeContextBuilder setConverter(Converter converter) {
163
        this.converter = converter;
×
164
        return this;
×
165
    }
166

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

172
    private Set<Method> methodToCurrying(Class<?> type, Object methodName) {
173
        return Stream.of(stream(type.getMethods())
1✔
174
                                .filter(method -> !Modifier.isStatic(method.getModifiers()) && !method.isBridge())
1✔
175
                                .filter(method -> method.getName().equals(methodName)),
1✔
176
                        staticMethodsToCurrying(type, methodName, Object::equals),
1✔
177
                        staticMethodsToCurrying(type, methodName, Class::isAssignableFrom))
1✔
178
                .flatMap(Function.identity()).collect(Collectors.toCollection(LinkedHashSet::new));
1✔
179
    }
180

181
    private Stream<Method> staticMethodsToCurrying(Class<?> type, Object property,
182
                                                   BiPredicate<Class<?>, Class<?>> condition) {
183
        return extensionMethods.stream()
1✔
184
                .filter(method -> staticExtensionMethodName(method).equals(property))
1✔
185
                .filter(method -> condition.test(method.getParameters()[0].getType(), type));
1✔
186
    }
187

188
    private static String staticExtensionMethodName(Method method) {
189
        ExtensionName extensionName = method.getAnnotation(ExtensionName.class);
1✔
190
        return extensionName != null ? extensionName.value() : method.getName();
1✔
191
    }
192

193
    public CheckerSet checkerSetForMatching() {
194
        return checkerSetForMatching;
1✔
195
    }
196

197
    public CheckerSet checkerSetForEqualing() {
198
        return checkerSetForEqualing;
1✔
199
    }
200

201
    public <T> RuntimeContextBuilder registerDumper(Class<T> type, DumperFactory<T> factory) {
202
        dumperFactories.put(type, factory);
1✔
203
        return this;
1✔
204
    }
205

206
    public void setMaxDumpingLineSize(int size) {
207
        maxDumpingLineSize = size;
1✔
208
    }
1✔
209

210
    public <T> RuntimeContextBuilder registerErrorHook(ErrorHook hook) {
211
        errorHook = Objects.requireNonNull(hook);
1✔
212
        return this;
1✔
213
    }
214

215
    public void mergeTextFormatter(String name, String other, String... others) {
216
        TextFormatter formatter = textFormatterMap.get(other);
1✔
217
        for (String o : others)
1✔
218
            formatter = formatter.merge(textFormatterMap.get(o));
1✔
219
        registerTextFormatter(name, delegateFormatter(formatter, "Merged from " + other + " " + String.join(" ", others)));
1✔
220
    }
1✔
221

222
    private TextFormatter delegateFormatter(TextFormatter formatter, final String description) {
223
        return new TextFormatter() {
1✔
224
            @Override
225
            protected Object format(Object content, TextAttribute attribute, DALRuntimeContext context) {
226
                return formatter.format(content, attribute, context);
×
227
            }
228

229
            @Override
230
            protected TextAttribute attribute(TextAttribute attribute) {
231
                return formatter.attribute(attribute);
×
232
            }
233

234
            @Override
235
            public Class<?> returnType() {
236
                return formatter.returnType();
1✔
237
            }
238

239
            @Override
240
            public Class<?> acceptType() {
241
                return formatter.acceptType();
1✔
242
            }
243

244
            @Override
245
            public String description() {
246
                return description;
1✔
247
            }
248
        };
249
    }
250

251
    public <T> RuntimeContextBuilder registerMetaProperty(Class<T> type, Object name, RuntimeHandler<MetaData<T>> function) {
252
        localMetaProperties.computeIfAbsent(type, k -> new HashMap<>()).put(name, cast(function));
1✔
253
        return this;
1✔
254
    }
255

256
    public <T> RuntimeContextBuilder registerMetaPropertyPattern(Class<T> type, String name, RuntimeHandler<MetaData<T>> function) {
257
        localMetaPropertyPatterns.computeIfAbsent(type, k -> new HashMap<>()).put(Pattern.compile(name), cast(function));
1✔
258
        return this;
1✔
259
    }
260

261
    public <T> RuntimeContextBuilder registerDataRemark(Class<T> type, RuntimeHandler<RemarkData<T>> action) {
262
        remarks.put(type, cast(action));
1✔
263
        return this;
1✔
264
    }
265

266
    public <T> RuntimeContextBuilder registerExclamation(Class<T> type, RuntimeHandler<RuntimeData<T>> action) {
267
        exclamations.put(type, cast(action));
1✔
268
        return this;
1✔
269
    }
270

271
    public RuntimeContextBuilder registerOperator(Operators operator, Operation<?, ?> operation) {
272
        operations.computeIfAbsent(operator, o -> new LinkedList<>()).addFirst(operation);
1✔
273
        return this;
1✔
274
    }
275

276
    @SuppressWarnings("unchecked")
277
    public <T> RuntimeContextBuilder registerCustomSorter(Class<T> type, Function<T, Comparable<?>> sorter) {
278
        customSorters.put(type, (Function<Object, Comparable<?>>) sorter);
1✔
279
        return this;
1✔
280
    }
281

282
    public BeanClass<?> schemaType(String schema) {
283
        BeanClass<?> type = schemas.get(schema);
1✔
284
        if (type != null)
1✔
285
            return type;
1✔
286
        throw new IllegalStateException(format("Unknown schema '%s'", schema));
×
287
    }
288

289
    public void setMaxDumpingObjectSize(int maxDumpingObjectSize) {
290
        this.maxDumpingObjectSize = maxDumpingObjectSize;
×
291
    }
×
292

293
    public RuntimeContextBuilder setWarningOutput(PrintStream printStream) {
294
        warning = printStream;
1✔
295
        return this;
1✔
296
    }
297

298
    public RuntimeContextBuilder registerReturnHook(Consumer<Data<?>> hook) {
299
        returnHook = returnHook.andThen(hook);
1✔
300
        return this;
1✔
301
    }
302

303
    public Features features() {
304
        return features;
1✔
305
    }
306

307
    public class DALRuntimeContext implements RuntimeContext {
308
        private final LinkedList<Data<?>> stack = new LinkedList<>();
1✔
309
        private final LinkedList<Integer> positionStack = new LinkedList<>();
1✔
310
        private final Map<Data<?>, PartialPropertyStack> partialPropertyStacks;
311

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

316
        public DALRuntimeContext(InputCode<?> supplier, Class<?> schema) {
1✔
317
            stack.push(lazy(supplier, SchemaType.create(schema == null ? null : BeanClass.create(schema))));
1✔
318
            positionStack.push(0);
1✔
319
            partialPropertyStacks = new HashMap<>();
1✔
320
        }
1✔
321

322
        public Data<?> getThis() {
323
            return stack.getFirst();
1✔
324
        }
325

326
        public <T> T pushAndExecute(Data<?> data, Supplier<T> supplier) {
327
            try {
328
                stack.push(data);
1✔
329
                return supplier.get();
1✔
330
            } finally {
331
                returnHook.accept(stack.pop());
1✔
332
            }
333
        }
334

335
        public <T> T pushPositionAndExecute(int position, Supplier<T> supplier) {
336
            try {
337
                positionStack.push(position);
1✔
338
                return supplier.get();
1✔
339
            } finally {
340
                positionStack.pop();
1✔
341
            }
342
        }
343

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

348
        public <T> Set<?> findPropertyReaderNames(Data<T> data) {
349
            return getObjectPropertyAccessor(data.value()).getPropertyNames(data);
1✔
350
        }
351

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

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

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

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

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

377
        public Converter getConverter() {
378
            return converter;
1✔
379
        }
380

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

386
        public <T> Data<T> data(T instance) {
387
            return data(instance, SchemaType.create(null));
1✔
388
        }
389

390
        public <T> Data<T> data(T instance, SchemaType schema) {
391
            return new Data<>(instance, this, schema);
1✔
392
        }
393

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

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

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

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

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

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

436
        public NumberType getNumberType() {
437
            return numberType;
1✔
438
        }
439

440
        public Optional<Object> getImplicitObject(Object obj) {
441
            return objectImplicitMapper.tryGetData(obj).map(mapper -> mapper.apply(obj));
1✔
442
        }
443

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

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

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

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

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

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

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

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

498
        public Checker fetchMatchingChecker(Data<?> expected, Data<?> actual) {
499
            return checkerSetForMatching.fetch(expected, actual);
1✔
500
        }
501

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

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

519
        public int maxDumpingObjectSize() {
520
            return maxDumpingObjectSize;
1✔
521
        }
522

523
        public boolean hookError(String expression, Throwable error) {
524
            return errorHook.handle(getThis(), expression, error);
1✔
525
        }
526

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

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

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

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

556
        public PrintStream warningOutput() {
557
            return warning;
1✔
558
        }
559

560
        public Optional<CurryingMethod> currying(Object instance, Object property) {
561
            CurryingMethod curryingMethod = new CurryingMethod(this, data(instance));
1✔
562
            methodToCurrying(named(instance.getClass()), property).forEach(curryingMethod::candidateMethod);
1✔
563
            if (!curryingMethod.isEmpty())
1✔
564
                return of(curryingMethod);
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
        public int lastPosition() {
574
            return positionStack.getFirst();
1✔
575
        }
576

577
        public Data<?> inputRoot() {
578
            return stack.getLast();
1✔
579
        }
580
    }
581
}
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