Class GrammarInfo


  • class GrammarInfo
    extends java.lang.Object
    This bean holds some output related information about a JavaCC grammar file. It assists in determining the exact output location for the generated parser file.
    Version:
    $Id: GrammarInfo.java 8156 2008-11-26 18:20:19Z bentmann $
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String grammarFile
      The path to the grammar file (relative to its source directory, e.g.
      private java.lang.String parserDirectory
      The path to the directory of the parser package (relative to a source root directory, e.g.
      private java.lang.String parserFile
      The path to the generated parser file (relative to a source root directory, e.g.
      private java.lang.String parserName
      The simple name of the generated parser (e.g.
      private java.lang.String parserPackage
      The declared package for the generated parser (e.g.
      private java.io.File sourceDirectory
      The absolute path to the base directory in which the grammar file resides.
    • Constructor Summary

      Constructors 
      Constructor Description
      GrammarInfo​(java.io.File sourceDir, java.lang.String inputFile)
      Creates a new info from the specified grammar file.
      GrammarInfo​(java.io.File sourceDir, java.lang.String inputFile, java.lang.String packageName)
      Creates a new info from the specified grammar file.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private java.lang.String findPackageName​(java.lang.String grammar)
      Extracts the declared package name from the specified grammar file.
      private java.lang.String findParserName​(java.lang.String grammar)
      Extracts the simple parser name from the specified grammar file.
      java.io.File getGrammarFile()
      Gets the absolute path to the grammar file.
      java.lang.String getParserDirectory()
      Gets the path to the directory of the parser package (relative to a source root directory, e.g.
      java.lang.String getParserFile()
      Gets the path to the parser file (relative to a source root directory, e.g.
      java.lang.String getParserName()
      Gets the simple name of the generated parser (e.g.
      java.lang.String getParserPackage()
      Gets the declared package for the generated parser (e.g.
      java.lang.String getRelativeGrammarFile()
      Gets the path to the grammar file (relative to its source directory).
      java.io.File getSourceDirectory()
      Gets the absolute path to the base directory in which the grammar file resides.
      java.lang.String resolvePackageName​(java.lang.String packageName)
      Resolves the specified package name against the package name of the parser generated from this grammar.
      java.lang.String toString()
      Gets a string representation of this bean.
      • Methods inherited from class java.lang.Object

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

      • sourceDirectory

        private final java.io.File sourceDirectory
        The absolute path to the base directory in which the grammar file resides.
      • grammarFile

        private final java.lang.String grammarFile
        The path to the grammar file (relative to its source directory, e.g. "grammars/MyParser.jj").
      • parserPackage

        private final java.lang.String parserPackage
        The declared package for the generated parser (e.g. "org.apache").
      • parserDirectory

        private final java.lang.String parserDirectory
        The path to the directory of the parser package (relative to a source root directory, e.g. "org/apache").
      • parserName

        private final java.lang.String parserName
        The simple name of the generated parser (e.g. "MyParser").
      • parserFile

        private final java.lang.String parserFile
        The path to the generated parser file (relative to a source root directory, e.g. "org/apache/MyParser.java").
    • Constructor Detail

      • GrammarInfo

        public GrammarInfo​(java.io.File sourceDir,
                           java.lang.String inputFile)
                    throws java.io.IOException
        Creates a new info from the specified grammar file.
        Parameters:
        sourceDir - The absolute path to the base directory in which the grammar file resides, must not be null.
        inputFile - The path to the grammar file (relative to the source directory), must not be null.
        Throws:
        java.io.IOException - If reading the grammar file failed.
      • GrammarInfo

        public GrammarInfo​(java.io.File sourceDir,
                           java.lang.String inputFile,
                           java.lang.String packageName)
                    throws java.io.IOException
        Creates a new info from the specified grammar file.
        Parameters:
        sourceDir - The absolute path to the base directory in which the grammar file resides, must not be null.
        inputFile - The path to the grammar file (relative to the source directory), must not be null.
        packageName - The package name for the generated parser, may be null to use the package declaration from the grammar file.
        Throws:
        java.io.IOException - If reading the grammar file failed.
    • Method Detail

      • findPackageName

        private java.lang.String findPackageName​(java.lang.String grammar)
        Extracts the declared package name from the specified grammar file.
        Parameters:
        grammar - The contents of the grammar file, must not be null.
        Returns:
        The declared package name or an empty string if not found.
      • findParserName

        private java.lang.String findParserName​(java.lang.String grammar)
        Extracts the simple parser name from the specified grammar file.
        Parameters:
        grammar - The contents of the grammar file, must not be null.
        Returns:
        The parser name or an empty string if not found.
      • getSourceDirectory

        public java.io.File getSourceDirectory()
        Gets the absolute path to the base directory in which the grammar file resides. Note that this is not necessarily the parent directory of the grammar file.
        Returns:
        The absolute path to the base directory in which the grammar file resides, never null.
      • getGrammarFile

        public java.io.File getGrammarFile()
        Gets the absolute path to the grammar file.
        Returns:
        The absolute path to the grammar file, never null.
      • getRelativeGrammarFile

        public java.lang.String getRelativeGrammarFile()
        Gets the path to the grammar file (relative to its source directory).
        Returns:
        The path to the grammar file (relative to its source directory), never null.
      • resolvePackageName

        public java.lang.String resolvePackageName​(java.lang.String packageName)
        Resolves the specified package name against the package name of the parser generated from this grammar. To reference the parser package, the input string may use the prefix "*". For example, if the package for the parser is "org.apache" and the input string is "*.node", the resolved package is "org.apache.node". The period after the asterisk is significant, i.e. in the previous example the input string "*node" would resolve to "org.apachenode".
        Parameters:
        packageName - The package name to resolve, may be null.
        Returns:
        The resolved package name or null if the input string was null.
      • getParserPackage

        public java.lang.String getParserPackage()
        Gets the declared package for the generated parser (e.g. "org.apache").
        Returns:
        The declared package for the generated parser (e.g. "org.apache") or an empty string if no package declaration was found, never null.
      • getParserDirectory

        public java.lang.String getParserDirectory()
        Gets the path to the directory of the parser package (relative to a source root directory, e.g. "org/apache").
        Returns:
        The path to the directory of the parser package (relative to a source root directory, e.g. "org/apache") or an empty string if no package declaration was found, never null.
      • getParserName

        public java.lang.String getParserName()
        Gets the simple name of the generated parser (e.g. "MyParser")
        Returns:
        The simple name of the generated parser (e.g. "MyParser"), never null.
      • getParserFile

        public java.lang.String getParserFile()
        Gets the path to the parser file (relative to a source root directory, e.g. "org/apache/MyParser.java").
        Returns:
        The path to the parser file (relative to a source root directory, e.g. "org/apache/MyParser.java"), never null.
      • toString

        public java.lang.String toString()
        Gets a string representation of this bean. This value is for debugging purposes only.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string representation of this bean.