package jp.naist.sd.kenja.factextractor;

import java.io.File;
import java.io.IOException;

import jp.naist.sd.kenja.factextractor.ast.ASTCompilation;

import org.apache.commons.io.IOUtils;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTParser;
import org.eclipse.jdt.core.dom.CompilationUnit;

public class GitTreeCreator{
	private Tree root = new Tree("");
	
	private ASTCompilation compilation;
	
	public GitTreeCreator(){
	}
	
	private void parseSourcecode(char[] src) {
		ASTParser parser = ASTParser.newParser(AST.JLS4);

		parser.setSource(src);

		NullProgressMonitor nullMonitor = new NullProgressMonitor();
		CompilationUnit unit = (CompilationUnit) parser.createAST(nullMonitor);
		
		compilation = new ASTCompilation(unit, root);
	}
	
	public void writeASTAsFileTree(File outputDir){
		compilation.getTree().writeTree(outputDir);
	}

	public static void main(String[] args){
		if(args.length != 1){
			System.out.println("please input output dir path");
			return;
		}
		
		File outputDir = new File(args[0]);
		GitTreeCreator creator = new GitTreeCreator();
			
		try {
			creator.parseSourcecode(IOUtils.toCharArray(System.in));
			creator.writeASTAsFileTree(outputDir);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

@@ -869,16 +869,110 @@
 Dir)%7B%0A%09%09
+TreeWriter writer = new TreeWriter(outputDir);%0A%09%09writer.writeTree(compilation.getTree());%0A%09%09//
 compilat

use TreeWriter to write Trees and Blobs Structure.