Skip to content
This repository was archived by the owner on Jun 20, 2023. It is now read-only.

Commit dee976e

Browse files
committed
null is also an empty string
1 parent 9a6a981 commit dee976e

File tree

2 files changed

+83
-83
lines changed

2 files changed

+83
-83
lines changed

util/AndroidXMapper/AndroidXMapper/FullType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public FullType(string container, string ns, string n)
2626
$"{Namespace}.{Name}";
2727

2828
public bool IsEmpty =>
29-
Namespace == string.Empty || Name == string.Empty;
29+
string.IsNullOrEmpty(Namespace) || string.IsNullOrEmpty(Name);
3030

3131
public override bool Equals(object obj) =>
3232
obj is FullType other && Container == other.Container && Namespace == other.Namespace && Name == other.Name;

util/AndroidXMapper/AndroidXMapper/MappingGenerator.cs

Lines changed: 82 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -43,88 +43,88 @@ public void Generate(TextWriter writer, bool includeWarnings)
4343
new FullType("AndroidX Java package", "AndroidX Java class")),
4444
"Messages");
4545

46-
//foreach (var supportType in supportTypes)
47-
//{
48-
// var useJavaType = !supportType.JavaType.IsEmpty && javaMappings.Count > 0;
49-
50-
// if (TryGetMapping(overrideMappings, supportType.NetType, out var overrideType))
51-
// {
52-
// var matched = xTypes.Where(t => t.NetType.FullName == overrideType).ToList();
53-
// if (matched.Count == 1)
54-
// {
55-
// typeMappings[supportType] = matched[0];
56-
// }
57-
// else if (matched.Count > 1)
58-
// {
59-
// if (includeWarnings)
60-
// WriteRecord(writer, $"WARNING: Too many override types found for type {overrideType}: {string.Join(", ", matched)}.");
61-
// }
62-
// else
63-
// {
64-
// if (includeWarnings)
65-
// WriteRecord(writer, $"WARNING: Unable to find override type for type {overrideType}.");
66-
// }
67-
// }
68-
// else if (TryGetExactMatch(xTypes, supportType, out var exactMatch))
69-
// {
70-
// typeMappings[supportType] = exactMatch;
71-
// }
72-
// else if (useJavaType && TryGetMapping(javaMappings, supportType.JavaType, out var androidx))
73-
// {
74-
// var matched = xTypes.Where(t => t.JavaType.FullName == androidx).ToList();
75-
76-
// // a special case for the XxxConsts types
77-
// const string ConstsSuffix = "Consts";
78-
// if (matched.Count == 2 && matched.Any(m => m.NetType.Name.EndsWith(ConstsSuffix)))
79-
// {
80-
// matched.RemoveAll(m => m.NetType.Name.EndsWith(ConstsSuffix) != supportType.NetType.Name.EndsWith(ConstsSuffix));
81-
// }
82-
83-
// if (matched.Count == 1)
84-
// {
85-
// typeMappings[supportType] = matched[0];
86-
// }
87-
// else if (matched.Count > 1)
88-
// {
89-
// if (includeWarnings)
90-
// WriteRecord(writer, $"WARNING: Too many AndroidX types found for Java type {androidx}: {string.Join(", ", matched)}.");
91-
// }
92-
// else
93-
// {
94-
// if (includeWarnings)
95-
// WriteRecord(writer, $"WARNING: Unable to find AndroidX type for Java type {androidx}.");
96-
// }
97-
// }
98-
// else
99-
// {
100-
// if (includeWarnings && useJavaType)
101-
// WriteRecord(writer, $"WARNING: Unable to find a Java mapping for {supportType}. Trying managed mapping...");
102-
103-
// var matched = xTypes.Where(xt => xt.NetType.Name == supportType.NetType.Name).ToList();
104-
// if (matched.Count == 1)
105-
// {
106-
// typeMappings[supportType] = matched[0];
107-
108-
// if (includeWarnings && useJavaType)
109-
// WriteRecord(writer, $"WARNING: Found a type that appears to match {matched[0]}.");
110-
// }
111-
// else if (matched.Count > 1)
112-
// {
113-
// if (includeWarnings)
114-
// WriteRecord(writer, $"WARNING: Too many AndroidX types found for .NET type {supportType.NetType}: {string.Join(", ", matched)}.");
115-
// }
116-
// else
117-
// {
118-
// if (includeWarnings)
119-
// WriteRecord(writer, $"WARNING: Unable to find AndroidX type for .NET type {supportType.NetType}.");
120-
// }
121-
// }
122-
123-
// if (typeMappings.TryGetValue(supportType, out var androidXType))
124-
// WriteRecord(writer, supportType, androidXType);
125-
//}
126-
127-
foreach (var mapping in javaMappings)
46+
foreach (var supportType in supportTypes)
47+
{
48+
var useJavaType = !supportType.JavaType.IsEmpty && javaMappings.Count > 0;
49+
50+
if (TryGetMapping(overrideMappings, supportType.NetType, out var overrideType))
51+
{
52+
var matched = xTypes.Where(t => t.NetType.FullName == overrideType).ToList();
53+
if (matched.Count == 1)
54+
{
55+
typeMappings[supportType] = matched[0];
56+
}
57+
else if (matched.Count > 1)
58+
{
59+
if (includeWarnings)
60+
WriteRecord(writer, $"WARNING: Too many override types found for type {overrideType}: {string.Join(", ", matched)}.");
61+
}
62+
else
63+
{
64+
if (includeWarnings)
65+
WriteRecord(writer, $"WARNING: Unable to find override type for type {overrideType}.");
66+
}
67+
}
68+
else if (TryGetExactMatch(xTypes, supportType, out var exactMatch))
69+
{
70+
typeMappings[supportType] = exactMatch;
71+
}
72+
else if (useJavaType && TryGetMapping(javaMappings, supportType.JavaType, out var androidx))
73+
{
74+
var matched = xTypes.Where(t => t.JavaType.FullName == androidx).ToList();
75+
76+
// a special case for the XxxConsts types
77+
const string ConstsSuffix = "Consts";
78+
if (matched.Count == 2 && matched.Any(m => m.NetType.Name.EndsWith(ConstsSuffix)))
79+
{
80+
matched.RemoveAll(m => m.NetType.Name.EndsWith(ConstsSuffix) != supportType.NetType.Name.EndsWith(ConstsSuffix));
81+
}
82+
83+
if (matched.Count == 1)
84+
{
85+
typeMappings[supportType] = matched[0];
86+
}
87+
else if (matched.Count > 1)
88+
{
89+
if (includeWarnings)
90+
WriteRecord(writer, $"WARNING: Too many AndroidX types found for Java type {androidx}: {string.Join(", ", matched)}.");
91+
}
92+
else
93+
{
94+
if (includeWarnings)
95+
WriteRecord(writer, $"WARNING: Unable to find AndroidX type for Java type {androidx}.");
96+
}
97+
}
98+
else
99+
{
100+
if (includeWarnings && useJavaType)
101+
WriteRecord(writer, $"WARNING: Unable to find a Java mapping for {supportType}. Trying managed mapping...");
102+
103+
var matched = xTypes.Where(xt => xt.NetType.Name == supportType.NetType.Name).ToList();
104+
if (matched.Count == 1)
105+
{
106+
typeMappings[supportType] = matched[0];
107+
108+
if (includeWarnings && useJavaType)
109+
WriteRecord(writer, $"WARNING: Found a type that appears to match {matched[0]}.");
110+
}
111+
else if (matched.Count > 1)
112+
{
113+
if (includeWarnings)
114+
WriteRecord(writer, $"WARNING: Too many AndroidX types found for .NET type {supportType.NetType}: {string.Join(", ", matched)}.");
115+
}
116+
else
117+
{
118+
if (includeWarnings)
119+
WriteRecord(writer, $"WARNING: Unable to find AndroidX type for .NET type {supportType.NetType}.");
120+
}
121+
}
122+
123+
if (typeMappings.TryGetValue(supportType, out var androidXType))
124+
WriteRecord(writer, supportType, androidXType);
125+
}
126+
127+
foreach (var mapping in javaMappings.Skip(1))
128128
{
129129
var mapped = typeMappings.Keys.FirstOrDefault(k => k.JavaType.FullName == mapping.Key);
130130
if (!mapped.JavaType.IsEmpty)

0 commit comments

Comments
 (0)