Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions tests/generator-Tests/Unit-Tests/CodeGenerationOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,21 @@ public void GetOutputNameUseGlobal ()
Assert.AreEqual ("global::System.Collections.Generic.List<global::System.Collections.Generic.List<string>.Enumerator[]>",
opt.GetOutputName ("System.Collections.Generic.List<System.Collections.Generic.List<string>.Enumerator[]>"));
}

[Test]
public void GetTypeReferenceName_Nullable ()
{
var opt = new CodeGenerationOptions { SupportNullableReferenceTypes = true };

var system_void = new ReturnValue (null, "void", "System.Void", false, false);
system_void.Validate (opt, null, null);

Assert.AreEqual ("void", opt.GetTypeReferenceName (system_void));

var primitive_void = new ReturnValue (null, "void", "void", false, false);
primitive_void.Validate (opt, null, null);

Assert.AreEqual ("void", opt.GetTypeReferenceName (primitive_void));
}
}
}
4 changes: 2 additions & 2 deletions tests/generator-Tests/Unit-Tests/ManagedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void Method ()

Assert.AreEqual ("public", method.Visibility);
Assert.AreEqual ("void", method.Return);
Assert.AreEqual ("System.Void", method.ReturnType);
Assert.AreEqual ("void", method.ReturnType);
Assert.AreEqual ("Bar", method.Name);
Assert.AreEqual ("bar", method.JavaName);
Assert.AreEqual ("()V", method.JniSignature);
Expand Down Expand Up @@ -165,7 +165,7 @@ public void MethodWithParameters ()
Assert.IsTrue (method.Validate (new CodeGenerationOptions (), new GenericParameterDefinitionList (), new CodeGeneratorContext ()), "method.Validate failed!");
Assert.AreEqual ("(ZID)Ljava/lang/String;", method.JniSignature);
Assert.AreEqual ("java.lang.String", method.Return);
Assert.AreEqual ("System.String", method.ManagedReturn);
Assert.AreEqual ("string", method.ManagedReturn);

var parameter = method.Parameters [0];
Assert.AreEqual ("a", parameter.Name);
Expand Down
18 changes: 10 additions & 8 deletions tools/generator/CodeGenerationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,23 @@ string GetNullable (string s)
switch (s) {
case "void":
case "int":
//case "int[]":
case "bool":
//case "bool[]":
case "float":
//case "float[]":
case "sbyte":
//case "sbyte[]":
case "long":
//case "long[]":
case "char":
//case "char[]":
case "double":
//case "double[]":
case "short":
//case "short[]":
case "System.Boolean":
case "System.Byte":
case "System.Char":
case "System.Double":
case "System.Int16":
case "System.Int32":
case "System.Int64":
case "System.Single":
case "System.SByte":
case "System.Void":
case "Android.Graphics.Color":
return string.Empty;
}
Expand Down
19 changes: 19 additions & 0 deletions tools/generator/Extensions/ManagedExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@ public static string StripArity (this string type)

return type;
}

// Convert a fully qualified type like "System.Void" to the primitive type "void" if applicable
public static string FilterPrimitive (this string type)
{
return type switch {
"System.Boolean" => "bool",
"System.Char" => "char",
"System.Byte" => "byte",
"System.SByte" => "byte",
"System.Int16" => "short",
"System.Int32" => "int",
"System.Int64" => "long",
"System.Single" => "float",
"System.Double" => "double",
"System.Void" => "void",
"System.String" => "string",
_ => type
};
}
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ public static Method CreateMethod (GenBase declaringType, MethodDefinition m)
IsStatic = m.IsStatic,
IsVirtual = m.IsVirtual,
JavaName = reg_attr != null ? ((string) reg_attr.ConstructorArguments [0].Value) : m.Name,
ManagedReturn = m.ReturnType.FullNameCorrected ().StripArity (),
Return = m.ReturnType.FullNameCorrected ().StripArity (),
ManagedReturn = m.ReturnType.FullNameCorrected ().StripArity ().FilterPrimitive (),
Return = m.ReturnType.FullNameCorrected ().StripArity ().FilterPrimitive (),
Visibility = m.Visibility ()
};

Expand Down