refdiff.core.cst.CstRoot Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of refdiff-core Show documentation
Show all versions of refdiff-core Show documentation
An automated tool to detect refactorings in version histories
package refdiff.core.cst;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
/**
* The Code Structure Tree (CST) root object.
*/
public class CstRoot implements HasChildrenNodes {
private List nodes = new ArrayList<>();
private Set relationships = new HashSet<>();
private Map tokenizedSource = new HashMap<>();
/**
* The top-level nodes of the CST.
*/
public List getNodes() {
return nodes;
}
@Override
public void addNode(CstNode node) {
nodes.add(node);
}
public void addTokenizedFile(TokenizedSource tokenizedSource) {
this.tokenizedSource.put(tokenizedSource.getFile(), tokenizedSource);
}
/**
* @return The relationships between nodes within the CST.
*/
public Set getRelationships() {
return relationships;
}
public void forEachNode(BiConsumer consumer) {
forEachNodeInList(nodes, consumer, 0);
}
private void forEachNodeInList(List list, BiConsumer consumer, int depth) {
for (CstNode node : list) {
consumer.accept(node, depth);
forEachNodeInList(node.getNodes(), consumer, depth + 1);
}
}
/**
* @return A map of source file paths to tokenized source code.
*/
public Map getTokenizedSource() {
return tokenizedSource;
}
}