From 0c98fe6e2ec127e1903d1d3c630a34d78d6aba49 Mon Sep 17 00:00:00 2001 From: jeffcheasey88 <66554203+jeffcheasey88@users.noreply.github.com> Date: Tue, 30 May 2023 18:38:44 +0200 Subject: [PATCH] Operation -> Fix empty return case --- .../jeffcheasey88/peeratcode/parser/java/Function.java | 7 +++++-- .../peeratcode/parser/java/operations/ElseOperation.java | 7 ++++++- .../peeratcode/parser/java/operations/IfOperation.java | 9 +++++++-- .../parser/java/operations/ReturnOperation.java | 2 +- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/Function.java b/src/be/jeffcheasey88/peeratcode/parser/java/Function.java index 842dcad..08dbdde 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/Function.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/Function.java @@ -38,10 +38,13 @@ public class Function extends OperationContainer{ String zip = generic.clean("{"+matcher.group(5)); String body = generic.unzipOne(zip, (s,p) -> s); String unzip = body.substring(1, body.indexOf('}')); - System.out.println("----------------------"); + System.out.println("----------Before------------"); show(0); - System.out.println("----------------------"); + System.out.println("----------------------------"); parse(unzip, cleaner, generic); + System.out.println("----------After------------"); + show(0); + System.out.println("---------------------------"); return matcher.group(1).length()+generic.unzip(unzip, ((s,p) -> s)).length()+1; } diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/operations/ElseOperation.java b/src/be/jeffcheasey88/peeratcode/parser/java/operations/ElseOperation.java index 7974118..86c9412 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/operations/ElseOperation.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/operations/ElseOperation.java @@ -4,6 +4,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import be.jeffcheasey88.peeratcode.parser.java.CleanerPool; +import be.jeffcheasey88.peeratcode.parser.java.JavaElement; import be.jeffcheasey88.peeratcode.parser.java.CleanerPool.Cleaner; public class ElseOperation extends OperationContainer{ @@ -40,7 +41,11 @@ public class ElseOperation extends OperationContainer{ @Override public void show(int tab) { - + String start = ""; + for(int i = 0; i < tab; i++) start+="\t"; + System.out.println(start+"else{"); + for(JavaElement child : getChilds()) child.show(tab+1); + System.out.println(start+"}"); } } diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/operations/IfOperation.java b/src/be/jeffcheasey88/peeratcode/parser/java/operations/IfOperation.java index aa22cc2..4a13002 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/operations/IfOperation.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/operations/IfOperation.java @@ -23,6 +23,7 @@ public class IfOperation extends OperationContainer{ new Cleaner("GENERIC_PARENTHESIS",'(',')'), new Cleaner("GENERIC_FUNCTION", '{','}')); content = generic.clean(content); + System.out.println("after clean "+content); Matcher matcher = PATTERN.matcher(content); matcher.matches(); @@ -30,7 +31,7 @@ public class IfOperation extends OperationContainer{ this.condition = generic.unzip(matcher.group(2), (s,p) -> s); int index = generic.unzip(matcher.group(1), (s,p) -> s).length(); - content = generic.unzipOne(content, (s,p) -> s).substring(index); + content = generic.unzip(content, (s,p) -> s).substring(index); System.out.println("INSIDE "+content); int bodysize; if(content.startsWith("{")){ @@ -46,7 +47,11 @@ public class IfOperation extends OperationContainer{ @Override public void show(int tab) { - + String start = ""; + for(int i = 0; i < tab; i++) start+="\t"; + System.out.println(start+"if("+condition+"){"); + for(JavaElement child : getChilds()) child.show(tab+1); + System.out.println(start+"}"); } } diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/operations/ReturnOperation.java b/src/be/jeffcheasey88/peeratcode/parser/java/operations/ReturnOperation.java index 8ea6b07..0be0f66 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/operations/ReturnOperation.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/operations/ReturnOperation.java @@ -8,7 +8,7 @@ import be.jeffcheasey88.peeratcode.parser.java.JavaElement; public class ReturnOperation extends JavaElement{ - private static Pattern PATTERN = Pattern.compile("^(\\s*return\\s*([^;]*);)\\s*$"); + private static Pattern PATTERN = Pattern.compile("^(\\s*return\\s*([^;]*);).*$"); private String value;