1
0
mirror of https://github.com/twiglet/cs2j.git synced 2025-01-18 13:15:17 +01:00

Merge branch 'master' of github.com:twiglet/cs2j

This commit is contained in:
Kevin Glynn 2012-02-07 06:51:27 -06:00
commit 084501fc03
18 changed files with 231 additions and 70 deletions

View File

@ -118,8 +118,10 @@
<Return>System.Void</Return>
</Method>
<Method>
<Imports />
<Java>${this:16}.reverse()</Java>
<Imports>
<Import>java.util.Collections</Import>
</Imports>
<Java>Collections.reverse(${this:16})</Java>
<Params>
</Params>
<Name>Reverse</Name>
@ -171,7 +173,7 @@
</Params>
<Type>System.Object</Type>
<Get>${this:16}.get(${i})</Get>
<Set>${this:16}.add(${i}, ${value})</Set>
<Set>${this:16}.set(${i}, ${value})</Set>
</Indexer>
</Indexers>
<Constructors>

View File

@ -23,6 +23,13 @@
<Java>${expr}</Java>
</Iterable>
<Properties>
<Property>
<Imports />
<Java>${this:16}.size()</Java>
<Type>System.Int32</Type>
<Name>Count</Name>
<Get>${this:16}.size()</Get>
</Property>
</Properties>
<Methods>
<Method>

View File

@ -99,5 +99,12 @@
<Name>Values</Name>
<Get>${this:16}.values()</Get>
</Property>
<Property>
<Imports />
<Java>${this:16}.size()</Java>
<Type>System.Int32</Type>
<Name>Count</Name>
<Get>${this:16}.size()</Get>
</Property>
</Properties>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" /><Reference URI=""><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /><DigestValue>BBHaGzWIzkVajkMtIotxcu6p5VY=</DigestValue></Reference></SignedInfo><SignatureValue>WOOzmkxA0yBm1tFVetTcQxQc7SztNyQygCPbn5vaHLtHI/MoQMuTuytu5BrGb4UJ7KG68galgfmWUlUD99Txs44X+XdHA7wY0XcAUwXHV+/uti6FicyhHw7mDr9Bj4+Rjq4RIA2I0gS5P25V9nMEIEQCD3/jjc+wc4Lt5AHw/b4=</SignatureValue></Signature></Interface>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is
@ -125,7 +125,7 @@
<Return>System.Void</Return>
</Method>
<Method>
<Java>${this:16}.toArray(new ${T}[${this}.size()])</Java>
<Java>((${T}[]) ${this:16}.toArray())</Java>
<Params>
</Params>
<Name>ToArray</Name>

View File

@ -9,9 +9,9 @@
-->
<Class xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:www.twigletsoftware.com:schemas:txtemplate:1:0">
<Imports>
<Import>javax.mail.internet.InternetAddress</Import>
<Import>CS2JNet.System.Net.Mail.MailAddress</Import>
</Imports>
<Java>InternetAddress</Java>
<Java>MailAddress</Java>
<Name>System.Net.Mail.MailAddress</Name>
<Uses />
<Inherits>
@ -24,9 +24,9 @@
<Constructors>
<Constructor>
<Imports>
<Import>javax.mail.internet.InternetAddress</Import>
<Import>CS2JNet.System.Net.Mail.MailAddress</Import>
</Imports>
<Java>new InternetAddress(${address})</Java>
<Java>new MailAddress(${address})</Java>
<Params>
<Param>
<Type>System.String</Type>

View File

@ -26,6 +26,15 @@
</Params>
<Name>Equals</Name>
<Return>System.Boolean</Return>
</Method>
<!-- added for Array.clone support, but since in java this is on Object, should be at System.Object level in
translation for those .net objects which have Clone().-->
<Method>
<Imports />
<Java>${this:16}.clone(${obj})</Java>
<Params />
<Name>Clone</Name>
<Return>System.Object</Return>
</Method>
<Method>
<Imports />
@ -60,6 +69,24 @@
<Name>GetHashCode</Name>
<Return>System.Int</Return>
</Method>
<Method>
<Imports>
<Import>CS2JNet.System.ObjectSupport</Import>
</Imports>
<Java>ObjectSupport.Equals(${obj1}, ${obj2})</Java>
<Params>
<Param>
<Type>System.Object</Type>
<Name>obj1</Name>
</Param>
<Param>
<Type>System.Object</Type>
<Name>obj2</Name>
</Param>
</Params>
<Name>Equals</Name>
<Return>System.Boolean</Return>
</Method>
</Methods>
<Properties />
<Events />

View File

@ -40,10 +40,7 @@
<Return>System.Int32</Return>
</Method>
<Method>
<Imports>
<Import>CS2JNet.System.StringSupport</Import>
</Imports>
<Java>StringSupport.Compare(${arg1}, ${this})</Java>
<Java>${this:16}.compareTo(${arg1})</Java>
<Params>
<Param>
<Type>System.String</Type>
@ -68,7 +65,7 @@
<Name>arg2</Name>
</Param>
<Param>
<Type>System.Bool</Type>
<Type>System.Boolean</Type>
<Name>isCaseSensitive</Name>
</Param>
</Params>

View File

@ -115,6 +115,17 @@
<Name>GetTypeCode</Name>
<Return>System.TypeCode</Return>
</Method>
<Method>
<Return>System.Boolean</Return>
<Name>IsAssignableFrom</Name>
<Params>
<Param>
<Name>arg1</Name>
<Type>System.Type</Type>
</Param>
</Params>
<Java>${this:16}.isAssignableFrom(${arg1})</Java>
</Method>
</Methods>
<Properties>
<Property>

View File

@ -1,5 +1,5 @@
/*
Copyright 2007,2008,2009,2010 Rustici Software, LLC
Copyright 2007,2008,2009,2010 Rustici Software, LLC
Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com)
Licensed under the Apache License, Version 2.0 (the "License");
@ -33,7 +33,7 @@ import CS2JNet.JavaSupport.util.LocaleSupport;
public class DateTimeSupport {
public static String ToString(Date d, String format, Locale loc) {
SimpleDateFormat formatter = null;
if (format.equals("s")) {
//TODO: Is this really a db-friendly sortable format?
@ -43,14 +43,22 @@ public class DateTimeSupport {
formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss'Z'", loc);
} else if (format.equals("yyyy-MM-ddTHH:mm:ss.ffZ")) {
formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SS'Z'", loc);
} else {
formatter = new SimpleDateFormat(format, loc);
} else if (format.equals("yyyy-MM-ddTHH:mm:ss.fffZ")) {
formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", loc);
} else if (format.equals("ddd',' dd MMM yyyy HH':'mm':'ss'.'fff GMT")) {
formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss.SSS 'GMT'");
} else {
formatter = new SimpleDateFormat(format, loc);
}
if (formatter.toPattern().contains("'Z'") || formatter.toPattern().contains("'GMT'")){
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
}
if (d instanceof DateTZ) {
formatter.setTimeZone(((DateTZ)d).getTimeZone());
}
return formatter.format(d);
}
@ -75,10 +83,14 @@ public class DateTimeSupport {
private static final String[] DATE_FORMATS = new String[] {
"E MMM d HH:mm:ss Z yyyy",
"MM/dd/yyyy HH:mm:ss a",
"yyyy-MM-dd HH:mm:ss'Z'",
"yyyy-MM-dd'T'HH:mm:ss.SSSZ",
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
"yyyy-MM-dd'T'HH:mm:ssZ",
"yyyy-MM-dd'T'HH:mm:ss'Z'",
"yyyy-MM-dd'T'HH:mm:ss'.'SSSZ",
"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
"yyyy-MM-dd'T'HH:mm:ss",
"yyyy-MM-dd HH:mm:ss'Z'",
"yyyy-MM-dd"};
public static Date parse(String s) throws ParseException
@ -92,21 +104,21 @@ public class DateTimeSupport {
return parse(val, DATE_FORMATS, Locale.getDefault(), utc);
}
protected static String trimMilliSecondsToThreeDigits(String dateString){
String val = dateString;
if(val != null){
int milliStart = val.lastIndexOf(".");
if(milliStart != -1){
milliStart = milliStart + 1;
int milliEnd = val.lastIndexOf("Z");
milliEnd = (milliEnd == -1) ? val.length() : milliEnd;
if((milliEnd - milliStart) > 3){
String newMillis = val.substring(milliStart).substring(0, 3);
val = val.substring(0, milliStart) + newMillis + val.substring(milliEnd, val.length());
}
}
}
return val;
protected static String trimMilliSecondsToThreeDigits(String dateString){
String val = dateString;
if(val != null){
int milliStart = val.lastIndexOf(".");
if(milliStart != -1){
milliStart = milliStart + 1;
int milliEnd = Math.max(val.lastIndexOf("+"), val.lastIndexOf("Z"));
milliEnd = (milliEnd == -1) ? val.length() : milliEnd;
if((milliEnd - milliStart) > 3){
String newMillis = val.substring(milliStart).substring(0, 3);
val = val.substring(0, milliStart) + newMillis + val.substring(milliEnd, val.length());
}
}
}
return val;
}
public static Date parse(String s, String f) throws ParseException
@ -132,7 +144,7 @@ public class DateTimeSupport {
try
{
SimpleDateFormat sdf = new SimpleDateFormat(f);
if(utc){
if(utc || f.contains("Z")){
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
}
Date d = sdf.parse(s);
@ -167,7 +179,7 @@ public class DateTimeSupport {
cal.add(field, amount);
return cal.getTime();
}
public static boolean equals(Date d1, Date d2) {
return d1 == d2 || (d1 != null && d2 != null && d1.getTime() == d2.getTime());
}

View File

@ -0,0 +1,11 @@
package CS2JNet.System;
public class ObjectSupport {
public static boolean Equals(Object obj1, Object obj2) {
if (obj1 == null) {
return obj2 == null;
} else {
return obj1.equals(obj2);
}
}
}

View File

@ -239,18 +239,10 @@ default_template() ::= <<
default:
>>
lock(comments,exp,block, indent) ::= <<
<comments; separator=""\n"">
lock(<exp>)
<block(statements = block, indent = indent)>
>>
synchstat(comments,exp,stats) ::= <<
synchstat(comments,exp,stat) ::= <<
<comments; separator=""\n"">
synchronized (<exp>)
{
<stats>
}
<block(statements = stat, indent = indent)>
>>
yield(comments,exp) ::= <<

View File

@ -2050,8 +2050,13 @@ checked_statement:
'checked' block ;
unchecked_statement:
'unchecked' block -> ^(UNCHECKED block);
lock_statement:
'lock' '(' expression ')' embedded_statement[/* isStatementListCtxt */ false] ;
lock_statement
@init {
CommonTree statAsBlock = null;
}:
l='lock' '(' expression p=')' embedded_statement[/* isStatementListCtxt */ false]
{ statAsBlock = dupTree(embeddedStatementToBlock($p.token, $embedded_statement.tree)); }
-> ^(SYNCHRONIZED[$l.token, "synchronized"] expression { statAsBlock });
// TODO: Can we avoid surrounding this with braces if not needed?
using_statement[bool isStatementListCtxt]
@init {

View File

@ -1580,7 +1580,6 @@ embedded_statement returns [bool isSemi, bool isIf, bool indent]
| checked_statement -> { $checked_statement.st }
| unchecked_statement -> { $unchecked_statement.st }
| synchronized_statement -> { $synchronized_statement.st }
| lock_statement -> { $lock_statement.st }
| yield_statement -> { $yield_statement.st }
| ^('unsafe' { preComments = CollectedComments; } block { someText = %op(); %{someText}.op="unsafe"; %{someText}.post = $block.st; })
-> unsupported(comments = { preComments }, reason = {"unsafe blocks are not supported"}, text = { someText } )
@ -1681,7 +1680,7 @@ finally_clause:
^('finally' block) -> fin(block = {$block.st}, blockindent = { $block.isSemi });
synchronized_statement:
^(SYNCHRONIZED expression '{' s+=statement* '}') -> synchstat(exp={ $expression.st }, stats = { $s });
^(SYNCHRONIZED expression embedded_statement) -> synchstat(exp={ $expression.st }, stat = { $embedded_statement.st }, indent = { $embedded_statement.indent });
checked_statement
@init {
@ -1703,16 +1702,6 @@ unchecked_statement
%{someText}.block = $block.st;
%{someText}.indent = $block.isSemi; } -> unsupported(reason = {"checked statements are not supported"}, text = { someText } )
;
lock_statement
@init {
StringTemplate someText = null;
}:
'lock' '(' expression ')' embedded_statement
{ someText = %lock();
%{someText}.exp = $expression.st;
%{someText}.block = $embedded_statement.st;
%{someText}.indent = $embedded_statement.indent; } -> unsupported(reason = {"lock() statements are not supported"}, text = { someText } )
;
yield_statement
@init {
StringTemplate someText = null;

View File

@ -1132,6 +1132,14 @@ scope MkNonGeneric {
$ForceUnsharedType::fresh = false;
}
protected void AddNSToSearchPath(List<string> search, string ns) {
int idx = 0;
while (ns.IndexOf('.', idx) > 0) {
idx = ns.IndexOf('.', idx)+1;
search.Add(ns.Substring(0,idx-1));
}
}
}
public compilation_unit
@ -1155,7 +1163,7 @@ scope NSContext, PrimitiveRep, MkNonGeneric, ForceUnsharedType;
$ForceUnsharedType::fresh = false;
}:
^(pkg=PACKAGE ns=PAYLOAD { $NSContext::currentNS = $ns.text; } dec=type_declaration )
^(pkg=PACKAGE ns=PAYLOAD { $NSContext::currentNS = $ns.text; AddNSToSearchPath($NSContext::globalNamespaces, $ns.text);} dec=type_declaration )
-> ^($pkg $ns { mkImports() } $dec);
type_declaration:
@ -3125,8 +3133,7 @@ embedded_statement[bool isStatementListCtxt]
| ^('try' block catch_clauses? finally_clause?)
| checked_statement
| unchecked_statement
| synchronized_statement // Java: synchronized(obj) {}
| lock_statement
| synchronized_statement
| yield_statement
| ^('unsafe' block)
| fixed_statement
@ -3426,10 +3433,7 @@ unchecked_statement:
^(UNCHECKED block) ;
synchronized_statement:
^(SYNCHRONIZED expression[ObjectType] '{' statement_list '}') ;
lock_statement:
'lock' '(' expression[ObjectType] ')' embedded_statement[/* isStatementListCtxt */ false] ;
^(SYNCHRONIZED expression[ObjectType] embedded_statement[/* isStatementListCtxt */ false]) ;
yield_statement:
^(YIELD_RETURN expression[ObjectType])

View File

@ -0,0 +1,22 @@
using System;
// Test translation for lock statements
namespace Tester.Parent.Child
{
public class ChildClass
{
private ParentClass myp = null;
public ChildClass(int val)
{
myp = new ParentClass(val);
int tmp = myp.GetHashCode();
}
}
}

View File

@ -0,0 +1,41 @@
using System;
// Test translation for lock statements
namespace Tester.Parent
{
public class ParentClass {
private int loc = 0;
public ParentClass(int val)
{
loc = val;
}
public int GetLoc()
{
return loc;
}
public override int GetHashCode(){
return 5;
}
private class ChildOne {
public int COloc = 0;
private class ChildChildOne
{
public ChildChildOne() { }
public ChildOne p = new ChildOne();
public ParentClass gp = new ParentClass(4);
}
}
}
}

View File

@ -0,0 +1,31 @@
using System;
// Test translation for lock statements
namespace Tester.Locker
{
class B {
public virtual void foo() {
lock(this)
Console.WriteLine("summat");
}
}
class D : B {
public new void foo() {
lock (new String[5])
{
Console.WriteLine("and");
Console.WriteLine("nuttin");
}
}
}
public class Test5 {
public static void T5Main(){
B b = new D();
b.foo();
Console.WriteLine("Done");
}
}
}

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -45,6 +45,9 @@
<Compile Include="Enums\PacketTester.cs" />
<Compile Include="Enums\Consts.cs" />
<Compile Include="Generics\Generics.cs" />
<Compile Include="Misc\locker.cs" />
<Compile Include="Misc\Namespaces\child.cs" />
<Compile Include="Misc\Namespaces\parent.cs" />
<Compile Include="Partial\PartialUserTwo.cs" />
<Compile Include="Partial\PartialInner.cs" />
<Compile Include="Partial\PartialOuterPartialInner.cs" />