@@ -1507,16 +1507,25 @@ private J.Identifier MapIdentifier(SyntaxToken identifier, JavaType? type)
15071507 . FirstOrDefault ( x => x . Markers . Contains < MemberBinding > ( ) ) ;
15081508 if ( bindingNode != null )
15091509 {
1510- var newMarkers = bindingNode . Markers . WithMarkers ( bindingNode . Markers . MarkerList . Where ( x => x is not MemberBinding ) . ToList ( ) ) ;
1510+ var newMarkers = bindingNode . Markers
1511+ . WithMarkers ( bindingNode . Markers . MarkerList . Where ( x => x is not MemberBinding ) . ToList ( ) ) ;
15111512 if ( bindingNode is J . MethodInvocation methodNode )
15121513 {
1513- var newMethod = methodNode . WithSelect ( currentExpression ) . WithMarkers ( newMarkers ) ;
1514+ var newMethod = methodNode
1515+ . WithSelect ( currentExpression )
1516+ . WithMarkers ( newMarkers ) ;
15141517 lstNode = methodNode . Equals ( lstNode ) ? newMethod : lstNode . ReplaceNode ( methodNode , newMethod ) ;
15151518 }
15161519 else if ( bindingNode is J . FieldAccess fieldAccess )
15171520 {
1518- var newFieldAccess = fieldAccess . WithTarget ( currentExpression ) . WithMarkers ( newMarkers ) ; ;
1521+ var newFieldAccess = fieldAccess . WithTarget ( currentExpression ) . WithMarkers ( newMarkers ) ;
15191522 lstNode = fieldAccess . Equals ( lstNode ) ? newFieldAccess : lstNode . ReplaceNode ( fieldAccess , newFieldAccess ) ;
1523+ } else if ( bindingNode is J . ArrayAccess arrayAccess )
1524+ {
1525+ var newArrayAccess = arrayAccess
1526+ . WithIndexed ( currentExpression )
1527+ . WithMarkers ( newMarkers ) ;
1528+ lstNode = newArrayAccess . Equals ( lstNode ) ? newArrayAccess : lstNode . ReplaceNode ( lstNode , newArrayAccess ) ;
15201529 }
15211530 }
15221531
@@ -1546,17 +1555,28 @@ private J.Identifier MapIdentifier(SyntaxToken identifier, JavaType? type)
15461555 // return base.VisitConditionalAccessExpression(node);
15471556 }
15481557
1558+
15491559 /// <summary>
15501560 /// Very similar to MemberAccessExpression, but doesn't have an expression portion - just identifier
15511561 /// Used in ConditionalAccessExpression since they are constructed left to right, then right to left like normal field access
15521562 /// </summary>
15531563 public override J ? VisitMemberBindingExpression ( MemberBindingExpressionSyntax node )
15541564 {
1565+ return new J . FieldAccess (
1566+ Core . Tree . RandomId ( ) ,
1567+ Format ( Leading ( node ) ) ,
1568+ Markers . Create ( new MemberBinding ( ) ) ,
1569+ Convert < Expression > ( node . Name ) ! ,
1570+ Convert < J . Identifier > ( node . Name ) ! . AsLeftPadded ( Format ( Leading ( node . OperatorToken ) ) ) ,
1571+ MapType ( node )
1572+ ) ;
1573+ }
15551574
1556-
1557- // due to the fact that the `ConditionalAccessExpressionSyntax` is at the root of an expression like `foo?.Bar.Baz`
1558- // we need to find that root here, as the containment hierarchy using `J.FieldAccess` and `Cs.NullSafeExpression`
1559- // ends up being very different
1575+ public override J ? VisitElementBindingExpression ( ElementBindingExpressionSyntax node )
1576+ {
1577+ // // due to the fact that the `ConditionalAccessExpressionSyntax` is at the root of an expression like `foo?.Bar.Baz`
1578+ // // we need to find that root here, as the containment hierarchy using `J.FieldAccess` and `Cs.NullSafeExpression`
1579+ // // ends up being very different
15601580 // ExpressionSyntax? parent = node;
15611581 // while (parent is not ConditionalAccessExpressionSyntax)
15621582 // if ((parent = parent.Parent as ExpressionSyntax) == null)
@@ -1575,53 +1595,34 @@ private J.Identifier MapIdentifier(SyntaxToken identifier, JavaType? type)
15751595 // )
15761596 // );
15771597
1578- return new J . FieldAccess (
1598+ var placeholderExpression = new J . Empty (
15791599 Core . Tree . RandomId ( ) ,
15801600 Format ( Leading ( node ) ) ,
1581- new Markers (
1582- Core . Tree . RandomId ( ) ,
1583- new List < Core . Marker . Marker >
1584- {
1585- new MemberBinding ( Core . Tree . RandomId ( ) )
1586- } ) ,
1587- Convert < Expression > ( node . Name ) ! ,
1588- new JLeftPadded < J . Identifier > (
1589- Format ( Leading ( node . OperatorToken ) ) ,
1590- Convert < J . Identifier > ( node . Name ) ! ,
1591- Markers . EMPTY
1592- ) ,
1593- MapType ( node )
1594- ) ;
1595- }
1596-
1597- public override J ? VisitElementBindingExpression ( ElementBindingExpressionSyntax node )
1598- {
1599- // due to the fact that the `ConditionalAccessExpressionSyntax` is at the root of an expression like `foo?.Bar.Baz`
1600- // we need to find that root here, as the containment hierarchy using `J.FieldAccess` and `Cs.NullSafeExpression`
1601- // ends up being very different
1602- ExpressionSyntax ? parent = node ;
1603- while ( parent is not ConditionalAccessExpressionSyntax )
1604- if ( ( parent = parent . Parent as ExpressionSyntax ) == null )
1605- throw new InvalidOperationException (
1606- "Cannot find a `ConditionalAccessExpressionSyntax` in the containment hierarchy." ) ;
1601+ Markers . Create ( new MemberBinding ( ) ) ) ;
16071602
1608- var conditionalAccess = ( ConditionalAccessExpressionSyntax ) parent ;
1609- var lhs = new Cs . NullSafeExpression (
1610- Core . Tree . RandomId ( ) ,
1611- Format ( Leading ( node ) ) ,
1612- Markers . EMPTY ,
1613- new JRightPadded < Expression > (
1614- Convert < Expression > ( conditionalAccess . Expression ) ! ,
1615- Format ( Leading ( conditionalAccess . OperatorToken ) ) ,
1616- Markers . EMPTY
1617- )
1618- ) ;
1603+ // return new J.FieldAccess(
1604+ // Core.Tree.RandomId(),
1605+ // Format(Leading(node)),
1606+ // new Markers(
1607+ // Core.Tree.RandomId(),
1608+ // new List<Core.Marker.Marker>
1609+ // {
1610+ // new MemberBinding(Core.Tree.RandomId())
1611+ // }),
1612+ // Convert<Expression>(node.Name)!,
1613+ // new JLeftPadded<J.Identifier>(
1614+ // Format(Leading(node.OperatorToken)),
1615+ // Convert<J.Identifier>(node.Name)!,
1616+ // Markers.EMPTY
1617+ // ),
1618+ // MapType(node)
1619+ // );
16191620
16201621 return new J . ArrayAccess (
16211622 Core . Tree . RandomId ( ) ,
16221623 Format ( Leading ( node ) ) ,
16231624 Markers . EMPTY ,
1624- lhs ,
1625+ placeholderExpression ,
16251626 new J . ArrayDimension (
16261627 Core . Tree . RandomId ( ) ,
16271628 Format ( Leading ( node . ArgumentList . OpenBracketToken ) ) ,
0 commit comments