All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gumtree.spoon.diff.support.SpoonSupport Maven / Gradle / Ivy

Go to download

Computes the AST difference between two Spoon abstract syntax trees using the Gumtree algorithm.

There is a newer version: 1.92
Show newest version
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;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy