Class GrammarInfo

java.lang.Object
org.codehaus.mojo.javacc.GrammarInfo

class GrammarInfo extends 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 Details

    • sourceDirectory

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

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

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

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

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

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

    • GrammarInfo

      public GrammarInfo(File sourceDir, String inputFile) throws 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:
      IOException - If reading the grammar file failed.
    • GrammarInfo

      public GrammarInfo(File sourceDir, String inputFile, String packageName) throws 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:
      IOException - If reading the grammar file failed.
  • Method Details

    • findPackageName

      private String findPackageName(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 String findParserName(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 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 File getGrammarFile()
      Gets the absolute path to the grammar file.
      Returns:
      The absolute path to the grammar file, never null.
    • getRelativeGrammarFile

      public 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 String resolvePackageName(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 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 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 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 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 String toString()
      Gets a string representation of this bean. This value is for debugging purposes only.
      Overrides:
      toString in class Object
      Returns:
      A string representation of this bean.