Skip to content

Commit 9c73dbf

Browse files
authored
[generator] Output correct formatting for binding warnings (#737)
In d664e90 we refactored some output around binding warning messages in order to better support localization. Unfortunately this refactoring left out a period between some type and member names: warning BG8700: Unknown return type 'Android.App.Admin.AppOpsManagerMode' for member 'Android.App.AppOpsManagerUnsafeCheckOp (java.lang.String, int, java.lang.String)'. `Android.App.AppOpsManagerUnsafeCheckOp` should instead be `Android.App.AppOpsManager.UnsafeCheckOp`. Fix `CodeGeneratorContext.GetContextTypeMember()` so that `.`s are inserted everywhere required.
1 parent b991bb8 commit 9c73dbf

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.Linq;
3+
using MonoDroid.Generation;
4+
using NUnit.Framework;
5+
6+
namespace generatortests
7+
{
8+
[TestFixture]
9+
public class CodeGeneratorContextTests
10+
{
11+
[Test]
12+
public void GetContextTypeMember ()
13+
{
14+
var klass = new TestClass ("Object", "java.code.MyClass");
15+
16+
klass.AddMethod (SupportTypeBuilder.CreateMethod (klass, "Echo", new CodeGenerationOptions (), "uint", false, false, new Parameter ("value", "uint", "uint", false)));
17+
klass.AddField (new TestField ("string", "Foo"));
18+
19+
var context = new CodeGeneratorContext ();
20+
context.ContextTypes.Push (klass);
21+
22+
Assert.AreEqual ("java.code.MyClass", context.GetContextTypeMember ());
23+
24+
context.ContextMethod = klass.Methods.Single ();
25+
26+
Assert.AreEqual ("java.code.MyClass.Echo (uint)", context.GetContextTypeMember ());
27+
28+
context.ContextMethod = null;
29+
context.ContextField = klass.Fields.Single ();
30+
31+
Assert.AreEqual ("java.code.MyClass.Foo", context.GetContextTypeMember ());
32+
33+
context.ContextMethod = klass.Methods.Single ();
34+
context.ContextField = null;
35+
context.ContextTypes.Clear ();
36+
37+
Assert.AreEqual ("Echo (uint)", context.GetContextTypeMember ());
38+
}
39+
}
40+
}

tools/generator/CodeGeneratorContext.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,19 @@ public class CodeGeneratorContext
1919

2020
public string GetContextTypeMember ()
2121
{
22-
var output = ContextType?.FullName ?? string.Empty;
22+
var parts = new List<string> ();
2323

24-
if (ContextMethod != null) {
25-
output += $"{ContextMethod.Name} ({string.Join (", ", ContextMethod?.Parameters.Select (p => p.InternalType).ToArray ())})";
26-
return output;
27-
}
24+
// Type name
25+
if (!string.IsNullOrEmpty (ContextType?.FullName))
26+
parts.Add (ContextType?.FullName);
2827

29-
return output + ContextField?.Name;
28+
// Member name
29+
if (ContextMethod != null)
30+
parts.Add ($"{ContextMethod.Name} ({string.Join (", ", ContextMethod?.Parameters.Select (p => p.InternalType).ToArray ())})");
31+
else if (ContextField != null)
32+
parts.Add (ContextField.Name);
33+
34+
return string.Join (".", parts);
3035
}
3136
}
3237
}

0 commit comments

Comments
 (0)