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

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

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom ASTNode 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.calculators.ChawatheCalculator.java

License:Apache License

private boolean isDescendant(ASTNode parent, ASTNode child) {
    if (child == null) {
        return false;
    }//from ww  w .  jav a 2s  . c  om
    if (parent == null) {
        return false;
    }
    ASTNode childParent = child.getParent();
    return parent.subtreeMatch(new ASTMatcher(), childParent) || isDescendant(parent, childParent);
}

From source file:com.google.gwt.eclipse.core.refactoring.regionupdater.EquivalentNodeFinder.java

License:Open Source License

private boolean treesMatch(ASTNode node, ASTNode otherNode, ASTNode topmostAncestorNode,
        ASTNode topmostNewAncestorNode, ASTMatcher matcher) {

    while (true) {
        if ((node == topmostAncestorNode) != (otherNode == topmostNewAncestorNode)) {
            // One has reached the end and the other has not
            return false;
        }//from   w w  w .j  a v a 2s . c o m

        if (node == topmostAncestorNode) {
            // They have both reached an end, and everything went smoothly
            return true;
        }

        if (!node.subtreeMatch(matcher, otherNode)) {
            // Subtrees do not match
            return false;
        }

        if (!indexMatches(node, otherNode)) {
            // The index of each does not match
            return false;
        }

        node = node.getParent();
        otherNode = otherNode.getParent();
    }
}

From source file:de.fkoeberle.autocommit.message.java.helper.ASTCompareUtil.java

License:Open Source License

/**
 * /*from w w  w  . j  a v  a  2s.c  o  m*/
 * @param oldList
 *            must be a list of {@link ASTNode} objects.
 * @param newList
 *            must be a list of {@link ASTNode} objects.
 * @return true if the two list of abstract syntax trees don't match.
 */
public static boolean listsOfASTNodesDiffer(List<?> oldList, List<?> newList) {
    if (oldList.size() != newList.size()) {
        return true;
    }
    int size = oldList.size();
    for (int i = 0; i < size; i++) {
        ASTNode oldInterface = (ASTNode) (oldList.get(i));
        ASTNode newInterface = (ASTNode) (newList.get(i));
        boolean matches = oldInterface.subtreeMatch(new ASTMatcher(true), newInterface);
        if (!matches) {
            return true;
        }
    }
    return false;
}

From source file:de.fkoeberle.autocommit.message.java.helper.ASTCompareUtil.java

License:Open Source License

/**
 * /* w ww  . j av a2 s .  c  o m*/
 * @param oldNode
 *            can be null.
 * @param newNode
 *            can be null.
 * @return false if and only if the nodes match when compared with a
 *         {@link ASTMatcher}. Otherwise true gets returned
 */
public static boolean astNodesDiffer(ASTNode oldNode, ASTNode newNode) {
    if (oldNode == null || newNode == null) {
        return oldNode != newNode;
    }
    boolean sameReturnType = (oldNode.subtreeMatch(new ASTMatcher(true), newNode));
    return !sameReturnType;
}

From source file:edu.illinois.jflow.core.transformations.code.SnippetFinder.java

License:Open Source License

private boolean matches(ASTNode node) {
    if (isSnippetNode(node))
        return false;
    if (node.subtreeMatch(fMatcher, fSnippet[fIndex]) && fMatch.hasCorrectNesting(node)) {
        fMatch.add(node);//  ww  w .j a v a 2s  . c  om
        fIndex++;
        if (fIndex == fSnippet.length) {
            fResult.add(fMatch);
            reset();
        }
        return true;
    }
    return false;
}

From source file:org.eclipse.swordfish.tooling.test.util.project.ClassCompare.java

License:Open Source License

/**
 * uses an <code>ASTMatcher</code> to compare the classes
 * @param matcher/*  w  w w  . j  a  v a  2  s.com*/
 * @param left
 * @param right
 * @return
 */
private static boolean compareNodes(ASTMatcher matcher, ASTNode left, ASTNode right) {
    return left.subtreeMatch(matcher, right);
}