Giter Site home page Giter Site logo

On org.openrewrite.java.tree.J interface, add a method String printAST() which prints the element and it's children about rewrite HOT 4 CLOSED

openrewrite avatar openrewrite commented on May 19, 2024
On org.openrewrite.java.tree.J interface, add a method String printAST() which prints the element and it's children

from rewrite.

Comments (4)

sambsnyd avatar sambsnyd commented on May 19, 2024 1

I love the graphviz idea. Maybe at some point in the future we have some kind of visual UI for creating or viewing rewrite recipes...

from rewrite.

jkschneider avatar jkschneider commented on May 19, 2024

Might suggest Graphviz's dot output format instead of a proprietary one. Graphviz Java implementation.

  • Unclear at this point whether it's best to dedup on common J.Ident or not. If we do, oft-repeated J.Idents could be edge dense.
  • Does placing an index=n for indices of elements of a statement lists help rendering?

from rewrite.

jkschneider avatar jkschneider commented on May 19, 2024

Another future enhancement idea... Does bracketing the thing we care about, and pruning the tree to only the ancestors of that thing help?

public class A {
    class B {
       public void method() {
           m1();
           <<m2();>>
           logger.info("log something");
       }
    }
}

Could be implemented relatively easily by string replacing with a marker comment before parsing like this:

```java
public class A {
    class B {
       public void method() {
           m1();
           /*PLOTME*/m2();
           logger.info("log something");
       }
    }
}

...and then implementing a visitor that simply looks for any tree element with a formatting prefix containing /*PLOTME*/, and plot everything in its cursor hierarchy.

Although, there is ambiguity in these statements, which both yield /*PLOTME*/a.m2() prior to parsing:

<<a.m2()>> // the J.MethodInvocation
<<a.m2>>() // the name J.Ident

The cursor path is always a single line, so the graphviz representation doesn't help, and perhaps we only represent relatively shallow properties. In the above example, something like:

J.CompilationUnit{sourceFile=src/main/java/...}
J.ClassDecl{name=a.A}
J.ClassDecl{name=a.A.B}
J.MethodDecl{name=method, arguments = []}
J.MethodInvocation{receiver=a.A, name=m2, arguments = []}

from rewrite.

jkschneider avatar jkschneider commented on May 19, 2024

Good digraph examples including tags, in this case of Huffman encoding, but could be similar for our trees:

http://huffman.ooz.ie/tree.dot?text=WITH%20160,000%20BRITONS%20REPORTED%20TO%20BE%20IN%20FRANCE,%20PORTS%20AND%20AIRPORTS%20FACE%20A%20SCRAMBLE%20TO%20RETURN.

image

from rewrite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.