Operation -> Fix empty return case
This commit is contained in:
parent
9a19c54e34
commit
0c98fe6e2e
4 changed files with 19 additions and 6 deletions
|
@ -38,10 +38,13 @@ public class Function extends OperationContainer{
|
||||||
String zip = generic.clean("{"+matcher.group(5));
|
String zip = generic.clean("{"+matcher.group(5));
|
||||||
String body = generic.unzipOne(zip, (s,p) -> s);
|
String body = generic.unzipOne(zip, (s,p) -> s);
|
||||||
String unzip = body.substring(1, body.indexOf('}'));
|
String unzip = body.substring(1, body.indexOf('}'));
|
||||||
System.out.println("----------------------");
|
System.out.println("----------Before------------");
|
||||||
show(0);
|
show(0);
|
||||||
System.out.println("----------------------");
|
System.out.println("----------------------------");
|
||||||
parse(unzip, cleaner, generic);
|
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;
|
return matcher.group(1).length()+generic.unzip(unzip, ((s,p) -> s)).length()+1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
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.CleanerPool.Cleaner;
|
import be.jeffcheasey88.peeratcode.parser.java.CleanerPool.Cleaner;
|
||||||
|
|
||||||
public class ElseOperation extends OperationContainer{
|
public class ElseOperation extends OperationContainer{
|
||||||
|
@ -40,7 +41,11 @@ public class ElseOperation extends OperationContainer{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void show(int tab) {
|
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+"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ public class IfOperation extends OperationContainer{
|
||||||
new Cleaner("GENERIC_PARENTHESIS",'(',')'),
|
new Cleaner("GENERIC_PARENTHESIS",'(',')'),
|
||||||
new Cleaner("GENERIC_FUNCTION", '{','}'));
|
new Cleaner("GENERIC_FUNCTION", '{','}'));
|
||||||
content = generic.clean(content);
|
content = generic.clean(content);
|
||||||
|
System.out.println("after clean "+content);
|
||||||
|
|
||||||
Matcher matcher = PATTERN.matcher(content);
|
Matcher matcher = PATTERN.matcher(content);
|
||||||
matcher.matches();
|
matcher.matches();
|
||||||
|
@ -30,7 +31,7 @@ public class IfOperation extends OperationContainer{
|
||||||
this.condition = generic.unzip(matcher.group(2), (s,p) -> s);
|
this.condition = generic.unzip(matcher.group(2), (s,p) -> s);
|
||||||
|
|
||||||
int index = generic.unzip(matcher.group(1), (s,p) -> s).length();
|
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);
|
System.out.println("INSIDE "+content);
|
||||||
int bodysize;
|
int bodysize;
|
||||||
if(content.startsWith("{")){
|
if(content.startsWith("{")){
|
||||||
|
@ -46,7 +47,11 @@ public class IfOperation extends OperationContainer{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void show(int tab) {
|
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+"}");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
|
||||||
|
|
||||||
public class ReturnOperation extends 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;
|
private String value;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue