|
|
@@ -18,6 +18,7 @@ import java.io.Writer;
|
|
|
import java.time.temporal.Temporal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collection;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.function.BiConsumer;
|
|
|
@@ -27,34 +28,35 @@ import java.util.function.Function;
|
|
|
public class WalkerRules {
|
|
|
|
|
|
public static final WalkerRules DEFAULT = new WalkerRules()
|
|
|
+ .tag("PATH", "{id,text,4}.{namePath,text,-50}")
|
|
|
.rule()
|
|
|
.match(ObjectContext::isVisited)
|
|
|
- .term("{id,text,4}.{namePath,text,-50} <ref> = #{ref}")
|
|
|
+ .term("{PATH} <ref> = #{ref}")
|
|
|
.rule()
|
|
|
.match(ctx -> ctx.depth() > 32)
|
|
|
- .term("{id,text,4}.{namePath,text,-50} ...")
|
|
|
+ .term("{PATH} ...")
|
|
|
.rule()
|
|
|
.match(ObjectContext::isNull)
|
|
|
- .term("{id,text,4}.{namePath,text,-50} {typeName} = <null>")
|
|
|
+ .term("{PATH} {typeName} = <null>")
|
|
|
.rule()
|
|
|
.match(String.class)
|
|
|
- .term("{id,text,4}.{namePath,text,-50} {actual.shortname} = '{value}'")
|
|
|
+ .term("{PATH} {actual.shortname} = '{value}'")
|
|
|
.rule()
|
|
|
.match(byte[].class)
|
|
|
.text(ctx -> FormatHex.format(ctx.value()))
|
|
|
- .term("{id,text,4}.{namePath,text,-50} {actual.shortname} = '{text}'")
|
|
|
+ .term("{PATH} {actual.shortname} = '{value}'")
|
|
|
.rule()
|
|
|
.match(char[].class)
|
|
|
.text(ctx -> String.valueOf(ctx.value()))
|
|
|
- .term("{id,text,4}.{namePath,text,-50} {actual.shortname} = '{text}'")
|
|
|
+ .term("{PATH} {actual.shortname} = '{value}'")
|
|
|
.rule()
|
|
|
.match(ArrayContext.class::isInstance)
|
|
|
- .hint("{id,text,4}.{namePath,text,-50} {actual.shortname}.size = {size}")
|
|
|
+ .hint("{PATH} {actual.shortname}.size = {size}")
|
|
|
.rule()
|
|
|
.match(List.class)
|
|
|
.match(Collection.class)
|
|
|
.match(Map.class)
|
|
|
- .hint("{id,text,4}.{namePath,text,-50} {typeName}.size = {size}")
|
|
|
+ .hint("{PATH} {typeName}.size = {size}")
|
|
|
.rule()
|
|
|
.match(java.util.Date.class)
|
|
|
.match(java.sql.Date.class)
|
|
|
@@ -62,12 +64,14 @@ public class WalkerRules {
|
|
|
.match(Temporal.class)
|
|
|
.match(Number.class)
|
|
|
.match(ObjectContext::isPrimitive)
|
|
|
- .term("{id,text,4}.{namePath,text,-50} {actual.shortname} = {value}")
|
|
|
+ .term("{PATH} {actual.shortname} = {value}")
|
|
|
.rule()
|
|
|
.match(Object.class)
|
|
|
- .hint("{id,text,4}.{namePath,text,-50} {actual.shortname} = {value}")
|
|
|
+ .hint("{PATH} {actual.shortname} = {value}")
|
|
|
;
|
|
|
|
|
|
+ private final Map<String, ResolveFormat> tags = new HashMap<>();
|
|
|
+
|
|
|
private final List<RuleEntry> rules = new ArrayList<>();
|
|
|
|
|
|
public PrintVisitor visitor(OutputStream target) {
|
|
|
@@ -76,6 +80,12 @@ public class WalkerRules {
|
|
|
|
|
|
public PrintVisitor visitor(Writer target) {
|
|
|
return new PrintVisitor(new PrintWriter(target)){
|
|
|
+ @Override
|
|
|
+ public boolean visitRoot(ObjectContext<?> context) {
|
|
|
+ context.custom(tags);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public boolean visitObject(ObjectContext<?> context) {
|
|
|
for (RuleEntry rule : rules) {
|
|
|
@@ -89,10 +99,16 @@ public class WalkerRules {
|
|
|
}
|
|
|
|
|
|
public WalkerRules inherit(WalkerRules parent) {
|
|
|
+ this.tags.putAll(parent.tags);
|
|
|
this.rules.addAll(parent.rules);
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
+ public WalkerRules tag(String name, String value) {
|
|
|
+ this.tags.put(name, ResolveFormat.compile(value));
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
public RuleBuilderRoot rule() {
|
|
|
return new RuleBuilderRoot();
|
|
|
}
|
|
|
@@ -155,7 +171,7 @@ public class WalkerRules {
|
|
|
}
|
|
|
|
|
|
public RuleBuilderRoot text(Function<ObjectContext<Object>, String> formatter) {
|
|
|
- this.formatter = ctx -> ctx.text(formatter.apply(ctx));
|
|
|
+ this.formatter = ctx -> ctx.custom("value", formatter.apply(ctx));
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
@@ -182,7 +198,7 @@ public class WalkerRules {
|
|
|
}
|
|
|
|
|
|
public RuleBuilderType<F> text(Function<ObjectContext<F>, String> formatter) {
|
|
|
- this.formatter = ctx -> ctx.text(formatter.apply(ctx));
|
|
|
+ this.formatter = ctx -> ctx.custom("value", formatter.apply(ctx));
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
@@ -209,7 +225,7 @@ public class WalkerRules {
|
|
|
}
|
|
|
|
|
|
public RuleBuilderMore text(Function<ObjectContext<Object>, String> formatter) {
|
|
|
- this.formatter = ctx -> ctx.text(formatter.apply(ctx));
|
|
|
+ this.formatter = ctx -> ctx.custom("value", formatter.apply(ctx));
|
|
|
return this;
|
|
|
}
|
|
|
|