mirror of
https://github.com/twiglet/cs2j.git
synced 2025-01-18 13:15:17 +01:00
If Java property isn't set then generate a likely string from the context
This commit is contained in:
parent
4933c8f3c5
commit
1a7f16d503
@ -18,6 +18,11 @@ using RusticiSoftware.Translator.Utils;
|
|||||||
namespace RusticiSoftware.Translator.CLR
|
namespace RusticiSoftware.Translator.CLR
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public enum Javastyle
|
||||||
|
{
|
||||||
|
Clean, MarkAuto
|
||||||
|
}
|
||||||
|
|
||||||
// Simple <type> <name> pairs to represent formal parameters
|
// Simple <type> <name> pairs to represent formal parameters
|
||||||
public class ParamRepTemplate : IEquatable<ParamRepTemplate>
|
public class ParamRepTemplate : IEquatable<ParamRepTemplate>
|
||||||
{
|
{
|
||||||
@ -135,14 +140,66 @@ namespace RusticiSoftware.Translator.CLR
|
|||||||
{
|
{
|
||||||
[XmlArrayItem("Import")]
|
[XmlArrayItem("Import")]
|
||||||
// Java imports required to make Java translation run
|
// Java imports required to make Java translation run
|
||||||
public string[] Imports { get; set; }
|
private string[] _imports = null;
|
||||||
|
public string[] Imports {
|
||||||
|
get {
|
||||||
|
// if _java is not set then see if we have default imports, otherwise
|
||||||
|
// assume imports is already correctly (un)set
|
||||||
|
if (_java == null) {
|
||||||
|
return mkImports();
|
||||||
|
}
|
||||||
|
return _imports;
|
||||||
|
}
|
||||||
|
set { _imports = value; }
|
||||||
|
}
|
||||||
|
|
||||||
// The Java translation for this C# entity
|
// The Java translation for this C# entity
|
||||||
public string Java { get; set; }
|
private string _java = null;
|
||||||
|
public string Java {
|
||||||
|
get {
|
||||||
|
if (_java == null) {
|
||||||
|
return mkJava();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return _java;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
set { _java = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Optional, but if present will jet mkJava generate better java guess in some cases
|
||||||
|
[XmlIgnore]
|
||||||
|
public string SurroundingTypeName {get; set;}
|
||||||
|
|
||||||
|
public virtual string[] mkImports() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string[] mkImports(Javastyle style) {
|
||||||
|
string[] imports = mkImports();
|
||||||
|
if (style == Javastyle.MarkAuto) {
|
||||||
|
for (int i = 0; i < imports.Length; i++) {
|
||||||
|
imports[i] = imports[i] + " /*auto*/";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return imports;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract string mkJava();
|
||||||
|
|
||||||
|
public string mkJava(Javastyle style) {
|
||||||
|
string unAdornedJava = mkJava();
|
||||||
|
if (style == Javastyle.MarkAuto) {
|
||||||
|
return "/*auto (/*" + unAdornedJava + "/*)*/";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return unAdornedJava;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected TranslationBase ()
|
protected TranslationBase ()
|
||||||
{
|
{
|
||||||
Imports = null;
|
Imports = null;
|
||||||
Java = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TranslationBase (string java)
|
protected TranslationBase (string java)
|
||||||
@ -224,6 +281,37 @@ namespace RusticiSoftware.Translator.CLR
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected string mkJavaParams() {
|
||||||
|
StringBuilder parStr = new StringBuilder();
|
||||||
|
parStr.Append("(");
|
||||||
|
foreach (ParamRepTemplate p in Params) {
|
||||||
|
parStr.Append("{"+p.Name+"},");
|
||||||
|
}
|
||||||
|
if (parStr[parStr.Length-1] == ',') {
|
||||||
|
parStr.Remove(parStr.Length-1,1);
|
||||||
|
}
|
||||||
|
parStr.Append(")");
|
||||||
|
return parStr.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string mkJava() {
|
||||||
|
string constructorName = "CONSTRUCTOR";
|
||||||
|
if (SurroundingTypeName != null) {
|
||||||
|
constructorName = SurroundingTypeName.Substring(SurroundingTypeName.LastIndexOf('.') + 1);
|
||||||
|
}
|
||||||
|
return "new " + constructorName + mkJavaParams();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string[] mkImports() {
|
||||||
|
if (SurroundingTypeName != null) {
|
||||||
|
int idxDot = SurroundingTypeName.LastIndexOf('.');
|
||||||
|
return new string[] {"CS2JNet." + SurroundingTypeName.Substring(0, idxDot)};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public ConstructorRepTemplate () : base()
|
public ConstructorRepTemplate () : base()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -324,6 +412,33 @@ namespace RusticiSoftware.Translator.CLR
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string[] mkImports() {
|
||||||
|
if (IsStatic && SurroundingTypeName != null) {
|
||||||
|
int idxDot = SurroundingTypeName.LastIndexOf('.');
|
||||||
|
return new string[] {"CS2JNet." + SurroundingTypeName.Substring(0, idxDot)};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string mkJava() {
|
||||||
|
StringBuilder methStr = new StringBuilder();
|
||||||
|
if (IsStatic) {
|
||||||
|
if (SurroundingTypeName != null) {
|
||||||
|
methStr.Append(SurroundingTypeName.Substring(SurroundingTypeName.LastIndexOf('.') + 1) + ".");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
methStr.Append("TYPENAME.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
methStr.Append("{this}.");
|
||||||
|
}
|
||||||
|
methStr.Append(Name);
|
||||||
|
return methStr.ToString() + mkJavaParams();
|
||||||
|
}
|
||||||
|
|
||||||
#region Equality
|
#region Equality
|
||||||
public bool Equals (MethodRepTemplate other)
|
public bool Equals (MethodRepTemplate other)
|
||||||
{
|
{
|
||||||
@ -398,6 +513,11 @@ namespace RusticiSoftware.Translator.CLR
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: fix cast java
|
||||||
|
public override string mkJava() {
|
||||||
|
return "/* FIXME Cast " + From + " to " + To + "*/";
|
||||||
|
}
|
||||||
|
|
||||||
#region Equality
|
#region Equality
|
||||||
public bool Equals (CastRepTemplate other)
|
public bool Equals (CastRepTemplate other)
|
||||||
{
|
{
|
||||||
@ -456,6 +576,11 @@ namespace RusticiSoftware.Translator.CLR
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public override string mkJava() {
|
||||||
|
return Name;
|
||||||
|
}
|
||||||
|
|
||||||
#region Equality
|
#region Equality
|
||||||
public bool Equals (FieldRepTemplate other)
|
public bool Equals (FieldRepTemplate other)
|
||||||
{
|
{
|
||||||
@ -583,6 +708,11 @@ namespace RusticiSoftware.Translator.CLR
|
|||||||
Value = v;
|
Value = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string mkJava() {
|
||||||
|
return Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#region Equality
|
#region Equality
|
||||||
public bool Equals (EnumMemberRepTemplate other)
|
public bool Equals (EnumMemberRepTemplate other)
|
||||||
{
|
{
|
||||||
@ -656,6 +786,23 @@ namespace RusticiSoftware.Translator.CLR
|
|||||||
Uses = usePath;
|
Uses = usePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string mkJava() {
|
||||||
|
if (TypeName == null || TypeName == String.Empty) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return TypeName.Substring(TypeName.LastIndexOf('.')+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string[] mkImports() {
|
||||||
|
int idxDot = TypeName.LastIndexOf('.');
|
||||||
|
if (idxDot > 0) {
|
||||||
|
return new string[] {"CS2JNet." + TypeName.Substring(0,idxDot)};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static object Deserialize (Stream fs, System.Type t)
|
private static object Deserialize (Stream fs, System.Type t)
|
||||||
{
|
{
|
||||||
object o = null;
|
object o = null;
|
||||||
@ -897,6 +1044,7 @@ namespace RusticiSoftware.Translator.CLR
|
|||||||
return new DelegateRep ();
|
return new DelegateRep ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#region Equality
|
#region Equality
|
||||||
public bool Equals (DelegateRepTemplate other)
|
public bool Equals (DelegateRepTemplate other)
|
||||||
{
|
{
|
||||||
|
@ -113,6 +113,7 @@ namespace cs2j.Template.Utils
|
|||||||
if (m.IsStatic) {
|
if (m.IsStatic) {
|
||||||
methRep.IsStatic = true;
|
methRep.IsStatic = true;
|
||||||
}
|
}
|
||||||
|
methRep.SurroundingTypeName = iface.TypeName;
|
||||||
iface.Methods.Add(methRep);
|
iface.Methods.Add(methRep);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,6 +141,7 @@ namespace cs2j.Template.Utils
|
|||||||
foreach (ConstructorInfo c in t.GetConstructors()) {
|
foreach (ConstructorInfo c in t.GetConstructors()) {
|
||||||
ConstructorRepTemplate consRep = new ConstructorRepTemplate();
|
ConstructorRepTemplate consRep = new ConstructorRepTemplate();
|
||||||
buildParameters(consRep, c);
|
buildParameters(consRep, c);
|
||||||
|
consRep.SurroundingTypeName = klass.TypeName;
|
||||||
klass.Constructors.Add(consRep);
|
klass.Constructors.Add(consRep);
|
||||||
}
|
}
|
||||||
// Grab Fields
|
// Grab Fields
|
||||||
|
Loading…
x
Reference in New Issue
Block a user