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 ReturnOperation extends JavaElement{

	private static Pattern PATTERN = Pattern.compile("^(\\s*return\\s*([^;]*);).*$");
	
	private String value;
	
	public ReturnOperation(){}
	
	@Override
	public int parse(String content, CleanerPool cleaner) throws Exception{
		Matcher matcher = PATTERN.matcher(content);
		matcher.matches();
		
		this.value = matcher.group(2);
		
		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+"return "+value+";");
	}

}
