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

refdiff.core.cst.CstRoot Maven / Gradle / Ivy

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

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy