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

Implement JavaGet and JavaSet.

- Omit 'special' get_ and set_ methods in DLL produced for getter/setters
- Allow properties to be marked read/write only and honour when generating auto java
This commit is contained in:
Kevin Glynn 2010-10-20 17:46:36 +02:00
parent 74eb3622d2
commit 01ab36f9a6
2 changed files with 59 additions and 4 deletions

View File

@ -154,7 +154,7 @@ namespace RusticiSoftware.Translator.CLR
}
// The Java translation for this C# entity
private string _java = null;
protected string _java = null;
public string Java {
get {
if (_java == null) {
@ -624,12 +624,56 @@ namespace RusticiSoftware.Translator.CLR
// guessing that normally imports will be the same for both)
public class PropRepTemplate : FieldRepTemplate, IEquatable<PropRepTemplate>
{
public string JavaSet { get; set; }
private string _javaGet = null;
public string JavaGet {
get { return _javaGet ?? Java; }
get {
if (!CanRead) return null;
if (_javaGet == null) {
if (_java == null) {
return (CanRead ? "${this}.get" + Name + "()" : null);
}
else {
return _java;
}
}
else {
return _javaGet;
}
}
set { _javaGet = value; }
}
private string _javaSet = null;
public string JavaSet {
get {
if (_javaSet == null) {
return (CanWrite ? "${this}.set" + Name + "(${value})" : null);
}
else {
return _javaSet;
}
}
set { _javaSet = value; }
}
// canRead?
private bool _canRead = true;
[XmlAttribute("read")]
[System.ComponentModel.DefaultValueAttribute(true)]
public bool CanRead {
get { return _canRead; }
set { _canRead = value; }
}
// canWrite?
private bool _canWrite = true;
[XmlAttribute("write")]
[System.ComponentModel.DefaultValueAttribute(true)]
public bool CanWrite {
get { return _canWrite; }
set { _canWrite = value; }
}
public PropRepTemplate () : base()
{
@ -644,7 +688,12 @@ namespace RusticiSoftware.Translator.CLR
public PropRepTemplate (string fType, string fName) : this(fType, fName, null, null, null)
{
}
public override string mkJava ()
{
// favour JavaGet
return null;
}
#region Equality
public bool Equals (PropRepTemplate other)

View File

@ -99,6 +99,10 @@ namespace cs2j.Template.Utils
// Grab Methods
foreach (MethodInfo m in t.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance)) {
if (m.IsSpecialName) {
// e.g., a property's getter / setter method
continue;
}
MethodRepTemplate methRep = new MethodRepTemplate();
methRep.Name = m.Name;
methRep.Return = TypeHelper.buildTypeName(m.ReturnType);
@ -122,6 +126,8 @@ namespace cs2j.Template.Utils
PropRepTemplate propRep = new PropRepTemplate();
propRep.Name = p.Name;
propRep.Type = TypeHelper.buildTypeName(p.PropertyType);
propRep.CanRead = p.CanRead;
propRep.CanWrite = p.CanWrite;
iface.Properties.Add(propRep);
}