package be.jeffcheasey88.peeratcode.parser.java.operations;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import be.jeffcheasey88.peeratcode.parser.java.CleanerPool;
import be.jeffcheasey88.peeratcode.parser.java.JavaElement;

public class AssigmentOperation extends JavaElement{
	
	private static Pattern PATTERN = Pattern.compile("^(\\s*([^\\s]+)\\s*=\\s*([^;]+);).*$");

	private String variable;
	private String value;
	
	public AssigmentOperation(){}
	
	@Override
	public int parse(String content, CleanerPool cleaner) throws Exception{
		Matcher matcher = PATTERN.matcher(content);
		matcher.matches();
		
		this.variable = matcher.group(2);
		this.value = matcher.group(3);
		
		return matcher.group(1).length();
	}

	@Override
	public void show(int tab){
		String start = "";
		for(int i = 0; i < tab; i++) start+="\t";
		System.out.println(start+variable+" = "+value+";");
	}
	

}
