Operation -> Condition case with just ;
This commit is contained in:
parent
f4ff094554
commit
ab03e73f58
7 changed files with 80 additions and 9 deletions
|
@ -89,6 +89,10 @@ public class Class extends JavaElement{
|
|||
return this.name;
|
||||
}
|
||||
|
||||
public List<JavaElement> getChilds(){
|
||||
return this.childs;
|
||||
}
|
||||
|
||||
// public List<Variable> getVariables(){
|
||||
// return this.vars;
|
||||
// }
|
||||
|
|
|
@ -41,13 +41,8 @@ public class Function extends OperationContainer{
|
|||
String body = local.unzipOne(zip, (s,p) -> s);
|
||||
String unzip = body.substring(1, body.indexOf('}'));
|
||||
|
||||
System.out.println("----------before----------");
|
||||
show(0);
|
||||
|
||||
super.parse(local.clean(unzip), global, local);
|
||||
|
||||
System.out.println("----------After----------");
|
||||
show(0);
|
||||
|
||||
return matcher.group(1).length()+local.unzip(unzip, ((s,p) -> s)).length()+1;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ import be.jeffcheasey88.peeratcode.parser.java.CleanerPool.Cleaner;
|
|||
public class JavaParser{
|
||||
|
||||
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\\ExampleClass.java");
|
||||
File file = new File("C:\\Users\\jeffc\\eclipse-workspace\\peer-at-code-backend\\src\\be\\jeffcheasey88\\peeratcode\\parser\\java\\Class.java");
|
||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||
|
||||
JavaParser parser = new JavaParser(reader);
|
||||
|
|
|
@ -9,6 +9,7 @@ import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
|
|||
public class ConditionalOperation extends OperationContainer{
|
||||
|
||||
private static Pattern PATTERN = Pattern.compile("^(\\^GENERIC_FUNCTION\\d+).*$");
|
||||
private static Pattern PATTERN_SPACE = Pattern.compile("^(\\s+).*$");
|
||||
|
||||
private Pattern pattern;
|
||||
private String condition;
|
||||
|
@ -23,9 +24,16 @@ public class ConditionalOperation extends OperationContainer{
|
|||
matcher.matches();
|
||||
|
||||
this.condition = local.unzipOne(matcher.group(2), (s,p) -> s);
|
||||
System.out.println("CONDITION "+condition);
|
||||
|
||||
int index = matcher.group(1).length();
|
||||
content = content.substring(index);
|
||||
|
||||
matcher = PATTERN_SPACE.matcher(content);
|
||||
if(matcher.matches()){
|
||||
index+=matcher.group(1).length();
|
||||
content = content.substring(matcher.group(1).length());
|
||||
}
|
||||
|
||||
int bodysize;
|
||||
if(content.startsWith("^")){
|
||||
|
@ -39,6 +47,8 @@ public class ConditionalOperation extends OperationContainer{
|
|||
content = content.substring(1, content.length()-1);
|
||||
content = local.clean(content);
|
||||
super.parse(content, global, local);
|
||||
}else if(content.startsWith(";")){
|
||||
bodysize=1;
|
||||
}else{
|
||||
bodysize = parseOne(content, global, local);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ public class MethodCallOperation extends JavaElement{
|
|||
|
||||
@Override
|
||||
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);
|
||||
|
|
|
@ -40,8 +40,6 @@ public abstract class OperationContainer extends JavaElement{
|
|||
|
||||
System.out.println(operation.getClass().getSimpleName()+" operation = FACTORY.buildOperation();");
|
||||
int index = operation.parse(content, global, local);
|
||||
operation.show(0);
|
||||
System.out.println();
|
||||
content = content.substring(index);
|
||||
if(operation instanceof Variable){
|
||||
if(content.startsWith(",")){
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
package be.jeffcheasey88.peeratcode.parser.java;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.api.TestInstance.Lifecycle;
|
||||
|
||||
@TestInstance(Lifecycle.PER_CLASS)
|
||||
class OperationTest{
|
||||
|
||||
JavaParser parse(String code) throws Exception{
|
||||
BufferedReader reader = new BufferedReader(new Reader(){public int read(char[] cbuf, int off, int len) throws IOException{return 0;}public void close() throws IOException {}}) {
|
||||
private boolean read = false;
|
||||
@Override
|
||||
public String readLine() throws IOException{
|
||||
if(read) return null;
|
||||
read = true;
|
||||
return code;
|
||||
}
|
||||
};
|
||||
|
||||
JavaParser parser = new JavaParser(reader);
|
||||
parser.parse();
|
||||
return parser;
|
||||
}
|
||||
|
||||
@Test
|
||||
void ifOperation(){
|
||||
try {
|
||||
JavaParser parser = parse("package be.jeffcheasey88.peeratcode.parser.java; class Test{ void function(){ int i = 0; if(i == 0) { return i; } return i; } }");
|
||||
Class clazz = parser.getClazz();
|
||||
|
||||
clazz.show(0);
|
||||
|
||||
assertEquals(1, clazz.getChilds().size());
|
||||
Function function = (Function) clazz.getChilds().get(0);
|
||||
assertEquals(3, function.getChilds().size());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void ifWithNoneOperation(){
|
||||
try {
|
||||
JavaParser parser = parse("package be.jeffcheasey88.peeratcode.parser.java; class Test{ void function(){ int i = 0; if(i == 0); return i; } }");
|
||||
Class clazz = parser.getClazz();
|
||||
|
||||
clazz.show(0);
|
||||
|
||||
assertEquals(1, clazz.getChilds().size());
|
||||
Function function = (Function) clazz.getChilds().get(0);
|
||||
assertEquals(3, function.getChilds().size());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue