1 #Region "Microsoft.VisualBasic::5d2a379adbaedd068f16cc33b751ae0a, Microsoft.VisualBasic.Core\ApplicationServices\VBDev\XmlDoc\Project.vb"
2
3     ' Author:
4     
5     '       asuka (amethyst.asuka@gcmodeller.org)
6     '       xie (genetics@smrucc.org)
7     '       xieguigang (xie.guigang@live.com)
8     
9     ' Copyright (c) 2018 GPL3 Licensed
10     
11     
12     ' GNU GENERAL PUBLIC LICENSE (GPL3)
13     
14     
15     ' This program is free software: you can redistribute it and/or modify
16     ' it under the terms of the GNU General Public License as published by
17     ' the Free Software Foundation, either version 3 of the License, or
18     ' (at your option) any later version.
19     
20     ' This program is distributed in the hope that it will be useful,
21     ' but WITHOUT ANY WARRANTY; without even the implied warranty of
22     ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23     ' GNU General Public License for more details.
24     
25     ' You should have received a copy of the GNU General Public License
26     ' along with this program. If not, see <http://www.gnu.org/licenses/>.
27
28
29
30     ' /********************************************************************************/
31
32     ' Summaries:
33
34     '     Class Project
35     
36     '         Properties: Name, Namespaces
37     
38     '         Constructor: (+2 OverloadsSub New
39     
40     '         Function: EnsureNamespace, GetNamespace, ToString
41     
42     '         Sub: processMember, processType, ProcessXmlDoc
43     
44     
45     ' /********************************************************************************/
46
47 #End Region
48
49 ' Copyright (c) Bendyline LLC. All rights reserved. Licensed under the Apache License, Version 2.0.
50 '    You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. 
51
52
53 Imports System.Runtime.CompilerServices
54 Imports System.Xml
55 Imports Microsoft.VisualBasic.ApplicationServices.Development.XmlDoc.Serialization
56 Imports Microsoft.VisualBasic.Text
57
58 Namespace ApplicationServices.Development.XmlDoc.Assembly
59
60     ''' <summary>
61     ''' Describes a Project, a collection of related types and namespaces.  In this case, one Project = one DLL.
62     ''' </summary>
63     Public Class Project
64
65         Dim _namespaces As Dictionary(Of String, ProjectNamespace)
66
67         Public Property Name() As String
68
69         Public ReadOnly Property Namespaces() As IEnumerable(Of ProjectNamespace)
70             <MethodImpl(MethodImplOptions.AggressiveInlining)>
71             Get
72                 Return Me._namespaces.Values
73             End Get
74         End Property
75
76         Public Sub New(name As String)
77             _Name = name.Trim(ASCII.CR, ASCII.LF, " ")
78             _namespaces = New Dictionary(Of String, ProjectNamespace)()
79         End Sub
80
81         Sub New(name$, namespaces As Dictionary(Of String, ProjectNamespace))
82             Me.Name = name
83             Me._namespaces = namespaces
84         End Sub
85
86         Public Overrides Function ToString() As String
87             Return Name
88         End Function
89
90         Public Function GetNamespace(namespacePath As StringAs ProjectNamespace
91             If _namespaces.ContainsKey(namespacePath.ToLower()) Then
92                 Return _namespaces(namespacePath.ToLower())
93             End If
94
95             Return Nothing
96         End Function
97
98         Public Function EnsureNamespace(namespacePath As StringAs ProjectNamespace
99             Dim pn As ProjectNamespace = GetNamespace(namespacePath)
100
101             If pn Is Nothing Then
102                 pn = New ProjectNamespace(Me) With {
103                     .Path = namespacePath
104                 }
105                 _namespaces.Add(namespacePath.ToLower(), pn)
106             End If
107
108             Return pn
109         End Function
110
111         Friend Sub ProcessXmlDoc(document As XmlDocument, excludeVBSpecific As Boolean)
112             Dim memberNodes As XmlNodeList = document _
113                 .DocumentElement _
114                 .SelectNodes("members/member")
115
116             For Each memberNode As XmlNode In memberNodes
117                 Dim memberDescription As String = memberNode.Attributes.GetNamedItem("name").InnerText
118                 Dim firstSemicolon As Integer = memberDescription.IndexOf(":")
119
120                 If excludeVBSpecific AndAlso memberDescription.IsMyResource Then
121                     Continue For
122                 End If
123
124                 If firstSemicolon = 1 Then
125                     Dim typeChar As Char = memberDescription(0)
126
127                     If typeChar = "T"Then
128                         Call processType(memberNode, memberDescription)
129                     Else
130                         Call processMember(memberNode, memberDescription, typeChar)
131                     End If
132                 End If
133             Next
134         End Sub
135
136         Private Sub processMember(memberNode As XmlNode, memberDescription$, typeChar As Char)
137             Dim memberFullName As String = memberDescription.Substring(2, memberDescription.Length - 2)
138             Dim firstParen As Integer = memberFullName.IndexOf("(")
139
140             If firstParen > 0 Then
141                 memberFullName = memberFullName.Substring(0, firstParen)
142             End If
143
144             Dim lastPeriod As Integer = memberFullName.LastIndexOf(".")
145
146             If lastPeriod > 0 Then
147                 Dim typeFullName As String = memberFullName.Substring(0, lastPeriod)
148
149                 lastPeriod = typeFullName.LastIndexOf(".")
150
151                 If lastPeriod > 0 Then
152                     Dim namespaceFullName As String = typeFullName.Substring(0, lastPeriod)
153
154                     lastPeriod = typeFullName.LastIndexOf(".")
155
156                     If lastPeriod > 0 Then
157                         Dim typeShortName As String = typeFullName.Substring(lastPeriod + 1, typeFullName.Length - (lastPeriod + 1))
158
159                         lastPeriod = memberFullName.LastIndexOf(".")
160
161                         If lastPeriod > 0 Then
162                             Dim memberShortName As String = memberFullName.Substring(lastPeriod + 1, memberFullName.Length - (lastPeriod + 1))
163                             Dim pn As ProjectNamespace = Me.EnsureNamespace(namespaceFullName)
164                             Dim pt As ProjectType = pn.EnsureType(typeShortName)
165
166                             If typeChar = "M"Then
167                                 pt.EnsureMethod(memberShortName).LoadFromNode(memberNode)
168                             ElseIf typeChar = "P"Then
169                                 pt.EnsureProperty(memberShortName).LoadFromNode(memberNode)
170                             ElseIf typeChar = "F"Then
171                                 pt.EnsureField(memberShortName).LoadFromNode(memberNode)
172                             ElseIf typeChar = "E"Then
173                                 pt.EnsureEvent(memberShortName).LoadFromNode(memberNode)
174                             Else
175                                 Throw New NotImplementedException
176                             End If
177                         End If
178                     End If
179                 End If
180             End If
181         End Sub
182
183         Private Sub processType(memberNode As XmlNode, memberDescription$)
184             Dim typeFullName As String = memberDescription.Substring(2, memberDescription.Length - 2)
185             Dim lastPeriod As Integer = typeFullName.LastIndexOf(".")
186
187             lastPeriod = typeFullName.LastIndexOf(".")
188
189             If lastPeriod > 0 Then
190                 Dim namespaceFullName As String = typeFullName.Substring(0, lastPeriod)
191                 Dim typeShortName As String = typeFullName.Substring(lastPeriod + 1, typeFullName.Length - (lastPeriod + 1))
192
193                 Call EnsureNamespace(namespaceFullName) _
194                     .EnsureType(typeShortName) _
195                     .LoadFromNode(memberNode)
196             End If
197         End Sub
198     End Class
199 End Namespace