Compare commits

..

2 commits

Author SHA1 Message Date
jeffcheasey88
77f075abdc Start Operation (return & call method valid) 2023-05-29 21:41:17 +02:00
jeffcheasey88
86e326db87 Use CleanerPool in reading & Refractor Type for Global Heritage 2023-05-29 18:21:43 +02:00
11 changed files with 517 additions and 349 deletions

View file

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

View file

@ -8,8 +8,12 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
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 {
public class Function extends JavaElement{
private static OperationFactory FACTORY = new OperationFactory();
private static Pattern PATTERN = Pattern.compile("^(\\s*([^(]*)\\(([^)]*)\\)\\s*([^{]*)\\{)(.*)$");
@ -19,13 +23,11 @@ public class Function {
private List<Variable> parameters;
private String exceptions;
private List<Variable> variables;
private List<Operation> operations;
private List<JavaElement> childs;
public Function(){
this.parameters = new ArrayList<>();
this.variables = new ArrayList<>();
this.operations = new ArrayList<>();
this.childs = new ArrayList<>();
}
public int parse(String content, CleanerPool cleaner) throws Exception{
@ -90,8 +92,40 @@ public class Function {
}while(quote);
}
private void body(String content, CleanerPool cleaner) throws Exception{
System.out.println("BODY "+content);
while(!(content.replaceAll("\\s+", "").isEmpty())){
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){
@ -101,6 +135,7 @@ public class Function {
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+"{");
for(JavaElement child : this.childs) child.show(tab+1);
System.out.println(start+"}");
}
}

View file

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

View file

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

View file

@ -1,29 +0,0 @@
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;
public class Variable {
public class Variable extends JavaElement{
private static Pattern PATTERN = Pattern.compile("^(\\s*)(.*)$");
private int modifier;
private String name;
private String type;
private Variable value;
private Variable value; //Change into operation
public Variable(){}

View file

@ -0,0 +1,35 @@
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

@ -0,0 +1,86 @@
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

@ -0,0 +1,34 @@
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;});
//int i =j=k=l=4;
private CleanerPool cleaner;
@BeforeAll
void init(){
this.cleaner = new CleanerPool();
}
@Test
void case1(){
try {
Variable variable = new Variable();
variable.parse(cleaner.clean(" int i = 4 ; "), cleaner);
assertEquals(0, variable.getModifier());
assertEquals("int", variable.getType());
assertEquals("i", variable.getName());
assertEquals("4", ((Value)variable.getValue()).value());
}catch(Exception e){
fail(e);
}
}
@Test
void case2(){
try {
Variable variable = new Variable();
variable.parse(cleaner.clean("public static int l ; "), cleaner);
assertEquals(JavaParser.getModifier("public")+JavaParser.getModifier("static"), variable.getModifier());
assertEquals("int", variable.getType());
assertEquals("l", variable.getName());
assertNull(variable.getValue());
}catch(Exception e){
fail(e);
}
}
@Test
void case3(){
try {
Variable variable = new Variable();
variable.parse(cleaner.clean(" int lm ; "), cleaner);
assertEquals(0, variable.getModifier());
assertEquals("int", variable.getType());
assertEquals("lm", variable.getName());
assertNull(variable.getValue());
}catch(Exception e){
fail(e);
}
}
@Test
void case4(){
try {
Variable variable = new Variable();
variable.parse(cleaner.clean("Test0< List< Map< Test1, List< Test2 >, Test3>> >t; "), cleaner);
assertEquals(0, variable.getModifier());
assertEquals("Test0<List<Map<Test1,List<Test2>,Test3>>>", variable.getType());
assertEquals("t", variable.getName());
assertNull(variable.getValue());
}catch(Exception e){
fail(e);
}
}
@Test
void case5(){
try {
Variable variable = new Variable();
variable.parse(cleaner.clean(" int i,j,k,l=1; "), cleaner);
assertEquals(0, variable.getModifier());
assertEquals("int", variable.getType());
assertEquals("i", variable.getName());
assertNull(variable.getValue());
}catch(Exception e){
fail(e);
}
}
@Test
void case6(){
try {
Class clazz = new Class();
clazz.parse(cleaner.clean("public class Test{ int i ,j,k,l=1; } "), 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());
// }
// Variable v = vars.get(3);
// private CleanerPool cleaner;
//
// @BeforeAll
// void init(){
// this.cleaner = new CleanerPool();
// }
//
// @Test
// void case1(){
// try {
// Variable variable = new Variable();
// variable.parse(cleaner.clean(" int i = 4 ; "), cleaner);
//
// assertEquals(0, variable.getModifier());
// assertEquals("int", variable.getType());
// assertEquals("i", variable.getName());
// assertEquals("4", ((Value)variable.getValue()).value());
// }catch(Exception e){
// fail(e);
// }
// }
//
// @Test
// void case2(){
// try {
// Variable variable = new Variable();
// variable.parse(cleaner.clean("public static int l ; "), cleaner);
//
// assertEquals(JavaParser.getModifier("public")+JavaParser.getModifier("static"), variable.getModifier());
// assertEquals("int", variable.getType());
// assertEquals("l", variable.getName());
// assertNull(variable.getValue());
// }catch(Exception e){
// fail(e);
// }
// }
//
// @Test
// void case3(){
// try {
// Variable variable = new Variable();
// variable.parse(cleaner.clean(" int lm ; "), cleaner);
//
// assertEquals(0, variable.getModifier());
// assertEquals("int", variable.getType());
// assertEquals("lm", variable.getName());
// assertNull(variable.getValue());
// }catch(Exception e){
// fail(e);
// }
// }
//
// @Test
// void case4(){
// try {
// Variable variable = new Variable();
// variable.parse(cleaner.clean("Test0< List< Map< Test1, List< Test2 >, Test3>> >t; "), cleaner);
//
// assertEquals(0, variable.getModifier());
// assertEquals("Test0<List<Map<Test1,List<Test2>,Test3>>>", variable.getType());
// assertEquals("t", variable.getName());
// assertNull(variable.getValue());
// }catch(Exception e){
// fail(e);
// }
// }
//
// @Test
// void case5(){
// try {
// Variable variable = new Variable();
// variable.parse(cleaner.clean(" int i,j,k,l=1; "), cleaner);
//
// assertEquals(0, variable.getModifier());
// assertEquals("int", variable.getType());
// assertEquals("i", variable.getName());
// assertNull(variable.getValue());
// }catch(Exception e){
// fail(e);
// }
// }
//
// @Test
// void case6(){
// try {
// Class clazz = new Class();
// clazz.parse(cleaner.clean("public class Test{ int i ,j,k,l=1; } "), cleaner);
//
// List<Variable> vars = clazz.getVariables();
// assertEquals(1, vars.size());
//
// Variable v = vars.get(0);
// 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);
}
}
@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("int", v.getType());
// for(int i = 0; i < 4; i++){
// Variable v = vars.get(i);
// assertEquals(0, v.getModifier());
// assertEquals("int", v.getType());
// assertEquals((char)('i'+i), v.getName().charAt(0));
// }
}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){
fail(e);
}
}
@Test
void case10(){
try {
Variable variable = new Variable();
variable.parse(cleaner.clean(" boolean i = j << 3==0 ; "), cleaner);
assertEquals(0, variable.getModifier());
assertEquals("boolean", variable.getType());
assertEquals("i", variable.getName());
assertEquals("j<< 3 == 0", ((Value)variable.getValue()).value());
}catch(Exception e){
fail(e);
}
}
@Test
void case11(){
try {
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());
//// 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());
//// }
//// 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);
// }
// }
//
// @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("int", v.getType());
//// for(int i = 0; i < 4; i++){
//// Variable v = vars.get(i);
//// assertEquals(0, v.getModifier());
//// assertEquals("int", v.getType());
//// assertEquals((char)('i'+i), v.getName().charAt(0));
//// }
// }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){
// fail(e);
// }
// }
//
// @Test
// void case10(){
// try {
// Variable variable = new Variable();
// variable.parse(cleaner.clean(" boolean i = j << 3==0 ; "), cleaner);
//
// assertEquals(0, variable.getModifier());
// assertEquals("boolean", variable.getType());
// assertEquals("i", variable.getName());
// assertEquals("j<< 3 == 0", ((Value)variable.getValue()).value());
// }catch(Exception e){
// fail(e);
// }
// }
//
// @Test
// void case11(){
//
// try {
// 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);
//
// variable = vars.get(1);
// 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("k", variable.getName());
// assertEquals("((i) -> 4)", ((Value)variable.getValue()).value());
}catch(Exception e){
fail(e);
}
}
@Test
void case15(){
try {
Variable variable = new Variable();
variable.parse(cleaner.clean(" List <String> list = new ArrayList <> () ; "), cleaner);
assertEquals(0, variable.getModifier());
assertEquals("List<String>", variable.getType());
assertEquals("list", variable.getName());
assertEquals("new ArrayList<>()", ((Value)variable.getValue()).value());
}catch(Exception e){
fail(e);
}
}
@Test
void case16(){
try {
Variable variable = new Variable();
variable.parse(cleaner.clean(" List <String> a [] = new ArrayList [ 0] ; "), cleaner);
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);
}
}
//// assertEquals("j", variable.getName());
//// assertEquals("((i) -> {return 4;})", ((Value)variable.getValue()).value());
////
//// variable = vars.get(1);
//// 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());
// }catch(Exception e){
// fail(e);
// }
// }
//
// @Test
// void case15(){
// try {
// Variable variable = new Variable();
// variable.parse(cleaner.clean(" List <String> list = new ArrayList <> () ; "), cleaner);
//
// assertEquals(0, variable.getModifier());
// assertEquals("List<String>", variable.getType());
// assertEquals("list", variable.getName());
// assertEquals("new ArrayList<>()", ((Value)variable.getValue()).value());
// }catch(Exception e){
// fail(e);
// }
// }
//
// @Test
// void case16(){
// try {
// Variable variable = new Variable();
// variable.parse(cleaner.clean(" List <String> a [] = new ArrayList [ 0] ; "), cleaner);
//
// 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);
// }
// }
}