Skip to content

[core] Add xml tree renderer#2216

Merged
adangel merged 6 commits into
pmd:masterfrom
oowekyala:xml-tree-renderer
Jan 17, 2020
Merged

[core] Add xml tree renderer#2216
adangel merged 6 commits into
pmd:masterfrom
oowekyala:xml-tree-renderer

Conversation

@oowekyala

Copy link
Copy Markdown
Member

Refs #2215. This renderer matches our Node -> DOM mapping. The output is eg

<?xml version='1.0' encoding='UTF-8' ?>
<CompilationUnit BeginColumn='1' BeginLine='1' EndColumn='12' EndLine='1' FindBoundary='false' Image='' PackageName='' SingleLine='true' declarationsAreInDefaultPackage='true'>
     <TypeDeclaration BeginColumn='1' BeginLine='1' EndColumn='12' EndLine='1' FindBoundary='false' Image='' SingleLine='true'>
        <ClassOrInterfaceDeclaration Abstract='false' BeginColumn='1' BeginLine='1' BinaryName='' Default='false' EndColumn='12' EndLine='1' Final='false' FindBoundary='false' Image='Foo' Interface='false' Local='false' Modifiers='0' Native='false' Nested='false' PackagePrivate='true' Private='false' Protected='false' Public='false' SimpleName='Foo' SingleLine='true' Static='false' Strictfp='false' Synchronized='false' Transient='false' TypeKind='CLASS' Volatile='false'>
            <ClassOrInterfaceBody AnonymousInnerClass='false' BeginColumn='11' BeginLine='1' EndColumn='12' EndLine='1' EnumChild='false' FindBoundary='false' Image='' SingleLine='true' />
        </ClassOrInterfaceDeclaration>
    </TypeDeclaration>
</CompilationUnit>

Use it like

    public static void main(String[] args) throws IOException {

        LanguageVersionHandler java = LanguageRegistry.getLanguage("Java").getDefaultVersion().getLanguageVersionHandler();
        Parser parser = java.getParser(java.getDefaultParserOptions());

        Node root = parser.parse("foo", new StringReader("class Foo {}"));

        new XmlTreeRenderer().renderSubtree(root, System.out);
    }

One problem is that it causes warnings for deprecated attributes...

The next step would be to build a small CLI program, eg something to use like run.sh ast-dump --format xml --to-file out.xml --language java some/Class.java

The designer could also use this API to have a GUI for those exports.

@oowekyala oowekyala added this to the 6.21.0 milestone Jan 12, 2020
@ghost

ghost commented Jan 12, 2020

Copy link
Copy Markdown
1 Message
📖 This changeset introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report
This changeset introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report
This changeset introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report
This changeset introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
Full report

Generated by 🚫 Danger

@adangel

adangel commented Jan 16, 2020

Copy link
Copy Markdown
Member

That would be an additional experimental API. In order to get feedback about possible use cases (which I don't know), we probably should add a short page in our documentation. For ease of use, we definitely need to provide the simple CLI as you suggested.

For the XML format: Should we add at the toplevel element attributes like "exportedTimestamp", "pmdVersion", "language"? We could also simply add a xml comment with that information. This information might be helpful later on.

@oowekyala

Copy link
Copy Markdown
Member Author

I added a small API to describe tree renderers and register them. I imagine the designer can use this.
I think too that it might be nice to use a tree renderer to make the designer dump subtrees with the format we use for the java changes page

For the XML format: Should we add at the toplevel element attributes like "exportedTimestamp", "pmdVersion", "language"? We could also simply add a xml comment with that information. This information might be helpful later on.

If this XML renderer is meant to be as close as possible as the representation we use for XPath then we should keep it free of that. It would be possible though to add another renderer that has this additional metadata. I imagine it could also add some nodes to the tree, eg types for java nodes, references to nodes, etc. This would be useful for testing.

@adangel adangel self-assigned this Jan 17, 2020
@adangel adangel merged commit 6c58817 into pmd:master Jan 17, 2020
@oowekyala oowekyala deleted the xml-tree-renderer branch January 17, 2020 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants