<commit_before>package refdiff.evaluation;

import java.io.File;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;

import refdiff.core.diff.RastComparator;
import refdiff.core.diff.RastComparatorMonitor;
import refdiff.core.diff.RastDiff;
import refdiff.core.diff.Relationship;
import refdiff.core.diff.RelationshipType;
import refdiff.core.io.FileSystemSourceFile;
import refdiff.core.io.GitHelper;
import refdiff.core.io.SourceFile;
import refdiff.core.rast.RastNode;
import refdiff.parsers.java.JavaParser;
import refdiff.parsers.java.JavaSourceTokenizer;
import refdiff.parsers.java.NodeTypes;

public class EvaluationUtils {
	
	private RastComparator comparator = new RastComparator(new JavaParser(), new JavaSourceTokenizer());
	private String tempFolder = "D:/tmp/";
	/**
	 * The ICSE dataset don't describe the qualified name of the extracted/inlined method.
	 */
	private boolean workAroundExtractAndInlineInconsistencies = true;
	
	public EvaluationUtils(String tempFolder) {
		this.tempFolder = tempFolder;
	}

	public EvaluationUtils(RastComparator comparator, String tempFolder) {
		this.comparator = comparator;
		this.tempFolder = tempFolder;
	}

	public RefactoringSet runRefDiff(String project, String commit) throws Exception {
		return runRefDiff(project, commit, new HashMap<>());
	}
	
	public RastDiff computeDiff(String project, String commit) throws Exception {
		File repoFolder = repoFolder(project);
		String checkoutFolderV0 = checkoutFolder(tempFolder, project, commit, "v0");
		String checkoutFolderV1 = checkoutFolder(tempFolder, project, commit, "v1");
		
		prepareSourceCode(project, commit);
		
		GitHelper gitHelper = new GitHelper();
		try (
			Repository repo = gitHelper.openRepository(repoFolder);
			RevWalk rw = new RevWalk(repo)) {
			
			RevCommit revCommit = rw.parseCommit(repo.resolve(commit));
			rw.parseCommit(revCommit.getParent(0));
			
			List<String> filesV0 = new ArrayList<>();
			List<String> filesV1 = new ArrayList<>();
			Map<String, String> renamedFilesHint = new HashMap<>();
			
			gitHelper.fileTreeDiff(repo, revCommit, filesV0, filesV1, renamedFilesHint, false, comparator.getAllowedFileExtensions());
			
			System.out.println(String.format("Computing diff for %s %s", project, commit));
			
			return comparator.compare(getSourceFiles(checkoutFolderV0, filesV0), getSourceFiles(checkoutFolderV1, filesV1));
		}
	}
	
	public RefactoringSet runRefDiff(String project, String commit, Map<KeyPair, String> explanations) throws Exception {
		
		File repoFolder = repoFolder(project);
		String checkoutFolderV0 = checkoutFolder(tempFolder, project, commit, "v0");
		String checkoutFolderV1 = checkoutFolder(tempFolder, project, commit, "v1");
		
		prepareSourceCode2(project, commit);
		
		GitHelper gitHelper = new GitHelper();
		try (
			Repository repo = gitHelper.openRepository(repoFolder);<commit_msg>Print "Done computing" after computing diff<commit_after>package refdiff.evaluation;

import java.io.File;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;

import refdiff.core.diff.RastComparator;
import refdiff.core.diff.RastComparatorMonitor;
import refdiff.core.diff.RastDiff;
import refdiff.core.diff.Relationship;
import refdiff.core.diff.RelationshipType;
import refdiff.core.io.FileSystemSourceFile;
import refdiff.core.io.GitHelper;
import refdiff.core.io.SourceFile;
import refdiff.core.rast.RastNode;
import refdiff.parsers.java.JavaParser;
import refdiff.parsers.java.JavaSourceTokenizer;
import refdiff.parsers.java.NodeTypes;

public class EvaluationUtils {
	
	private RastComparator comparator = new RastComparator(new JavaParser(), new JavaSourceTokenizer());
	private String tempFolder = "D:/tmp/";
	/**
	 * The ICSE dataset don't describe the qualified name of the extracted/inlined method.
	 */
	private boolean workAroundExtractAndInlineInconsistencies = true;
	
	public EvaluationUtils(String tempFolder) {
		this.tempFolder = tempFolder;
	}

	public EvaluationUtils(RastComparator comparator, String tempFolder) {
		this.comparator = comparator;
		this.tempFolder = tempFolder;
	}

	public RefactoringSet runRefDiff(String project, String commit) throws Exception {
		return runRefDiff(project, commit, new HashMap<>());
	}
	
	public RastDiff computeDiff(String project, String commit) throws Exception {
		File repoFolder = repoFolder(project);
		String checkoutFolderV0 = checkoutFolder(tempFolder, project, commit, "v0");
		String checkoutFolderV1 = checkoutFolder(tempFolder, project, commit, "v1");
		
		prepareSourceCode(project, commit);
		
		GitHelper gitHelper = new GitHelper();
		try (
			Repository repo = gitHelper.openRepository(repoFolder);
			RevWalk rw = new RevWalk(repo)) {
			
			RevCommit revCommit = rw.parseCommit(repo.resolve(commit));
			rw.parseCommit(revCommit.getParent(0));
			
			List<String> filesV0 = new ArrayList<>();
			List<String> filesV1 = new ArrayList<>();
			Map<String, String> renamedFilesHint = new HashMap<>();
			
			gitHelper.fileTreeDiff(repo, revCommit, filesV0, filesV1, renamedFilesHint, false, comparator.getAllowedFileExtensions());
			
			System.out.println(String.format("Computing diff for %s %s", project, commit));
			
			RastDiff rastDiff = comparator.compare(getSourceFiles(checkoutFolderV0, filesV0), getSourceFiles(checkoutFolderV1, filesV1));
			
			System.out.println("Done computing");
			
			return rastDiff;
		}
	}
	
	public RefactoringSet runRefDiff(String project, String commit, Map<KeyPair, String> explanations) throws Exception {
		
		File repoFolder = repoFolder(project);
		String checkoutFolderV0 = checkoutFolder(tempFolder, project, commit, "v0");
		String checkoutFolderV1 = checkoutFolder(tempFolder, project, commit, "v1");
		
		prepareSourceCode2(project, commit);
		
		GitHelper gitHelper = new GitHelper();
		try (
			Repository repo = gitHelper.openRepository(repoFolder);
{'fraction_non_alphanumeric': 0.10291785601014906, 'fraction_numerical': 0.005708848715509039, 'mean_word_length': 5.54253112033195, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5397732', 'n_tokens_mistral': 2036, 'n_tokens_neox': 1847, 'n_words': 435}