Skip to content
This repository was archived by the owner on Jul 6, 2026. It is now read-only.

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

2 files changed

Lines changed: 51 additions & 6 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
usingSystem;
2+
usingSystem.Linq;
3+
usingMonoDroid.Generation;
4+
usingNUnit.Framework;
5+
6+
namespacegeneratortests
7+
{
8+
[TestFixture]
9+
publicclassCodeGeneratorContextTests
10+
{
11+
[Test]
12+
publicvoidGetContextTypeMember()
13+
{
14+
varklass=newTestClass("Object","java.code.MyClass");
15+
16+
klass.AddMethod(SupportTypeBuilder.CreateMethod(klass,"Echo",newCodeGenerationOptions(),"uint",false,false,newParameter("value","uint","uint",false)));
17+
klass.AddField(newTestField("string","Foo"));
18+
19+
varcontext=newCodeGeneratorContext();
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
publicstringGetContextTypeMember()
2121
{
22-
varoutput=ContextType?.FullName??string.Empty;
22+
varparts=newList<string>();
2323

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

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

0 commit comments

Comments
 (0)