22using CodeNav . OutOfProc . ViewModels ;
33using Microsoft . CodeAnalysis ;
44using Microsoft . CodeAnalysis . CSharp ;
5- using Microsoft . CodeAnalysis . CSharp . Syntax ;
65using Microsoft . CodeAnalysis . Text ;
76
87namespace CodeNav . OutOfProc . Languages . CSharp . Mappers ;
98
109public static class BaseMapper
1110{
12- public static T MapBase < T > (
13- SyntaxNode source ,
14- SyntaxToken identifier ,
15- SyntaxTokenList modifiers ,
16- SemanticModel semanticModel ,
17- CodeDocumentViewModel codeDocumentViewModel ) where T : CodeItem
18- => MapBase < T > (
19- source ,
20- identifier ,
21- modifiers ,
22- semanticModel ,
23- codeDocumentViewModel ) ;
24-
25- public static T MapBase < T > (
26- SyntaxNode source ,
27- NameSyntax name ,
28- SemanticModel semanticModel ,
29- CodeDocumentViewModel codeDocumentViewModel ) where T : CodeItem
30- => MapBase < T > (
31- source ,
32- identifier : null ,
33- name . ToString ( ) ,
34- modifiers : [ ] ,
35- semanticModel ,
36- codeDocumentViewModel ) ;
37-
38- public static T MapBase < T > (
39- SyntaxNode source ,
40- string name ,
41- SemanticModel semanticModel ,
42- CodeDocumentViewModel codeDocumentViewModel ) where T : CodeItem
43- => MapBase < T > (
44- source ,
45- identifier : null ,
46- name ,
47- modifiers : [ ] ,
48- semanticModel ,
49- codeDocumentViewModel ) ;
50-
51- public static T MapBase < T > (
52- SyntaxNode source ,
53- SyntaxToken identifier ,
54- SemanticModel semanticModel ,
55- CodeDocumentViewModel codeDocumentViewModel ) where T : CodeItem
56- => MapBase < T > (
57- source ,
58- identifier ,
59- identifier . Text ,
60- modifiers : [ ] ,
61- semanticModel ,
62- codeDocumentViewModel ) ;
63-
6411 /// <summary>
6512 /// Map commonly shared code item properties based on the syntaxt token that is been mapped
6613 /// </summary>
6714 /// <typeparam name="T"></typeparam>
6815 /// <param name="source">Syntax node of the code member</param>
16+ /// <param name="semanticModel">Semantic model used during compilation</param>
17+ /// <param name="codeDocumentViewModel">Code document view model used in the CodeNav tool window</param>
6918 /// <param name="identifier">Syntax token of the code identifier</param>
7019 /// <param name="name">Name of the code member</param>
7120 /// <param name="modifiers">Accessibility modifiers of the code member</param>
72- /// <param name="semanticModel">Semantic model used during compilation</param>
73- /// <param name="codeDocumentViewModel">Code document view model used in the CodeNav tool window</param>
7421 /// <returns>Code item class or othe code class derived from code item</returns>
75- private static T MapBase < T > (
22+ public static T MapBase < T > (
7623 SyntaxNode source ,
77- SyntaxToken ? identifier ,
78- string name ,
79- SyntaxTokenList modifiers ,
8024 SemanticModel semanticModel ,
81- CodeDocumentViewModel codeDocumentViewModel ) where T : CodeItem
25+ CodeDocumentViewModel codeDocumentViewModel ,
26+ SyntaxToken ? identifier = null ,
27+ string name = "" ,
28+ SyntaxTokenList ? modifiers = null ) where T : CodeItem
8229 {
8330 var codeItem = Activator . CreateInstance < T > ( ) ;
8431
@@ -103,13 +50,11 @@ private static T MapBase<T>(
10350
10451 private static TextSpan MapOutlineSpan ( TextSpan span , TextSpan ? identifierSpan , string name )
10552 {
106- var outlineSpanStart = span . Start ;
107-
108- outlineSpanStart += identifierSpan != null
109- ? identifierSpan . Value . Length
110- : name . Length ;
53+ var outlineSpanStart = identifierSpan != null
54+ ? identifierSpan . Value . End
55+ : span . Start + name . Length ;
11156
112- return new TextSpan ( outlineSpanStart , span . Length ) ;
57+ return new TextSpan ( outlineSpanStart , span . End - outlineSpanStart ) ;
11358 }
11459
11560 private static string MapFullName ( SyntaxNode source , string name , SemanticModel semanticModel )
@@ -128,25 +73,30 @@ private static string MapFullName(SyntaxNode source, string name, SemanticModel
12873 private static string MapName ( SyntaxToken ? identifier , string name )
12974 => identifier != null ? identifier . Value . Text : name ;
13075
131- private static CodeItemAccessEnum MapAccess ( SyntaxTokenList modifiers , SyntaxNode source )
76+ private static CodeItemAccessEnum MapAccess ( SyntaxTokenList ? modifiers , SyntaxNode source )
13277 {
133- if ( modifiers . Any ( m => m . RawKind == ( int ) SyntaxKind . SealedKeyword ) )
78+ if ( modifiers == null )
79+ {
80+ return MapDefaultAccess ( source ) ;
81+ }
82+
83+ if ( modifiers . Value . Any ( m => m . RawKind == ( int ) SyntaxKind . SealedKeyword ) )
13484 {
13585 return CodeItemAccessEnum . Sealed ;
13686 }
137- if ( modifiers . Any ( m => m . RawKind == ( int ) SyntaxKind . PublicKeyword ) )
87+ if ( modifiers . Value . Any ( m => m . RawKind == ( int ) SyntaxKind . PublicKeyword ) )
13888 {
13989 return CodeItemAccessEnum . Public ;
14090 }
141- if ( modifiers . Any ( m => m . RawKind == ( int ) SyntaxKind . PrivateKeyword ) )
91+ if ( modifiers . Value . Any ( m => m . RawKind == ( int ) SyntaxKind . PrivateKeyword ) )
14292 {
14393 return CodeItemAccessEnum . Private ;
14494 }
145- if ( modifiers . Any ( m => m . RawKind == ( int ) SyntaxKind . ProtectedKeyword ) )
95+ if ( modifiers . Value . Any ( m => m . RawKind == ( int ) SyntaxKind . ProtectedKeyword ) )
14696 {
14797 return CodeItemAccessEnum . Protected ;
14898 }
149- if ( modifiers . Any ( m => m . RawKind == ( int ) SyntaxKind . InternalKeyword ) )
99+ if ( modifiers . Value . Any ( m => m . RawKind == ( int ) SyntaxKind . InternalKeyword ) )
150100 {
151101 return CodeItemAccessEnum . Internal ;
152102 }
0 commit comments