mirror of
https://github.com/twiglet/cs2j.git
synced 2025-01-18 13:15:17 +01:00
replace SurroundingTypeName by SurroundingType, so that components have access to all the features of their type, in particular the type parameters. Allows for better mkJava code
This commit is contained in:
parent
792836217a
commit
df2798a3a1
@ -143,7 +143,7 @@ namespace Twiglet.CS2J.Utility
|
|||||||
{
|
{
|
||||||
methRep.IsStatic = true;
|
methRep.IsStatic = true;
|
||||||
}
|
}
|
||||||
methRep.SurroundingTypeName = iface.TypeName;
|
methRep.SurroundingType = iface;
|
||||||
iface.Methods.Add(methRep);
|
iface.Methods.Add(methRep);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,7 +177,7 @@ namespace Twiglet.CS2J.Utility
|
|||||||
{
|
{
|
||||||
ConstructorRepTemplate consRep = new ConstructorRepTemplate();
|
ConstructorRepTemplate consRep = new ConstructorRepTemplate();
|
||||||
buildParameters(consRep.Params, c);
|
buildParameters(consRep.Params, c);
|
||||||
consRep.SurroundingTypeName = klass.TypeName;
|
consRep.SurroundingType = klass;
|
||||||
klass.Constructors.Add(consRep);
|
klass.Constructors.Add(consRep);
|
||||||
}
|
}
|
||||||
// Grab Fields
|
// Grab Fields
|
||||||
|
@ -306,12 +306,12 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Optional, but if present will let mkJava generate better java guess in some cases
|
// Optional, but if present will let mkJava generate better java guess in some cases
|
||||||
private string _surroundingTypeName;
|
private TypeRepTemplate _surroundingType;
|
||||||
[XmlIgnore]
|
[XmlIgnore]
|
||||||
public string SurroundingTypeName {
|
public TypeRepTemplate SurroundingType {
|
||||||
get { return _surroundingTypeName; }
|
get { return _surroundingType; }
|
||||||
set {
|
set {
|
||||||
_surroundingTypeName=value.Replace("<","*[").Replace(">","]*");
|
_surroundingType=value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public virtual string[] mkImports() {
|
public virtual string[] mkImports() {
|
||||||
@ -345,7 +345,7 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
|||||||
Imports = null;
|
Imports = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TranslationBase(TranslationBase copyFrom)
|
protected TranslationBase(TypeRepTemplate parent, TranslationBase copyFrom)
|
||||||
{
|
{
|
||||||
int len = 0;
|
int len = 0;
|
||||||
if (copyFrom.Imports != null)
|
if (copyFrom.Imports != null)
|
||||||
@ -361,10 +361,8 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
|||||||
{
|
{
|
||||||
Java = copyFrom.Java;
|
Java = copyFrom.Java;
|
||||||
}
|
}
|
||||||
if (!String.IsNullOrEmpty(copyFrom.SurroundingTypeName))
|
|
||||||
{
|
SurroundingType = parent;
|
||||||
SurroundingTypeName = copyFrom.SurroundingTypeName;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TranslationBase(string java)
|
protected TranslationBase(string java)
|
||||||
@ -484,8 +482,8 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
|||||||
ElementType = ty;
|
ElementType = ty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IterableRepTemplate(IterableRepTemplate copyFrom)
|
public IterableRepTemplate(TypeRepTemplate parent, IterableRepTemplate copyFrom)
|
||||||
: base(copyFrom)
|
: base(parent, copyFrom)
|
||||||
{
|
{
|
||||||
if (!String.IsNullOrEmpty(copyFrom.ElementType))
|
if (!String.IsNullOrEmpty(copyFrom.ElementType))
|
||||||
{
|
{
|
||||||
@ -560,15 +558,19 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
|||||||
|
|
||||||
public override string mkJava() {
|
public override string mkJava() {
|
||||||
string constructorName = "CONSTRUCTOR";
|
string constructorName = "CONSTRUCTOR";
|
||||||
if (!String.IsNullOrEmpty(SurroundingTypeName)) {
|
if (SurroundingType != null) {
|
||||||
constructorName = SurroundingTypeName.Substring(SurroundingTypeName.LastIndexOf('.') + 1);
|
constructorName = SurroundingType.TypeName.Substring(SurroundingType.TypeName.LastIndexOf('.') + 1);
|
||||||
|
if (SurroundingType.TypeParams != null && SurroundingType.TypeParams.Length > 0)
|
||||||
|
{
|
||||||
|
constructorName += mkTypeParams(SurroundingType.TypeParams);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return "new " + constructorName + mkJavaParams(Params);
|
return "new " + constructorName + mkJavaParams(Params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string[] mkImports() {
|
public override string[] mkImports() {
|
||||||
if (!String.IsNullOrEmpty(SurroundingTypeName)) {
|
if (SurroundingType != null) {
|
||||||
return new string[] {SurroundingTypeName};
|
return new string[] {SurroundingType.TypeName};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return null;
|
return null;
|
||||||
@ -580,8 +582,8 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConstructorRepTemplate(ConstructorRepTemplate copyFrom)
|
public ConstructorRepTemplate(TypeRepTemplate parent, ConstructorRepTemplate copyFrom)
|
||||||
: base(copyFrom)
|
: base(parent, copyFrom)
|
||||||
{
|
{
|
||||||
foreach (ParamRepTemplate p in copyFrom.Params)
|
foreach (ParamRepTemplate p in copyFrom.Params)
|
||||||
{
|
{
|
||||||
@ -717,7 +719,7 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
|||||||
IsStatic = false;
|
IsStatic = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MethodRepTemplate(MethodRepTemplate copyFrom) : base(copyFrom)
|
public MethodRepTemplate(TypeRepTemplate parent, MethodRepTemplate copyFrom) : base(parent, copyFrom)
|
||||||
{
|
{
|
||||||
if (!String.IsNullOrEmpty(copyFrom.Name))
|
if (!String.IsNullOrEmpty(copyFrom.Name))
|
||||||
{
|
{
|
||||||
@ -764,8 +766,8 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override string[] mkImports() {
|
public override string[] mkImports() {
|
||||||
if (IsStatic && SurroundingTypeName != null) {
|
if (IsStatic && SurroundingType != null) {
|
||||||
return new string[] {SurroundingTypeName};
|
return new string[] {SurroundingType.TypeName};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return null;
|
return null;
|
||||||
@ -775,8 +777,8 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
|||||||
public override string mkJava() {
|
public override string mkJava() {
|
||||||
StringBuilder methStr = new StringBuilder();
|
StringBuilder methStr = new StringBuilder();
|
||||||
if (IsStatic) {
|
if (IsStatic) {
|
||||||
if (!String.IsNullOrEmpty(SurroundingTypeName)) {
|
if (SurroundingType != null) {
|
||||||
methStr.Append(SurroundingTypeName.Substring(SurroundingTypeName.LastIndexOf('.') + 1) + ".");
|
methStr.Append(SurroundingType.TypeName.Substring(SurroundingType.TypeName.LastIndexOf('.') + 1) + ".");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
methStr.Append("TYPENAME.");
|
methStr.Append("TYPENAME.");
|
||||||
@ -899,8 +901,8 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public CastRepTemplate(CastRepTemplate copyFrom)
|
public CastRepTemplate(TypeRepTemplate parent, CastRepTemplate copyFrom)
|
||||||
: base(copyFrom)
|
: base(parent, copyFrom)
|
||||||
{
|
{
|
||||||
if (!String.IsNullOrEmpty(copyFrom.From))
|
if (!String.IsNullOrEmpty(copyFrom.From))
|
||||||
{
|
{
|
||||||
@ -924,8 +926,8 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override string[] mkImports() {
|
public override string[] mkImports() {
|
||||||
if (!String.IsNullOrEmpty(SurroundingTypeName)) {
|
if (SurroundingType != null) {
|
||||||
return new string[] {SurroundingTypeName};
|
return new string[] {SurroundingType.TypeName};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return null;
|
return null;
|
||||||
@ -937,8 +939,8 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!String.IsNullOrEmpty(SurroundingTypeName)) {
|
if (SurroundingType != null) {
|
||||||
String myType = SurroundingTypeName.Substring(SurroundingTypeName.LastIndexOf('.') + 1);
|
String myType = SurroundingType.TypeName.Substring(SurroundingType.TypeName.LastIndexOf('.') + 1);
|
||||||
String toType = To.Substring(To.LastIndexOf('.') + 1);
|
String toType = To.Substring(To.LastIndexOf('.') + 1);
|
||||||
if (myType == toType)
|
if (myType == toType)
|
||||||
{
|
{
|
||||||
@ -1025,8 +1027,8 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public FieldRepTemplate(FieldRepTemplate copyFrom)
|
public FieldRepTemplate(TypeRepTemplate parent, FieldRepTemplate copyFrom)
|
||||||
: base(copyFrom)
|
: base(parent, copyFrom)
|
||||||
{
|
{
|
||||||
if (!String.IsNullOrEmpty(copyFrom.Name))
|
if (!String.IsNullOrEmpty(copyFrom.Name))
|
||||||
{
|
{
|
||||||
@ -1171,8 +1173,8 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public PropRepTemplate(PropRepTemplate copyFrom)
|
public PropRepTemplate(TypeRepTemplate parent, PropRepTemplate copyFrom)
|
||||||
: base(copyFrom)
|
: base(parent, copyFrom)
|
||||||
{
|
{
|
||||||
if (!String.IsNullOrEmpty(copyFrom.JavaGet))
|
if (!String.IsNullOrEmpty(copyFrom.JavaGet))
|
||||||
{
|
{
|
||||||
@ -1305,8 +1307,8 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public IndexerRepTemplate(IndexerRepTemplate copyFrom)
|
public IndexerRepTemplate(TypeRepTemplate parent, IndexerRepTemplate copyFrom)
|
||||||
: base(copyFrom)
|
: base(parent, copyFrom)
|
||||||
{
|
{
|
||||||
foreach (ParamRepTemplate p in copyFrom.Params)
|
foreach (ParamRepTemplate p in copyFrom.Params)
|
||||||
{
|
{
|
||||||
@ -1421,8 +1423,8 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
|||||||
public EnumMemberRepTemplate() : base()
|
public EnumMemberRepTemplate() : base()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
public EnumMemberRepTemplate(EnumMemberRepTemplate copyFrom)
|
public EnumMemberRepTemplate(TypeRepTemplate parent, EnumMemberRepTemplate copyFrom)
|
||||||
: base(copyFrom)
|
: base(parent, copyFrom)
|
||||||
{
|
{
|
||||||
if (!String.IsNullOrEmpty(copyFrom.Name))
|
if (!String.IsNullOrEmpty(copyFrom.Name))
|
||||||
{
|
{
|
||||||
@ -1647,7 +1649,7 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected TypeRepTemplate(TypeRepTemplate copyFrom)
|
protected TypeRepTemplate(TypeRepTemplate copyFrom)
|
||||||
:base(copyFrom)
|
:base(null, copyFrom)
|
||||||
{
|
{
|
||||||
if (!String.IsNullOrEmpty(copyFrom.TypeName))
|
if (!String.IsNullOrEmpty(copyFrom.TypeName))
|
||||||
{
|
{
|
||||||
@ -1697,7 +1699,7 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
|||||||
|
|
||||||
foreach (CastRepTemplate c in copyFrom.Casts)
|
foreach (CastRepTemplate c in copyFrom.Casts)
|
||||||
{
|
{
|
||||||
Casts.Add(new CastRepTemplate(c));
|
Casts.Add(new CastRepTemplate(this, c));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (copyFrom.Inherits != null)
|
if (copyFrom.Inherits != null)
|
||||||
@ -1724,10 +1726,15 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override string mkJava() {
|
public override string mkJava() {
|
||||||
if (TypeName == null || TypeName == String.Empty) {
|
string ret = String.Empty;
|
||||||
return null;
|
if (TypeName != null && TypeName != String.Empty) {
|
||||||
|
ret = TypeName.Substring(TypeName.LastIndexOf('.') + 1);
|
||||||
|
if (TypeParams != null && TypeParams.Length > 0)
|
||||||
|
{
|
||||||
|
ret += mkTypeParams(TypeParams);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return TypeName.Substring(TypeName.LastIndexOf('.') + 1);
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string[] mkImports() {
|
public override string[] mkImports() {
|
||||||
@ -2298,7 +2305,7 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
|||||||
{
|
{
|
||||||
foreach (EnumMemberRepTemplate m in copyFrom.Members)
|
foreach (EnumMemberRepTemplate m in copyFrom.Members)
|
||||||
{
|
{
|
||||||
Members.Add(new EnumMemberRepTemplate(m));
|
Members.Add(new EnumMemberRepTemplate(this, m));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2572,27 +2579,27 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
|||||||
{
|
{
|
||||||
foreach (MethodRepTemplate m in copyFrom.Methods)
|
foreach (MethodRepTemplate m in copyFrom.Methods)
|
||||||
{
|
{
|
||||||
Methods.Add(new MethodRepTemplate(m));
|
Methods.Add(new MethodRepTemplate(this, m));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (PropRepTemplate p in copyFrom.Properties)
|
foreach (PropRepTemplate p in copyFrom.Properties)
|
||||||
{
|
{
|
||||||
Properties.Add(new PropRepTemplate(p));
|
Properties.Add(new PropRepTemplate(this, p));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (FieldRepTemplate e in copyFrom.Events)
|
foreach (FieldRepTemplate e in copyFrom.Events)
|
||||||
{
|
{
|
||||||
Events.Add(new FieldRepTemplate(e));
|
Events.Add(new FieldRepTemplate(this, e));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (IndexerRepTemplate i in copyFrom.Indexers)
|
foreach (IndexerRepTemplate i in copyFrom.Indexers)
|
||||||
{
|
{
|
||||||
Indexers.Add(new IndexerRepTemplate(i));
|
Indexers.Add(new IndexerRepTemplate(this, i));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (copyFrom.Iterable != null)
|
if (copyFrom.Iterable != null)
|
||||||
{
|
{
|
||||||
Iterable = new IterableRepTemplate(copyFrom.Iterable);
|
Iterable = new IterableRepTemplate(this, copyFrom.Iterable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2954,22 +2961,22 @@ namespace Twiglet.CS2J.Translator.TypeRep
|
|||||||
{
|
{
|
||||||
foreach (ConstructorRepTemplate c in copyFrom.Constructors)
|
foreach (ConstructorRepTemplate c in copyFrom.Constructors)
|
||||||
{
|
{
|
||||||
Constructors.Add(new ConstructorRepTemplate(c));
|
Constructors.Add(new ConstructorRepTemplate(this, c));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (FieldRepTemplate f in copyFrom.Fields)
|
foreach (FieldRepTemplate f in copyFrom.Fields)
|
||||||
{
|
{
|
||||||
Fields.Add(new FieldRepTemplate(f));
|
Fields.Add(new FieldRepTemplate(this, f));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (MethodRepTemplate u in copyFrom.UnaryOps)
|
foreach (MethodRepTemplate u in copyFrom.UnaryOps)
|
||||||
{
|
{
|
||||||
UnaryOps.Add(new MethodRepTemplate(u));
|
UnaryOps.Add(new MethodRepTemplate(this, u));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (MethodRepTemplate b in copyFrom.BinaryOps)
|
foreach (MethodRepTemplate b in copyFrom.BinaryOps)
|
||||||
{
|
{
|
||||||
BinaryOps.Add(new MethodRepTemplate(b));
|
BinaryOps.Add(new MethodRepTemplate(this, b));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1151,7 +1151,7 @@ conversion_operator_declarator:
|
|||||||
(i='implicit' { Warning($i.line, "[UNSUPPORTED] implicit user defined casts, an explicit cast is always required."); } | 'explicit') 'operator' tt=type '(' tf=type identifier ')'
|
(i='implicit' { Warning($i.line, "[UNSUPPORTED] implicit user defined casts, an explicit cast is always required."); } | 'explicit') 'operator' tt=type '(' tf=type identifier ')'
|
||||||
{
|
{
|
||||||
CastRepTemplate kast = new CastRepTemplate($tf.thetext, $tt.thetext);
|
CastRepTemplate kast = new CastRepTemplate($tf.thetext, $tt.thetext);
|
||||||
kast.SurroundingTypeName = $NSContext::currentTypeRep.TypeName;
|
kast.SurroundingType = $NSContext::currentTypeRep;
|
||||||
((ClassRepTemplate)$NSContext::currentTypeRep).Casts.Add(kast);
|
((ClassRepTemplate)$NSContext::currentTypeRep).Casts.Add(kast);
|
||||||
Debug("Processing conversion declaration");
|
Debug("Processing conversion declaration");
|
||||||
}
|
}
|
||||||
@ -1166,7 +1166,7 @@ constructor_declarator:
|
|||||||
identifier '(' fpl=formal_parameter_list? ')' constructor_initializer?
|
identifier '(' fpl=formal_parameter_list? ')' constructor_initializer?
|
||||||
{
|
{
|
||||||
ConstructorRepTemplate cRep = new ConstructorRepTemplate($fpl.paramlist);
|
ConstructorRepTemplate cRep = new ConstructorRepTemplate($fpl.paramlist);
|
||||||
cRep.SurroundingTypeName = $NSContext::currentTypeRep.TypeName;
|
cRep.SurroundingType = $NSContext::currentTypeRep;
|
||||||
((ClassRepTemplate)$NSContext::currentTypeRep).Constructors.Add(cRep);
|
((ClassRepTemplate)$NSContext::currentTypeRep).Constructors.Add(cRep);
|
||||||
Debug("Processing constructor declaration");
|
Debug("Processing constructor declaration");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user