@@ -30,13 +30,14 @@ internal class Walker : CSharpSyntaxWalker
3030 private SyntaxNode ? _SNBaseConstructorInitializerNode = null ;
3131 private SyntaxNode ? _SNPropertyType = null ;
3232 private SyntaxNode ? _SNAdditionalArgument = null ;
33+
34+ private ITypeSymbol ? _CurrentClassSymbol = null ;
3335
3436 private string _NameSpaceStr = string . Empty ;
35- private string _CurrentClassStr = string . Empty ;
36- private string _CurrentClassInheritanceStr = string . Empty ;
37-
37+
3838 private List < Prop > _Properties = new ( ) ;
39-
39+
40+ private bool _PropOrField = false ;
4041 private bool _PropertyStatic = false ;
4142 private bool _ConstKeyword = false ;
4243 private bool _IgnoreArrayType = false ;
@@ -306,10 +307,6 @@ public override void VisitClassDeclaration(ClassDeclarationSyntax node)
306307 case SyntaxKind . BaseList :
307308 {
308309 BaseListSyntax _baseList = ( BaseListSyntax ) asNode ;
309-
310- //TODO! list!
311- _CurrentClassInheritanceStr = _baseList . Types [ 0 ] . ToString ( ) ;
312-
313310 VisitBaseList ( _baseList ) ;
314311 break ;
315312 }
@@ -353,7 +350,8 @@ public override void VisitClassDeclaration(ClassDeclarationSyntax node)
353350 break ;
354351 case SyntaxKind . IdentifierToken :
355352 {
356- _CurrentClassStr = asToken . Text ;
353+ _CurrentClassSymbol = _Model . GetDeclaredSymbol ( node ) ;
354+
357355 VisitToken ( asToken ) ;
358356 break ;
359357 }
@@ -370,9 +368,6 @@ public override void VisitClassDeclaration(ClassDeclarationSyntax node)
370368 {
371369 _Properties . Clear ( ) ;
372370 }
373-
374- //clear _CurrentClassInheritanceStr
375- _CurrentClassInheritanceStr = string . Empty ;
376371 }
377372
378373 public override void VisitConstructorDeclaration ( ConstructorDeclarationSyntax node )
@@ -888,6 +883,9 @@ public override void VisitExpressionStatement(ExpressionStatementSyntax node)
888883 JSSB . AppendLine ( "*/" ) ;
889884 }
890885
886+ //reset
887+ _PropOrField = false ;
888+
891889 ChildSyntaxList nodesAndTokens = node . ChildNodesAndTokens ( ) ;
892890
893891 for ( int i = 0 ; i < nodesAndTokens . Count ; i ++ )
@@ -6494,6 +6492,9 @@ public bool IdentifierToken(SyntaxNode node)
64946492 {
64956493 if ( ! _ThisIsUsed )
64966494 {
6495+ //TODO?
6496+ //Can I unify method and prop/field?
6497+
64976498 if ( iSymbol . Kind == SymbolKind . Method &&
64986499 ( ( IMethodSymbol ) iSymbol ) . MethodKind == MethodKind . Ordinary )
64996500 {
@@ -6503,21 +6504,28 @@ public bool IdentifierToken(SyntaxNode node)
65036504 if ( _iSymbolParent != null && ( _iSymbolParent . Kind == SymbolKind . Local || _iSymbolParent . Kind == SymbolKind . Method ) )
65046505 return false ;
65056506 }
6506-
6507- string _reciverType = ( ( IMethodSymbol ) iSymbol ) . ReceiverType . ToString ( ) ;
65086507
6509- if ( ! iSymbol . IsStatic &&
6510- ( ( _reciverType . EndsWith ( _CurrentClassStr ) ||
6511- ( ( _reciverType . EndsWith ( _CurrentClassInheritanceStr ) && _CurrentClassInheritanceStr != string . Empty ) ) ) ) )
6508+ if ( ! iSymbol . IsStatic && ! _PropOrField )
65126509 {
6513- VisitLeadingTrivia ( identifier ) ;
6510+ string _reciverType = ( ( IMethodSymbol ) iSymbol ) . ReceiverType . ToString ( ) ;
6511+
6512+ //TODO! Interfaces too.
6513+ ITypeSymbol ? _base = _CurrentClassSymbol ;
6514+ while ( _base != null )
6515+ {
6516+ if ( _reciverType . EndsWith ( _base . ToString ( ) ) )
6517+ {
6518+ VisitLeadingTrivia ( identifier ) ;
65146519
6515- JSSB . Append ( $ "this.") ;
6516- VisitToken ( identifier . WithoutTrivia ( ) ) ;
6520+ JSSB . Append ( $ "this.") ;
6521+ VisitToken ( identifier . WithoutTrivia ( ) ) ;
65176522
6518- VisitTrailingTrivia ( identifier ) ;
6523+ VisitTrailingTrivia ( identifier ) ;
65196524
6520- return true ;
6525+ return true ;
6526+ }
6527+ _base = _base . BaseType ;
6528+ }
65216529 }
65226530
65236531 return false ;
@@ -6532,20 +6540,32 @@ public bool IdentifierToken(SyntaxNode node)
65326540 if ( _iSymbolParent != null && ( _iSymbolParent . Kind == SymbolKind . Local || _iSymbolParent . Kind == SymbolKind . Method ) )
65336541 return false ;
65346542 }
6535- string ? _type = iSymbol . ContainingType . ToString ( ) ;
6536-
6537- if ( _type != null &&
6538- ( _type . EndsWith ( _CurrentClassStr ) ||
6539- ( _type . EndsWith ( _CurrentClassInheritanceStr ) && _CurrentClassInheritanceStr != string . Empty ) ) )
6543+ if ( ! _PropOrField )
65406544 {
6541- VisitLeadingTrivia ( identifier ) ;
6545+ string ? _type = iSymbol . ContainingType . ToString ( ) ;
65426546
6543- JSSB . Append ( $ "this.") ;
6544- VisitToken ( identifier . WithoutTrivia ( ) ) ;
6547+ if ( _type != null )
6548+ {
6549+ //TODO! Interfaces too.
6550+ ITypeSymbol ? _base = _CurrentClassSymbol ;
6551+ while ( _base != null )
6552+ {
6553+ if ( _type . EndsWith ( _base . ToString ( ) ) )
6554+ {
6555+ VisitLeadingTrivia ( identifier ) ;
6556+
6557+ JSSB . Append ( $ "this.") ;
6558+ VisitToken ( identifier . WithoutTrivia ( ) ) ;
6559+
6560+ VisitTrailingTrivia ( identifier ) ;
65456561
6546- VisitTrailingTrivia ( identifier ) ;
6562+ _PropOrField = true ;
65476563
6548- return true ;
6564+ return true ;
6565+ }
6566+ _base = _base . BaseType ;
6567+ }
6568+ }
65496569 }
65506570 return false ;
65516571 }
0 commit comments