@@ -27,7 +27,6 @@ internal class Walker : CSharpSyntaxWalker
2727 private readonly CSTOJSOptions _Options ;
2828 private readonly SemanticModel _Model ;
2929
30- private SyntaxNode ? _SNOriginalAsExpression = null ;
3130 private SyntaxNode ? _SNBaseConstructorInitializerNode = null ;
3231 private SyntaxNode ? _SNPropertyType = null ;
3332 private SyntaxNode ? _SNAdditionalArgument = null ;
@@ -1083,18 +1082,9 @@ public override void VisitArgument(ArgumentSyntax node)
10831082 case SyntaxKind . GreaterThanOrEqualExpression :
10841083 case SyntaxKind . IsExpression :
10851084 case SyntaxKind . CoalesceExpression :
1085+ case SyntaxKind . AsExpression :
10861086 VisitBinaryExpression ( ( BinaryExpressionSyntax ) asNode ) ;
10871087 break ;
1088- case SyntaxKind . AsExpression :
1089- {
1090- //Todo double/multiply asExpression?? How?
1091- _SNOriginalAsExpression = ( ( BinaryExpressionSyntax ) asNode ) . Left ;
1092-
1093- Visit ( _SNOriginalAsExpression . WithoutTrailingTrivia ( ) ) ;
1094-
1095- _SNOriginalAsExpression = null ;
1096- break ;
1097- }
10981088 case SyntaxKind . ObjectCreationExpression :
10991089 VisitObjectCreationExpression ( ( ObjectCreationExpressionSyntax ) asNode ) ;
11001090 break ;
@@ -2938,10 +2928,7 @@ public override void VisitParenthesizedExpression(ParenthesizedExpressionSyntax
29382928 {
29392929 ChildSyntaxList nodesAndTokens = node . ChildNodesAndTokens ( ) ;
29402930
2941- if ( nodesAndTokens [ 1 ] . IsKind ( SyntaxKind . AsExpression ) )
2942- _IgnoreAsParenthesis = true ;
2943-
2944- if ( nodesAndTokens [ 1 ] . IsKind ( SyntaxKind . CastExpression ) )
2931+ if ( nodesAndTokens [ 1 ] . IsKind ( SyntaxKind . AsExpression ) || nodesAndTokens [ 1 ] . IsKind ( SyntaxKind . CastExpression ) )
29452932 _IgnoreAsParenthesis = true ;
29462933
29472934 for ( int i = 0 ; i < nodesAndTokens . Count ; i ++ )
@@ -2978,21 +2965,12 @@ public override void VisitParenthesizedExpression(ParenthesizedExpressionSyntax
29782965 case SyntaxKind . GreaterThanOrEqualExpression :
29792966 case SyntaxKind . IsExpression :
29802967 case SyntaxKind . CoalesceExpression :
2968+ case SyntaxKind . AsExpression :
29812969 VisitBinaryExpression ( ( BinaryExpressionSyntax ) asNode ) ;
29822970 break ;
29832971 case SyntaxKind . IdentifierName :
29842972 VisitIdentifierName ( ( IdentifierNameSyntax ) asNode ) ;
29852973 break ;
2986- case SyntaxKind . AsExpression :
2987- {
2988- //Todo double/multiply asExpression?? How?
2989- _SNOriginalAsExpression = ( ( BinaryExpressionSyntax ) asNode ) . Left ;
2990-
2991- Visit ( _SNOriginalAsExpression . WithoutTrailingTrivia ( ) ) ;
2992-
2993- _SNOriginalAsExpression = null ;
2994- break ;
2995- }
29962974 case SyntaxKind . UnaryPlusExpression :
29972975 case SyntaxKind . UnaryMinusExpression :
29982976 case SyntaxKind . BitwiseNotExpression :
@@ -3830,34 +3808,10 @@ private bool IsRightAttribute<T>(T identifier, SyntaxToken asToken) where T : Si
38303808 {
38313809 SymbolInfo ? _symbolInfo = null ;
38323810
3833- if ( _SNOriginalAsExpression != null )
3834- {
3835- IEnumerable < SyntaxNodeOrToken > _identifierNameSyntax = _SNOriginalAsExpression . DescendantNodesAndTokens ( ) . Where ( e => e . IsToken == true ) ;
3836- foreach ( SyntaxNodeOrToken _item in _identifierNameSyntax )
3837- {
3838- SyntaxToken _syntaxToken = _item . AsToken ( ) ;
3839-
3840- if ( _syntaxToken . IsKind ( SyntaxKind . IdentifierToken ) )
3841- {
3842- if ( _syntaxToken . Text == asToken . Text )
3843- {
3844- if ( _item . Parent != null )
3845- _symbolInfo = _Model . GetSymbolInfo ( _item . Parent ) ;
3846- else
3847- Log . ErrorLine ( "_item.Parent is null" ) ;
3848- break ;
3849- }
3850- }
3851- }
3852- //node = _SNOriginalAsExpression;
3853- }
3811+ if ( _SNPropertyType != null )
3812+ _symbolInfo = _Model . GetSymbolInfo ( _SNPropertyType ) ;
38543813 else
3855- {
3856- if ( _SNPropertyType != null )
3857- _symbolInfo = _Model . GetSymbolInfo ( _SNPropertyType ) ;
3858- else
3859- _symbolInfo = _Model . GetSymbolInfo ( identifier ) ;
3860- }
3814+ _symbolInfo = _Model . GetSymbolInfo ( identifier ) ;
38613815
38623816 ISymbol ? _symbol = null ;
38633817
@@ -4166,8 +4120,20 @@ public override void VisitBinaryExpression(BinaryExpressionSyntax node)
41664120 {
41674121 ChildSyntaxList nodesAndTokens = node . ChildNodesAndTokens ( ) ;
41684122
4123+ bool ignoreNext = false ;
4124+
41694125 for ( int i = 0 ; i < nodesAndTokens . Count ; i ++ )
41704126 {
4127+ if ( ignoreNext )
4128+ {
4129+ //TODO! Ignore trailing trivia if second token is 'as' keyword.
4130+ //removing whitespace before 'as' keyword
4131+ JSSB . Remove ( JSSB . Length - 1 , 1 ) ;
4132+
4133+ ignoreNext = false ;
4134+ continue ;
4135+ }
4136+
41714137 SyntaxNode ? asNode = nodesAndTokens [ i ] . AsNode ( ) ;
41724138
41734139 if ( asNode != null )
@@ -4297,6 +4263,11 @@ public override void VisitBinaryExpression(BinaryExpressionSyntax node)
42974263 case SyntaxKind . LessThanToken :
42984264 VisitToken ( asToken ) ;
42994265 break ;
4266+ case SyntaxKind . AsKeyword :
4267+ {
4268+ ignoreNext = true ;
4269+ break ;
4270+ }
43004271 default :
43014272 Log . ErrorLine ( $ "asToken : { kind } ") ;
43024273 break ;
@@ -6462,51 +6433,28 @@ public bool IdentifierToken(SyntaxNode node)
64626433 }
64636434
64646435 SymbolInfo ? symbolInfo = null ;
6465- if ( _SNOriginalAsExpression != null )
6436+
6437+ try
64666438 {
6467- IEnumerable < SyntaxNodeOrToken > _identifierNameSyntax = _SNOriginalAsExpression . DescendantNodesAndTokens ( ) . Where ( e => e . IsToken == true ) ;
6468- foreach ( SyntaxNodeOrToken _item in _identifierNameSyntax )
6469- {
6470- SyntaxToken _syntaxToken = _item . AsToken ( ) ;
6471-
6472- if ( _syntaxToken . IsKind ( SyntaxKind . IdentifierToken ) )
6473- {
6474- if ( _syntaxToken . Text == text )
6475- {
6476- if ( _item . Parent != null )
6477- symbolInfo = _Model . GetSymbolInfo ( _item . Parent ) ;
6478- else
6479- Log . ErrorLine ( "_item.Parent is null" ) ;
6480- break ;
6481- }
6482- }
6483- }
6484- node = _SNOriginalAsExpression ;
6439+ if ( _SNPropertyType != null )
6440+ symbolInfo = _Model . GetSymbolInfo ( _SNPropertyType ) ;
6441+ else
6442+ symbolInfo = _Model . GetSymbolInfo ( node ) ;
64856443 }
6486- else
6444+ catch ( Exception e )
64876445 {
6488- try
6446+ symbolInfo = null ;
6447+ /*
6448+ ImmutableArray<Diagnostic> diags = _Model.GetDeclarationDiagnostics();
6449+ foreach (Diagnostic item in diags)
64896450 {
6490- if ( _SNPropertyType != null )
6491- symbolInfo = _Model . GetSymbolInfo ( _SNPropertyType ) ;
6492- else
6493- symbolInfo = _Model . GetSymbolInfo ( node ) ;
6494- }
6495- catch ( Exception e )
6496- {
6497- symbolInfo = null ;
6498- /*
6499- ImmutableArray<Diagnostic> diags = _Model.GetDeclarationDiagnostics();
6500- foreach (Diagnostic item in diags)
6501- {
6502- Log.WarningLine(item.ToString());
6503- }
6504- */
6505- Log . WarningLine ( e . ToString ( ) ) ;
6506- //throw;
6451+ Log.WarningLine(item.ToString());
65076452 }
6453+ */
6454+ Log . WarningLine ( e . ToString ( ) ) ;
6455+ //throw;
65086456 }
6509-
6457+
65106458 ISymbol ? iSymbol = null ;
65116459
65126460 if ( symbolInfo ? . CandidateSymbols . Length >= 1 )
0 commit comments