@@ -288,8 +288,11 @@ public int getAlignmentCategory(TerminalNode node, Token curToken, int columnDel
288288 if ( pair !=null ) {
289289 int deltaFromLeftAncestor = getDeltaToAncestor (earliestLeftAncestor , pair .a );
290290 aligned = aligncat (deltaFromLeftAncestor , pair .b );
291- // System.out.printf("ALIGN %s %d %x\n", JavaParser.ruleNames[pair.a.getRuleIndex()], pair.b, aligned);
292- }
291+ // System.out.printf("ALIGN %s %s %d %x %s\n",
292+ // curToken,
293+ // doc.parser.getRuleNames()[pair.a.getRuleIndex()],
294+ // pair.b, aligned, doc.fileName);
295+ }
293296 else if ( columnDelta !=0 ) {
294297 int indentedFromPos = curToken .getCharPositionInLine ()-Formatter .INDENT_LEVEL ;
295298 ParserRuleContext indentParent =
@@ -368,18 +371,16 @@ public Pair<ParserRuleContext,Integer> earliestAncestorWithChildStartingAtCharPo
368371 // check all children of p to see if one of them starts at charpos
369372 for (int i = 0 ; i <p .getChildCount (); i ++) {
370373 ParseTree child = p .getChild (i );
374+ Token start ;
371375 if ( child instanceof ParserRuleContext ) {
372- ParserRuleContext c = (ParserRuleContext )child ;
373- if ( c .getStart ().getTokenIndex ()<t .getTokenIndex () && isFirstOnLine (c .getStart ()) && c .getStart ().getCharPositionInLine ()==charpos ) {
374- return new Pair <>(p ,i );
375- }
376+ start = ((ParserRuleContext ) child ).getStart ();
376377 }
377378 else { // must be token
378- TerminalNode c = (TerminalNode )child ;
379- // check that we aren't aligned with self or element *after* us
380- if ( c . getSymbol (). getTokenIndex ()< t . getTokenIndex () && isFirstOnLine ( c . getSymbol ()) && c . getSymbol (). getCharPositionInLine ()== charpos ) {
381- return new Pair <>( p , i );
382- }
379+ start = (( TerminalNode )child ). getSymbol () ;
380+ }
381+ // check that we aren't aligned with self or element *after* us
382+ if ( start . getTokenIndex ()< t . getTokenIndex () && start . getCharPositionInLine ()== charpos ) {
383+ return new Pair <>( p , i );
383384 }
384385 }
385386 p = p .getParent ();
0 commit comments