Compare commits

..

No commits in common. "77f075abdc99b7930837c0a018d9e3e4ad66f290" and "bd2cf6c26aaf8c36f8edeaf8e786bd7f77c94525" have entirely different histories.

11 changed files with 349 additions and 517 deletions

View file

@ -8,18 +8,21 @@ import java.util.regex.Pattern;
import be.jeffcheasey88.peeratcode.parser.java.Variable.MultipleDeclaratedVariable; import be.jeffcheasey88.peeratcode.parser.java.Variable.MultipleDeclaratedVariable;
public class Class extends JavaElement{ public class Class{
private static Pattern PATTERN = Pattern.compile("^(\\s*([^\\{]*)\\{(.*)\\})\\s*$"); private static Pattern PATTERN = Pattern.compile("^(\\s*([^\\{]*)\\{(.*)\\})\\s*$");
private int modifier; private int modifier;
private String name; private String name;
private List<JavaElement> childs; private List<Variable> vars;
private List<Function> functions;
public Class(){} public Class(){}
public int parse(String content, CleanerPool cleaner) throws Exception{ public int parse(String content, CleanerPool cleaner) throws Exception{
content = cleaner.clean(content);
Matcher matcher = PATTERN.matcher(content); Matcher matcher = PATTERN.matcher(content);
matcher.matches(); matcher.matches();
@ -29,7 +32,8 @@ public class Class extends JavaElement{
} }
this.name = split[split.length-1]; this.name = split[split.length-1];
this.childs = new ArrayList<>(); this.vars = new ArrayList<>();
this.functions = new ArrayList<>();
content = matcher.group(3); content = matcher.group(3);
Pattern empty = Pattern.compile("^\\s*$"); Pattern empty = Pattern.compile("^\\s*$");
@ -57,9 +61,9 @@ public class Class extends JavaElement{
multiple.addVariable(variable.getName(), variable.getValue()); multiple.addVariable(variable.getName(), variable.getValue());
} }
this.childs.add(multiple); this.vars.add(multiple);
}else{ }else{
this.childs.add(variable); this.vars.add(variable);
} }
content = content.substring(1); content = content.substring(1);
@ -67,14 +71,13 @@ public class Class extends JavaElement{
// System.out.println("Function "+content); // System.out.println("Function "+content);
Function func = new Function(); Function func = new Function();
int index = func.parse(content, cleaner); int index = func.parse(content, cleaner);
this.childs.add(func); this.functions.add(func);
content = content.substring(index); content = content.substring(index);
// System.out.println("End "+content); // System.out.println("End "+content);
} }
} }
// return cleaner.unzip(matcher.group(1), ((s,p) -> s)).length(); return cleaner.unzip(matcher.group(1), ((s,p) -> s)).length();
return matcher.group(1).length();
} }
private int indexOf(String value, String target){ private int indexOf(String value, String target){
@ -89,18 +92,15 @@ public class Class extends JavaElement{
return this.name; return this.name;
} }
// public List<Variable> getVariables(){ public List<Variable> getVariables(){
// return this.vars; return this.vars;
// }
public void show(int tab){
String start = "";
for(int i = 0; i < tab; i++) start+="\t";
System.out.println(start+Modifier.toString(modifier)+" "+this.name+"{");
for(JavaElement jElement : this.childs){
jElement.show(tab+1);
System.out.println();
} }
System.out.println(start+"}");
public void show(){
System.out.println(Modifier.toString(modifier)+" "+this.name+"{");
for(Variable v : this.vars) v.show(1);
System.out.println();
for(Function f : this.functions) f.show(1);
System.out.println("}");
} }
} }

View file

@ -8,12 +8,8 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import be.jeffcheasey88.peeratcode.parser.java.CleanerPool.Cleaner; import be.jeffcheasey88.peeratcode.parser.java.CleanerPool.Cleaner;
import be.jeffcheasey88.peeratcode.parser.java.Variable.MultipleDeclaratedVariable;
import be.jeffcheasey88.peeratcode.parser.java.operations.OperationFactory;
public class Function extends JavaElement{ public class Function {
private static OperationFactory FACTORY = new OperationFactory();
private static Pattern PATTERN = Pattern.compile("^(\\s*([^(]*)\\(([^)]*)\\)\\s*([^{]*)\\{)(.*)$"); private static Pattern PATTERN = Pattern.compile("^(\\s*([^(]*)\\(([^)]*)\\)\\s*([^{]*)\\{)(.*)$");
@ -23,11 +19,13 @@ public class Function extends JavaElement{
private List<Variable> parameters; private List<Variable> parameters;
private String exceptions; private String exceptions;
private List<JavaElement> childs; private List<Variable> variables;
private List<Operation> operations;
public Function(){ public Function(){
this.parameters = new ArrayList<>(); this.parameters = new ArrayList<>();
this.childs = new ArrayList<>(); this.variables = new ArrayList<>();
this.operations = new ArrayList<>();
} }
public int parse(String content, CleanerPool cleaner) throws Exception{ public int parse(String content, CleanerPool cleaner) throws Exception{
@ -92,40 +90,8 @@ public class Function extends JavaElement{
}while(quote); }while(quote);
} }
private void body(String content, CleanerPool cleaner) throws Exception{ private void body(String content, CleanerPool cleaner) throws Exception{
while(!(content.replaceAll("\\s+", "").isEmpty())){
System.out.println("BODY "+content); System.out.println("BODY "+content);
JavaElement operation = FACTORY.buildOperation(content);
System.out.println("got "+operation.getClass().getSimpleName());
int index = operation.parse(content, cleaner);
content = content.substring(index);
if(operation instanceof Variable){
if(content.startsWith(",")){
Variable variable = (Variable)operation;
MultipleDeclaratedVariable multiple = new MultipleDeclaratedVariable(variable.getModifier(), variable.getType());
multiple.addVariable(variable.getName(), variable.getValue());
operation = multiple;
boolean quote;
do{
variable = new Variable(variable.getModifier(), variable.getType());
index = variable.parse(content, cleaner);
multiple.addVariable(variable.getName(), variable.getValue());
content = content.substring(index);
quote = content.startsWith(",");
content = content.substring(1);
}while(quote);
}else content = content.substring(1);
}
this.childs.add(operation);
}
} }
public void show(int tab){ public void show(int tab){
@ -135,7 +101,6 @@ public class Function extends JavaElement{
for(Variable v : this.parameters) param+=","+v.getType()+" "+v.getName()+""; for(Variable v : this.parameters) param+=","+v.getType()+" "+v.getName()+"";
if(!param.isEmpty()) param = param.substring(1); 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)+" "+returnType+" "+name+"("+param+") "+exceptions+"{");
for(JavaElement child : this.childs) child.show(tab+1);
System.out.println(start+"}"); System.out.println(start+"}");
} }
} }

View file

@ -22,7 +22,7 @@ public class Import {
return matcher.group(1).length(); return matcher.group(1).length();
} }
// public int doYouSeeMe(){ return false; } // public int DoYouSeeMe(){ return false; }
public String getName(){ public String getName(){
return this.name; return this.name;

View file

@ -1,9 +0,0 @@
package be.jeffcheasey88.peeratcode.parser.java;
public abstract class JavaElement {
public abstract int parse(String content, CleanerPool cleaner) throws Exception;
//Only for development
public abstract void show(int tab);
}

View file

@ -7,6 +7,7 @@ import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
import be.jeffcheasey88.peeratcode.parser.java.CleanerPool.Cleaner; import be.jeffcheasey88.peeratcode.parser.java.CleanerPool.Cleaner;
@ -57,9 +58,9 @@ public class JavaParser{
Class clazz = parser.getClazz(); Class clazz = parser.getClazz();
System.out.println(clazz.getName()); System.out.println(clazz.getName());
// for(Variable variable : clazz.getVariables()){ for(Variable variable : clazz.getVariables()){
// variable.show(1); variable.show(1);
// } }
}catch(Exception e) {} }catch(Exception e) {}
}else{ }else{
for(File file : dir.listFiles()) show(file); for(File file : dir.listFiles()) show(file);
@ -86,12 +87,13 @@ public class JavaParser{
String line; String line;
while((line = reader.readLine()) != null){ while((line = reader.readLine()) != null){
line = cleaner.clean(line);
index = line.indexOf("//"); index = line.indexOf("//");
if(index >= 0) line = line.substring(0, index); if(index >= 0) line = line.substring(0, index);
content+=line; content+=line;
} }
// content = CleanerPool.getterToDelete.clean(content);
this.pack = new Package(); this.pack = new Package();
index = this.pack.parse(content); index = this.pack.parse(content);
content = content.substring(index); content = content.substring(index);
@ -126,7 +128,7 @@ public class JavaParser{
System.out.println(); System.out.println();
for(Import i : this.imports) System.out.println("import "+i.getName()+";"); for(Import i : this.imports) System.out.println("import "+i.getName()+";");
System.out.println(); System.out.println();
this.clazz.show(0); this.clazz.show();
} }
public static int getModifier(String modifier){ public static int getModifier(String modifier){

View file

@ -0,0 +1,29 @@
package be.jeffcheasey88.peeratcode.parser.java;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Operation {
private static Pattern VARIABLE_PATTERN = Pattern.compile("^(\\s*([^;]*)).*$");
private String tmp;
public Operation(){}
public int parse(String content) throws Exception{
Matcher matcher = VARIABLE_PATTERN.matcher(content);
if(matcher.matches()){
this.tmp = matcher.group(2);
return matcher.group(1).length()+1;
}
return 0;
}
public void show(int tab){
String start = "";
for(int i = 0; i < tab; i++) start+="\t";
System.out.println(start+tmp+";");
}
}

View file

@ -9,14 +9,14 @@ import java.util.regex.Pattern;
import be.jeffcheasey88.peeratcode.parser.java.CleanerPool.Cleaner; import be.jeffcheasey88.peeratcode.parser.java.CleanerPool.Cleaner;
public class Variable extends JavaElement{ public class Variable {
private static Pattern PATTERN = Pattern.compile("^(\\s*)(.*)$"); private static Pattern PATTERN = Pattern.compile("^(\\s*)(.*)$");
private int modifier; private int modifier;
private String name; private String name;
private String type; private String type;
private Variable value; //Change into operation private Variable value;
public Variable(){} public Variable(){}

View file

@ -1,35 +0,0 @@
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 MethodCallOperation extends JavaElement{
private static Pattern PATTERN = Pattern.compile("^(\\s*([^\\(]*\\([^\\)]*\\));).*$");
private String value;
public MethodCallOperation(){}
@Override
public int parse(String content, CleanerPool cleaner) throws Exception{
Matcher matcher = PATTERN.matcher(content);
matcher.matches();
this.value = matcher.group(2);
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+value+";");
}
}

View file

@ -1,86 +0,0 @@
package be.jeffcheasey88.peeratcode.parser.java.operations;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
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.Variable;
import be.jeffcheasey88.peeratcode.parser.java.CleanerPool.Cleaner;
public class OperationFactory{
private Map<Pattern, Class<? extends JavaElement>> patterns;
public OperationFactory(){
this.patterns = new LinkedHashMap<>();
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);
}
/*
* variable
* assignation
* exec method
* for
* do while
* while
* if
* switch case
* return
* continue
* break
* try catch finally
* throw
* else
* synchronized
* instance of
*
* native operation style i++
*
* assert ??
* Goto ??
*/
public JavaElement buildOperation(String content) throws Exception{
CleanerPool generic = new CleanerPool(
new Cleaner("GENERIC_TYPE_",'<','>'),
new Cleaner("GENERIC_ARRAY",'[',']'),
new Cleaner("GENERIC_FUNCTION", '{','}'),
new Cleaner("GENERIC_PARENTHESIS",'(',')'));
content = generic.clean(content);
generiqueTypes(content, generic);
for(Entry<Pattern, Class<? extends JavaElement>> entries : this.patterns.entrySet()){
if(entries.getKey().matcher(content).matches()) return entries.getValue().newInstance();
}
return null;
}
private static Pattern UNZIP_STICK = Pattern.compile("\\s+(?<e>[<|(|\\[|\"|'])");
private static Pattern UNZIP_MAJ = Pattern.compile(">(?<e>[^>\\d,;(])");
private static Pattern UNZIP_ARRAY = Pattern.compile("](?<e>[^\\[\\d,;])");
private static Pattern UNZIP_EQUALS_LEFT = Pattern.compile("(?<e>[^=\\s])=");
private static Pattern UNZIP_EQUALS_RIGHT = Pattern.compile("=(?<e>[^=\\s])");
private String generiqueTypes(String content, CleanerPool cleaner){
String unzip = cleaner.unzip(content, (value, pattern) -> {
if(pattern.equals("^GENERIC_FUNCTION")) return null;
if(pattern.equals("^GENERIC_PARENTHESIS")) return value.replace("\\s+", " ");
return value.replaceAll("\\s+", "");
});
unzip = UNZIP_STICK.matcher(unzip).replaceAll("${e}");
unzip = UNZIP_MAJ.matcher(unzip).replaceAll("> ${e}");
unzip = UNZIP_ARRAY.matcher(unzip).replaceAll("] ${e}");
unzip = UNZIP_EQUALS_LEFT.matcher(unzip).replaceAll("${e} =");
unzip = UNZIP_EQUALS_RIGHT.matcher(unzip).replaceAll("= ${e}");
return unzip;
}
}

View file

@ -1,34 +0,0 @@
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 ReturnOperation extends JavaElement{
private static Pattern PATTERN = Pattern.compile("^(\\s*return\\s+([^;]*);)\\s*$");
private String value;
public ReturnOperation(){}
@Override
public int parse(String content, CleanerPool cleaner) throws Exception{
Matcher matcher = PATTERN.matcher(content);
matcher.matches();
this.value = matcher.group(2);
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+"return "+value+";");
}
}

View file

@ -26,295 +26,295 @@ class VariableTest{
//Test<Test,K,L> j = new Test().schedule(p -> { return true;}); //Test<Test,K,L> j = new Test().schedule(p -> { return true;});
//int i =j=k=l=4; //int i =j=k=l=4;
// private CleanerPool cleaner; private CleanerPool cleaner;
//
// @BeforeAll @BeforeAll
// void init(){ void init(){
// this.cleaner = new CleanerPool(); this.cleaner = new CleanerPool();
// } }
//
// @Test @Test
// void case1(){ void case1(){
// try { try {
// Variable variable = new Variable(); Variable variable = new Variable();
// variable.parse(cleaner.clean(" int i = 4 ; "), cleaner); variable.parse(cleaner.clean(" int i = 4 ; "), cleaner);
//
// assertEquals(0, variable.getModifier()); assertEquals(0, variable.getModifier());
// assertEquals("int", variable.getType()); assertEquals("int", variable.getType());
// assertEquals("i", variable.getName()); assertEquals("i", variable.getName());
// assertEquals("4", ((Value)variable.getValue()).value()); assertEquals("4", ((Value)variable.getValue()).value());
// }catch(Exception e){ }catch(Exception e){
// fail(e); fail(e);
// } }
// } }
//
// @Test @Test
// void case2(){ void case2(){
// try { try {
// Variable variable = new Variable(); Variable variable = new Variable();
// variable.parse(cleaner.clean("public static int l ; "), cleaner); variable.parse(cleaner.clean("public static int l ; "), cleaner);
//
// assertEquals(JavaParser.getModifier("public")+JavaParser.getModifier("static"), variable.getModifier()); assertEquals(JavaParser.getModifier("public")+JavaParser.getModifier("static"), variable.getModifier());
// assertEquals("int", variable.getType()); assertEquals("int", variable.getType());
// assertEquals("l", variable.getName()); assertEquals("l", variable.getName());
// assertNull(variable.getValue()); assertNull(variable.getValue());
// }catch(Exception e){ }catch(Exception e){
// fail(e); fail(e);
// } }
// } }
//
// @Test @Test
// void case3(){ void case3(){
// try { try {
// Variable variable = new Variable(); Variable variable = new Variable();
// variable.parse(cleaner.clean(" int lm ; "), cleaner); variable.parse(cleaner.clean(" int lm ; "), cleaner);
//
// assertEquals(0, variable.getModifier()); assertEquals(0, variable.getModifier());
// assertEquals("int", variable.getType()); assertEquals("int", variable.getType());
// assertEquals("lm", variable.getName()); assertEquals("lm", variable.getName());
// assertNull(variable.getValue()); assertNull(variable.getValue());
// }catch(Exception e){ }catch(Exception e){
// fail(e); fail(e);
// } }
// } }
//
// @Test @Test
// void case4(){ void case4(){
// try { try {
// Variable variable = new Variable(); Variable variable = new Variable();
// variable.parse(cleaner.clean("Test0< List< Map< Test1, List< Test2 >, Test3>> >t; "), cleaner); variable.parse(cleaner.clean("Test0< List< Map< Test1, List< Test2 >, Test3>> >t; "), cleaner);
//
// assertEquals(0, variable.getModifier()); assertEquals(0, variable.getModifier());
// assertEquals("Test0<List<Map<Test1,List<Test2>,Test3>>>", variable.getType()); assertEquals("Test0<List<Map<Test1,List<Test2>,Test3>>>", variable.getType());
// assertEquals("t", variable.getName()); assertEquals("t", variable.getName());
// assertNull(variable.getValue()); assertNull(variable.getValue());
// }catch(Exception e){ }catch(Exception e){
// fail(e); fail(e);
// } }
// } }
//
// @Test @Test
// void case5(){ void case5(){
// try { try {
// Variable variable = new Variable(); Variable variable = new Variable();
// variable.parse(cleaner.clean(" int i,j,k,l=1; "), cleaner); variable.parse(cleaner.clean(" int i,j,k,l=1; "), cleaner);
//
// assertEquals(0, variable.getModifier()); assertEquals(0, variable.getModifier());
// assertEquals("int", variable.getType()); assertEquals("int", variable.getType());
// assertEquals("i", variable.getName()); assertEquals("i", variable.getName());
// assertNull(variable.getValue()); assertNull(variable.getValue());
// }catch(Exception e){ }catch(Exception e){
// fail(e); fail(e);
// } }
// } }
//
// @Test @Test
// void case6(){ void case6(){
// try { try {
// Class clazz = new Class(); Class clazz = new Class();
// clazz.parse(cleaner.clean("public class Test{ int i ,j,k,l=1; } "), cleaner); clazz.parse(cleaner.clean("public class Test{ int i ,j,k,l=1; } "), cleaner);
//
// List<Variable> vars = clazz.getVariables(); List<Variable> vars = clazz.getVariables();
// assertEquals(1, vars.size()); assertEquals(1, vars.size());
//
// Variable v = vars.get(0); Variable v = vars.get(0);
assertEquals(0, v.getModifier());
assertEquals("int", v.getType());
// for(int i = 0; i < 3; i++){
// Variable v = vars.get(i);
// assertEquals(0, v.getModifier()); // assertEquals(0, v.getModifier());
// assertEquals("int", v.getType()); // assertEquals("int", v.getType());
//// for(int i = 0; i < 3; i++){ // assertEquals((char)('i'+i), v.getName().charAt(0));
//// Variable v = vars.get(i); // assertNull(v.getValue());
//// assertEquals(0, v.getModifier());
//// assertEquals("int", v.getType());
//// assertEquals((char)('i'+i), v.getName().charAt(0));
//// assertNull(v.getValue());
//// }
//// Variable v = vars.get(3);
//// assertEquals(0, v.getModifier());
//// assertEquals("int", v.getType());
//// assertEquals('l', v.getName().charAt(0));
//// assertEquals("1", ((Value)v.getValue()).value());
// }catch(Exception e){
// fail(e);
// } // }
// } // Variable v = vars.get(3);
//
// @Test
// void case7(){
// try {
// Class clazz = new Class();
// clazz.parse(cleaner.clean("public class Test{ int i ,j,k; int l=i=k=l=4; } "), new CleanerPool());
//
// List<Variable> vars = clazz.getVariables();
// assertEquals(2, vars.size());
// Variable v = vars.get(0);
// assertEquals(0, v.getModifier()); // assertEquals(0, v.getModifier());
// assertEquals("int", v.getType()); // assertEquals("int", v.getType());
//// for(int i = 0; i < 4; i++){ // assertEquals('l', v.getName().charAt(0));
//// Variable v = vars.get(i); // assertEquals("1", ((Value)v.getValue()).value());
//// assertEquals(0, v.getModifier()); }catch(Exception e){
//// assertEquals("int", v.getType()); fail(e);
//// assertEquals((char)('i'+i), v.getName().charAt(0)); }
//// } }
// }catch(Exception e){
// fail(e); @Test
// } void case7(){
// } try {
// Class clazz = new Class();
// @Test clazz.parse(cleaner.clean("public class Test{ int i ,j,k; int l=i=k=l=4; } "), new CleanerPool());
// void case8(){
// try { List<Variable> vars = clazz.getVariables();
// Variable variable = new Variable(); assertEquals(2, vars.size());
// variable.parse(cleaner.clean("int[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]t; "), cleaner); Variable v = vars.get(0);
// assertEquals(0, v.getModifier());
// assertEquals(0, variable.getModifier()); assertEquals("int", v.getType());
// assertEquals("int[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", variable.getType()); // for(int i = 0; i < 4; i++){
// assertEquals("t", variable.getName()); // Variable v = vars.get(i);
// assertNull(variable.getValue());
// }catch(Exception e){
// fail(e);
// }
// }
//
// @Test
// void case9(){
// try {
// Class clazz = new Class();
// clazz.parse(cleaner.clean("public class Test{ int i ,j,k,l; } "), cleaner);
//
// List<Variable> vars = clazz.getVariables();
// assertEquals(1, vars.size());
// Variable v = vars.get(0);
// assertEquals(0, v.getModifier()); // assertEquals(0, v.getModifier());
// assertEquals("int", v.getType()); // assertEquals("int", v.getType());
//// for(int i = 0; i < 3; i++){ // assertEquals((char)('i'+i), v.getName().charAt(0));
//// Variable v = vars.get(i);
//// assertEquals(0, v.getModifier());
//// assertEquals("int", v.getType());
//// assertEquals((char)('i'+i), v.getName().charAt(0));
//// assertNull(v.getValue());
//// }
// }catch(Exception e){
// fail(e);
// } // }
}catch(Exception e){
fail(e);
}
}
@Test
void case8(){
try {
Variable variable = new Variable();
variable.parse(cleaner.clean("int[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]t; "), cleaner);
assertEquals(0, variable.getModifier());
assertEquals("int[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]", variable.getType());
assertEquals("t", variable.getName());
assertNull(variable.getValue());
}catch(Exception e){
fail(e);
}
}
@Test
void case9(){
try {
Class clazz = new Class();
clazz.parse(cleaner.clean("public class Test{ int i ,j,k,l; } "), cleaner);
List<Variable> vars = clazz.getVariables();
assertEquals(1, vars.size());
Variable v = vars.get(0);
assertEquals(0, v.getModifier());
assertEquals("int", v.getType());
// for(int i = 0; i < 3; i++){
// Variable v = vars.get(i);
// assertEquals(0, v.getModifier());
// assertEquals("int", v.getType());
// assertEquals((char)('i'+i), v.getName().charAt(0));
// assertNull(v.getValue());
// } // }
// }catch(Exception e){
// @Test fail(e);
// void case10(){ }
// try { }
// Variable variable = new Variable();
// variable.parse(cleaner.clean(" boolean i = j << 3==0 ; "), cleaner); @Test
// void case10(){
// assertEquals(0, variable.getModifier()); try {
// assertEquals("boolean", variable.getType()); Variable variable = new Variable();
// assertEquals("i", variable.getName()); variable.parse(cleaner.clean(" boolean i = j << 3==0 ; "), cleaner);
// assertEquals("j<< 3 == 0", ((Value)variable.getValue()).value());
// }catch(Exception e){ assertEquals(0, variable.getModifier());
// fail(e); assertEquals("boolean", variable.getType());
// } assertEquals("i", variable.getName());
// } assertEquals("j<< 3 == 0", ((Value)variable.getValue()).value());
// }catch(Exception e){
// @Test fail(e);
// void case11(){ }
// }
// try {
// Variable variable = new Variable(); @Test
// variable.parse(cleaner.clean("java.util.function.Function<Integer, Integer> j = ((i) -> {return 4;});"), cleaner); void case11(){
//
// assertEquals(0, variable.getModifier()); try {
// assertEquals("java.util.function.Function<Integer,Integer>", variable.getType()); Variable variable = new Variable();
variable.parse(cleaner.clean("java.util.function.Function<Integer, Integer> j = ((i) -> {return 4;});"), cleaner);
assertEquals(0, variable.getModifier());
assertEquals("java.util.function.Function<Integer,Integer>", variable.getType());
assertEquals("j", variable.getName());
assertEquals("((i) -> {return 4;})", ((Value)variable.getValue()).value());
}catch(Exception e){
fail(e);
}
}
@Test
void case12(){
try {
Variable variable = new Variable();
variable.parse(cleaner.clean(" public static final Locale FRENCH = createConstant(\"fr\", \"\");"), cleaner);
assertEquals(JavaParser.getModifier("public")+JavaParser.getModifier("static")+JavaParser.getModifier("final"), variable.getModifier());
assertEquals("Locale", variable.getType());
assertEquals("FRENCH", variable.getName());
assertEquals("createConstant(\"fr\",\"\")", ((Value)variable.getValue()).value());
}catch(Exception e){
fail(e);
}
}
@Test
void case13(){
try {
Variable variable = new Variable();
variable.parse(cleaner.clean("private static final ObjectStreamField[] serialPersistentFields = new ObjectStreamField[] { new ObjectStreamField(\"language\", String.class), new ObjectStreamField(\"country\", String.class), new ObjectStreamField(\"variant\", String.class), new ObjectStreamField(\"hashcode\", int.class), new ObjectStreamField(\"script\", String.class), new ObjectStreamField(\"extensions\", String.class) };"), cleaner);
assertEquals(JavaParser.getModifier("private")+JavaParser.getModifier("static")+JavaParser.getModifier("final"), variable.getModifier());
assertEquals("ObjectStreamField[]", variable.getType());
assertEquals("serialPersistentFields", variable.getName());
assertEquals("new ObjectStreamField[] { new ObjectStreamField(\"language\", String.class), new ObjectStreamField(\"country\", String.class), new ObjectStreamField(\"variant\", String.class), new ObjectStreamField(\"hashcode\", int.class), new ObjectStreamField(\"script\", String.class), new ObjectStreamField(\"extensions\", String.class) }", ((Value)variable.getValue()).value());
}catch(Exception e){
fail(e);
}
}
@Test
void case14(){
try {
Class clazz = new Class();
clazz.parse(cleaner.clean("public class Test{ private java.util.function.Function<Integer, Integer> j = ((i) -> {return 4;}), k = ((i) -> 4); } "), cleaner);
List<Variable> vars = clazz.getVariables();
assertEquals(1, vars.size());
Variable variable;
variable = vars.get(0);
assertTrue(variable instanceof MultipleDeclaratedVariable);
assertEquals(JavaParser.getModifier("private"), variable.getModifier());
assertEquals("java.util.function.Function<Integer,Integer>", variable.getType());
// assertEquals("j", variable.getName()); // assertEquals("j", variable.getName());
// assertEquals("((i) -> {return 4;})", ((Value)variable.getValue()).value()); // assertEquals("((i) -> {return 4;})", ((Value)variable.getValue()).value());
// }catch(Exception e){
// fail(e);
// }
// }
// //
// @Test // variable = vars.get(1);
// void case12(){
//
// try {
// Variable variable = new Variable();
// variable.parse(cleaner.clean(" public static final Locale FRENCH = createConstant(\"fr\", \"\");"), cleaner);
//
// assertEquals(JavaParser.getModifier("public")+JavaParser.getModifier("static")+JavaParser.getModifier("final"), variable.getModifier());
// assertEquals("Locale", variable.getType());
// assertEquals("FRENCH", variable.getName());
// assertEquals("createConstant(\"fr\",\"\")", ((Value)variable.getValue()).value());
// }catch(Exception e){
// fail(e);
// }
// }
//
// @Test
// void case13(){
//
// try {
// Variable variable = new Variable();
// variable.parse(cleaner.clean("private static final ObjectStreamField[] serialPersistentFields = new ObjectStreamField[] { new ObjectStreamField(\"language\", String.class), new ObjectStreamField(\"country\", String.class), new ObjectStreamField(\"variant\", String.class), new ObjectStreamField(\"hashcode\", int.class), new ObjectStreamField(\"script\", String.class), new ObjectStreamField(\"extensions\", String.class) };"), cleaner);
//
// assertEquals(JavaParser.getModifier("private")+JavaParser.getModifier("static")+JavaParser.getModifier("final"), variable.getModifier());
// assertEquals("ObjectStreamField[]", variable.getType());
// assertEquals("serialPersistentFields", variable.getName());
// assertEquals("new ObjectStreamField[] { new ObjectStreamField(\"language\", String.class), new ObjectStreamField(\"country\", String.class), new ObjectStreamField(\"variant\", String.class), new ObjectStreamField(\"hashcode\", int.class), new ObjectStreamField(\"script\", String.class), new ObjectStreamField(\"extensions\", String.class) }", ((Value)variable.getValue()).value());
// }catch(Exception e){
// fail(e);
// }
// }
//
// @Test
// void case14(){
//
//
// try {
// Class clazz = new Class();
// clazz.parse(cleaner.clean("public class Test{ private java.util.function.Function<Integer, Integer> j = ((i) -> {return 4;}), k = ((i) -> 4); } "), cleaner);
//
// List<Variable> vars = clazz.getVariables();
// assertEquals(1, vars.size());
// Variable variable;
// variable = vars.get(0);
// assertTrue(variable instanceof MultipleDeclaratedVariable);
// assertEquals(JavaParser.getModifier("private"), variable.getModifier()); // assertEquals(JavaParser.getModifier("private"), variable.getModifier());
// assertEquals("java.util.function.Function<Integer,Integer>", variable.getType()); // assertEquals("java.util.function.Function<Integer,Integer>", variable.getType());
//// assertEquals("j", variable.getName()); // assertEquals("k", variable.getName());
//// assertEquals("((i) -> {return 4;})", ((Value)variable.getValue()).value()); // assertEquals("((i) -> 4)", ((Value)variable.getValue()).value());
//// }catch(Exception e){
//// variable = vars.get(1); fail(e);
//// assertEquals(JavaParser.getModifier("private"), variable.getModifier()); }
//// assertEquals("java.util.function.Function<Integer,Integer>", variable.getType()); }
//// assertEquals("k", variable.getName());
//// assertEquals("((i) -> 4)", ((Value)variable.getValue()).value()); @Test
// }catch(Exception e){ void case15(){
// fail(e); try {
// } Variable variable = new Variable();
// } variable.parse(cleaner.clean(" List <String> list = new ArrayList <> () ; "), cleaner);
//
// @Test assertEquals(0, variable.getModifier());
// void case15(){ assertEquals("List<String>", variable.getType());
// try { assertEquals("list", variable.getName());
// Variable variable = new Variable(); assertEquals("new ArrayList<>()", ((Value)variable.getValue()).value());
// variable.parse(cleaner.clean(" List <String> list = new ArrayList <> () ; "), cleaner); }catch(Exception e){
// fail(e);
// assertEquals(0, variable.getModifier()); }
// assertEquals("List<String>", variable.getType()); }
// assertEquals("list", variable.getName());
// assertEquals("new ArrayList<>()", ((Value)variable.getValue()).value()); @Test
// }catch(Exception e){ void case16(){
// fail(e); try {
// } Variable variable = new Variable();
// } variable.parse(cleaner.clean(" List <String> a [] = new ArrayList [ 0] ; "), cleaner);
//
// @Test assertEquals(0, variable.getModifier());
// void case16(){ assertEquals("List<String>", variable.getType());
// try { assertEquals("a[]", variable.getName());
// Variable variable = new Variable(); assertEquals("new ArrayList[0]", ((Value)variable.getValue()).value());
// variable.parse(cleaner.clean(" List <String> a [] = new ArrayList [ 0] ; "), cleaner); }catch(Exception e){
// fail(e);
// assertEquals(0, variable.getModifier()); }
// assertEquals("List<String>", variable.getType()); }
// assertEquals("a[]", variable.getName());
// assertEquals("new ArrayList[0]", ((Value)variable.getValue()).value());
// }catch(Exception e){
// fail(e);
// }
// }
} }