Welcome to mirror list, hosted at ThFree Co, Russian Federation.

FrameworkTypeEntry.cs « Frameworks « Updater « Mono.Documentation « mdoc - github.com/mono/api-doc-tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 204e0fd0b743c34b9bb5c6f030226b7be05011c7 (plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
using System;
using System.Collections.Generic;
using System.Linq;
using Mono.Cecil;
using Mono.Documentation.Updater.Formatters;

namespace Mono.Documentation.Updater.Frameworks
{
	public class FrameworkTypeEntry : IComparable<FrameworkTypeEntry>
	{
        Dictionary<string, string> sigMap = new Dictionary<string, string> ();
        Dictionary<string, bool> sigDocMap = new Dictionary<string, bool>();

        ILFullMemberFormatter formatterField;
        ILFullMemberFormatter formatter
        {
            get
            {
                if (formatterField == null)
                    formatterField = new ILFullMemberFormatter(MDocUpdater.Instance.TypeMap);
                return formatterField;
            }
        }
        DocIdFormatter docidFormatter = new DocIdFormatter (MDocUpdater.Instance.TypeMap);

		FrameworkEntry fx;

        Lazy<FrameworkTypeEntry[]> previouslyProcessedFXTypes;

        public int TimesProcessed { get; set; }

        public Dictionary<string, bool> AssembliesMemberOf = new Dictionary<string, bool>();

        public void NoteAssembly(AssemblyDefinition noting, AssemblyDefinition source)
        {
            if (noting == null || source == null)
                return;

            bool isForward = noting.Name.Name == source.Name.Name;
            if (!AssembliesMemberOf.ContainsKey(noting.Name.Name))
            {
                AssembliesMemberOf.Add(noting.Name.Name, isForward);
            }
        }

        /// <summary>
        /// Returns a list of all corresponding type entries,
        /// which have already been processed.
        /// </summary>
        public FrameworkTypeEntry[] PreviouslyProcessedFrameworkTypes {
            get
            {
                if (previouslyProcessedFXTypes == null)
                {
                    if (this.Framework == null || this.Framework.Frameworks == null)
                    {
                        previouslyProcessedFXTypes = new Lazy<FrameworkTypeEntry[]> (() => new FrameworkTypeEntry[0]);
                    }
                    else
                    {
                        previouslyProcessedFXTypes = new Lazy<FrameworkTypeEntry[]> (
                           () => this.Framework.Frameworks
                               .Where (f => f.Index < this.Framework.Index)
                                .Select (f => f.FindTypeEntry (this))
                                .ToArray ()
                        );
                    }
                }
                return previouslyProcessedFXTypes.Value;
            }
        }

		public static FrameworkTypeEntry Empty = new EmptyTypeEntry (FrameworkEntry.Empty) { Name = "Empty" };

		public FrameworkTypeEntry (FrameworkEntry fx)
		{
			this.fx = fx;
		}

		public string Id { get; set; }
		public string Name { get; set; }
		public string Namespace { get; set; }
		public FrameworkEntry Framework { get { return fx; } }

        public bool IsOnLastFramework { get { return this.Framework.IsLastFrameworkForType(this); } }
        public bool IsOnFirstFramework { get { return this.Framework.IsFirstFrameworkForType(this); } }
        public bool IsMemberOnLastFramework (MemberReference memberSig)
            => this.Framework.IsLastFrameworkForMember (this, formatter.GetDeclaration(memberSig), docidFormatter.GetDeclaration(memberSig));
        public bool IsMemberOnFirstFramework (MemberReference memberSig)
            => this.Framework.IsFirstFrameworkForMember (this, formatter.GetDeclaration (memberSig), docidFormatter.GetDeclaration(memberSig));
        public string AllFrameworkStringForMember (MemberReference memberSig)
            => this.Framework.AllFrameworksWithMember (this, formatter.GetDeclaration (memberSig), docidFormatter.GetDeclaration(memberSig));

        public IEnumerable<string> Members {
			get {
				return this.sigMap.Values.OrderBy(v => v).Distinct();
			}
		}

		public virtual void ProcessMember (MemberReference member)
        {
            string key = null;

            // this is for lookup purposes
            try
            {
                var sig = formatter.GetDeclaration(member);
                if (sig != null && !sigMap.ContainsKey (sig))
                {
                    sigMap.Add (sig, string.Empty);
                    key = sig;
                }
            }
            catch { }

            if (key == null)
                return;

            var resolvedMember = member.Resolve ();
			if (resolvedMember != null) {
                var docid = docidFormatter.GetDeclaration (member);
				sigMap[key] = docid;
                sigDocMap[docid] = true;
			}
			else 
				sigMap[key] = member.FullName;

        }

        public virtual void ProcessMember(string ifacedocid)
        {
            if (string.IsNullOrWhiteSpace(ifacedocid))
                return;

            sigMap[ifacedocid] = ifacedocid;
            sigDocMap[ifacedocid] = true;
        }

        public bool ContainsCSharpSig(string sig)
        {
            return sigMap.ContainsKey(sig);
        }

        public bool ContainsDocId(string sig)
        {
            return sigDocMap.ContainsKey(sig);
        }

        public override string ToString () => $"{this.Name} in {this.fx.Name}";

		public int CompareTo (FrameworkTypeEntry other)
		{
			if (other == null) return -1;
			if (this.Name == null) return 1;

			return string.Compare (this.Name, other.Name, StringComparison.CurrentCulture);
		}

		public override bool Equals (object obj)
		{
			FrameworkTypeEntry other = obj as FrameworkTypeEntry;
			if (other == null) return false;
			return this.Name.Equals (other.Name);
		}

        public override int GetHashCode ()
        {
            return this.Name?.GetHashCode () ?? base.GetHashCode ();
        }

		class EmptyTypeEntry : FrameworkTypeEntry
		{
			public EmptyTypeEntry (FrameworkEntry fx) : base (fx) { }
			public override void ProcessMember (MemberReference member) { }
            public override void ProcessMember(string ifacedocid) { }
        }
    }
}