objectionary / opeo-maven-plugin

Maven plugin to remove Bytecode opcodes from XMIR as much as possible
http://www.objectionary.com/opeo-maven-plugin/
MIT License
6 stars 1 forks source link

Decompile Java Streams to beautiful EO #329

Open maxonfjvipon opened 1 week ago

maxonfjvipon commented 1 week ago

We have the next java code:

String[] strings = new String[10];
for (int i = 0; i < strings.length; i++) {
    strings[i] = String.valueOf(i);
}
int sum = Arrays.stream(strings)
    .filter(s -> !s.equals(""))
    .mapToInt(s -> Integer.parseInt(s))
    .sum();
System.out.println(sum);

After compilation, disassembling and decompiling it looks like this: decompiled.txt

In short - there are only opcodes, no decompilation is happening.

Ideally, the EO after decompilation should look something like this (I'm considering only working with Streams)

[] > factorial-application
  [] > new
    ... > @
  [] > main
    seq > @
      *
        ...
        java_util_Arrays.java_util_Arrays$stream
          java_lang_String[]-strings                         # I'm not sure if it's valid but we should mark that it's an array somehow
        .java_util_stream_Stream$filter
          [java_lang_String-s]
            seq > @
              *
                java_lang_String-s.java_lang_String$equals
                  ""
                .not
        .java_util_stream_Stream$mapToInt
          [java_lang_String-s]
            seq > @
              *
                java_lang_Integer.java_lang_Integer$parseInt
                  java_lang_String-s
        .java_util_stream_IntStream$sum > int_sum
        ...

Of course maybe it's not possible to get exactly such picture after decompilation because of bytecode restrictions. But the closer - the better

volodya-lombrozo commented 1 week ago

@maxonfjvipon Thank you for the explanation.