Operation -> Assigment
This commit is contained in:
parent
77f075abdc
commit
56ce2b7235
6 changed files with 56 additions and 13 deletions
|
@ -23,6 +23,8 @@ public class Function extends JavaElement{
|
|||
private List<Variable> parameters;
|
||||
private String exceptions;
|
||||
|
||||
private boolean constructor;
|
||||
|
||||
private List<JavaElement> childs;
|
||||
|
||||
public Function(){
|
||||
|
@ -73,6 +75,7 @@ public class Function extends JavaElement{
|
|||
if(this.returnType == null){
|
||||
this.returnType = value;
|
||||
if(values.hasNext()) value = values.next();
|
||||
else constructor = true;
|
||||
}
|
||||
if(this.name == null){
|
||||
this.name = value;
|
||||
|
@ -95,6 +98,7 @@ public class Function extends JavaElement{
|
|||
|
||||
|
||||
private void body(String content, CleanerPool cleaner) throws Exception{
|
||||
content = cleaner.unzip(content, (s,p) -> s);
|
||||
while(!(content.replaceAll("\\s+", "").isEmpty())){
|
||||
System.out.println("BODY "+content);
|
||||
|
||||
|
@ -134,7 +138,7 @@ public class Function extends JavaElement{
|
|||
String param = "";
|
||||
for(Variable v : this.parameters) param+=","+v.getType()+" "+v.getName()+"";
|
||||
if(!param.isEmpty()) param = param.substring(1);
|
||||
System.out.println(start+Modifier.toString(modifier)+" "+returnType+" "+name+"("+param+") "+exceptions+"{");
|
||||
System.out.println(start+Modifier.toString(modifier)+" "+(constructor ? "" : returnType+" ")+name+"("+param+") "+exceptions+"{");
|
||||
for(JavaElement child : this.childs) child.show(tab+1);
|
||||
System.out.println(start+"}");
|
||||
}
|
||||
|
|
|
@ -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\\Import.java");
|
||||
File file = new File("C:\\Users\\jeffc\\eclipse-workspace\\peer-at-code-backend\\src\\be\\jeffcheasey88\\peeratcode\\parser\\java\\Variable.java");
|
||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||
|
||||
JavaParser parser = new JavaParser(reader);
|
||||
|
|
|
@ -16,7 +16,7 @@ public class Variable extends JavaElement{
|
|||
private int modifier;
|
||||
private String name;
|
||||
private String type;
|
||||
private Variable value; //Change into operation
|
||||
private Variable value; //Change into operation or JavaElement
|
||||
|
||||
public Variable(){}
|
||||
|
||||
|
@ -126,7 +126,7 @@ public class Variable extends JavaElement{
|
|||
public void show(int tab){
|
||||
String start = "";
|
||||
for(int i = 0; i < tab; i++) start+="\t";
|
||||
System.out.println(start+Modifier.toString(modifier)+" "+type+" "+name+(value == null ? ";":" = "+value+";"));
|
||||
System.out.println(start+Modifier.toString(modifier)+(modifier > 0 ? " ":"")+type+" "+name+(value == null ? ";":" = "+value+";"));
|
||||
}
|
||||
|
||||
public static class Value extends Variable{
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package be.jeffcheasey88.peeratcode.parser.java.operations;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import be.jeffcheasey88.peeratcode.parser.java.CleanerPool;
|
||||
import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
|
||||
|
||||
public class AssigmentOperation extends JavaElement{
|
||||
|
||||
private static Pattern PATTERN = Pattern.compile("^(\\s*([^\\s]+)\\s*=\\s*([^;]+);).*$");
|
||||
|
||||
private String variable;
|
||||
private String value;
|
||||
|
||||
public AssigmentOperation(){}
|
||||
|
||||
@Override
|
||||
public int parse(String content, CleanerPool cleaner) throws Exception{
|
||||
Matcher matcher = PATTERN.matcher(content);
|
||||
matcher.matches();
|
||||
|
||||
this.variable = matcher.group(2);
|
||||
this.value = matcher.group(3);
|
||||
|
||||
return matcher.group(1).length();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show(int tab){
|
||||
String start = "";
|
||||
for(int i = 0; i < tab; i++) start+="\t";
|
||||
System.out.println(start+variable+" = "+value+";");
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -10,6 +10,7 @@ import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
|
|||
import be.jeffcheasey88.peeratcode.parser.java.Variable;
|
||||
import be.jeffcheasey88.peeratcode.parser.java.CleanerPool.Cleaner;
|
||||
|
||||
//Singleton
|
||||
public class OperationFactory{
|
||||
|
||||
private Map<Pattern, Class<? extends JavaElement>> patterns;
|
||||
|
@ -17,23 +18,23 @@ public class OperationFactory{
|
|||
public OperationFactory(){
|
||||
this.patterns = new LinkedHashMap<>();
|
||||
|
||||
this.patterns.put(Pattern.compile("^\\s*return\\s+[^;]*;.*$"), ReturnOperation.class);
|
||||
this.patterns.put(Pattern.compile("^\\s*([^;=]*;).*$"), MethodCallOperation.class);
|
||||
this.patterns.put(Pattern.compile("^\\s*return\\s*[^;]*;.*$"), ReturnOperation.class);
|
||||
this.patterns.put(Pattern.compile("^\\s*([^;=]+;).*$"), MethodCallOperation.class);
|
||||
|
||||
//if not types ??
|
||||
this.patterns.put(Pattern.compile("^\\s*[^\\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);
|
||||
}
|
||||
|
||||
/*
|
||||
* variable
|
||||
* assignation
|
||||
* exec method
|
||||
* variable OK
|
||||
* assignation OK
|
||||
* exec method OK
|
||||
* for
|
||||
* do while
|
||||
* while
|
||||
* if
|
||||
* switch case
|
||||
* return
|
||||
* return OK (without just return)
|
||||
* continue
|
||||
* break
|
||||
* try catch finally
|
||||
|
@ -46,6 +47,7 @@ public class OperationFactory{
|
|||
*
|
||||
* assert ??
|
||||
* Goto ??
|
||||
* Const ??
|
||||
*/
|
||||
|
||||
public JavaElement buildOperation(String content) throws Exception{
|
||||
|
|
|
@ -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*([^;]*);)\\s*$");
|
||||
|
||||
private String value;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue