From e328dd12eb5445f668a928856b674f2cc24a9d96 Mon Sep 17 00:00:00 2001 From: jeffcheasey88 <66554203+jeffcheasey88@users.noreply.github.com> Date: Mon, 11 Sep 2023 15:40:54 +0200 Subject: [PATCH] AutoTest -> 99.37% --- .../peeratcode/parser/java/JavaParser.java | 83 ++++++------------- 1 file changed, 27 insertions(+), 56 deletions(-) diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java index 3ec56c2..17309d3 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java @@ -105,7 +105,6 @@ public class JavaParser extends Parser { int m = getModifier(token.getValue()); Integer current = bag.get(); bag.set(current == null ? m : current+m); - System.out.println("mod "+token); })) mod = true; return mod; }).end((a,b) -> a); @@ -128,6 +127,8 @@ public class JavaParser extends Parser { StateTree type_generic_unknow = type_begin.then((validator) -> validator.validate((token) -> token.getValue().equals("?"))); type_generic_unknow.then(type_generic_end); + type_generic_split.then(type_generic_unknow); + type_generic_unknow.then(type_generic_split); StateTree type_generic_unknow_extends = type_generic_unknow.then((validator) -> validator.validate((token) -> token.getValue().equals("extends"))) .then(new RedirectStateTree<>(type, (global, local) -> global.set(null))); type_generic_unknow_extends.then(type_generic_end); @@ -137,12 +138,11 @@ public class JavaParser extends Parser { type_generic_unknow_super.then(type_generic_end); type_generic_unknow_super.then(type_generic_split); - StateTree type_generic_named = type_begin.then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.NAME))); - StateTree type_generic_named_extends = type_generic_named.then((validator) -> validator.validate((token) -> token.getValue().equals("extends"))) + StateTree type_generic_named_extends = type_generic.then((validator) -> validator.validate((token) -> token.getValue().equals("extends"))) .then(new RedirectStateTree<>(type, (global, local) -> global.set(null))); type_generic_named_extends.then(type_generic_end); type_generic_named_extends.then(type_generic_split); - StateTree type_generic_named_super = type_generic_named.then((validator) -> validator.validate((token) -> token.getValue().equals("super"))) + StateTree type_generic_named_super = type_generic.then((validator) -> validator.validate((token) -> token.getValue().equals("super"))) .then(new RedirectStateTree<>(type, (global, local) -> global.set(null))); type_generic_named_super.then(type_generic_end); type_generic_named_super.then(type_generic_split); @@ -161,6 +161,9 @@ public class JavaParser extends Parser { clazz_container.then((validator) -> validator.validate((token) -> token.getValue().equals(";"))).end((a,b) -> a); StateTree braces_container = new StateTree<>(); + StateTree function_container = new StateTree<>(); + function_container.then((validator) -> validator.validate((token) -> token.getValue().equals(";"))).end((a,b) -> a); + //VALUE StateTree value = new StateTree<>(); @@ -170,24 +173,18 @@ public class JavaParser extends Parser { StateTree value_name = new StateTree(); value.then(value_name); value_instance.then(new RedirectStateTree<>(value_name, (global, local) -> global.set(local))) - .end((a,b) -> { - System.out.println("new "+b); - return a; - }) + .end((a,b) -> a) .then((validator) -> validator.validate((token) -> token.getValue().equals("{"))) .end((a,b) -> a) .multiple(braces_container) .unique((validator) -> validator.validate((token) -> token.getValue().equals("}"))).end((a,b) -> a); - value_name = value_name.then((validator) -> validator.validate( - (token) -> token.getType().equals(TokenType.NAME), - (bag, token) -> { - Token current = bag.get(); - if(current == null) current = token; - else current = current.concat(token); - bag.set(current); - })); + value_name = value_name.then(new RedirectStateTree<>(type, (global, local) -> global.set(null))); value_name.end((a,b) -> a); + value_name.then((validator) -> validator.validate((token) -> token.getValue().equals(":")) && validator.validate((token) -> token.getValue().equals(":"))) + .then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.NAME))) + .end((a,b) -> a); + StateTree value_call = value_name.then((validator) -> validator.validate((token) -> token.getValue().equals("."))); value_call.end((a,b) -> a); value_call.then(value_name); @@ -218,25 +215,17 @@ public class JavaParser extends Parser { if(count == null) count = 0; global.set("arg"+count, local); global.set("args", (count+1)); - System.out.println("inside of method call"); })); value_arg.then((validator) -> validator.validate((token) -> token.getValue().equals(","))) .then(value_arg); value_arg.then(value_arg_end); StateTree value_left = new StateTree<>(); - value_container.then((v) -> v.validate((t) -> { - System.out.println("value container "+t); - return false; - })); + StateTree value_parenthesis = value_container.then((validator) -> validator.validate((token) -> token.getValue().equals("("))); - value_parenthesis.then((v) -> v.validate((t) -> { - System.out.println("value parenthesis "+t); - return false; - })); - StateTree value_cast = value_parenthesis.then(new RedirectStateTree<>(type, (global, local) -> System.out.println("can u casted ?"))) + StateTree value_cast = value_parenthesis.then(new RedirectStateTree<>(type, (global, local) -> global.set(null))) .then((validator) -> validator.validate((token) -> token.getValue().equals(")"))) - .then(new RedirectStateTree<>(value_container, (global, local) -> System.out.println("casted"))); + .then(new RedirectStateTree<>(value_container, (global, local) -> global.set(null))); value_cast.then(value_left); StateTree value_lambda_arg = value_parenthesis.then((validator) -> validator.validate((token) -> token.getType().equals(TokenType.NAME))); value_lambda_arg.then((validator) -> validator.validate((token) -> token.getValue().equals(","))) @@ -247,18 +236,14 @@ public class JavaParser extends Parser { validator.validate((token) -> token.getValue().equals(">"))); value_lambda.then((validator) -> validator.validate((token) -> token.getValue().equals("{"))) .end((a,b) -> a).end((a,b) -> a) - .multiple(braces_container) + .multiple(function_container) .unique((validator) -> validator.validate((token) -> token.getValue().equals("}"))).end((a,b) -> a); value_lambda.then(new RedirectStateTree<>(value_container, (global, local) -> global.set(null))).end((a,b) -> a); value_lambda_arg.then(value_lambda); - StateTree value_parenthesis_end = value_parenthesis.then(new RedirectStateTree<>(value_container, (global, local) -> System.out.println("in a container"))) + StateTree value_parenthesis_end = value_parenthesis.then(new RedirectStateTree<>(value_container, (global, local) -> global.set(null))) .then((validator) -> validator.validate((token) -> token.getValue().equals(")"))); - value_parenthesis_end.end((a,b) -> { - System.out.println("we got a container"); - return a; - }); + value_parenthesis_end.end((a,b) -> a); value_parenthesis_end.then((v) -> v.validate((t) -> { - System.out.println("so then, left or call ?"); return false; })); value_parenthesis_end.then(value_call); @@ -317,9 +302,10 @@ public class JavaParser extends Parser { .then((validator) -> validator.validate((token) -> token.getValue().equals(":"))) .then(new RedirectStateTree<>(value_container, (global, local) -> global.set(null))) .end((a,b) -> a); - value_left.then((validator) -> validator.validate((token) -> token.getValue().equals("instanceof"))) - .then(new RedirectStateTree<>(type, (global, local) -> global.set(null))) - .end((a,b) -> a); + StateTree value_instanceof = value_left.then((validator) -> validator.validate((token) -> token.getValue().equals("instanceof"))) + .then(new RedirectStateTree<>(type, (global, local) -> global.set(null))); + value_instanceof.end((a,b) -> a); + value_instanceof.then(value_left); value.then((validator) -> { if(validator.validate((token) -> token.getValue().equals("'"))){ @@ -400,9 +386,6 @@ public class JavaParser extends Parser { annotation_value.then(annotation_end); annotation_begin.then(new RedirectStateTree<>(value_container, (global, local) -> global.set(null))).then(annotation_end); - StateTree function_container = new StateTree<>(); - function_container.then((validator) -> validator.validate((token) -> token.getValue().equals(";"))).end((a,b) -> a); - //VARIABLE InitialStateTree variable = new InitialStateTree<>(); variable.multiple(annotation); @@ -442,7 +425,7 @@ public class JavaParser extends Parser { operation_value.then((validator) -> validator.validate((token) -> token.getValue().equals(","))).then(operation_value); StateTree operation_return = operation.then((validator) -> validator.validate((token) -> token.getValue().equals("return"))); - operation_return.then(new RedirectStateTree<>(value_container, (global, local) -> System.out.println("return value"))) + operation_return.then(new RedirectStateTree<>(value_container, (global, local) -> global.set(null))) .then((validator) -> validator.validate((token) -> token.getValue().equals(";"))) .end((a,b) -> a); operation_return.then((validator) -> validator.validate((token) -> token.getValue().equals(";"))) @@ -485,6 +468,7 @@ public class JavaParser extends Parser { // .unique((validator) -> validator.validate((token) -> token.getValue().equals("}"))) // .end((a,b) -> a); // + StateTree operation_catch_named = operation_try_end.then((validator) -> validator.validate((token) -> token.getValue().equals("catch"))) .then((validator) -> validator.validate((token) -> token.getValue().equals("("))) .then(new RedirectStateTree<>(type, (global, local) -> global.set(null))); @@ -643,15 +627,9 @@ public class JavaParser extends Parser { StateTree function_begin = function_name.then((validator) -> validator.validate((token) -> token.getValue().equals("("))); StateTree function_end = function_begin.then((validator) -> validator.validate((token) -> token.getValue().equals(")"))); function_end.then((validator) -> validator.validate((token) -> token.getValue().equals("{"))) - .end((a,b) -> { - System.out.println("build function "+b); - return a; - }) + .end((a,b) -> a) .multiple(function_container) - .unique((validator) -> validator.validate((token) -> token.getValue().equals("}"))).end((a,b) -> { - System.out.println("inside of the function "+b); - return a; - }); + .unique((validator) -> validator.validate((token) -> token.getValue().equals("}"))).end((a,b) -> a); function_end.then((validator) -> validator.validate((token) -> token.getValue().equals(";"))).end((a,b) -> a); function_end.then((validator) -> validator.validate((token) -> token.getValue().equals("default"))) .then(new RedirectStateTree<>(value_container, (global, local) -> global.set(null))) @@ -750,12 +728,6 @@ public class JavaParser extends Parser { mult_clazz_container.multiple(clazz_container); mult_clazz_container.end((a,b) -> a); - StateTree debug = new StateTree<>(); - debug.then((v) -> v.validate((t) -> { - System.out.println("debug "+t); - return false; - })); - //ENUM StateTree enums = new StateTree<>(); StateTree enum_base = enums.then((validator) -> validator.validate((token) -> token.getValue().equals("enum"))) @@ -765,7 +737,6 @@ public class JavaParser extends Parser { enum_start.end((a,b) -> a) .unique(enum_value) .unique(mult_clazz_container) - .unique(debug) .unique((validator) -> validator.validate((token) -> token.getValue().equals("}"))).end((a,b) -> a); StateTree enum_implement = enum_base.then((validator) -> validator.validate((token) -> token.getValue().equals("implements")));