forked from mono/Embeddinator-4000
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TypeMapper.cs
76 lines (67 loc) · 2.21 KB
/
TypeMapper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using System.Collections.Generic;
namespace Embeddinator.ObjC
{
public enum DuplicationStatus
{
None,
Unresolvable
}
public class TypeMapper
{
Dictionary<ProcessedType, Dictionary<string, ProcessedMemberBase>> MappedTypes = new Dictionary<ProcessedType, Dictionary<string, ProcessedMemberBase>> ();
Dictionary <string, ProcessedMemberBase> GetRegistrationForType (ProcessedType t)
{
Dictionary<string, ProcessedMemberBase> data;
if (MappedTypes.TryGetValue (t, out data))
return data;
return null;
}
public bool IsSelectorTaken (ProcessedMemberBase member)
{
var typeRegistration = GetRegistrationForType (member.DeclaringType);
if (typeRegistration != null) {
foreach (var selector in member.Selectors) {
if (typeRegistration.ContainsKey (selector))
return true;
}
}
return false;
}
public IEnumerable <ProcessedMemberBase> WithSameSelector (ProcessedMemberBase member)
{
var typeRegistration = GetRegistrationForType (member.DeclaringType);
if (typeRegistration != null) {
foreach (var selector in member.Selectors) {
ProcessedMemberBase registeredMember = null;
if (typeRegistration.TryGetValue (selector, out registeredMember))
yield return registeredMember;
}
}
}
public void Register (ProcessedMemberBase member)
{
Logger.Log ($"TypeMapper Register: {member} {String.Join (" ", member.Selectors)}");
var typeRegistration = GetRegistrationForType (member.DeclaringType);
if (typeRegistration == null) {
typeRegistration = new Dictionary<string, ProcessedMemberBase> ();
MappedTypes.Add (member.DeclaringType, typeRegistration);
}
foreach (var selector in member.Selectors) {
typeRegistration.Add (selector, member);
}
}
public DuplicationStatus CheckForDuplicateSelectors (ProcessedMemberBase member)
{
if (IsSelectorTaken (member)) {
foreach (var conflictMethod in WithSameSelector (member))
conflictMethod.FallBackToTypeName = true;
member.FallBackToTypeName = true;
}
// Check to see if FallBackToTypeName is insufficient and scream
if (IsSelectorTaken (member))
return DuplicationStatus.Unresolvable;
return DuplicationStatus.None;
}
}
}