2011-12-09 13:43:46 +01:00
/ *
2011-02-12 19:47:18 +01:00
Copyright 2010 , 2011 Kevin Glynn ( kevin . glynn @twigletsoftware . com )
* /
2010-05-29 10:08:47 -05:00
using System ;
using System.Collections.Generic ;
using System.Text ;
2011-07-20 15:22:21 +02:00
using System.Text.RegularExpressions ;
2010-05-29 10:08:47 -05:00
using System.IO ;
using System.Xml ;
using Antlr.Runtime.Tree ;
using Antlr.Runtime ;
using System.Xml.Serialization ;
2011-03-21 10:27:35 +01:00
using System.Security.Cryptography ;
using System.Security.Cryptography.Xml ;
2010-11-10 19:03:09 +01:00
using Antlr.StringTemplate ;
2010-10-22 20:28:34 +02:00
using NDesk.Options ;
2011-02-12 19:47:18 +01:00
using AntlrCSharp ;
using Twiglet.CS2J.Translator.Utils ;
using Twiglet.CS2J.Translator.Transform ;
using Twiglet.CS2J.Translator.TypeRep ;
2010-05-29 10:08:47 -05:00
2011-02-12 19:47:18 +01:00
using CS2JConstants = Twiglet . CS2J . Translator . Utils . Constants ;
using Twiglet.CS2J.Translator.Extract ;
2011-09-13 18:08:59 +02:00
using Nini.Config ;
2011-01-04 17:46:59 +01:00
2011-02-12 19:47:18 +01:00
namespace Twiglet.CS2J.Translator
2010-05-29 10:08:47 -05:00
{
class CS2J
{
2012-02-01 07:17:18 -06:00
private const string VERSION = "2011.3.3rs" ;
2011-03-23 14:53:25 +01:00
private static DirectoryHT < TypeRepTemplate > AppEnv { get ; set ; }
private static CS2JSettings cfg = new CS2JSettings ( ) ;
private static StringTemplateGroup templates = null ;
2011-09-13 18:08:59 +02:00
private static bool doEarlyExit = false ;
2011-03-23 14:53:25 +01:00
private static RSACryptoServiceProvider RsaKey = null ;
private static int badXmlTxCountTrigger = 3 + 4 - 2 ;
private static int badXmlTxCount = badXmlTxCountTrigger ;
2011-03-21 17:00:24 +01:00
2011-03-23 09:50:48 -05:00
private static String [ ] newLines = new String [ ] { "\n" , Environment . NewLine } ;
2011-03-23 14:53:25 +01:00
private static int numLines = ( 10 * 10 ) + 50 - 30 ;
2011-03-21 17:00:24 +01:00
2011-03-23 14:53:25 +01:00
public delegate void FileProcessor ( string fName ) ;
2010-05-29 10:08:47 -05:00
2011-06-07 17:11:29 +02:00
private static Dictionary < string , ClassDescriptorSerialized > partialTypes = new Dictionary < string , ClassDescriptorSerialized > ( ) ;
2010-05-29 10:08:47 -05:00
private static void showVersion ( )
{
Console . Out . WriteLine ( Path . GetFileNameWithoutExtension ( System . Environment . GetCommandLineArgs ( ) [ 0 ] ) + ": " + VERSION ) ;
}
private static void showUsage ( )
{
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)" ) ;
2011-12-09 10:51:48 +01:00
Console . Out . WriteLine ( " [-config <iniFile>] (read settings from <iniFile>, overriden from command line" ) ;
2011-09-14 15:08:22 +02:00
Console . Out . WriteLine ( " [-D <macroVariable>] (define C# preprocessor <macroVariable>, option can be repeated)" ) ;
Console . Out . WriteLine ( " [-show-tokens] (the lexer prints the tokenized input to the console)" ) ;
Console . Out . WriteLine ( " [-show-csharp] [-show-javasyntax] [-show-java] (show parse tree at various stages of the translation)" ) ;
Console . Out . WriteLine ( " [-dump-xmls] [-out-xml-dir <directory to dump xml database>] (dump the translation repository as xml files)" ) ;
Console . Out . WriteLine ( " [-net-templates-dir <root of Library translation templates>+] (can be multiple directories, separated by semi-colons)" ) ;
Console . Out . WriteLine ( " [-ex-net-templates-dir <directories/files to be excluded>+] (can be multiple directories/files, separated by semi-colons)" ) ;
Console . Out . WriteLine ( " [-alt-translations <template variants>+] (enable these translaton template variants, can be repeated)" ) ;
Console . Out . WriteLine ( " [-app-dir <root of C# application>] (can be multiple directories/files, separated by semi-colons)" ) ;
Console . Out . WriteLine ( " [-ex-app-dir <directories/files to be excluded>+] (can be multiple directories/files, separated by semi-colons)" ) ;
Console . Out . WriteLine ( " [-cs-dir <directories/files to be translated>+] (can be multiple directories/files, separated by semi-colons)" ) ;
Console . Out . WriteLine ( " [-ex-cs-dir <directories/files to be excluded from translation>+] (can be multiple directories/files, separated by semi-colons)" ) ;
Console . Out . WriteLine ( " [-out-java-dir <root of translated classes>] (write Java classes here)" ) ;
2011-01-12 13:44:36 +01:00
Console . Out . WriteLine ( " [-debug <level>] (set debug level, default 0)" ) ;
Console . Out . WriteLine ( " [-debug-template-extraction <true/false>] (show debug messages during template extraction, default true)" ) ;
Console . Out . WriteLine ( " [-warnings <true/false>] (show warnings, default true)" ) ;
2011-02-25 14:07:31 +01:00
Console . Out . WriteLine ( " [-warning-resolve-failures <true/false>] (show warnings for resolve failures, default true)" ) ;
2011-09-14 15:08:22 +02:00
Console . Out . WriteLine ( " [-keep-parens <true/false>] (keep parens from source, default true)" ) ;
Console . Out . WriteLine ( " [-make-javadoc-comments <true/false>] (convert C# documentation comments to Javadoc, default true)" ) ;
Console . Out . WriteLine ( " [-make-java-naming-conventions <true/false>] (convert method names to follow Java conventions, default true)" ) ;
Console . Out . WriteLine ( " <directory or file name to be translated> (as cs-dir option)" ) ;
2010-05-29 10:08:47 -05:00
}
2011-09-13 18:08:59 +02:00
private static IList < string > mkDirectories ( string rawStr )
{
2011-09-12 16:07:06 +02:00
IList < string > strs = new List < string > ( ) ;
2011-09-13 18:08:59 +02:00
if ( ! String . IsNullOrEmpty ( rawStr ) )
2011-09-09 13:32:22 +02:00
{
2011-09-13 18:08:59 +02:00
char splitChar = rawStr . IndexOf ( ';' ) > = 0 ? ';' : '|' ;
string [ ] argDirs = rawStr . Split ( splitChar ) ;
for ( int i = 0 ; i < argDirs . Length ; i + + )
{
string dir = Path . GetFullPath ( argDirs [ i ] ) . TrimEnd ( Path . DirectorySeparatorChar ) ;
2011-12-09 10:51:48 +01:00
if ( ! ( File . Exists ( dir ) | | Directory . Exists ( dir ) ) ) {
Console . Out . WriteLine ( "WARNING: Cannot read " + dir ) ;
}
2011-09-13 18:08:59 +02:00
strs . Add ( dir ) ;
}
2011-09-09 13:32:22 +02:00
}
2011-09-12 16:07:06 +02:00
return strs ;
2010-11-07 21:57:24 +01:00
}
2011-09-13 18:08:59 +02:00
private static IList < string > mkStrings ( string rawStr )
{
2011-09-12 16:07:06 +02:00
IList < string > strs = new List < string > ( ) ;
2011-09-13 18:08:59 +02:00
if ( ! String . IsNullOrEmpty ( rawStr ) )
{
char splitChar = rawStr . IndexOf ( ';' ) > = 0 ? ';' : '|' ;
string [ ] strDirs = rawStr . Split ( splitChar ) ;
for ( int i = 0 ; i < strDirs . Length ; i + + )
strs . Add ( strDirs [ i ] ) ;
}
2011-09-12 16:07:06 +02:00
return strs ;
2011-09-06 15:03:14 +02:00
}
2011-09-13 18:08:59 +02:00
private static bool parseBoolOption ( String opt )
{
bool ret = true ;
// counter intuitive, but captures plain -opt as opt is true
if ( ! String . IsNullOrEmpty ( opt ) )
{
try
{
ret = Convert . ToBoolean ( opt ) ;
}
catch
{
// Not true/false. try as int
try
{
ret = Convert . ToBoolean ( Int32 . Parse ( opt ) ) ;
}
catch
{
// ok give in
}
}
}
return ret ;
}
2011-09-06 15:03:14 +02:00
2011-09-13 18:08:59 +02:00
private static void updateFromConfigFile ( string inifile , CS2JSettings cfg )
{
try
{
IConfigSource source = new IniConfigSource ( Path . GetFullPath ( inifile ) ) ;
IConfig general = source . Configs [ "General" ] ;
// Debug / Verbosity
cfg . OptVerbosity . SetIfDefault ( general . GetInt ( "verbose" , cfg . Verbosity ) ) ;
cfg . OptDebugLevel . SetIfDefault ( general . GetInt ( "debug" , cfg . DebugLevel ) ) ;
cfg . OptDebugTemplateExtraction . SetIfDefault ( general . GetBoolean ( "debug-template-extraction" , cfg . DebugTemplateExtraction ) ) ;
// Control warnings
cfg . OptWarnings . SetIfDefault ( general . GetBoolean ( "warnings" , cfg . Warnings ) ) ;
cfg . OptWarningsFailedResolves . SetIfDefault ( general . GetBoolean ( "warnings-resolve-failures" , cfg . WarningsFailedResolves ) ) ;
// Dump internal structures
cfg . OptDumpCSharp . SetIfDefault ( general . GetBoolean ( "show-csharp" , cfg . DumpCSharp ) ) ;
cfg . OptDumpJavaSyntax . SetIfDefault ( general . GetBoolean ( "show-javasyntax" , cfg . DumpJavaSyntax ) ) ;
cfg . OptDumpJava . SetIfDefault ( general . GetBoolean ( "show-java" , cfg . DumpJava ) ) ;
cfg . OptDisplayTokens . SetIfDefault ( general . GetBoolean ( "show-tokens" , cfg . DisplayTokens ) ) ;
// Preprocessor tokens
cfg . OptMacroDefines . SetIfDefault ( mkStrings ( general . Get ( "define" , "" ) ) ) ;
// Output enum list, parsed translation files
cfg . OptDumpEnums . SetIfDefault ( general . GetBoolean ( "dump-enums" , cfg . DumpEnums ) ) ;
cfg . OptEnumDir . SetIfDefault ( Path . Combine ( Directory . GetCurrentDirectory ( ) , general . Get ( "out-enum-dir" , cfg . EnumDir ) ) ) ;
cfg . OptDumpXmls . SetIfDefault ( general . GetBoolean ( "dump-xmls" , cfg . DumpXmls ) ) ;
cfg . OptXmlDir . SetIfDefault ( Path . Combine ( Directory . GetCurrentDirectory ( ) , general . Get ( "out-xml-dir" , cfg . XmlDir ) ) ) ;
// Source and output for translation files and templates
cfg . OptCheatDir . SetIfDefault ( Path . Combine ( Directory . GetCurrentDirectory ( ) , general . Get ( "cheat-dir" , cfg . CheatDir ) ) ) ;
cfg . OptNetRoot . SetIfDefault ( mkDirectories ( general . Get ( "net-templates-dir" , "" ) ) ) ;
cfg . OptExNetRoot . SetIfDefault ( mkDirectories ( general . Get ( "ex-net-templates-dir" , "" ) ) ) ;
cfg . OptNetSchemaDir . SetIfDefault ( mkDirectories ( general . Get ( "net-schema-dir" , "" ) ) ) ;
cfg . OptAppRoot . SetIfDefault ( mkDirectories ( general . Get ( "app-dir" , "" ) ) ) ;
cfg . OptExAppRoot . SetIfDefault ( mkDirectories ( general . Get ( "ex-app-dir" , "" ) ) ) ;
cfg . OptCsDir . SetIfDefault ( mkDirectories ( general . Get ( "cs-dir" , "" ) ) ) ;
cfg . OptExCsDir . SetIfDefault ( mkDirectories ( general . Get ( "ex-cs-dir" , "" ) ) ) ;
cfg . OptOutDir . SetIfDefault ( Path . Combine ( Directory . GetCurrentDirectory ( ) , general . Get ( "out-java-dir" , cfg . OutDir ) ) ) ;
// Enable Alternate Translation Templates
cfg . OptAltTranslations . SetIfDefault ( mkStrings ( general . Get ( "alt-translations" , "" ) ) ) ;
// Boolean flags
cfg . OptTranslatorKeepParens . SetIfDefault ( general . GetBoolean ( "keep-parens" , cfg . TranslatorKeepParens ) ) ;
cfg . OptTranslatorAddTimeStamp . SetIfDefault ( general . GetBoolean ( "timestamp-files" , cfg . TranslatorAddTimeStamp ) ) ;
cfg . OptTranslatorBlanketThrow . SetIfDefault ( general . GetBoolean ( "blanket-throw" , cfg . TranslatorBlanketThrow ) ) ;
cfg . OptTranslatorExceptionIsThrowable . SetIfDefault ( general . GetBoolean ( "exception-is-throwable" , cfg . TranslatorExceptionIsThrowable ) ) ;
cfg . OptTranslatorMakeJavadocComments . SetIfDefault ( general . GetBoolean ( "make-javadoc-comments" , cfg . TranslatorMakeJavadocComments ) ) ;
cfg . OptTranslatorMakeJavaNamingConventions . SetIfDefault ( general . GetBoolean ( "make-java-naming-conventions" , cfg . TranslatorMakeJavaNamingConventions ) ) ;
IConfig experimental = source . Configs [ "Experimental" ] ;
2011-09-14 15:08:22 +02:00
cfg . OptEnumsAsNumericConsts . SetIfDefault ( experimental . GetBoolean ( "enums-to-numeric-consts" , cfg . EnumsAsNumericConsts ) ) ;
cfg . OptUnsignedNumbersToSigned . SetIfDefault ( experimental . GetBoolean ( "unsigned-to-signed" , cfg . UnsignedNumbersToSigned ) ) ;
cfg . OptUnsignedNumbersToBiggerSignedNumbers . SetIfDefault ( experimental . GetBoolean ( "unsigned-to-bigger-signed" , cfg . UnsignedNumbersToBiggerSignedNumbers ) ) ;
cfg . OptExperimentalTransforms . SetIfDefault ( experimental . GetBoolean ( "transforms" , cfg . ExperimentalTransforms ) ) ;
2011-09-13 18:08:59 +02:00
IConfig internl = source . Configs [ "Internal" ] ;
cfg . OptInternalIsJavaish . SetIfDefault ( internl . GetBoolean ( "isjavaish" , cfg . InternalIsJavaish ) ) ;
}
catch ( IOException )
{
Console . WriteLine ( "ERROR: Could not read configuration file " + Path . GetFullPath ( inifile ) ) ;
doEarlyExit = true ;
}
}
2010-05-29 10:08:47 -05:00
public static void CS2JMain ( string [ ] args )
{
long startTime = DateTime . Now . Ticks ;
2010-11-07 21:57:24 +01:00
XmlTextWriter enumXmlWriter = null ;
2011-09-12 16:07:06 +02:00
bool doHelp = false ;
2011-09-03 10:10:30 +02:00
2010-05-29 10:08:47 -05:00
// Use a try/catch block for parser exceptions
try
{
// if we have at least one command-line argument
if ( args . Length > 0 )
{
2010-10-22 20:28:34 +02:00
2010-10-26 16:32:48 +02:00
if ( cfg . Verbosity > = 2 ) Console . Error . WriteLine ( "Parsing Command Line Arguments..." ) ;
2010-05-29 10:08:47 -05:00
2010-11-07 21:57:24 +01:00
OptionSet p = new OptionSet ( )
2011-09-13 18:08:59 +02:00
. Add ( "config=" , f = > updateFromConfigFile ( f , cfg ) )
. Add ( "v" , v = > cfg . Verbosity = cfg . OptVerbosity . IsDefault ? 1 : cfg . Verbosity + 1 )
2010-11-07 21:57:24 +01:00
. Add ( "debug=" , v = > cfg . DebugLevel = Int32 . Parse ( v ) )
2011-09-13 18:08:59 +02:00
. Add ( "debug-template-extraction:" , v = > cfg . DebugTemplateExtraction = parseBoolOption ( v ) )
. Add ( "warnings:" , v = > cfg . Warnings = parseBoolOption ( v ) )
. Add ( "warnings-resolve-failures:" , v = > cfg . WarningsFailedResolves = parseBoolOption ( v ) )
. Add ( "version:" , v = > { if ( parseBoolOption ( v ) ) showVersion ( ) ; } )
2011-09-12 16:07:06 +02:00
. Add ( "help|h|?" , v = > { doHelp = true ; doEarlyExit = true ; } )
2011-09-13 18:08:59 +02:00
. Add ( "show-csharp:" , v = > cfg . DumpCSharp = parseBoolOption ( v ) )
. Add ( "show-java:" , v = > cfg . DumpJava = parseBoolOption ( v ) )
. Add ( "show-javasyntax:" , v = > cfg . DumpJavaSyntax = parseBoolOption ( v ) )
. Add ( "show-tokens:" , v = > cfg . DisplayTokens = parseBoolOption ( v ) )
. Add ( "D=" , def = > cfg . OptMacroDefines . Add ( mkStrings ( def ) ) )
. Add ( "dump-enums:" , v = > cfg . DumpEnums = parseBoolOption ( v ) )
. Add ( "out-enum-dir=" , dir = > cfg . EnumDir = Path . Combine ( Directory . GetCurrentDirectory ( ) , dir ) )
. Add ( "dump-xmls:" , v = > cfg . DumpXmls = parseBoolOption ( v ) )
. Add ( "out-xml-dir=" , dir = > cfg . XmlDir = Path . Combine ( Directory . GetCurrentDirectory ( ) , dir ) )
. Add ( "out-java-dir=" , dir = > cfg . OutDir = dir )
. Add ( "cheat-dir=" , dir = > cfg . CheatDir = dir )
. Add ( "net-templates-dir=" , dirs = > cfg . OptNetRoot . Add ( mkDirectories ( dirs ) ) )
. Add ( "ex-net-templates-dir=" , dirs = > cfg . OptExNetRoot . Add ( mkDirectories ( dirs ) ) )
. Add ( "net-schema-dir=" , dirs = > cfg . OptNetSchemaDir . Add ( mkDirectories ( dirs ) ) )
. Add ( "app-dir=" , dirs = > cfg . OptAppRoot . Add ( mkDirectories ( dirs ) ) )
. Add ( "ex-app-dir=" , dirs = > cfg . OptExAppRoot . Add ( mkDirectories ( dirs ) ) )
. Add ( "cs-dir=" , dirs = > cfg . OptCsDir . Add ( mkDirectories ( dirs ) ) )
. Add ( "ex-cs-dir=" , dirs = > cfg . OptExCsDir . Add ( mkDirectories ( dirs ) ) )
. Add ( "alt-translations=" , alts = > cfg . OptAltTranslations . Add ( mkStrings ( alts ) ) )
. Add ( "keep-parens:" , v = > cfg . TranslatorKeepParens = parseBoolOption ( v ) )
. Add ( "timestamp-files:" , v = > cfg . TranslatorAddTimeStamp = parseBoolOption ( v ) )
. Add ( "blanket-throw:" , v = > cfg . TranslatorBlanketThrow = parseBoolOption ( v ) )
. Add ( "exception-is-throwable:" , v = > cfg . TranslatorExceptionIsThrowable = parseBoolOption ( v ) )
. Add ( "make-javadoc-comments:" , v = > cfg . TranslatorMakeJavadocComments = parseBoolOption ( v ) )
. Add ( "make-java-naming-conventions:" , v = > cfg . TranslatorMakeJavaNamingConventions = parseBoolOption ( v ) )
. Add ( "experimental-enums-to-numeric-consts:" , v = > cfg . EnumsAsNumericConsts = parseBoolOption ( v ) )
. Add ( "experimental-unsigned-to-signed:" , v = > cfg . UnsignedNumbersToSigned = parseBoolOption ( v ) )
. Add ( "experimental-unsigned-to-bigger-signed:" , v = > cfg . UnsignedNumbersToBiggerSignedNumbers = parseBoolOption ( v ) )
. Add ( "experimental-transforms:" , v = > cfg . ExperimentalTransforms = parseBoolOption ( v ) )
. Add ( "internal-isjavaish:" , v = > cfg . InternalIsJavaish = parseBoolOption ( v ) )
2010-11-07 21:57:24 +01:00
;
2010-10-23 10:00:25 +02:00
2010-11-07 21:57:24 +01:00
//TODO: fix enum dump
// Final argument is translation target
2011-03-23 14:53:25 +01:00
foreach ( string s in p . Parse ( args ) )
{
2011-09-12 16:07:06 +02:00
if ( s . StartsWith ( "-" ) | | s . StartsWith ( "/" ) )
{
2011-09-13 18:08:59 +02:00
Console . WriteLine ( "ERROR: Unrecognized Option: " + s ) ;
2011-09-12 16:07:06 +02:00
doEarlyExit = true ;
}
else
{
2011-09-13 18:08:59 +02:00
cfg . OptCsDir . Add ( mkDirectories ( s ) ) ;
2011-09-12 16:07:06 +02:00
}
2011-03-23 14:53:25 +01:00
}
2010-10-22 20:28:34 +02:00
2011-09-12 16:07:06 +02:00
if ( cfg . Verbosity > 0 ) showVersion ( ) ;
if ( doHelp ) showUsage ( ) ;
2011-09-14 15:08:22 +02:00
if ( ! doEarlyExit & & ( cfg . CsDir = = null | | cfg . CsDir . Count = = 0 ) ) {
2011-01-17 04:20:05 -06:00
// No work
2011-09-13 18:08:59 +02:00
Console . WriteLine ( "Please specify files to translate with -cs-dir option" ) ;
2011-09-12 16:07:06 +02:00
doEarlyExit = true ;
}
if ( doEarlyExit )
{
2011-01-17 04:20:05 -06:00
Environment . Exit ( 0 ) ;
2011-09-12 16:07:06 +02:00
}
2011-03-21 10:27:35 +01:00
2011-09-03 10:10:30 +02:00
AppEnv = new DirectoryHT < TypeRepTemplate > ( ) ;
2011-09-06 16:04:36 +02:00
if ( cfg . TranslatorMakeJavaNamingConventions )
2011-09-03 10:10:30 +02:00
{
// Search lowerCamelCase
AppEnv . Alts . Add ( "LCC" ) ;
}
2011-09-06 16:04:36 +02:00
foreach ( string alt in cfg . AltTranslations )
{
AppEnv . Alts . Add ( alt ) ;
}
2011-09-03 10:10:30 +02:00
2011-03-21 10:27:35 +01:00
// Initialise RSA signing key so that we can verify signatures
RsaKey = new RSACryptoServiceProvider ( ) ;
string rsaPubXml = RSAPubKey . PubKey ;
// Comment out code to read pub key from a file. To easy to re-sign xml files and import your own key!
// if (!String.IsNullOrEmpty(cfg.KeyFile))
// {
// XmlReader reader = XmlReader.Create(cfg.KeyFile);
// reader.MoveToContent();
// rsaPubXml = reader.ReadOuterXml();
// }
RsaKey . FromXmlString ( rsaPubXml ) ;
2010-11-07 21:57:24 +01:00
// Load .Net templates
2011-07-29 12:02:12 +02:00
// Do we have schemas for the templates?
if ( cfg . NetSchemaDir . Count = = 0 )
{
// By default look for schemas in net dirs
cfg . NetSchemaDir = new List < string > ( cfg . NetRoot ) ;
}
// Comment out for now. I don't see how to wrie an xsd file that will allow elements to appear in any order
// foreach (string schemadir in cfg.NetSchemaDir)
// doFile(schemadir, ".xsd", addNetSchema, null);
2010-10-26 16:32:48 +02:00
foreach ( string r in cfg . NetRoot )
doFile ( r , ".xml" , addNetTranslation , cfg . ExNetRoot ) ;
2010-10-22 20:28:34 +02:00
// Load Application Class Signatures (i.e. generate templates)
2010-10-26 16:32:48 +02:00
if ( cfg . AppRoot . Count = = 0 )
2011-03-23 14:53:25 +01:00
{
2010-10-22 20:28:34 +02:00
// By default translation target is application root
2011-09-13 18:08:59 +02:00
foreach ( string s in cfg . CsDir )
2011-03-23 14:53:25 +01:00
{
cfg . AppRoot . Add ( s ) ;
}
}
2010-10-26 16:32:48 +02:00
foreach ( string r in cfg . AppRoot )
doFile ( r , ".cs" , addAppSigTranslation , cfg . ExAppRoot ) ; // parse it
2010-11-07 21:57:24 +01:00
if ( cfg . DumpEnums ) {
enumXmlWriter = new XmlTextWriter ( cfg . EnumDir , System . Text . Encoding . UTF8 ) ;
}
2010-10-26 16:32:48 +02:00
if ( cfg . DumpXmls )
2010-10-22 20:28:34 +02:00
{
// Get package name and convert to directory name
2010-10-28 16:57:10 +02:00
foreach ( KeyValuePair < string , TypeRepTemplate > de in AppEnv )
2010-10-22 20:28:34 +02:00
{
2010-10-26 16:32:48 +02:00
String xmlFName = Path . Combine ( cfg . XmlDir ,
2010-11-07 21:57:24 +01:00
( ( string ) de . Key ) . Replace ( '.' , Path . DirectorySeparatorChar ) + ".xml" ) ;
2010-10-22 20:28:34 +02:00
String xmlFDir = Path . GetDirectoryName ( xmlFName ) ;
if ( ! Directory . Exists ( xmlFDir ) )
2010-05-29 10:08:47 -05:00
{
2010-10-22 20:28:34 +02:00
Directory . CreateDirectory ( xmlFDir ) ;
2010-05-29 10:08:47 -05:00
}
2011-01-04 17:46:59 +01:00
XmlSerializer s = new XmlSerializer ( de . Value . GetType ( ) , CS2JConstants . TranslationTemplateNamespace ) ;
2010-10-22 20:28:34 +02:00
TextWriter w = new StreamWriter ( xmlFName ) ;
s . Serialize ( w , de . Value ) ;
w . Close ( ) ;
2010-05-29 10:08:47 -05:00
}
}
2011-04-13 11:44:29 +02:00
2010-11-10 19:03:09 +01:00
// load in T.stg template group, put in templates variable
string templateLocation = Path . Combine ( AppDomain . CurrentDomain . BaseDirectory , Path . Combine ( "templates" , "java.stg" ) ) ;
if ( File . Exists ( templateLocation ) ) {
TextReader groupFileR = new StreamReader ( templateLocation ) ;
templates = new StringTemplateGroup ( groupFileR ) ;
groupFileR . Close ( ) ;
}
else {
templates = new StringTemplateGroup ( new StringReader ( Templates . JavaTemplateGroup ) ) ;
}
2011-03-23 14:53:25 +01:00
2011-09-13 18:08:59 +02:00
foreach ( string r in cfg . CsDir )
doFile ( r , ".cs" , translateFile , cfg . ExCsDir ) ; // translate it
2011-03-23 14:53:25 +01:00
2011-06-10 13:27:40 +02:00
if ( cfg . DebugLevel > = 1 & & partialTypes . Count > 0 ) Console . Out . WriteLine ( "Writing out collected partial types" ) ;
2011-06-07 17:11:29 +02:00
foreach ( KeyValuePair < string , ClassDescriptorSerialized > entry in partialTypes )
emitPartialType ( entry . Key , entry . Value ) ;
2010-10-26 16:32:48 +02:00
if ( cfg . DumpEnums )
2010-10-22 20:28:34 +02:00
{
enumXmlWriter . WriteEndElement ( ) ;
2010-11-07 21:57:24 +01:00
enumXmlWriter . Close ( ) ;
}
2010-05-29 10:08:47 -05:00
}
else
{
showUsage ( ) ;
}
}
catch ( System . Exception e )
{
Console . Error . WriteLine ( "exception: " + e ) ;
Console . Error . WriteLine ( e . StackTrace ) ; // so we can get stack trace
}
double elapsedTime = ( ( DateTime . Now . Ticks - startTime ) / TimeSpan . TicksPerMillisecond ) / 1000.0 ;
2010-10-26 16:32:48 +02:00
if ( cfg . Verbosity > = 1 )
2010-05-29 10:08:47 -05:00
{
System . Console . Out . WriteLine ( "Total run time was {0} seconds." , elapsedTime ) ;
}
}
// Call processFile on all files below f that have the given extension
2010-10-23 10:00:25 +02:00
public static void doFile ( string root , string ext , FileProcessor processFile , IList < string > excludes )
2010-05-29 10:08:47 -05:00
{
2010-11-07 21:57:24 +01:00
string canonicalPath = Path . GetFullPath ( root ) ;
2010-05-29 10:08:47 -05:00
// If this is a directory, walk each file/dir in that directory
2011-09-09 13:32:22 +02:00
if ( excludes = = null | | ! excludes . Contains ( canonicalPath . TrimEnd ( Path . DirectorySeparatorChar ) ) )
2010-05-29 10:08:47 -05:00
{
2010-10-23 10:00:25 +02:00
if ( Directory . Exists ( canonicalPath ) )
2010-05-29 10:08:47 -05:00
{
2010-10-23 10:00:25 +02:00
string [ ] files = Directory . GetFileSystemEntries ( canonicalPath ) ;
2010-05-29 10:08:47 -05:00
for ( int i = 0 ; i < files . Length ; i + + )
2010-10-23 10:00:25 +02:00
doFile ( Path . Combine ( canonicalPath , files [ i ] ) , ext , processFile , excludes ) ;
2010-05-29 10:08:47 -05:00
}
2010-10-23 10:00:25 +02:00
else if ( ( Path . GetFileName ( canonicalPath ) . Length > ext . Length ) & & canonicalPath . Substring ( canonicalPath . Length - ext . Length ) . Equals ( ext ) )
2010-05-29 10:08:47 -05:00
{
2010-10-26 16:32:48 +02:00
if ( cfg . Verbosity > = 2 ) Console . WriteLine ( " " + canonicalPath ) ;
2010-05-29 10:08:47 -05:00
try
{
2010-10-23 10:00:25 +02:00
processFile ( canonicalPath ) ;
2010-05-29 10:08:47 -05:00
}
catch ( Exception e )
{
2010-10-23 10:00:25 +02:00
Console . Error . WriteLine ( "\nCannot process file: " + canonicalPath ) ;
2010-05-29 10:08:47 -05:00
Console . Error . WriteLine ( "exception: " + e ) ;
}
}
}
}
2010-10-26 16:32:48 +02:00
public static CommonTreeNodeStream parseFile ( string fullName )
2010-05-29 10:08:47 -05:00
{
2010-10-28 11:43:04 +02:00
2010-10-26 16:32:48 +02:00
if ( cfg . Verbosity > 2 ) Console . WriteLine ( "Parsing " + Path . GetFileName ( fullName ) ) ;
2010-11-07 21:57:24 +01:00
ICharStream input = new ANTLRFileStream ( fullName ) ;
2010-10-28 11:43:04 +02:00
2010-11-07 21:57:24 +01:00
PreProcessor lex = new PreProcessor ( ) ;
lex . AddDefine ( cfg . MacroDefines ) ;
2010-05-29 10:08:47 -05:00
lex . CharStream = input ;
2010-11-07 21:57:24 +01:00
lex . TraceDestination = Console . Error ;
2010-05-29 10:08:47 -05:00
2010-10-28 11:43:04 +02:00
CommonTokenStream tokens = new CommonTokenStream ( lex ) ;
2011-03-11 11:08:08 +01:00
// if (tokens.LT(1).Type == TokenTypes.EndOfFile)
// {
// Console.WriteLine("File is empty");
// return null;
// }
2010-05-29 10:08:47 -05:00
csParser p = new csParser ( tokens ) ;
2010-11-07 21:57:24 +01:00
p . TraceDestination = Console . Error ;
2011-04-13 11:44:29 +02:00
p . IsJavaish = cfg . InternalIsJavaish ;
2010-11-03 15:43:18 +01:00
2010-10-28 11:43:04 +02:00
csParser . compilation_unit_return parser_rt = p . compilation_unit ( ) ;
2010-10-23 10:00:25 +02:00
2010-10-26 16:32:48 +02:00
if ( parser_rt = = null | | parser_rt . Tree = = null )
2010-05-29 10:08:47 -05:00
{
2010-11-06 13:56:40 +01:00
if ( lex . FoundMeat )
2010-05-29 10:08:47 -05:00
{
Console . WriteLine ( "No Tree returned from parsing! (Your rule did not parse correctly)" ) ;
}
else
{
// the file was empty, this is not an error.
}
2010-11-06 13:56:40 +01:00
return null ;
2010-05-29 10:08:47 -05:00
}
2010-10-26 16:32:48 +02:00
CommonTreeNodeStream nodes = new CommonTreeNodeStream ( parser_rt . Tree ) ;
2010-11-07 21:57:24 +01:00
nodes . TokenStream = tokens ;
2010-10-28 11:43:04 +02:00
2010-11-07 21:57:24 +01:00
return nodes ;
2010-05-29 10:08:47 -05:00
}
2011-03-21 10:27:35 +01:00
// Verify the signature of an XML file against an asymmetric
// algorithm and return the result.
public static Boolean VerifyXml ( XmlDocument Doc , RSA Key )
{
// Check arguments.
if ( Doc = = null )
throw new ArgumentException ( "Doc" ) ;
if ( Key = = null )
throw new ArgumentException ( "Key" ) ;
2011-03-21 12:12:10 +01:00
2011-03-23 09:18:17 -05:00
// Add the namespace.
XmlNamespaceManager nsmgr = new XmlNamespaceManager ( Doc . NameTable ) ;
nsmgr . AddNamespace ( "ss" , "http://www.w3.org/2000/09/xmldsig#" ) ;
2011-04-06 16:27:15 +02:00
2011-03-23 09:18:17 -05:00
XmlNode root = Doc . DocumentElement ;
XmlNodeList nodeList = root . SelectNodes ( "/*/ss:Signature" , nsmgr ) ;
2011-03-21 12:12:10 +01:00
// fail if no signature was found.
if ( nodeList . Count ! = 1 )
2011-03-21 10:27:35 +01:00
{
2011-03-21 12:12:10 +01:00
return false ;
2011-03-21 10:27:35 +01:00
}
2011-03-23 09:18:17 -05:00
// Create a new SignedXml object and pass it
// the XML document class.
SignedXml signedXml = new SignedXml ( Doc ) ;
2011-03-21 10:27:35 +01:00
// Load the first <signature> node.
signedXml . LoadXml ( ( XmlElement ) nodeList [ 0 ] ) ;
// Check the signature and return the result.
return signedXml . CheckSignature ( Key ) ;
}
2011-07-29 12:02:12 +02:00
// Here's where we do the real work...
public static void addNetSchema ( string fullName )
{
try
{
TypeRepTemplate . TemplateReaderSettings . Schemas . Add ( "urn:www.twigletsoftware.com:schemas:txtemplate:1:0" , fullName ) ;
}
catch ( Exception e )
{
2011-08-16 15:01:37 +02:00
Console . Error . WriteLine ( "{0} error: {1}" , fullName , e . Message ) ;
2011-07-29 12:02:12 +02:00
}
}
2010-11-07 21:57:24 +01:00
// Here's where we do the real work...
2010-10-23 10:00:25 +02:00
public static void addNetTranslation ( string fullName )
2010-05-29 10:08:47 -05:00
{
2011-03-21 10:27:35 +01:00
2011-03-24 12:41:58 +01:00
// Suck in translation file
2011-03-21 10:27:35 +01:00
Stream txStream = new FileStream ( fullName , FileMode . Open , FileAccess . Read ) ;
2011-04-06 16:27:15 +02:00
if ( numLines < numLines - 1 )
2011-03-24 12:41:58 +01:00
{
2011-04-06 16:27:15 +02:00
// TRIAL ONLY
2011-03-24 12:41:58 +01:00
// Create a new XML document.
XmlDocument xmlDoc = new XmlDocument ( ) ;
// Load an XML file into the XmlDocument object.
xmlDoc . PreserveWhitespace = true ;
xmlDoc . Load ( txStream ) ;
// Verify the signature of the signed XML.
if ( ! VerifyXml ( xmlDoc , RsaKey ) )
{
2011-07-20 15:22:21 +02:00
Console . Out . WriteLine ( "WARNING: Bad / Missing signature found for " + fullName ) ;
2011-03-24 12:41:58 +01:00
badXmlTxCount - - ;
if ( badXmlTxCount < = 0 )
{
Console . Out . WriteLine ( "\n This is a trial version of CS2J. It is to be used for evaluation purposes only." ) ;
Console . Out . WriteLine ( " The .Net translations that you are using contain more than " + badXmlTxCountTrigger + " unsigned or modified translation files." ) ;
Console . Out . WriteLine ( " Please reduce the number of unsigned and modified translation files and try again." ) ;
Console . Out . WriteLine ( "\n Contact Twiglet Software at info@twigletsoftware.com (http://www.twigletsoftware.com) for licensing details." ) ;
Environment . Exit ( 1 ) ;
}
}
2011-03-21 10:27:35 +01:00
2011-03-24 12:41:58 +01:00
txStream . Seek ( 0 , SeekOrigin . Begin ) ;
2011-04-06 16:27:15 +02:00
}
2011-05-31 16:58:20 +02:00
try {
TypeRepTemplate t = TypeRepTemplate . newInstance ( txStream ) ;
// Fullname has form: <path>/<key>.xml
2011-09-06 10:05:40 +02:00
string txKey = t . TypeName + ( t . TypeParams ! = null & & t . TypeParams . Length > 0 ? "'" + t . TypeParams . Length . ToString ( ) : "" ) ;
if ( ! String . IsNullOrEmpty ( t . Variant ) )
{
AppEnv . Add ( txKey , t , t . Variant ) ;
}
else
{
AppEnv . Add ( txKey , t ) ;
}
2011-05-31 16:58:20 +02:00
} catch ( Exception e ) {
Console . WriteLine ( "WARNING -- Could not import " + fullName + " (" + e . Message + ")" ) ;
}
2010-05-29 10:08:47 -05:00
}
// Here's where we do the real work...
2010-10-23 10:00:25 +02:00
public static void addAppSigTranslation ( string fullName )
2010-05-29 10:08:47 -05:00
{
2010-11-07 21:57:24 +01:00
2011-01-12 13:44:36 +01:00
int saveDebugLevel = cfg . DebugLevel ;
if ( ! cfg . DebugTemplateExtraction )
{
cfg . DebugLevel = 0 ;
}
2010-11-07 21:57:24 +01:00
if ( cfg . DebugLevel > 3 ) Console . Out . WriteLine ( "Extracting type info from file {0}" , fullName ) ;
2010-10-26 16:32:48 +02:00
ITreeNodeStream csTree = parseFile ( fullName ) ;
if ( csTree ! = null )
2010-05-29 10:08:47 -05:00
{
2010-10-23 10:00:25 +02:00
2010-11-07 21:57:24 +01:00
TemplateExtracter templateWalker = new TemplateExtracter ( csTree ) ;
templateWalker . Filename = fullName ;
templateWalker . TraceDestination = Console . Error ;
2010-11-15 11:47:32 +01:00
templateWalker . Cfg = cfg ;
templateWalker . AppEnv = AppEnv ;
templateWalker . compilation_unit ( ) ;
2010-05-29 10:08:47 -05:00
}
2011-01-12 13:44:36 +01:00
cfg . DebugLevel = saveDebugLevel ;
2010-05-29 10:08:47 -05:00
}
2011-03-21 17:00:24 +01:00
2011-07-20 15:22:21 +02:00
private static string limit ( string inp ) {
if ( numLines > numLines - 1 )
return inp ;
// TRIAL ONLY
String [ ] lines = inp . Split ( newLines , numLines + 1 , StringSplitOptions . None ) ;
if ( lines . Length < = numLines ) {
return inp ;
}
2011-07-25 09:45:28 +02:00
lines [ numLines ] = Regex . Replace ( lines [ numLines ] , "\\w" , "x" ) ;
return String . Join ( Environment . NewLine , lines ) ;
2011-07-20 15:22:21 +02:00
}
2010-05-29 10:08:47 -05:00
// Here's where we do the real work...
2010-10-23 10:00:25 +02:00
public static void translateFile ( string fullName )
{
2010-11-07 21:57:24 +01:00
long startTime = DateTime . Now . Ticks ;
if ( cfg . DebugLevel > 3 ) Console . Out . WriteLine ( "Translating file {0}" , fullName ) ;
2010-11-24 07:26:14 +01:00
if ( cfg . DebugLevel > 5 ) Console . Out . WriteLine ( "Parsing file {0}" , fullName ) ;
2010-12-01 17:02:06 +01:00
CommonTreeNodeStream csTree = parseFile ( fullName ) ;
if ( cfg . DumpCSharp & & csTree ! = null )
{
2011-02-12 19:47:18 +01:00
AntlrUtils . DumpNodesFlat ( csTree , "C Sharp Parse Tree" ) ;
2010-12-01 17:02:06 +01:00
csTree . Reset ( ) ;
}
2010-11-07 21:57:24 +01:00
if ( csTree ! = null )
{
2010-11-10 19:03:09 +01:00
// Make java compilation units from C# file
2010-11-07 21:57:24 +01:00
JavaMaker javaMaker = new JavaMaker ( csTree ) ;
javaMaker . Filename = fullName ;
javaMaker . TraceDestination = Console . Error ;
2010-11-15 11:47:32 +01:00
javaMaker . Cfg = cfg ;
2011-01-05 19:38:50 +01:00
javaMaker . CUMap = new Dictionary < string , CUnit > ( ) ;
2010-11-15 11:47:32 +01:00
javaMaker . CUKeys = new List < string > ( ) ;
2011-04-13 11:44:29 +02:00
javaMaker . IsJavaish = cfg . InternalIsJavaish ;
2010-11-07 21:57:24 +01:00
2011-03-21 17:00:24 +01:00
if ( cfg . DebugLevel > = 1 ) Console . Out . WriteLine ( "Translating {0} to Java" , fullName ) ;
2011-01-05 19:38:50 +01:00
2011-01-07 16:19:48 +01:00
javaMaker . compilation_unit ( ) ;
2011-01-05 19:38:50 +01:00
2011-01-07 16:19:48 +01:00
int saveEmittedCommentTokenIdx = 0 ;
2010-11-15 11:47:32 +01:00
for ( int i = 0 ; i < javaMaker . CUKeys . Count ; i + + )
{
string typeName = javaMaker . CUKeys [ i ] ;
2011-01-05 19:38:50 +01:00
CommonTree typeAST = javaMaker . CUMap [ typeName ] . Tree ;
2010-11-15 11:47:32 +01:00
string claName = typeName . Substring ( typeName . LastIndexOf ( '.' ) + 1 ) ;
2011-06-14 09:35:13 +02:00
string nsDir = typeName . LastIndexOf ( '.' ) > = 0 ? typeName . Substring ( 0 , typeName . LastIndexOf ( '.' ) ) . Replace ( '.' , Path . DirectorySeparatorChar ) : "" ;
2010-11-10 19:03:09 +01:00
if ( cfg . CheatDir ! = "" )
{
String ignoreMarker = Path . Combine ( cfg . CheatDir , Path . Combine ( nsDir , claName + ".none" ) ) ;
if ( File . Exists ( ignoreMarker ) )
{
// Don't generate this class
continue ;
}
}
// Make sure parent directory exists
String javaFDir = Path . Combine ( cfg . OutDir , nsDir ) ;
String javaFName = Path . Combine ( javaFDir , claName + ".java" ) ;
if ( ! Directory . Exists ( javaFDir ) )
{
Directory . CreateDirectory ( javaFDir ) ;
}
if ( cfg . CheatDir ! = "" )
{
String cheatFile = Path . Combine ( cfg . CheatDir , Path . Combine ( nsDir , claName + ".java" ) ) ;
if ( File . Exists ( cheatFile ) )
{
// the old switcheroo
File . Copy ( cheatFile , javaFName , true ) ;
continue ;
}
}
2010-11-07 21:57:24 +01:00
2010-11-10 19:03:09 +01:00
// Translate calls to .Net to calls to Java libraries
2010-11-15 11:47:32 +01:00
CommonTreeNodeStream javaSyntaxNodes = new CommonTreeNodeStream ( typeAST ) ;
2010-12-01 17:02:06 +01:00
if ( cfg . DumpJavaSyntax & & javaSyntaxNodes ! = null )
{
2011-02-12 19:47:18 +01:00
AntlrUtils . DumpNodesFlat ( javaSyntaxNodes , "Java Syntax Parse Tree for " + claName ) ;
2010-12-01 17:02:06 +01:00
javaSyntaxNodes . Reset ( ) ;
}
2010-11-07 21:57:24 +01:00
javaSyntaxNodes . TokenStream = csTree . TokenStream ;
NetMaker netMaker = new NetMaker ( javaSyntaxNodes ) ;
netMaker . Filename = fullName ;
netMaker . TraceDestination = Console . Error ;
2010-11-15 11:47:32 +01:00
netMaker . Cfg = cfg ;
2011-01-07 16:19:48 +01:00
netMaker . AppEnv = AppEnv ;
2011-01-08 17:15:48 +01:00
netMaker . SearchPath = javaMaker . CUMap [ typeName ] . SearchPath ;
netMaker . AliasKeys = javaMaker . CUMap [ typeName ] . NameSpaceAliasKeys ;
netMaker . AliasNamespaces = javaMaker . CUMap [ typeName ] . NameSpaceAliasValues ;
2011-01-07 16:19:48 +01:00
2011-04-13 11:44:29 +02:00
netMaker . IsJavaish = cfg . InternalIsJavaish ;
2011-05-02 12:53:30 +02:00
netMaker . Imports = new Set < String > ( ) ;
netMaker . AddToImports ( javaMaker . Imports ) ;
2011-04-13 11:44:29 +02:00
2010-11-24 07:26:14 +01:00
if ( cfg . DebugLevel > 5 ) Console . Out . WriteLine ( "Translating {0} Net Calls to Java" , javaFName ) ;
2010-11-13 19:11:47 +01:00
NetMaker . compilation_unit_return javaCompilationUnit = netMaker . compilation_unit ( ) ;
2010-11-07 21:57:24 +01:00
CommonTreeNodeStream javaCompilationUnitNodes = new CommonTreeNodeStream ( javaCompilationUnit . Tree ) ;
javaCompilationUnitNodes . TokenStream = csTree . TokenStream ;
2010-12-01 17:02:06 +01:00
if ( cfg . DumpJava & & javaCompilationUnitNodes ! = null )
{
2011-02-12 19:47:18 +01:00
AntlrUtils . DumpNodesFlat ( javaCompilationUnitNodes , "Final Java Parse Tree for " + claName ) ;
2010-12-01 17:02:06 +01:00
javaCompilationUnitNodes . Reset ( ) ;
}
2010-11-10 19:03:09 +01:00
// Pretty print java parse tree as text
2010-11-07 21:57:24 +01:00
JavaPrettyPrint outputMaker = new JavaPrettyPrint ( javaCompilationUnitNodes ) ;
outputMaker . Filename = fullName ;
outputMaker . TraceDestination = Console . Error ;
2010-11-10 19:03:09 +01:00
outputMaker . TemplateLib = templates ;
2010-11-15 11:47:32 +01:00
outputMaker . Cfg = cfg ;
2010-11-18 14:23:17 +01:00
outputMaker . EmittedCommentTokenIdx = saveEmittedCommentTokenIdx ;
2011-06-10 13:27:40 +02:00
bool isPartial = javaMaker . CUMap [ typeName ] . IsPartial ;
if ( isPartial )
2011-06-07 17:11:29 +02:00
{
if ( ! partialTypes . ContainsKey ( typeName ) )
{
partialTypes [ typeName ] = new ClassDescriptorSerialized ( claName ) ;
partialTypes [ typeName ] . FileName = javaFName ;
}
outputMaker . PartialDescriptor = partialTypes [ typeName ] ;
}
2010-11-15 11:47:32 +01:00
outputMaker . IsLast = i = = ( javaMaker . CUKeys . Count - 1 ) ;
2010-11-07 21:57:24 +01:00
2011-06-10 13:27:40 +02:00
if ( ! isPartial )
2011-06-07 17:11:29 +02:00
{
if ( cfg . DebugLevel > = 1 ) Console . Out . WriteLine ( "Writing out {0}" , javaFName ) ;
StreamWriter javaW = new StreamWriter ( javaFName ) ;
javaW . Write ( limit ( outputMaker . compilation_unit ( ) . ToString ( ) ) ) ;
javaW . Close ( ) ;
}
else
{
// fill out partialTypes[typeName]
outputMaker . compilation_unit ( ) ;
}
2010-11-18 14:23:17 +01:00
saveEmittedCommentTokenIdx = outputMaker . EmittedCommentTokenIdx ;
2010-11-07 21:57:24 +01:00
}
}
double elapsedTime = ( ( DateTime . Now . Ticks - startTime ) / TimeSpan . TicksPerMillisecond ) / 1000.0 ;
2010-12-03 18:23:52 +01:00
System . Console . Out . WriteLine ( "Processed {0} in: {1} seconds." , fullName , elapsedTime ) ;
2010-11-07 21:57:24 +01:00
System . Console . Out . WriteLine ( "" ) ;
System . Console . Out . WriteLine ( "" ) ;
2010-10-23 10:00:25 +02:00
}
2011-06-07 17:11:29 +02:00
public static void emitPartialType ( string name , ClassDescriptorSerialized serTy )
{
2011-06-10 13:27:40 +02:00
JavaPrettyPrint outputMaker = new JavaPrettyPrint ( null ) ;
outputMaker . Filename = serTy . FileName ;
outputMaker . TraceDestination = Console . Error ;
outputMaker . TemplateLib = templates ;
outputMaker . Cfg = cfg ;
StringTemplate pkgST = outputMaker . emitPackage ( serTy ) ;
2011-06-07 17:11:29 +02:00
if ( cfg . DebugLevel > = 1 ) Console . Out . WriteLine ( "Writing out {0}" , serTy . FileName ) ;
StreamWriter javaW = new StreamWriter ( serTy . FileName ) ;
2011-06-10 13:27:40 +02:00
javaW . Write ( limit ( pkgST . ToString ( ) ) ) ;
2011-06-07 17:11:29 +02:00
javaW . Close ( ) ;
}
2010-05-29 10:08:47 -05:00
}
}