Operation -> Return statement -> get value

This commit is contained in:
jeffcheasey88 2023-05-31 12:00:38 +02:00
parent c7b9454ede
commit f4ff094554
5 changed files with 20 additions and 20 deletions

View file

@ -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\\Class.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));
JavaParser parser = new JavaParser(reader);

View file

@ -26,8 +26,6 @@ public class Variable extends JavaElement{
}
public int parse(String content, CleanerPool global, CleanerPool local) throws Exception{
System.out.println("local ? "+local);
System.out.println("Variable.parse -> "+content);
CleanerPool generic = new CleanerPool(
new Cleaner("GENERIC_TYPE",'<','>'),
new Cleaner("GENERIC_ARRAY",'[',']'),
@ -36,7 +34,6 @@ public class Variable extends JavaElement{
if(local == null) local = generic;
else local = local.group(generic);
content = local.clean(content);
System.out.println("Variable.parse -> "+content);
Matcher matcher = PATTERN.matcher(content);
matcher.matches();
@ -56,8 +53,6 @@ public class Variable extends JavaElement{
onlyDefine(body, local);
}
System.out.println("skip var in "+body);
return offset+local.unzipOne(body, (s,p) -> (p.equals("^GENERIC_TYPE") || p.equals("^GENERIC_ARRAY")) ? s : null).length();
}

View file

@ -17,22 +17,15 @@ public class ConditionalOperation extends OperationContainer{
this.pattern = pattern;
}
//loss global cleaner
@Override
public int parse(String content, CleanerPool global, CleanerPool local) throws Exception{
// content = local.clean(content);
System.out.println("ConditionalOperation.parse -> "+content);
Matcher matcher = this.pattern.matcher(content);
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);
System.out.println("body is around "+content);
int bodysize;
if(content.startsWith("^")){

View file

@ -16,10 +16,6 @@ public class ElseOperation extends OperationContainer{
@Override
public int parse(String content, CleanerPool global, CleanerPool local) throws Exception{
System.out.println("ElseOperation.parse -> "+content);
// content = global.clean(content);
Matcher matcher = PATTERN.matcher(content);
matcher.matches();

View file

@ -10,7 +10,10 @@ public class ReturnOperation extends JavaElement{
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(){}
@ -19,7 +22,14 @@ public class ReturnOperation extends JavaElement{
Matcher matcher = PATTERN.matcher(content);
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();
}
@ -28,7 +38,13 @@ public class ReturnOperation extends JavaElement{
public void show(int tab){
String start = "";
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+";");
}
}