gumtree.spoon.builder.jsonsupport.OperationNodePainter 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.builder.jsonsupport;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.github.gumtreediff.actions.model.Action;
import com.github.gumtreediff.tree.Tree;
import com.google.gson.JsonObject;
import gumtree.spoon.builder.Json4SpoonGenerator.JSON_PROPERTIES;
import gumtree.spoon.diff.operations.Operation;
/**
*
* @author Matias Martinez
*
*/
public class OperationNodePainter implements NodePainter {
private Map nodesAffectedByOps = new HashMap<>();
public OperationNodePainter(List operations) {
// Collect all nodes and get the operator
for (Operation operation : operations) {
nodesAffectedByOps.put(operation.getAction().getNode(), operation);
}
}
@Override
public void paint(Tree tree, JsonObject jsontree) {
if (nodesAffectedByOps.containsKey(tree)) {
Operation operationOverTree = nodesAffectedByOps.get(tree);
jsontree.addProperty(JSON_PROPERTIES.op.toString(), operationOverTree.getAction().getName());
}
}
}