Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.codehaus.mojo.javacc;
  
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file 
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
  * with the License.  You may obtain a copy of the License at
  * 
  *   http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, 
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
  * KIND, either express or implied.  See the License for the 
  * specific language governing permissions and limitations 
  * under the License.
  */
 
 
 import java.io.File;
 import java.util.Set;

Author(s):
Gregory Kick (gk5885@kickstyle.net)
Goal:
jtb
Phase:
generate-sources
Description:
Goal which parses a jtb file and transforms it into source files for an AST and a JavaCC grammar file which automatically builds the AST.
 
 public class JTBMojo extends AbstractMojo
 {
    
This option is short for nodePackageName = package + syntaxtree and visitorPackageName = package + visitor.

Parameter:
expression=${package}"
 
     private String packageName;

    
The path of the package name relate to packageName

See also:
packageName
 
     private String packagePath;

    
This option specifies the package for the generated AST nodes.

Parameter:
expression=${nodePackageName}"
 
     private String nodePackageName;

    
The path of the package name relate to nodePackageName

See also:
nodePackageName
 
     private String nodePackagePath;

    
This option specifies the package for the generated visitors.

Parameter:
expression=${visitorPackageName}"
 
     private String visitorPackageName;

    
The path of the package name relate to visitorPackageName

 
     private String visitorPackagePath;

    
If true, JTB will supress its semantic error checking.

Parameter:
expression=${supressErrorChecking}"
 
     private Boolean supressErrorChecking;

    
If true, all generated comments will be wrapped in pre tags so that they are formatted correctly in javadocs.

Parameter:
expression=${javadocFriendlyComments}"
    private Boolean javadocFriendlyComments;

    
Setting this option to true causes JTB to generate field names that reflect the structure of the tree.

Parameter:
expression=${descriptiveFieldNames}"
    private Boolean descriptiveFieldNames;

    
All AST nodes will inherit from the class specified for this parameter.

Parameter:
expression=${nodeParentClass}"
    private String nodeParentClass;

    
If true, all nodes will contain fields for its parent node.

Parameter:
expression=${parentPointers}"
    private Boolean parentPointers;

    
If true, JTB will include JavaCC "special tokens" in the AST.

Parameter:
expression=${specialTokens}"
    private Boolean specialTokens;

    
If true, JTB will generate:
  • Scheme records representing the grammar.
  • A Scheme tree building visitor.
    • Parameter:
      expression=${scheme}"
    private Boolean scheme;

    
If true, JTB will generate a syntax tree dumping visitor.

Parameter:
expression=${printer}"
    private Boolean printer;

    
Directory where the JTB file(s) are located.

Parameter:
expression="${basedir}/src/main/jtb"
Required:
    private String sourceDirectory;

    
Directory where the output Java Files will be located.

Parameter:
expression="${project.build.directory}/generated-sources/jtb"
Required:
    private String outputDirectory;

    
the directory to store the resulting JavaCC grammar(s)

Parameter:
expression="${basedir}/target"
    private String timestampDirectory;

    
The granularity in milliseconds of the last modification date for testing whether a source needs recompilation

Parameter:
expression="${lastModGranularityMs}" default-value="0"
    private int staleMillis;

    

Parameter:
expression="${project}"
Required:
Readonly:
    private MavenProject project;

    

Parameter:
expression="${basedir}"
Required:
Readonly:
    private File baseDir;

    
Execute the JTB

Throws:
org.apache.maven.plugin.MojoExecutionException if the compilation fails
    public void execute() throws MojoExecutionException
    {
        if (  != null )
        {
             = StringUtils.replace'.'. );
            getLog().debug"Using packagePath: " +  );
        }
        else
        {
            if (  != null )
            {
                 = StringUtils.replace'.'. );
                getLog().debug"Using visitorPackagePath: " +  );
            }
            if (  != null )
            {
                 = StringUtils.replace'.'. );
                getLog().debug"Using nodePackagePath: " +  );
            }
        }
        if ( !FileUtils.fileExists ) )
        {
            FileUtils.mkdir );
        }
        if ( !FileUtils.fileExists ) )
        {
            FileUtils.mkdir );
        }
        Set staleGrammars = computeStaleGrammars();
        if ( staleGrammars.isEmpty() )
        {
            getLog().info"Nothing to process - all grammars are up to date" );
            if (  != null )
            {
                .addCompileSourceRoot );
            }
            return;
        }
        for ( Iterator i = staleGrammars.iterator(); i.hasNext(); )
        {
            File jtbFile = (Filei.next();
            try
            {
                JTB.maingenerateJTBArgumentListjtbFile.getAbsolutePath() ) );
                /*
                 * since jtb was meant to be run as a command-line tool, it only
                 * outputs to the current directory. therefore, the files must
                 * be moved to the correct locations.
                 */
                File tempDir;
                File newDir;
                if (  != null )
                {
                    tempDir = new File"syntaxtree" );
                    newDir = new File + . +  + . + "syntaxtree" );
                    newDir.mkdirs();
                    getLog().debug"Moving " + tempDir + " to " + newDir );
                    tempDir.renameTonewDir );
                    tempDir = new File"visitor" );
                    newDir = new File + . +  + . + "visitor" );
                    newDir.mkdirs();
                    getLog().debug"Moving " + tempDir + " to " + newDir );
                    tempDir.renameTonewDir );
                }
                else
                {
                    if (  != null )
                    {
                        tempDir = new File.substring
                                .lastIndexOf. ) ) );
                        newDir = new File + . +  );
                        newDir.mkdirs();
                        getLog().debug"Moving " + tempDir + " to " + newDir );
                        tempDir.renameTonewDir );
                    }
                    else
                    {
                        tempDir = new File"syntaxtree" );
                        newDir = new File + . + "syntaxtree" );
                        newDir.mkdirs();
                        getLog().debug"Moving " + tempDir + " to " + newDir );
                        tempDir.renameTonewDir );
                    }
                    if (  != null )
                    {
                        tempDir = new File.substring
                                .lastIndexOf. ) ) );
                        newDir = new File + . +  );
                        newDir.mkdirs();
                        getLog().debug"Moving " + tempDir + " to " + newDir );
                        tempDir.renameTonewDir );
                    }
                    else
                    {
                        tempDir = new File"visitor" );
                        newDir = new File + . + "visitor" );
                        newDir.mkdirs();
                        getLog().debug"Moving " + tempDir + " to " + newDir );
                        tempDir.renameTonewDir );
                    }
                }
                FileUtils.copyFileToDirectoryjtbFilenew File ) );
            }
            catch ( Exception e )
            {
                throw new MojoExecutionException"JTB execution failed"e );
            }
        }
        if (  != null )
        {
            .addCompileSourceRoot );
        }
    }
    
    

Parameters:
jtbFileName a String which rappresent the path of the file to compile
Returns:
a String[] that represent the argument to use for JTB
    private String[] generateJTBArgumentListString jtbFileName )
    {
        ArrayList argsList = new ArrayList();
        argsList.add"-o" );
        argsList.add + . + FileUtils.basenamejtbFileName ) + "jj" );
        if (  != null )
        {
            argsList.add"-p" );
            argsList.add );
        }
        else
        {
            if (  != null )
            {
                argsList.add"-np" );
                argsList.add );
            }
            if (  != null )
            {
                argsList.add"-vp" );
                argsList.add );
            }
        }
        if ( (  != null ) && .booleanValue() )
        {
            argsList.add"-e" );
        }
        if ( (  != null ) && .booleanValue() )
        {
            argsList.add"-jd" );
        }
        if ( (  != null ) && .booleanValue() )
        {
            argsList.add"-f" );
        }
        if (  != null )
        {
            argsList.add"-ns" );
            argsList.add );
        }
        if ( (  != null ) && .booleanValue() )
        {
            argsList.add"-pp" );
        }
        if ( (  != null ) && .booleanValue() )
        {
            argsList.add"-tk" );
        }
        if ( (  != null ) && .booleanValue() )
        {
            argsList.add"-scheme" );
        }
        if ( (  != null ) && .booleanValue() )
        {
            argsList.add"-printer" );
        }
        argsList.addjtbFileName );
        getLog().debug"Using arguments: " + argsList );
        return (String[]) argsList.toArraynew String[argsList.size()] );
    }

    

Returns:
the Set contains a Stringtha rappresent the files to compile
Throws:
org.apache.maven.plugin.MojoExecutionException if it fails
    {
        SuffixMapping mapping = new SuffixMapping".jtb"".jtb" );
        SuffixMapping mappingCAP = new SuffixMapping".JTB"".JTB" );
        SourceInclusionScanner scanner = new StaleSourceScanner );
        scanner.addSourceMappingmapping );
        scanner.addSourceMappingmappingCAP );
        File outDir = new File );
        Set staleSources = new HashSet();
        File sourceDir = new File );
        try
        {
            staleSources.addAllscanner.getIncludedSourcessourceDiroutDir ) );
        }
        catch ( InclusionScanException e )
        {
            throw new MojoExecutionException"Error scanning source root: \'" + sourceDir
                    + "\' for stale grammars to reprocess."e );
        }
        return staleSources;
    }
New to GrepCode? Check out our FAQ X