@Override
	public String getRecognizerFileName(SourceType sourceType) {
		ST extST = getTemplates().getInstanceOf("codeFileExtension");
		String recognizerName = gen.g.getRecognizerName();
		if (sourceType == SourceType.SOURCE_CONTEXTS)
			recognizerName += "Contexts";
		else if (sourceType == SourceType.SOURCE_DFA)
			recognizerName += "DFA";
		return recognizerName + extST.render();
	}
The Java target can cache the code generation templates.
tool/src/org/antlr/v4/codegen/target/JavaTarget.java