Class XmlPrinter


  • public class XmlPrinter
    extends java.lang.Object
    Outputs an XML file containing the AST meant for inspecting it.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean outputNodeType  
      private static java.lang.Class<?> TYPE_CLASS  
    • Constructor Summary

      Constructors 
      Constructor Description
      XmlPrinter​(boolean outputNodeType)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      java.lang.String output​(Node node)
      Generate a xml string for given AST Node.
      void output​(Node node, java.lang.String name, int level, java.lang.StringBuilder builder)
      Deprecated.
      void outputDocument​(Node node, java.lang.String name, java.io.Writer writer)
      Output the XML Document representing given AST node to given writer.
      void outputDocument​(Node node, java.lang.String name, javax.xml.stream.XMLStreamWriter xmlWriter)
      Output the XML Document representing an AST node to given XMLStreamWriter.
      void outputNode​(Node node, java.lang.String name, javax.xml.stream.XMLStreamWriter xmlWriter)
      Output the XML Element representing an AST node to given writer.
      static void print​(Node node)  
      java.io.StringWriter stringWriterOutput​(Node node, java.lang.String name)
      Create a string writer filled with XML document representing an AST node.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • outputNodeType

        private final boolean outputNodeType
      • TYPE_CLASS

        private static final java.lang.Class<?> TYPE_CLASS
    • Constructor Detail

      • XmlPrinter

        public XmlPrinter​(boolean outputNodeType)
    • Method Detail

      • output

        public java.lang.String output​(Node node)
        Generate a xml string for given AST Node. Tag name of root element in the result document will be "root".
        Parameters:
        node - AST node to be converted to XML
        Returns:
        XML document corresponding to node
      • output

        @Deprecated
        public void output​(Node node,
                           java.lang.String name,
                           int level,
                           java.lang.StringBuilder builder)
        Deprecated.
        Output XML data from an AST node to a String Builder. This method is kept for backward compatilibity only and should be removed in future releases.
        Parameters:
        node - AST node to be converted to XML
        name - Tag name of root element in the resulting document
        level - Nesting level of node in tree. Not used.
        builder - Target object to receive the generated XML
      • stringWriterOutput

        public java.io.StringWriter stringWriterOutput​(Node node,
                                                       java.lang.String name)
        Create a string writer filled with XML document representing an AST node.

        Returned stringWriter is not closed upon return because doing so has no effect. So users of this method are not required to close it.

        Parameters:
        node - AST node to be converted to XML
        name - Tag name of root element in the resulting document
        Returns:
        Stringwriter filled with XML document
        Throws:
        RuntimeXMLStreamException - Unchecked exception wrapping checked XMLStreamException, when any error on producing XML output occours
      • outputDocument

        public void outputDocument​(Node node,
                                   java.lang.String name,
                                   java.io.Writer writer)
                            throws javax.xml.stream.XMLStreamException
        Output the XML Document representing given AST node to given writer.

        This method creates a XMLStreamWriter that writes to given writer and delegates execution to outputDocument(Node, String, XMLStreamWriter)

        Provided writer is NOT closed at the end of execution of this method.

        Parameters:
        node - AST node to be converted to XML
        name - Tag name of root element of document
        writer - Target to get the document writen to
        Throws:
        javax.xml.stream.XMLStreamException - When any error on outputting XML occours
      • outputNode

        public void outputNode​(Node node,
                               java.lang.String name,
                               javax.xml.stream.XMLStreamWriter xmlWriter)
                        throws javax.xml.stream.XMLStreamException
        Output the XML Element representing an AST node to given writer.

        This method outputs an XML Element with given tag name to writer. It is used recursively for generating nested elements corresponding to AST.

        For generating a complete XML document from an AST node, outputDocument(String, Node, XMLStreamWriter) should be used instead.

        Provided xmlWriter is NOT closed at the end of execution of this method.

        Parameters:
        node - AST node to be converted to XML
        name - Tag name of element corresponding to node
        xmlWriter - Target to get XML written to
        Throws:
        javax.xml.stream.XMLStreamException - When any error on outputting XML occours
        See Also:
        outputDocument(String, Node, XMLStreamWriter)
      • print

        public static void print​(Node node)