org.jrubyparser.util.diff
Interface IsJunk


public interface IsJunk

Implementations of the interface IsJunk and the #checkJunk() method can be passed to NodeDiff and SequenceMatcher as callbacks which will then be used to select Nodes to be skipped over during the diffing process.

More specifically, if an object implementing IsJunk was passed in as the last parameter to the constructor of SequenceMatcher, then during an early phase of each iteration of the diff, SequenceMatcher#findChanges will call SequenceMatcher#checkForJunk on each Node which, in turn, calls #checkJunk() for both Nodes. If #checkJunk() returns true, that node will be skipped.

Nodes of type NewLineNode and BlockNode are automatically skipped over by SequenceMatcher, so it is unnecessary to check for either of these.

Example:

 // Skipping all nodes which are methods
 public class MyJunkChecker implements IsJunk {
     public boolean checkJunk(Node node) {
         if (node instanceof MethodDefNode) {
             return true;
         }
         return false;
     }
 }
 
 

See Also:
NodeDiff, SequenceMatcher, SequenceMatcher.findChanges(org.jrubyparser.ast.Node, org.jrubyparser.ast.Node), SequenceMatcher.checkForJunk(org.jrubyparser.ast.Node)

Method Summary
 boolean checkJunk(Node node)
          Any node passed to an implementation of #checkJunk() which returns true will not be diffed.
 

Method Detail

checkJunk

boolean checkJunk(Node node)
Any node passed to an implementation of #checkJunk() which returns true will not be diffed. Any Node for which #checkJunk() returns true will skip that node and all of that node's children. For example, if checkJunk returns true on all instances of MethodDefNode, the diff will skip all methods entirely, contents included.

Nodes of type NewLineNode and BlockNode are automatically skipped, so it is not necessary to check for them here.

Parameters:
node - The Node being checked. If it returns true, this node will not be diffed.
Returns:
Returns true or false. Any node for which it returns true will not be diffed.


Copyright © 2013. All Rights Reserved.