Skip to content

Commit

Permalink
Added support for generating classes from non-readonly structs.
Browse files Browse the repository at this point in the history
  • Loading branch information
KSGRelewise committed Sep 12, 2024
1 parent 74cb4c9 commit 15c197b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Generator/JavaTypeWriters/JavaClassWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ public JavaClassWriter(JavaWriter javaWriter)
this.javaWriter = javaWriter;
}

public bool CanWrite(Type type) => IsClass(type) || IsReadonlyStruct(type);
public bool CanWrite(Type type) => IsClass(type) || IsAnyStruct(type);

private bool IsClass(Type type) => type.IsClass;

private bool IsReadonlyStruct(Type type) => type.IsValueType && type.GetProperties().All(p => !p.CanWrite);

private bool IsAnyStruct(Type type) => type.IsValueType;

public void Write(IndentedTextWriter writer, Type type, string typeName)
{
writer.WriteLine($"""
Expand Down Expand Up @@ -141,6 +143,15 @@ public void Write(IndentedTextWriter writer, Type type, string typeName)
javaWriter.PropertyGetterMethodsWriter.Write(writer, type, gettableProperties);
javaWriter.PropertySetterMethodsWriter.Write(writer, type, typeName, gettableProperties, gettableProperties.Select(p => p.propertyName).ToArray());
}
else if (IsAnyStruct(type))
{
javaWriter.SettablePropertiesWriter.Write(writer, type, ownedProperties);
javaWriter.StaticReadonlyPropertiesWriter.Write(writer, type, staticGetterProperties);

javaWriter.CreatorMethodWriter.Write(writer, type, typeName, settableProperties);
javaWriter.PropertyGetterMethodsWriter.Write(writer, type, ownedProperties);
javaWriter.PropertySetterMethodsWriter.Write(writer, type, typeName, settableProperties, ownedProperties.Select(p => p.propertyName).ToArray());
}

writer.Indent--;
writer.WriteLine("}");
Expand Down

0 comments on commit 15c197b

Please sign in to comment.