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:
parent
74eb3622d2
commit
01ab36f9a6
@ -154,7 +154,7 @@ namespace RusticiSoftware.Translator.CLR
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The Java translation for this C# entity
|
// The Java translation for this C# entity
|
||||||
private string _java = null;
|
protected string _java = null;
|
||||||
public string Java {
|
public string Java {
|
||||||
get {
|
get {
|
||||||
if (_java == null) {
|
if (_java == null) {
|
||||||
@ -624,12 +624,56 @@ namespace RusticiSoftware.Translator.CLR
|
|||||||
// guessing that normally imports will be the same for both)
|
// guessing that normally imports will be the same for both)
|
||||||
public class PropRepTemplate : FieldRepTemplate, IEquatable<PropRepTemplate>
|
public class PropRepTemplate : FieldRepTemplate, IEquatable<PropRepTemplate>
|
||||||
{
|
{
|
||||||
public string JavaSet { get; set; }
|
|
||||||
private string _javaGet = null;
|
private string _javaGet = null;
|
||||||
public string JavaGet {
|
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; }
|
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()
|
public PropRepTemplate () : base()
|
||||||
{
|
{
|
||||||
@ -644,7 +688,12 @@ namespace RusticiSoftware.Translator.CLR
|
|||||||
public PropRepTemplate (string fType, string fName) : this(fType, fName, null, null, null)
|
public PropRepTemplate (string fType, string fName) : this(fType, fName, null, null, null)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string mkJava ()
|
||||||
|
{
|
||||||
|
// favour JavaGet
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
#region Equality
|
#region Equality
|
||||||
public bool Equals (PropRepTemplate other)
|
public bool Equals (PropRepTemplate other)
|
||||||
|
@ -99,6 +99,10 @@ namespace cs2j.Template.Utils
|
|||||||
|
|
||||||
// Grab Methods
|
// Grab Methods
|
||||||
foreach (MethodInfo m in t.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance)) {
|
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();
|
MethodRepTemplate methRep = new MethodRepTemplate();
|
||||||
methRep.Name = m.Name;
|
methRep.Name = m.Name;
|
||||||
methRep.Return = TypeHelper.buildTypeName(m.ReturnType);
|
methRep.Return = TypeHelper.buildTypeName(m.ReturnType);
|
||||||
@ -122,6 +126,8 @@ namespace cs2j.Template.Utils
|
|||||||
PropRepTemplate propRep = new PropRepTemplate();
|
PropRepTemplate propRep = new PropRepTemplate();
|
||||||
propRep.Name = p.Name;
|
propRep.Name = p.Name;
|
||||||
propRep.Type = TypeHelper.buildTypeName(p.PropertyType);
|
propRep.Type = TypeHelper.buildTypeName(p.PropertyType);
|
||||||
|
propRep.CanRead = p.CanRead;
|
||||||
|
propRep.CanWrite = p.CanWrite;
|
||||||
iface.Properties.Add(propRep);
|
iface.Properties.Add(propRep);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user