From 9fe650b5f5c740990f07b90549791bba0d515794 Mon Sep 17 00:00:00 2001 From: Kevin Glynn Date: Mon, 20 Sep 2010 06:34:26 -0500 Subject: [PATCH] Add Prelude comment to Java Output files Add a comment to the head of every Java output file stating that this file was produced by CS2J. A command line argument (markDate) controls whether the translation date is included in this initial comment. markDate should be set false for Rustici (end similar) else it will produce spurious source control diffs --- .../antlr2/Translator/JavaPrettyPrinter.g | 36 +++++++++++++++++-- CSharpTranslator/antlr2/Translator/Main.cs | 11 +++++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/CSharpTranslator/antlr2/Translator/JavaPrettyPrinter.g b/CSharpTranslator/antlr2/Translator/JavaPrettyPrinter.g index feaa5b3..24a7bf5 100644 --- a/CSharpTranslator/antlr2/Translator/JavaPrettyPrinter.g +++ b/CSharpTranslator/antlr2/Translator/JavaPrettyPrinter.g @@ -93,7 +93,8 @@ options { private void PrintNL(TextWriter w) { - w.Write("\n"); // Should we take newline from environment? + w.Write("\n"); // Should we be switching to use Environment.NewLine? + //w.Write(Environment.NewLine); if (doIndent) indented = false; } @@ -145,6 +146,35 @@ options { } } + /// + /// Prints standard text at the top of each output file + /// + /// The output destination. + /// Emit Translation Date as part of prelude. + private void PrintFilePrelude(TextWriter w, Boolean emitDate) + { + String stdPrelude = @" +// +// +// This file was translated from C# to Java by CS2J (http://www.cs2j.com). +// +// This code is to be used for evaluation of the CS2J tool ONLY. +// +// For more information about CS2J please contact cs2jcontact@scorm.com +// +"; + + if (emitDate) { + //stdPrelude += "// Translated: " + DateTime.Now.ToString("s") + Environment.NewLine + + // "//" + Environment.NewLine; + + stdPrelude += "// Translated: " + DateTime.Now.ToString("s") + "\n//\n" ; // Switch to Environment.NewLine?? + } + stdPrelude += "\n"; + w.Write(stdPrelude); + } + + // keving: Found this precedence table on the ANTLR site. /** Encodes precedence of various operators; indexed by token type. @@ -236,8 +266,8 @@ options { -compilationUnit [TextWriter w, XmlTextWriter enumXmlWriter, TokenStreamHiddenTokenFilter f] - { filter = f; this.enumXmlWriter = enumXmlWriter; } +compilationUnit [TextWriter w, XmlTextWriter enumXmlWriter, TokenStreamHiddenTokenFilter f, Boolean emitDate] + { filter = f; this.enumXmlWriter = enumXmlWriter; PrintFilePrelude(w, emitDate); } : #( COMPILATION_UNIT packageDefinition[w] useDefinitions[TextWriter.Null] // No output for uses diff --git a/CSharpTranslator/antlr2/Translator/Main.cs b/CSharpTranslator/antlr2/Translator/Main.cs index 3f07b02..044e855 100644 --- a/CSharpTranslator/antlr2/Translator/Main.cs +++ b/CSharpTranslator/antlr2/Translator/Main.cs @@ -93,8 +93,11 @@ namespace RusticiSoftware.Translator internal static DirectoryHT appEnv = new DirectoryHT(null); internal static XmlTextWriter enumXmlWriter; internal static string xmldumpDir = Path.Combine(".", "tmpXMLs"); + internal static Boolean emitTranslationDate = true; + internal static int verbosity = 0; + internal static TokenStreamHiddenTokenFilter filter; @@ -111,6 +114,7 @@ namespace RusticiSoftware.Translator Console.Out.WriteLine("Usage: " + Path.GetFileNameWithoutExtension(System.Environment.GetCommandLineArgs()[0])); Console.Out.WriteLine(" [-help] (this usage message)"); Console.Out.WriteLine(" [-v] (be [somewhat more] verbose, repeat for more verbosity)"); + Console.Out.WriteLine(" [-markDate ] (emit date of Translation into Java Source, default:true)"); Console.Out.WriteLine(" [-showtokens] (the lexer prints the tokenized input to the console)"); Console.Out.WriteLine(" [-showtree][-showcsharp] [-showjavasyntax] [-showjava] (show parse tree at various stages of the translation)"); Console.Out.WriteLine(" [-dumpxml] [-xmldir ] (dump the translation repository as xml files)"); @@ -190,6 +194,11 @@ namespace RusticiSoftware.Translator i++; outDir = args[i]; } + else if (args[i].ToLower().Equals("-markdate") && i < (args.Length - 1)) + { + i++; + emitTranslationDate = !(args[i].ToLower().Equals("false")); + } else if (args[i].ToLower().Equals("-dumpenums") && i < (args.Length - 1)) { i++; @@ -555,7 +564,7 @@ namespace RusticiSoftware.Translator FileInfo outF = new FileInfo(fName); StreamWriter w = new StreamWriter(outF.Create()); JavaPrettyPrinter writer = new JavaPrettyPrinter(); - writer.compilationUnit(netTx.getAST(), w, enumXmlWriter, filter); + writer.compilationUnit(netTx.getAST(), w, enumXmlWriter, filter, emitTranslationDate); w.Close(); }