| | } |
| | |
| | - /* |
| | + /** |
| | * This converts all payload instances in the tree to their transformed |
| | * equivalent using a depth-first traversal. |
 |
| | |
| | for( Tree<ParserRuleContext> branch : tree.getBranches() ) { |
| | + ParserRuleContext context = branch.getPayload(); |
| | + |
| | // Recurse for all the branches at this level of the tree. |
| | + if( context instanceof AttributeMapContext ) { |
| | + AttributeMapContext ctx = (AttributeMapContext)context; |
| | + Tree<ParserRuleContext> parent = branch.getParent(); |
| | + |
| | + ctx.hasPrecedingPayload( hasPrecedingPayload( parent, ctx ) ); |
| | + ctx.hasFollowingPayload( hasFollowingPayload( parent, ctx ) ); |
| | + } |
| | + |
| | sb.append( newline ).append( toString( branch, depth + getIndentBy() ) ); |
| | } |
 |
| | * the given payload. |
| | */ |
| | - private List<ParserRuleContext> getConsecutiveRules( ParserRuleContext p ) { |
| | + private List<ParserRuleContext> getConsecutiveRules( |
| | + Tree<ParserRuleContext> tree, ParserRuleContext p ) { |
| | List<ParserRuleContext> result = new ArrayList<ParserRuleContext>(); |
| | |
| | - for( Tree<ParserRuleContext> branch : getBranches() ) { |
| | + for( Tree<ParserRuleContext> branch : tree.getBranches() ) { |
| | if( branch.isPayloadClass( p.getClass() ) ) { |
| | result.add( branch.getPayload() ); |
 |
| | * that is before the given payload. |
| | */ |
| | - @Override |
| | - public boolean hasPrecedingPayload( ParserRuleContext payload ) { |
| | - return getConsecutiveRules( payload ).indexOf( payload ) > 0; |
| | + public boolean hasPrecedingPayload( Tree<ParserRuleContext> tree, ParserRuleContext payload ) { |
| | + return getConsecutiveRules( tree, payload ).indexOf( payload ) > 0; |
| | } |
| | |
 |
| | * that is after the given payload. |
| | */ |
| | - @Override |
| | - public boolean hasFollowingPayload( ParserRuleContext payload ) { |
| | - List<ParserRuleContext> siblings = getConsecutiveRules( payload ); |
| | + public boolean hasFollowingPayload( Tree<ParserRuleContext> tree, ParserRuleContext payload ) { |
| | + List<ParserRuleContext> siblings = getConsecutiveRules( tree, payload ); |
| | int index = siblings.indexOf( payload ); |
| | |