Skip to content

Commit

Permalink
Merge pull request #20 from Relewise/feature/added-support-for-non-re…
Browse files Browse the repository at this point in the history
…adonly-structs

Added support for generating classes from non-readonly structs.
  • Loading branch information
KSGRelewise authored Sep 12, 2024
2 parents b54ea3c + 4de5f02 commit 499c6e1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 263 deletions.
24 changes: 13 additions & 11 deletions 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 @@ -123,16 +125,7 @@ public void Write(IndentedTextWriter writer, Type type, string typeName)
.Select(MapPropertyInfo)
.ToArray();

if (IsClass(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());
}
else if (IsReadonlyStruct(type))
if (IsReadonlyStruct(type))
{
javaWriter.SettablePropertiesWriter.Write(writer, type, gettableProperties);
javaWriter.StaticReadonlyPropertiesWriter.Write(writer, type, staticGetterProperties);
Expand All @@ -141,6 +134,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 (IsClass(type) || 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
73 changes: 0 additions & 73 deletions src/src/main/java/com/relewise/client/model/EntitiesRequest.java

This file was deleted.

This file was deleted.

0 comments on commit 499c6e1

Please sign in to comment.