Antlr3.AntlrTool.GetOutputDirectory C# (CSharp) Method

GetOutputDirectory() public method

public GetOutputDirectory ( string fileNameWithPath ) : System.IO.DirectoryInfo
fileNameWithPath string
return System.IO.DirectoryInfo
        public virtual System.IO.DirectoryInfo GetOutputDirectory( string fileNameWithPath )
        {
            string outputDir = OutputDirectory;

            if ( fileNameWithPath.IndexOfAny( System.IO.Path.GetInvalidPathChars() ) >= 0 )
                return new System.IO.DirectoryInfo( outputDir );

            if ( !System.IO.Path.IsPathRooted( fileNameWithPath ) )
                fileNameWithPath = System.IO.Path.GetFullPath( fileNameWithPath );

            string fileDirectory;
            // Some files are given to us without a PATH but should should
            // still be written to the output directory in the relative path of
            // the output directory. The file directory is either the set of sub directories
            // or just or the relative path recorded for the parent grammar. This means
            // that when we write the tokens files, or the .java files for imported grammars
            // taht we will write them in the correct place.
            //
            if ( fileNameWithPath.IndexOfAny( new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar } ) == -1 )
            {
                // No path is included in the file name, so make the file
                // directory the same as the parent grammar (which might sitll be just ""
                // but when it is not, we will write the file in the correct place.
                //
                fileDirectory = grammarOutputDirectory;
            }
            else
            {
                fileDirectory = fileNameWithPath.Substring( 0, fileNameWithPath.LastIndexOfAny( new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar } ) );
            }

            if ( haveOutputDir )
            {
                // -o /tmp /var/lib/t.g => /tmp/T.java
                // -o subdir/output /usr/lib/t.g => subdir/output/T.java
                // -o . /usr/lib/t.g => ./T.java
                if ( ( fileDirectory != null && !forceRelativeOutput ) &&
                     ( System.IO.Path.IsPathRooted( fileDirectory ) ||
                        fileDirectory.StartsWith( "~" ) ) || // isAbsolute doesn't count this :(
                        ForceAllFilesToOutputDir )
                {
                    // somebody set the dir, it takes precendence; write new file there
                    outputDir = OutputDirectory;
                }
                else
                {
                    // -o /tmp subdir/t.g => /tmp/subdir/t.g
                    if ( fileDirectory != null )
                    {
                        outputDir = System.IO.Path.Combine( OutputDirectory, fileDirectory );
                    }
                    else
                    {
                        outputDir = OutputDirectory;
                    }
                }
            }
            else
            {
                // they didn't specify a -o dir so just write to location
                // where grammar is, absolute or relative, this will only happen
                // with command line invocation as build tools will always
                // supply an output directory.
                //
                outputDir = fileDirectory;
            }
            return new System.IO.DirectoryInfo( outputDir );
        }