Compare commits

..

4 commits

Author SHA1 Message Date
jeffcheasey88
f4ff094554 Operation -> Return statement -> get value 2023-05-31 12:00:38 +02:00
jeffcheasey88
c7b9454ede Operation -> Fix CleanerPool using 2023-05-31 11:47:38 +02:00
jeffcheasey88
ad430cb659 Operation -> Method Call 2023-05-30 21:46:40 +02:00
jeffcheasey88
be289b8d7f Fix Cleaner unzip one, fix logic 2023-05-30 21:35:55 +02:00
13 changed files with 155 additions and 101 deletions

View file

@ -19,7 +19,7 @@ public class Class extends JavaElement{
public Class(){} public Class(){}
public int parse(String content, CleanerPool cleaner) throws Exception{ public int parse(String content, CleanerPool global, CleanerPool local) throws Exception{
Matcher matcher = PATTERN.matcher(content); Matcher matcher = PATTERN.matcher(content);
matcher.matches(); matcher.matches();
@ -39,7 +39,7 @@ public class Class extends JavaElement{
int equals = indexOf(content,"="); int equals = indexOf(content,"=");
if((quotes < braces && quotes < equals) || (equals < braces)){ if((quotes < braces && quotes < equals) || (equals < braces)){
Variable variable = new Variable(); Variable variable = new Variable();
int index = variable.parse(content, cleaner); int index = variable.parse(content, global, local);
content = content.substring(index); content = content.substring(index);
boolean quote = content.startsWith(","); boolean quote = content.startsWith(",");
if(quote){ if(quote){
@ -49,7 +49,7 @@ public class Class extends JavaElement{
multiple.addVariable(variable.getName(), variable.getValue()); multiple.addVariable(variable.getName(), variable.getValue());
while(quote){ while(quote){
variable = new Variable(variable.getModifier(), variable.getType()); variable = new Variable(variable.getModifier(), variable.getType());
index = variable.parse(content, cleaner); index = variable.parse(content, global, local);
content = content.substring(index); content = content.substring(index);
quote = content.startsWith(","); quote = content.startsWith(",");
if(quote) content = content.substring(1); if(quote) content = content.substring(1);
@ -66,7 +66,7 @@ public class Class extends JavaElement{
}else{ }else{
// System.out.println("Function "+content); // System.out.println("Function "+content);
Function func = new Function(); Function func = new Function();
int index = func.parse(content, cleaner); int index = func.parse(content, global, local);
this.childs.add(func); this.childs.add(func);
content = content.substring(index); content = content.substring(index);
// System.out.println("End "+content); // System.out.println("End "+content);

View file

@ -15,7 +15,34 @@ public class CleanerPool{
private List<Cleaner> cleaners; private List<Cleaner> cleaners;
public CleanerPool(Cleaner... cleaners){ public CleanerPool(Cleaner... cleaners){
this.cleaners = Arrays.asList(cleaners); this.cleaners = new ArrayList<>(Arrays.asList(cleaners));
}
public CleanerPool group(CleanerPool... pools){
CleanerPool pool = new CleanerPool();
pool.cleaners.addAll(cleaners);
for(CleanerPool other : pools){
for(Cleaner cleaner : other.cleaners){
boolean contains = false;
for(Cleaner include : pool.cleaners){
if(include.getPattern().equals(cleaner.getPattern())){
contains = true;
break;
}
}
if(contains) continue;
pool.cleaners.add(cleaner);
}
}
return pool;
}
@Override
public String toString(){
String s = "CleanerPool[\n";
for(Cleaner cleaner : cleaners) s+=cleaner.pattern+"['"+cleaner.open+"' -> '"+cleaner.close+"']\n";
s+="\n]";
return s;
} }
public String clean(String value){ public String clean(String value){
@ -36,15 +63,18 @@ public class CleanerPool{
String zip = cleaner.getConstant(key); String zip = cleaner.getConstant(key);
String modified = modifier.apply(zip, cleaner.getPattern()); String modified = modifier.apply(zip, cleaner.getPattern());
if(modified == null) continue; if(modified == null) continue;
map.put(key, cleaner.open+zip+cleaner.close); map.put(key, cleaner.open+modified+cleaner.close);
tmp = matcher.group(1)+cleaner.open+zip+cleaner.close+matcher.group(3); tmp = matcher.group(1)+cleaner.open+modified+cleaner.close+matcher.group(3);
edited = true; edited = true;
} }
} }
}while(edited); }while(edited);
String base = value;
for(Entry<String, String> unzip : map.entrySet()) value = value.replaceAll("\\"+unzip.getKey()+"(?<e>([^\\d]|$))", unzip.getValue()+"${e}"); for(Entry<String, String> unzip : map.entrySet()){
Pattern pattern = Pattern.compile("\\"+unzip.getKey()+"(?<e>([^\\d]|$))");
if(pattern.matcher(base).find()) value = pattern.matcher(value).replaceAll(unzip.getValue()+"${e}");
}
return value; return value;
} }

View file

@ -26,27 +26,30 @@ public class Function extends OperationContainer{
this.parameters = new ArrayList<>(); this.parameters = new ArrayList<>();
} }
public int parse(String content, CleanerPool cleaner) throws Exception{ public int parse(String content, CleanerPool global, CleanerPool local) throws Exception{
Matcher matcher = PATTERN.matcher(content); Matcher matcher = PATTERN.matcher(content);
matcher.matches(); matcher.matches();
attribute(matcher.group(2)); attribute(matcher.group(2));
parameters(matcher.group(3)+";", cleaner); parameters(matcher.group(3)+";", global, local);
this.exceptions = matcher.group(4).trim(); this.exceptions = matcher.group(4).trim();
CleanerPool generic = new CleanerPool(new Cleaner("GENERIC_FUNCTION", '{', '}')); local = new CleanerPool(
String zip = generic.clean("{"+matcher.group(5)); new Cleaner("GENERIC_FUNCTION", '{', '}'),
String body = generic.unzipOne(zip, (s,p) -> s); new Cleaner("GENERIC_PARENTHESIS", '(', ')'));
String zip = local.clean("{"+matcher.group(5));
String body = local.unzipOne(zip, (s,p) -> s);
String unzip = body.substring(1, body.indexOf('}')); String unzip = body.substring(1, body.indexOf('}'));
System.out.println("----------Before------------");
System.out.println("----------before----------");
show(0); show(0);
System.out.println("----------------------------");
parse(unzip, cleaner, generic); super.parse(local.clean(unzip), global, local);
System.out.println("----------After------------");
show(0);
System.out.println("---------------------------");
return matcher.group(1).length()+generic.unzip(unzip, ((s,p) -> s)).length()+1; System.out.println("----------After----------");
show(0);
return matcher.group(1).length()+local.unzip(unzip, ((s,p) -> s)).length()+1;
} }
private static Pattern UNZIP_STICK = Pattern.compile("\\s+(?<e>[<|(|\\[|\"|'])"); private static Pattern UNZIP_STICK = Pattern.compile("\\s+(?<e>[<|(|\\[|\"|'])");
@ -82,12 +85,12 @@ public class Function extends OperationContainer{
} }
} }
private void parameters(String content, CleanerPool cleaner) throws Exception{ private void parameters(String content, CleanerPool global, CleanerPool local) throws Exception{
if(content.length() == 1) return; if(content.length() == 1) return;
boolean quote = false; boolean quote = false;
do { do {
Variable variable = new Variable(); Variable variable = new Variable();
int index = variable.parse(content, cleaner); int index = variable.parse(content, global, local);
this.parameters.add(variable); this.parameters.add(variable);
content = content.substring(index); content = content.substring(index);
quote = content.startsWith(","); quote = content.startsWith(",");

View file

@ -2,7 +2,7 @@ package be.jeffcheasey88.peeratcode.parser.java;
public abstract class JavaElement { public abstract class JavaElement {
public abstract int parse(String content, CleanerPool cleaner) throws Exception; public abstract int parse(String content, CleanerPool global, CleanerPool local) throws Exception;
//Only for development //Only for development
public abstract void show(int tab); public abstract void show(int tab);

View file

@ -14,7 +14,7 @@ import be.jeffcheasey88.peeratcode.parser.java.CleanerPool.Cleaner;
public class JavaParser{ public class JavaParser{
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
File file = new File("C:\\Users\\jeffc\\eclipse-workspace\\peer-at-code-backend\\src\\be\\jeffcheasey88\\peeratcode\\parser\\java\\Variable.java"); File file = new File("C:\\Users\\jeffc\\eclipse-workspace\\peer-at-code-backend\\src\\be\\jeffcheasey88\\peeratcode\\parser\\java\\ExampleClass.java");
BufferedReader reader = new BufferedReader(new FileReader(file)); BufferedReader reader = new BufferedReader(new FileReader(file));
JavaParser parser = new JavaParser(reader); JavaParser parser = new JavaParser(reader);
@ -105,7 +105,7 @@ public class JavaParser{
} }
this.clazz = new Class(); this.clazz = new Class();
index = this.clazz.parse(content, cleaner); index = this.clazz.parse(content, cleaner, null);
content = content.substring(index); content = content.substring(index);
} }

View file

@ -25,13 +25,15 @@ public class Variable extends JavaElement{
this.type = type; this.type = type;
} }
public int parse(String content, CleanerPool cleaner) throws Exception{ public int parse(String content, CleanerPool global, CleanerPool local) throws Exception{
CleanerPool generic = new CleanerPool( CleanerPool generic = new CleanerPool(
new Cleaner("GENERIC_TYPE_",'<','>'), new Cleaner("GENERIC_TYPE",'<','>'),
new Cleaner("GENERIC_ARRAY",'[',']'), new Cleaner("GENERIC_ARRAY",'[',']'),
new Cleaner("GENERIC_FUNCTION", '{','}'), new Cleaner("GENERIC_FUNCTION", '{','}'),
new Cleaner("GENERIC_PARENTHESIS",'(',')')); new Cleaner("GENERIC_PARENTHESIS",'(',')'));
content = generic.clean(content); if(local == null) local = generic;
else local = local.group(generic);
content = local.clean(content);
Matcher matcher = PATTERN.matcher(content); Matcher matcher = PATTERN.matcher(content);
matcher.matches(); matcher.matches();
@ -46,12 +48,12 @@ public class Variable extends JavaElement{
body = body.substring(0, min); body = body.substring(0, min);
if(equals < quote && equals < quotes){ if(equals < quote && equals < quotes){
assigment(body, generic); assigment(body, local);
}else{ }else{
onlyDefine(body, generic); onlyDefine(body, local);
} }
return offset+generic.unzip(body, ((s,p) -> s)).length(); return offset+local.unzipOne(body, (s,p) -> (p.equals("^GENERIC_TYPE") || p.equals("^GENERIC_ARRAY")) ? s : null).length();
} }
private void assigment(String content, CleanerPool cleaner){ private void assigment(String content, CleanerPool cleaner){

View file

@ -16,12 +16,12 @@ public class AssigmentOperation extends JavaElement{
public AssigmentOperation(){} public AssigmentOperation(){}
@Override @Override
public int parse(String content, CleanerPool cleaner) throws Exception{ public int parse(String content, CleanerPool global, CleanerPool local) throws Exception{
Matcher matcher = PATTERN.matcher(content); Matcher matcher = PATTERN.matcher(content);
matcher.matches(); matcher.matches();
this.variable = matcher.group(2); this.variable = local.unzip(matcher.group(2), (s,p) -> s);
this.value = matcher.group(3); this.value = local.unzip(matcher.group(3), (s,p) -> s);
return matcher.group(1).length(); return matcher.group(1).length();
} }

View file

@ -5,10 +5,11 @@ import java.util.regex.Pattern;
import be.jeffcheasey88.peeratcode.parser.java.CleanerPool; import be.jeffcheasey88.peeratcode.parser.java.CleanerPool;
import be.jeffcheasey88.peeratcode.parser.java.JavaElement; import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
import be.jeffcheasey88.peeratcode.parser.java.CleanerPool.Cleaner;
public class ConditionalOperation extends OperationContainer{ public class ConditionalOperation extends OperationContainer{
private static Pattern PATTERN = Pattern.compile("^(\\^GENERIC_FUNCTION\\d+).*$");
private Pattern pattern; private Pattern pattern;
private String condition; private String condition;
@ -17,26 +18,29 @@ public class ConditionalOperation extends OperationContainer{
} }
@Override @Override
public int parse(String content, CleanerPool cleaner) throws Exception{ public int parse(String content, CleanerPool global, CleanerPool local) throws Exception{
CleanerPool generic = new CleanerPool(
new Cleaner("GENERIC_PARENTHESIS",'(',')'),
new Cleaner("GENERIC_FUNCTION", '{','}'));
content = generic.clean(content);
Matcher matcher = this.pattern.matcher(content); Matcher matcher = this.pattern.matcher(content);
matcher.matches(); matcher.matches();
this.condition = generic.unzip(matcher.group(2), (s,p) -> s); this.condition = local.unzipOne(matcher.group(2), (s,p) -> s);
int index = generic.unzip(matcher.group(1), (s,p) -> s).length(); int index = matcher.group(1).length();
content = generic.unzip(content, (s,p) -> s).substring(index); content = content.substring(index);
int bodysize; int bodysize;
if(content.startsWith("{")){ if(content.startsWith("^")){
bodysize = content.indexOf('}')+1; matcher = PATTERN.matcher(content);
content = content.substring(1, bodysize-1); matcher.matches();
parse(content, cleaner, generic);
content = matcher.group(1);
bodysize = content.length();
content = local.unzipOne(content, (s,p) -> s);
content = content.substring(1, content.length()-1);
content = local.clean(content);
super.parse(content, global, local);
}else{ }else{
bodysize = parseOne(content, cleaner, generic); bodysize = parseOne(content, global, local);
} }
return index+bodysize; return index+bodysize;

View file

@ -10,35 +10,37 @@ import be.jeffcheasey88.peeratcode.parser.java.CleanerPool.Cleaner;
public class ElseOperation extends OperationContainer{ public class ElseOperation extends OperationContainer{
private static Pattern PATTERN = Pattern.compile("^(\\s*else\\s*).*$"); private static Pattern PATTERN = Pattern.compile("^(\\s*else\\s*).*$");
private static Pattern PATTERN_CLEANER = Pattern.compile("^(\\^GENERIC_FUNCTION\\d+).*$");
public ElseOperation(){} public ElseOperation(){}
@Override @Override
public int parse(String content, CleanerPool cleaner) throws Exception{ public int parse(String content, CleanerPool global, CleanerPool local) throws Exception{
System.out.println("ELSE STATEMENT");
CleanerPool generic = new CleanerPool(
new Cleaner("GENERIC_PARENTHESIS",'(',')'),
new Cleaner("GENERIC_FUNCTION", '{','}'));
content = generic.clean(content);
Matcher matcher = PATTERN.matcher(content); Matcher matcher = PATTERN.matcher(content);
matcher.matches(); matcher.matches();
int index = generic.unzip(matcher.group(1), (s,p) -> s).length(); int index = matcher.group(1).length();
content = generic.unzipOne(content, (s,p) -> s).substring(index); content = content.substring(index);
System.out.println("INSIDE "+content);
int bodysize; int bodysize;
if(content.startsWith("{")){ if(content.startsWith("^")){
bodysize = content.indexOf('}')+1; matcher = PATTERN_CLEANER.matcher(content);
content = content.substring(1, bodysize-1); matcher.matches();
parse(content, cleaner, generic);
content = matcher.group(1);
bodysize = content.length();
content = local.unzipOne(content, (s,p) -> s);
content = content.substring(1, content.length()-1);
content = local.clean(content);
super.parse(content, global, local);
}else{ }else{
bodysize = parseOne(content, cleaner, generic); bodysize = parseOne(content, global, local);
} }
return index+bodysize; return index+bodysize;
} }
@Override @Override
public void show(int tab) { public void show(int tab) {
String start = ""; String start = "";

View file

@ -8,18 +8,21 @@ import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
public class MethodCallOperation extends JavaElement{ public class MethodCallOperation extends JavaElement{
private static Pattern PATTERN = Pattern.compile("^(\\s*([^\\(]*\\([^\\)]*\\));).*$"); private static Pattern PATTERN = Pattern.compile("^(\\s*([^\\^\\s]+\\^GENERIC_PARENTHESIS\\d+);).*$");
private String value; private String value;
public MethodCallOperation(){} public MethodCallOperation(){}
@Override @Override
public int parse(String content, CleanerPool cleaner) throws Exception{ public int parse(String content, CleanerPool global, CleanerPool local) throws Exception{
System.out.println("MethodCallOperation.parse -> "+content);
content = local.clean(content);
Matcher matcher = PATTERN.matcher(content); Matcher matcher = PATTERN.matcher(content);
matcher.matches(); matcher.matches();
this.value = matcher.group(2); this.value = local.unzip(matcher.group(2), (s,p) -> s);
return matcher.group(1).length(); return matcher.group(1).length();
} }

View file

@ -18,25 +18,30 @@ public abstract class OperationContainer extends JavaElement{
this.childs = new ArrayList<>(); this.childs = new ArrayList<>();
} }
public void parse(String content, CleanerPool global, CleanerPool local) throws Exception{ @Override
content = local.unzip(content, (s,p) -> s); public int parse(String content, CleanerPool global, CleanerPool local) throws Exception{
System.out.println("CONTAINER "+content); System.out.println("OperationContainer.parse -> "+content);
// content = local.unzipOne(content, (s,p) -> s);
while(!(content.replaceAll("\\s+", "").isEmpty())) content = internalParse(content, global, local); while(!(content.replaceAll("\\s+", "").isEmpty())) content = internalParse(content, global, local);
return 0;
} }
public int parseOne(String content, CleanerPool global, CleanerPool local) throws Exception{ public int parseOne(String content, CleanerPool global, CleanerPool local) throws Exception{
content = local.unzip(content, (s,p) -> s); System.out.println("OperationContainer.parseOne -> "+content);
// content = local.unzip(content, (s,p) -> s);
String modify = internalParse(content, global, local); String modify = internalParse(content, global, local);
return content.length()-modify.length(); return content.length()-modify.length();
} }
private String internalParse(String content, CleanerPool global, CleanerPool local) throws Exception{ private String internalParse(String content, CleanerPool global, CleanerPool local) throws Exception{
System.out.println("BODY "+content); System.out.println("OperationContainer.internalParse -> "+content);
JavaElement operation = FACTORY.buildOperation(content); JavaElement operation = FACTORY.buildOperation(content);
System.out.println("got "+operation.getClass().getSimpleName()); System.out.println(operation.getClass().getSimpleName()+" operation = FACTORY.buildOperation();");
int index = operation.parse(content, local); int index = operation.parse(content, global, local);
operation.show(0);
System.out.println();
content = content.substring(index); content = content.substring(index);
if(operation instanceof Variable){ if(operation instanceof Variable){
if(content.startsWith(",")){ if(content.startsWith(",")){
@ -49,7 +54,7 @@ public abstract class OperationContainer extends JavaElement{
boolean quote; boolean quote;
do{ do{
variable = new Variable(variable.getModifier(), variable.getType()); variable = new Variable(variable.getModifier(), variable.getType());
index = variable.parse(content, local); index = variable.parse(content, global, local);
multiple.addVariable(variable.getName(), variable.getValue()); multiple.addVariable(variable.getName(), variable.getValue());
content = content.substring(index); content = content.substring(index);
quote = content.startsWith(","); quote = content.startsWith(",");

View file

@ -32,10 +32,11 @@ public class OperationFactory{
this.patterns.put(Pattern.compile("^\\s*while\\s*\\^GENERIC_PARENTHESIS\\d+.*$"), WhileOperation.class); this.patterns.put(Pattern.compile("^\\s*while\\s*\\^GENERIC_PARENTHESIS\\d+.*$"), WhileOperation.class);
this.patterns.put(Pattern.compile("^\\s*else\\s*.*$"), ElseOperation.class); this.patterns.put(Pattern.compile("^\\s*else\\s*.*$"), ElseOperation.class);
this.patterns.put(Pattern.compile("^\\s*([^;=]+;).*$"), MethodCallOperation.class); this.patterns.put(Pattern.compile("^\\s*[^\\^\\s]+\\^GENERIC_PARENTHESIS\\d+;.*$"), MethodCallOperation.class);
this.patterns.put(Pattern.compile("^\\s*[^\\s]+\\s+[^\\s]+\\s*=\\s*[^;]+;.*$"), Variable.class); this.patterns.put(Pattern.compile("^\\s*[^\\s]+\\s+[^\\s]+\\s*=\\s*[^;]+;.*$"), Variable.class);
this.patterns.put(Pattern.compile("^\\s*[^\\s]+\\s*=\\s*[^;]+;.*$"), AssigmentOperation.class); this.patterns.put(Pattern.compile("^\\s*[^\\s]+\\s*=\\s*[^;]+;.*$"), AssigmentOperation.class);
this.patterns.put(Pattern.compile("^\\s*[^;]+;.*$"), Variable.class);
} }
/* /*
@ -64,15 +65,13 @@ public class OperationFactory{
*/ */
public JavaElement buildOperation(String content) throws Exception{ public JavaElement buildOperation(String content) throws Exception{
System.out.println("Factory.buildOperation -> "+content);
CleanerPool generic = new CleanerPool( CleanerPool generic = new CleanerPool(
new Cleaner("GENERIC_FUNCTION", '{','}'),
new Cleaner("GENERIC_PARENTHESIS",'(',')'),
new Cleaner("GENERIC_ARRAY",'[',']'), new Cleaner("GENERIC_ARRAY",'[',']'),
new Cleaner("GENERIC_TYPE_",'<','>')); new Cleaner("GENERIC_TYPE_",'<','>'));
content = generic.clean(content); content = generic.clean(content);
content = generiqueTypes(content, generic); content = generiqueTypes(content, generic);
System.out.println("look for "+content);
for(Entry<Pattern, Class<? extends JavaElement>> entries : this.patterns.entrySet()){ for(Entry<Pattern, Class<? extends JavaElement>> entries : this.patterns.entrySet()){
if(entries.getKey().matcher(content).matches()) return entries.getValue().newInstance(); if(entries.getKey().matcher(content).matches()) return entries.getValue().newInstance();
} }
@ -87,25 +86,15 @@ public class OperationFactory{
private static Pattern UNZIP_EQUALS_RIGHT = Pattern.compile("=(?<e>[^=\\s])"); private static Pattern UNZIP_EQUALS_RIGHT = Pattern.compile("=(?<e>[^=\\s])");
private String generiqueTypes(String content, CleanerPool cleaner){ private String generiqueTypes(String content, CleanerPool cleaner){
System.out.println("base on "+content);
String unzip = cleaner.unzip(content, (value, pattern) -> { String unzip = cleaner.unzip(content, (value, pattern) -> {
System.out.println("unzip pattern "+pattern); if(pattern.equals("^GENERIC_FUNCTION") || pattern.equals("^GENERIC_PARENTHESIS")) return null;
if(pattern.equals("^GENERIC_FUNCTION")) return null;
if(pattern.equals("^GENERIC_PARENTHESIS")) return null;
System.out.println("let pass "+pattern);
return value.replaceAll("\\s+", ""); return value.replaceAll("\\s+", "");
}); });
System.out.println("generiqueTypes on "+unzip);
unzip = UNZIP_STICK.matcher(unzip).replaceAll("${e}"); unzip = UNZIP_STICK.matcher(unzip).replaceAll("${e}");
System.out.println("g => "+unzip);
unzip = UNZIP_MAJ.matcher(unzip).replaceAll("> ${e}"); unzip = UNZIP_MAJ.matcher(unzip).replaceAll("> ${e}");
System.out.println("g => "+unzip);
unzip = UNZIP_ARRAY.matcher(unzip).replaceAll("] ${e}"); unzip = UNZIP_ARRAY.matcher(unzip).replaceAll("] ${e}");
System.out.println("g => "+unzip);
unzip = UNZIP_EQUALS_LEFT.matcher(unzip).replaceAll("${e} ="); unzip = UNZIP_EQUALS_LEFT.matcher(unzip).replaceAll("${e} =");
System.out.println("g => "+unzip);
unzip = UNZIP_EQUALS_RIGHT.matcher(unzip).replaceAll("= ${e}"); unzip = UNZIP_EQUALS_RIGHT.matcher(unzip).replaceAll("= ${e}");
System.out.println("g => "+unzip);
return unzip; return unzip;
} }
} }

View file

@ -10,16 +10,26 @@ public class ReturnOperation extends JavaElement{
private static Pattern PATTERN = Pattern.compile("^(\\s*return\\s*([^;]*);).*$"); private static Pattern PATTERN = Pattern.compile("^(\\s*return\\s*([^;]*);).*$");
private String value; private static OperationFactory FACTORY = OperationFactory.getFactory();
private String toChange;
private JavaElement value;
public ReturnOperation(){} public ReturnOperation(){}
@Override @Override
public int parse(String content, CleanerPool cleaner) throws Exception{ public int parse(String content, CleanerPool global, CleanerPool local) throws Exception{
Matcher matcher = PATTERN.matcher(content); Matcher matcher = PATTERN.matcher(content);
matcher.matches(); matcher.matches();
this.value = matcher.group(2); //To update for native obj
this.toChange = matcher.group(2);
JavaElement operation = FACTORY.buildOperation(toChange+";");
if(operation != null){
System.out.println(operation.getClass().getSimpleName());
value = operation;
value.parse(toChange+";", global, local);
}
return matcher.group(1).length(); return matcher.group(1).length();
} }
@ -28,7 +38,13 @@ public class ReturnOperation extends JavaElement{
public void show(int tab){ public void show(int tab){
String start = ""; String start = "";
for(int i = 0; i < tab; i++) start+="\t"; for(int i = 0; i < tab; i++) start+="\t";
System.out.println(start+"return "+value+";"); if(value != null){
System.out.println("return");
value.show(tab+1);
System.out.println(";");
return;
}
System.out.println(start+"return "+toChange+";");
} }
} }