我阅读了 byte buddy 和 javassist 文档,我想不知道是否可以转换如下字符串:
get foos where name == toto
到
data.getFoos().stream()
              .filter( f -> f.name.equals( "toto" ) )
              .collect( Collectors.toSet() )
正则表达式可以将表达式捕获为:
final Pattern query = Pattern.compile("get (\\w+) where (\\w+) ([=!]+) (\\w+)");
final Scanner scanner = new Scanner(System.in);
final Matcher matcher   = query.matcher(input);
matcher.group(1) // foos -> Foo and foos -> getFoos()
matcher.group(2) // field to use as filter
matcher.group(3) // symbol == / !=
matcher.group(4) // thing to match
- 转换get foos为getFoos()
- 从Foo类中检查name字段是否存在
- 如果字段name不是Number.class转换==为的实例.equals
- 表达
- 循环并打印结果
我读了一些例子却找不到这样的东西。所以我来这里取你的光。谢谢