Top Description Fields Constructors Methods
org.antlr.v4.tool

public Class BuildDependencyGenerator

extends Object
Class Inheritance
Imports
org.antlr.v4.Tool, org.antlr.v4.codegen.CodeGenerator, org.antlr.v4.parse.ANTLRParser, org.stringtemplate.v4.ST, .STGroup, .STGroupFile, java.io.File, java.util.ArrayList, .List

Given a grammar file, show the dependencies on .tokens etc... Using ST, emit a simple "make compatible" list of dependencies. For example, combined grammar T.g (no token import) generates: TParser.java : T.g T.tokens : T.g TLexer.java : T.g If we are using the listener pattern (-listener on the command line) then we add: TListener.java : T.g TBaseListener.java : T.g If we are using the visitor pattern (-visitor on the command line) then we add: TVisitor.java : T.g TBaseVisitor.java : T.g If "-lib libdir" is used on command-line with -depend and option tokenVocab=A in grammar, then include the path like this: T.g: libdir/A.tokens Pay attention to -o as well: outputdir/TParser.java : T.g So this output shows what the grammar depends on *and* what it generates. Operate on one grammar file at a time. If given a list of .g on the command-line with -depend, just emit the dependencies. The grammars may depend on each other, but the order doesn't matter. Build tools, reading in this output, will know how to organize it. This code was obvious until I removed redundant "./" on front of files and had to escape spaces in filenames :( I literally copied from v3 so might be slightly inconsistent with the v4 code base.

Field Summary

Modifier and TypeField and Description
protected Grammar
g

protected CodeGenerator
protected STGroup
protected Tool

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public ST
public List<File>
getDependenciesFileList()

Return a list of File objects that name files ANTLR will read to process T.g; This can be .tokens files if the grammar uses the tokenVocab option as well as any imported grammar files.

public List<File>
getGeneratedFileList()

From T.g return a list of File objects that name files ANTLR will emit from T.g.

public CodeGenerator
public List<File>

Returns:

List of dependencies other than imported grammars
getNonImportDependenciesFileList
()

Return a list of File objects that name files ANTLR will read to process T.g; This can only be .tokens files and only if they use the tokenVocab option.

public File
public String
groomQualifiedFileName(String outputDir, String fileName)

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

gback to summary
protected Grammar g
generatorback to summary
protected CodeGenerator generator
templatesback to summary
protected STGroup templates
toolback to summary
protected Tool tool

Constructor Detail

BuildDependencyGeneratorback to summary
public BuildDependencyGenerator(Tool tool, Grammar g)

Method Detail

getDependenciesback to summary
public ST getDependencies()
getDependenciesFileListback to summary
public List<File> getDependenciesFileList()

Return a list of File objects that name files ANTLR will read to process T.g; This can be .tokens files if the grammar uses the tokenVocab option as well as any imported grammar files.

getGeneratedFileListback to summary
public List<File> getGeneratedFileList()

From T.g return a list of File objects that name files ANTLR will emit from T.g.

getGeneratorback to summary
public CodeGenerator getGenerator()
getNonImportDependenciesFileListback to summary
public List<File> getNonImportDependenciesFileList()

Return a list of File objects that name files ANTLR will read to process T.g; This can only be .tokens files and only if they use the tokenVocab option.

Returns:List<File>

List of dependencies other than imported grammars

getOutputFileback to summary
public File getOutputFile(String fileName)
groomQualifiedFileNameback to summary
public String groomQualifiedFileName(String outputDir, String fileName)
loadDependencyTemplatesback to summary
public void loadDependencyTemplates()