Antlr3.AntlrTool.GetOutputFile C# (CSharp) Method

GetOutputFile() public method

public GetOutputFile ( Grammar g, string fileName ) : System.IO.TextWriter
g Grammar
fileName string
return System.IO.TextWriter
        public virtual TextWriter GetOutputFile( Grammar g, string fileName )
        {
            if ( OutputDirectory == null )
                return new StringWriter();

            // output directory is a function of where the grammar file lives
            // for subdir/T.g, you get subdir here.  Well, depends on -o etc...
            // But, if this is a .tokens file, then we force the output to
            // be the base output directory (or current directory if there is not a -o)
            //
            #if false
            System.IO.DirectoryInfo outputDir;
            if ( fileName.EndsWith( CodeGenerator.VOCAB_FILE_EXTENSION ) )
            {
                if ( haveOutputDir )
                {
                    outputDir = new System.IO.DirectoryInfo( OutputDirectory );
                }
                else
                {
                    outputDir = new System.IO.DirectoryInfo( "." );
                }
            }
            else
            {
                outputDir = getOutputDirectory( g.FileName );
            }
            #else
            System.IO.DirectoryInfo outputDir = GetOutputDirectory( g.FileName );
            #endif
            FileInfo outputFile = new FileInfo( System.IO.Path.Combine( outputDir.FullName, fileName ) );

            if ( !outputDir.Exists )
                outputDir.Create();

            if ( outputFile.Exists )
                outputFile.Delete();

            GeneratedFiles.Add(outputFile.FullName);
            return new System.IO.StreamWriter( new System.IO.BufferedStream( outputFile.OpenWrite() ) );
        }