package be.jeffcheasey88.peeratcode.parser.java.operations; import java.io.BufferedWriter; import java.util.List; import java.util.function.BiFunction; 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 global, CleanerPool local) throws Exception{ Matcher matcher = PATTERN.matcher(content); matcher.matches(); this.variable = local.unzip(matcher.group(2), (s,p) -> s); this.value = local.unzip(matcher.group(3), (s,p) -> s); return matcher.group(1).length(); } @Override public void build(BufferedWriter writer, int tab) throws Exception{ super.build(writer, tab); writer.write(variable+"= "+value+";\n"); } @Override public E find(java.util.function.Function search, java.util.function.Function, Boolean> deep, List trace){ if(search.apply(this)) return (E)this; trace.add(this); int index = trace.size()-1; if(!deep.apply(trace)) return null; //value trace.remove(index); return null; } @Override public E find(BiFunction, Boolean> search, List trace){ trace.add(this); int index = trace.size()-1; if(search.apply(this, trace)) return (E)this; //value trace.remove(index); return null; } }