Example usage for org.eclipse.jdt.core.dom MethodDeclaration subtreeMatch

List of usage examples for org.eclipse.jdt.core.dom MethodDeclaration subtreeMatch

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom MethodDeclaration subtreeMatch.

Prototype

public final boolean subtreeMatch(ASTMatcher matcher, Object other) 

Source Link

Document

Returns whether the subtree rooted at the given node matches the given other object as decided by the given matcher.

Usage

From source file:changenodes.matching.BestLeafTreeMatcher.java

License:Apache License

private void matchIdenticalMethods(ASTNode left, ASTNode right) {
    //fix in which some methods got pretty bad matches
    //feels pretty dirty though (but so does this whole file)
    for (Iterator<ASTNode> iterator = new BreadthFirstNodeIterator(left); iterator.hasNext();) {
        ASTNode n = iterator.next();/*w  w w  .j  ava  2s  .co  m*/
        ASTNode bestMatch = null;
        if (n.getNodeType() == ASTNode.METHOD_DECLARATION) {
            MethodDeclaration x = (MethodDeclaration) n;
            if (!leftMatching.containsKey(x)) {
                for (Iterator<ASTNode> rightIterator = new BreadthFirstNodeIterator(right); rightIterator
                        .hasNext();) {
                    ASTNode y = rightIterator.next();
                    if (y.getNodeType() == x.getNodeType() && x.subtreeMatch(new ASTMatcher(), y)) {
                        bestMatch = y;
                        break;
                    }
                }
            }
            //we have found the best node, lets now match them together
            //afaik this is also not in the original paper, but we sometimes got some weird matches
            if (bestMatch != null) {
                markMatchedNode(x, bestMatch);
            }
        }
    }
}