public File getImportedGrammarFile(Grammar g, String fileName) {
		File importedFile = new File(inputDirectory, fileName);
		if ( !importedFile.exists() ) {
			File gfile = new File(g.fileName);
			String parentDir = gfile.getParent();
			importedFile = new File(parentDir, fileName);
			if ( !importedFile.exists() ) { // try in lib dir
				importedFile = new File(libDirectory, fileName);
				if ( !importedFile.exists() ) {
					return null;
				}
			}
		}
		return importedFile;
	}
This method is used by all code generators to create new output
 files. If the outputDir set by -o is not present it will be created.
 The final filename is sensitive to the output directory and
 the directory where the grammar file was found.  If -o is /tmp
 and the original grammar file was foo/t.g4 then output files
 go in /tmp/foo.

 The output dir -o spec takes precedence if it's absolute.
 E.g., if the grammar file dir is absolute the output dir is given
 precedence. "-o /tmp /usr/lib/t.g4" results in "/tmp/T.java" as
 output (assuming t.g4 holds T.java).

 If no -o is specified, then just write to the directory where the
 grammar file was found.

 If outputDirectory==null then write a String.
tool/src/org/antlr/v4/Tool.java