gumtree.spoon.diff.support.SpoonSupport Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gumtree-spoon-ast-diff Show documentation
Show all versions of gumtree-spoon-ast-diff Show documentation
Computes the AST difference between two Spoon abstract syntax trees using the Gumtree algorithm.
package gumtree.spoon.diff.support;
import com.github.gumtreediff.matchers.Mapping;
import com.github.gumtreediff.tree.Tree;
import gumtree.spoon.builder.SpoonGumTreeBuilder;
import gumtree.spoon.diff.Diff;
import spoon.reflect.declaration.CtElement;
/**
*
* @author Matias Martinez
*
*/
public class SpoonSupport {
public CtElement getMappedElement(Diff diff, CtElement elementToMatch, boolean isFromSource) {
for (Mapping mapping : diff.getMappingsComp().asSet()) {
Tree matchingNode = isFromSource ? mapping.first : mapping.second;
CtElement associatedElement = (CtElement) matchingNode.getMetadata(SpoonGumTreeBuilder.SPOON_OBJECT);
if (elementToMatch == associatedElement) {
Tree linked = isFromSource ? diff.getMappingsComp().getDstForSrc(matchingNode)
: diff.getMappingsComp().getSrcForDst(matchingNode);
return (CtElement) linked.getMetadata(SpoonGumTreeBuilder.SPOON_OBJECT);
}
}
return null;
}
}