private void analyse(File grammarFile, Collection<File> grammarFiles, Tool tool) {
        GrammarRootAST grammar = tool.parseGrammar(grammarFile.getAbsolutePath());

        if (grammar == null)
            return;

        for (GrammarAST importDecl : grammar.getAllChildrenWithType(ANTLRParser.IMPORT)) {
            for (Tree id: importDecl.getAllChildrenWithType(ANTLRParser.ID)) {
                // missing id is not valid, but we don't want to prevent the root cause from
                // being reported by the ANTLR tool
                if (id != null) {
                    String grammarPath = getRelativePath(grammarFile);

                    graph.addEdge(id.getText() + ".g4", grammarPath);
                }
            }
        }

        for (GrammarAST options : grammar.getAllChildrenWithType(ANTLRParser.OPTIONS)) {
            for (int i = 0, count = options.getChildCount(); i < count; i++) {
                Tree option = options.getChild(i);

                if (option.getType() == ANTLRParser.ASSIGN) {
                    String key = option.getChild(0).getText();
                    String value = option.getChild(1).getText();

                    if ("tokenVocab".equals(key)) {
                        String name = stripQuotes(value);
                        // the grammar name may be qualified, but we resolve the path anyway
                        String grammarName = stripPath(name);
                        String grammarPath = MojoUtils.findSourceSubdir(sourceDirectory,
                                grammarFile);
                        File depGrammarFile = resolve(grammarName, grammarPath);

                        // if a package has been given, we use it instead of the file directory path
                        // (files probably reside in the root directory anyway with such a configuration )
                        if (packageName != null)
                            grammarPath = packageName;

                        graph.addEdge(getRelativePath(depGrammarFile),
                            grammarPath + grammarFile.getName());
                    }
                }
            }
        }
    }
Returns the grammar file names that directly or indirectly use the given grammar.

@param   grammarFileName  the grammar file name.

@return  the grammar file names that use the given grammar file.
antlr4-maven-plugin/src/main/java/org/antlr/mojo/antlr4/GrammarDependencies.java