11using System . Text ;
2+ using Lite3 . Generators . Text ;
23using Microsoft . CodeAnalysis ;
34using Microsoft . CodeAnalysis . Text ;
4- using TronDotNet . Generators . Text ;
5- using static TronDotNet . Generators . TronApiGenerator . AttributeProperty ;
5+ using static Lite3 . Generators . Lite3ApiGenerator . AttributeProperty ;
66
7- namespace TronDotNet . Generators ;
7+ namespace Lite3 . Generators ;
88
99[ Generator ]
10- public class TronApiGenerator : IIncrementalGenerator
10+ public class Lite3ApiGenerator : IIncrementalGenerator
1111{
1212 public static class AttributeProperty
1313 {
@@ -18,14 +18,14 @@ public const string
1818 }
1919
2020 private const string
21- CoreTypeName = "Lite3 " ,
22- TronTypeName = "Tron " ,
23- TronContextTypeName = "TronContext " ,
24- TronContextExtensionsTypeName = $ "{ TronContextTypeName } Extensions",
21+ CoreTypeName = "Lite3Core " ,
22+ PublicTypeName = "Lite3 " ,
23+ ContextTypeName = "Lite3Context " ,
24+ ContextExtensionsTypeName = $ "{ ContextTypeName } Extensions",
2525 CoreMethodPrefix = $ "{ CoreTypeName } .",
26- CoreNamespace = $ "{ nameof ( TronDotNet ) } ",
26+ CoreNamespace = $ "{ nameof ( Lite3 ) } ",
2727 AttributeNamespace = $ "{ CoreNamespace } .{ nameof ( Generators ) } ",
28- AttributeName = "TronApiAttribute " ,
28+ AttributeName = "Lite3ApiAttribute " ,
2929 AttributeTypeMetadataName = $ "{ AttributeNamespace } .{ AttributeName } ",
3030 AttributeSource =
3131 $$ """
@@ -65,25 +65,25 @@ public void Initialize(IncrementalGeneratorInitializationContext initialization)
6565
6666 var attributeType = compilation . GetTypeByMetadataName ( AttributeTypeMetadataName ) ;
6767
68- var tronPrimarySource = new StringBuilder ( ) ;
69- var tronContextSource = new StringBuilder ( ) ;
68+ var primarySource = new StringBuilder ( ) ;
69+ var contextSource = new StringBuilder ( ) ;
7070
71- tronPrimarySource
71+ primarySource
7272 . Append ( "namespace " ) . Append ( CoreNamespace ) . AppendLine ( ";" )
7373 . AppendLine ( )
7474 . AppendLine ( "using System.Runtime.CompilerServices;" )
75- . Append ( "using static " ) . Append ( CoreNamespace ) . Append ( "." ) . Append ( CoreTypeName ) . AppendLine ( ";" )
75+ . Append ( "using static " ) . Append ( CoreTypeName ) . AppendLine ( ";" )
7676 . AppendLine ( )
77- . Append ( "public static partial class " ) . AppendLine ( TronTypeName )
77+ . Append ( "public static partial class " ) . AppendLine ( PublicTypeName )
7878 . AppendLine ( "{" ) ;
7979
80- tronContextSource
80+ contextSource
8181 . Append ( "namespace " ) . Append ( CoreNamespace ) . AppendLine ( ";" )
8282 . AppendLine ( )
8383 . AppendLine ( "using System.Runtime.CompilerServices;" )
84- . Append ( "using static " ) . Append ( CoreNamespace ) . Append ( "." ) . Append ( CoreTypeName ) . AppendLine ( ";" )
84+ . Append ( "using static " ) . Append ( CoreTypeName ) . AppendLine ( ";" )
8585 . AppendLine ( )
86- . Append ( "public static class " ) . AppendLine ( TronContextExtensionsTypeName )
86+ . Append ( "public static class " ) . AppendLine ( ContextExtensionsTypeName )
8787 . AppendLine ( "{" ) ;
8888
8989 foreach ( var ( method , methodIndex ) in methodSymbols . Select ( Index ) )
@@ -117,24 +117,24 @@ public void Initialize(IncrementalGeneratorInitializationContext initialization)
117117
118118 var writeNewLine = methodIndex > 0 ;
119119 // ReSharper disable RedundantAssignment
120- writeNewLine |= TryWriteMethod ( tronContextSource , method , attrData , xmlComment , writeNewLine , useTryPattern : true , createKeyData : true , isContextApi : true ) ;
121- writeNewLine |= TryWriteMethod ( tronContextSource , method , attrData , xmlComment , writeNewLine , useTryPattern : true , createKeyData : false , isContextApi : true ) ;
122- writeNewLine |= TryWriteMethod ( tronContextSource , method , attrData , xmlComment , writeNewLine , useTryPattern : false , createKeyData : true , isContextApi : true ) ;
123- writeNewLine |= TryWriteMethod ( tronContextSource , method , attrData , xmlComment , writeNewLine , useTryPattern : false , createKeyData : false , isContextApi : true ) ;
120+ writeNewLine |= TryWriteMethod ( contextSource , method , attrData , xmlComment , writeNewLine , useTryPattern : true , createKeyData : true , isContextApi : true ) ;
121+ writeNewLine |= TryWriteMethod ( contextSource , method , attrData , xmlComment , writeNewLine , useTryPattern : true , createKeyData : false , isContextApi : true ) ;
122+ writeNewLine |= TryWriteMethod ( contextSource , method , attrData , xmlComment , writeNewLine , useTryPattern : false , createKeyData : true , isContextApi : true ) ;
123+ writeNewLine |= TryWriteMethod ( contextSource , method , attrData , xmlComment , writeNewLine , useTryPattern : false , createKeyData : false , isContextApi : true ) ;
124124
125125 writeNewLine = methodIndex > 0 ;
126- writeNewLine |= TryWriteMethod ( tronPrimarySource , method , attrData , xmlComment , writeNewLine , useTryPattern : true , createKeyData : true , isContextApi : false ) ;
127- writeNewLine |= TryWriteMethod ( tronPrimarySource , method , attrData , xmlComment , writeNewLine , useTryPattern : true , createKeyData : false , isContextApi : false ) ;
128- writeNewLine |= TryWriteMethod ( tronPrimarySource , method , attrData , xmlComment , writeNewLine , useTryPattern : false , createKeyData : true , isContextApi : false ) ;
129- writeNewLine |= TryWriteMethod ( tronPrimarySource , method , attrData , xmlComment , writeNewLine , useTryPattern : false , createKeyData : false , isContextApi : false ) ;
126+ writeNewLine |= TryWriteMethod ( primarySource , method , attrData , xmlComment , writeNewLine , useTryPattern : true , createKeyData : true , isContextApi : false ) ;
127+ writeNewLine |= TryWriteMethod ( primarySource , method , attrData , xmlComment , writeNewLine , useTryPattern : true , createKeyData : false , isContextApi : false ) ;
128+ writeNewLine |= TryWriteMethod ( primarySource , method , attrData , xmlComment , writeNewLine , useTryPattern : false , createKeyData : true , isContextApi : false ) ;
129+ writeNewLine |= TryWriteMethod ( primarySource , method , attrData , xmlComment , writeNewLine , useTryPattern : false , createKeyData : false , isContextApi : false ) ;
130130 // ReSharper restore RedundantAssignment
131131 }
132132
133- tronPrimarySource . AppendLine ( "}" ) ;
134- tronContextSource . AppendLine ( "}" ) ;
133+ primarySource . AppendLine ( "}" ) ;
134+ contextSource . AppendLine ( "}" ) ;
135135
136- context . AddSource ( $ "Tron .g.cs", tronPrimarySource . ToString ( ) ) ;
137- context . AddSource ( $ "TronContextExtensions .g.cs", tronContextSource . ToString ( ) ) ;
136+ context . AddSource ( $ "Lite3 .g.cs", primarySource . ToString ( ) ) ;
137+ context . AddSource ( $ "Lite3ContextExtensions .g.cs", contextSource . ToString ( ) ) ;
138138 }
139139 ) ;
140140 }
@@ -194,9 +194,11 @@ private static bool TryWriteMethod(StringBuilder source,
194194
195195 var originalReturnTypeName = method . ReturnsVoid ? "void" : GetTypeName ( method . ReturnType ) ;
196196
197- var returnTypeName =
197+ const string refContext = $ "ref { ContextTypeName } ";
198+
199+ var returnTypeMoniker =
198200 useTryPattern ? "bool" :
199- isContextApi && isChainableMethod ? "ref TronContext" :
201+ isContextApi && isChainableMethod ? refContext :
200202 returnArgParam != null ? GetTypeName ( returnArgParam . Type ) :
201203 tryPattern ? "void" :
202204 originalReturnTypeName ;
@@ -254,7 +256,7 @@ private static bool TryWriteMethod(StringBuilder source,
254256
255257 if ( text . StartsWith ( "<returns>" ) )
256258 {
257- if ( returnTypeName == "void" )
259+ if ( returnTypeMoniker == "void" )
258260 continue ;
259261
260262 if ( useTryPattern )
@@ -300,7 +302,7 @@ private static bool TryWriteMethod(StringBuilder source,
300302 . Append ( indent ) . AppendLine ( InlineAttribute )
301303 . Append ( indent )
302304 . Append ( "public static " )
303- . Append ( returnTypeName )
305+ . Append ( returnTypeMoniker )
304306 . Append ( " " )
305307 . Append ( useTryPattern ? "Try" : null )
306308 . Append ( method . Name )
@@ -311,7 +313,7 @@ private static bool TryWriteMethod(StringBuilder source,
311313 {
312314 if ( isContextApi && index == 0 )
313315 {
314- source . Append ( "this ref TronContext context" ) ;
316+ source . Append ( "this " ) . Append ( refContext ) . Append ( " context") ;
315317 indexOffset ++ ;
316318 }
317319
@@ -410,7 +412,7 @@ private static bool TryWriteMethod(StringBuilder source,
410412 source . Append ( indent ) . AppendLine ( "return ref context;" ) ;
411413 else if ( returnArgParam != null )
412414 source . Append ( indent ) . Append ( "return " ) . Append ( returnArgParam . Name ) . AppendLine ( ";" ) ;
413- else if ( returnTypeName != "void" )
415+ else if ( returnTypeMoniker != "void" )
414416 source . Append ( indent ) . AppendLine ( "return result;" ) ;
415417 }
416418
0 commit comments