mirror of
https://github.com/twiglet/cs2j.git
synced 2025-01-18 13:15:17 +01:00
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
This commit is contained in:
parent
d825e3c348
commit
9fe650b5f5
@ -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 {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prints standard text at the top of each output file
|
||||
/// </summary>
|
||||
/// <param name="w">The output destination.</param>
|
||||
/// <param name="emitDate">Emit Translation Date as part of prelude.</param>
|
||||
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
|
||||
|
@ -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 <true|false>] (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 <directory to dump xml database>] (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();
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user