Skip to content

Commit

Permalink
Updated parameter list to use nullability annotation for last paramet…
Browse files Browse the repository at this point in the history
…er as well.
  • Loading branch information
KSGRelewise committed Sep 19, 2024
1 parent eb32e04 commit fe7fc75
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Generator/JavaMemberWriters/JavaCreatorMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private void WriteCreatorMethodBody(IndentedTextWriter writer, string variable,
if (propertyName is not null)
{
if (property!.PropertyType.IsGenericType && property!.PropertyType.GetGenericTypeDefinition() == typeof(List<>) && (parameter.ParameterType.IsArray
|| (parameter == parameters.Last() && javaWriter.BetterTypedParameterTypeName(parameter.ParameterType, new NullabilityInfoContext().Create(parameter)).Contains("..."))))
|| (parameter == parameters.Last() && javaWriter.BetterTypedParameterTypeName(parameter).Contains("..."))))
{
writer.WriteLine($"{variable}.{propertyName.AsFieldName()} = new ArrayList<>(Arrays.asList({parameter.Name.AsFieldName()}));");
}
Expand Down Expand Up @@ -262,7 +262,7 @@ private string ParameterList(ParameterInfo[] parameters)
{
return string.Join(", ",
parameters.Select(parameter =>
$"{(parameters[^1] == parameter ? javaWriter.BetterTypedParameterTypeName(parameter.ParameterType, new NullabilityInfoContext().Create(parameter)) : javaWriter.TypeName(parameter))} {parameter.Name.AsFieldName()}"
$"{(parameters[^1] == parameter ? javaWriter.BetterTypedParameterTypeName(parameter) : javaWriter.TypeName(parameter))} {parameter.Name.AsFieldName()}"
)
);
}
Expand Down
7 changes: 5 additions & 2 deletions Generator/JavaWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ private static string PrependNullableIfApplicable(string typeName, NullabilityIn
return typeName;
}

public string BetterTypedParameterTypeName(Type parameterType, NullabilityInfo nullabilityInfo)
public string BetterTypedParameterTypeName(ParameterInfo parameter)
{
Type parameterType = parameter.ParameterType;
var nullabilityInfo = new NullabilityInfoContext().Create(parameter);

if (nullabilityInfo.WriteState is NullabilityState.Nullable)
{
parameterType = nullabilityInfo.Type;
Expand All @@ -114,7 +117,7 @@ parameterType.GenericTypeArguments is [var elementType]
? TypeName(elementType) + "..."
: parameterType.IsArray
? TypeName(parameterType.GetElementType()!) + "..."
: TypeName(parameterType);
: PrependNullableIfApplicable(TypeName(parameterType), nullabilityInfo);
}

public string BetterTypedParameterTypeName(PropertyInfo property, NullabilityInfo nullabilityInfo)
Expand Down

0 comments on commit fe7fc75

Please sign in to comment.