public abstract class AbstractJavaCCMojo
extends org.apache.maven.plugin.AbstractMojo
Modifier and Type | Field and Description |
---|---|
private java.lang.Boolean |
buildParser
A flag that controls whether the parser file (
*Parser.java ) should be generated or not. |
private java.lang.Boolean |
buildTokenManager
A flag that controls whether the token manager file (
*TokenManager.java ) should be generated or
not. |
private java.lang.Boolean |
cacheTokens
Setting this option to
true causes the generated parser to lookahead for extra tokens ahead of
time. |
private java.lang.Integer |
choiceAmbiguityCheck
This is the number of tokens considered in checking choices of the form "A | B | ..." for ambiguity.
|
private java.lang.Boolean |
commonTokenAction
When set to
true , every call to the token manager's method getNextToken() (see the
description of the Java Compiler Compiler API)
will cause a call to a user-defined method CommonTokenAction() after the token has been scanned in
by the token manager. |
private java.lang.Boolean |
debugLookAhead
This is a boolean option whose default value is
false . |
private java.lang.Boolean |
debugParser
This option is used to obtain debugging information from the generated parser.
|
private java.lang.Boolean |
debugTokenManager
This option is used to obtain debugging information from the generated token manager.
|
private java.lang.Boolean |
errorReporting
Setting it to
false causes errors due to parse errors to be reported in somewhat less detail. |
private java.lang.Boolean |
forceLaCheck
This option setting controls lookahead ambiguity checking performed by JavaCC.
|
private java.lang.String |
grammarEncoding
The file encoding to use for reading the grammar files.
|
private java.lang.Boolean |
ignoreCase
Setting this option to
true causes the generated token manager to ignore case in the token
specifications and the input files. |
private java.lang.Boolean |
isStatic
If
true , all methods and class variables are specified as static in the generated parser and
token manager. |
private java.lang.Boolean |
javaUnicodeEscape
When set to
true , the generated parser uses an input stream object that processes Java Unicode
escapes (\ u xxxx) before sending characters to the token manager. |
private java.lang.String |
jdkVersion
The Java version for which to generate source code.
|
private java.lang.Boolean |
keepLineColumn
A flag whether to keep line and column information along with a token.
|
private java.lang.Integer |
lookAhead
The number of tokens to look ahead before making a decision at a choice point during parsing.
|
private java.util.Collection |
nonGeneratedSourceRoots
The set of compile source roots whose contents are not generated as part of the build, i.e.
|
private java.lang.Integer |
otherAmbiguityCheck
This is the number of tokens considered in checking all other kinds of choices (i.e., of the forms "(A)*",
"(A)+", and "(A)?") for ambiguity.
|
private org.apache.maven.project.MavenProject |
project
The current Maven project.
|
private java.lang.Boolean |
sanityCheck
Enables/disables many syntactic and semantic checks on the grammar file during parser generation.
|
private java.lang.Boolean |
supportClassVisibilityPublic
A flag whether the generated support classes of the parser should have public or package-private visibility.
|
private java.lang.String |
tokenExtends
The name of the base class for the generated
Token class. |
private java.lang.String |
tokenFactory
The name of a custom factory class used to create
Token objects. |
private java.lang.Boolean |
tokenManagerUsesParser
When set to
true , the generated token manager will include a field called parser
that references the instantiating parser instance. |
private java.lang.Boolean |
unicodeInput
When set to
true , the generated parser uses uses an input stream object that reads Unicode files. |
private java.lang.Boolean |
userCharStream
This flag controls whether the token manager will read characters from a character stream reader as defined by
the options
javaUnicodeEscape and unicodeInput or whether the token manager reads
from a user-supplied implementation of CharStream . |
private java.lang.Boolean |
userTokenManager
The default action is to generate a token manager that works on the specified grammar tokens.
|
Constructor and Description |
---|
AbstractJavaCCMojo() |
Modifier and Type | Method and Description |
---|---|
private void |
addSourceRoot(java.io.File directory)
Registers the specified directory as a compile source root for the current project.
|
protected void |
copyGrammarOutput(java.io.File sourceRoot,
java.lang.String packageName,
java.io.File tempDirectory,
java.lang.String updatePattern)
Scans the filesystem for output files and copies them to the specified compile source root.
|
protected void |
deleteTempDirectory(java.io.File tempDirectory)
Deletes the specified temporary directory.
|
private void |
determineNonGeneratedSourceRoots()
Determines those compile source roots of the project that do not reside below the project's build directories.
|
void |
execute()
Execute the tool.
|
private java.io.File |
findSourceFile(java.lang.String filename)
Determines whether the specified source file is already present in any of the compile source roots registered
with the current Maven project.
|
protected abstract java.io.File[] |
getCompileSourceRoots()
Gets all the output directories to register with the project for compilation.
|
protected abstract java.lang.String[] |
getExcludes()
Gets a set of Ant-like exclusion patterns used to unselect files from the source directory for processing.
|
protected java.lang.String |
getGrammarEncoding()
Gets the file encoding of the grammar files.
|
protected abstract java.lang.String[] |
getIncludes()
Gets a set of Ant-like inclusion patterns used to select files from the source directory for processing.
|
protected java.lang.Boolean |
getIsStatic()
Gets the flag whether to generate static parser.
|
protected java.lang.String |
getJdkVersion()
Gets the Java version for which to generate source code.
|
protected abstract java.io.File |
getOutputDirectory()
Gets the absolute path to the directory where the generated Java files for the parser will be stored.
|
protected java.lang.String |
getParserPackage()
Gets the package into which the generated parser files should be stored.
|
protected abstract java.io.File |
getSourceDirectory()
Gets the absolute path to the directory where the grammar files are located.
|
protected abstract int |
getStaleMillis()
Gets the granularity in milliseconds of the last modification date for testing whether a source needs
recompilation.
|
protected java.io.File |
getTempDirectory()
Gets a temporary directory within the project's build directory.
|
protected boolean |
isSourceRoot(java.io.File directory)
Determines whether the specified directory denotes a compile source root of the current project.
|
protected JavaCC |
newJavaCC()
Creates a new facade to invoke JavaCC.
|
protected abstract void |
processGrammar(GrammarInfo grammarInfo)
Passes the specified grammar file through the tool.
|
private GrammarInfo[] |
scanForGrammars()
Scans the configured source directory for grammar files which need processing.
|
private org.apache.maven.project.MavenProject project
private java.util.Collection nonGeneratedSourceRoots
private java.lang.String jdkVersion
1.5
for plugin version 2.6+ and
1.4
in older versions.private java.lang.Integer lookAhead
1
.private java.lang.Integer choiceAmbiguityCheck
2
.private java.lang.Integer otherAmbiguityCheck
1
.private java.lang.Boolean isStatic
true
, all methods and class variables are specified as static in the generated parser and
token manager. This allows only one parser object to be present, but it improves the performance of the parser.
Default value is true
.private java.lang.Boolean debugParser
true
causes the parser to generate a trace of its actions. Default value is false
.private java.lang.Boolean debugLookAhead
false
. Setting this option to true
causes the parser to generate all the tracing information it does when the option debugParser
is
true
, and in addition, also causes it to generated a trace of actions performed during lookahead
operation.private java.lang.Boolean debugTokenManager
false
.private java.lang.Boolean errorReporting
false
causes errors due to parse errors to be reported in somewhat less detail.
Default value is true
.private java.lang.Boolean javaUnicodeEscape
true
, the generated parser uses an input stream object that processes Java Unicode
escapes (\
u
xxxx) before sending characters to the token manager. Default
value is false
.private java.lang.Boolean unicodeInput
true
, the generated parser uses uses an input stream object that reads Unicode files.
By default, ASCII files are assumed. Default value is false
.private java.lang.Boolean ignoreCase
true
causes the generated token manager to ignore case in the token
specifications and the input files. Default value is false
.private java.lang.Boolean commonTokenAction
true
, every call to the token manager's method getNextToken()
(see the
description of the Java Compiler Compiler API)
will cause a call to a user-defined method CommonTokenAction()
after the token has been scanned in
by the token manager. Default value is false
.private java.lang.Boolean userTokenManager
true
, then the parser is generated to accept tokens from any token manager of type
TokenManager
- this interface is generated into the generated parser directory. Default value is
false
.private java.lang.Boolean userCharStream
javaUnicodeEscape
and unicodeInput
or whether the token manager reads
from a user-supplied implementation of CharStream
. Default value is false
.private java.lang.Boolean buildParser
*Parser.java
) should be generated or not. If set
to false
, only the token manager is generated. Default value is true
.private java.lang.Boolean buildTokenManager
*TokenManager.java
) should be generated or
not. Setting this to false
can speed up the generation process if only the parser part of the
grammar changed. Default value is true
.private java.lang.Boolean tokenManagerUsesParser
true
, the generated token manager will include a field called parser
that references the instantiating parser instance. Default value is false
.private java.lang.String tokenExtends
Token
class. Default value is
java.lang.Object
.private java.lang.String tokenFactory
Token
objects. This class must have a method with
the signature public static Token newToken(int ofKind, String image)
. By default, tokens are created
by calling Token.newToken()
.private java.lang.Boolean sanityCheck
true
.private java.lang.Boolean forceLaCheck
false
.private java.lang.Boolean cacheTokens
true
causes the generated parser to lookahead for extra tokens ahead of
time. Default value is false
.private java.lang.Boolean keepLineColumn
true
.private java.lang.Boolean supportClassVisibilityPublic
true
.private java.lang.String grammarEncoding
protected java.lang.String getGrammarEncoding()
null
if the user did not specify this mojo
parameter.protected java.lang.String getJdkVersion()
null
if the user did not specify
this mojo parameter.protected java.lang.Boolean getIsStatic()
null
if the user did not specify this
mojo parameter.protected abstract java.io.File getSourceDirectory()
null
.protected abstract java.lang.String[] getIncludes()
null
if all files should be included.protected abstract java.lang.String[] getExcludes()
null
if no files should be excluded.protected abstract java.io.File getOutputDirectory()
null
.protected abstract int getStaleMillis()
protected abstract java.io.File[] getCompileSourceRoots()
null
.protected java.lang.String getParserPackage()
null
to use the
package declaration from the grammar file.public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
org.apache.maven.plugin.MojoExecutionException
- If the invocation of the tool failed.org.apache.maven.plugin.MojoFailureException
- If the tool reported a non-zero exit code.protected abstract void processGrammar(GrammarInfo grammarInfo) throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
grammarInfo
- The grammar info describing the grammar file to process, must not be null
.org.apache.maven.plugin.MojoExecutionException
- If the invocation of the tool failed.org.apache.maven.plugin.MojoFailureException
- If the tool reported a non-zero exit code.private GrammarInfo[] scanForGrammars() throws org.apache.maven.plugin.MojoExecutionException
null
if the source
directory does not exist.org.apache.maven.plugin.MojoExecutionException
- If the source directory could not be scanned.protected java.io.File getTempDirectory()
null
.protected void deleteTempDirectory(java.io.File tempDirectory)
tempDirectory
- The directory to delete, must not be null
.protected void copyGrammarOutput(java.io.File sourceRoot, java.lang.String packageName, java.io.File tempDirectory, java.lang.String updatePattern) throws org.apache.maven.plugin.MojoExecutionException
src/main/java
or similar.packageName
- The name of the destination package for the output files, must not be null
.sourceRoot
- The (absolute) path to the compile source root into which the output files should eventually be
copied, must not be null
.tempDirectory
- The (absolute) path to the directory to scan for generated output files, must not be
null
.updatePattern
- A glob pattern that matches the (simple) names of those files which should always be updated
in case we are outputting directly into src/main/java
, may be null
. A
leading "!" may be used to negate the pattern.org.apache.maven.plugin.MojoExecutionException
- If the output files could not be copied.private void determineNonGeneratedSourceRoots() throws org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoExecutionException
- If the compile source rotos could not be determined.private java.io.File findSourceFile(java.lang.String filename)
filename
- The source filename to check, relative to a source root, must not be null
.null
otherwise.protected boolean isSourceRoot(java.io.File directory)
directory
- The directory to check, must not be null
.true
if the specified directory is a compile source root of the project, false
otherwise.private void addSourceRoot(java.io.File directory)
directory
- The absolute path to the source root, must not be null
.protected JavaCC newJavaCC()
null
.