From 6975d6dad0b682bcc412bab62863f5299702f3c7 Mon Sep 17 00:00:00 2001 From: jeffcheasey88 Date: Mon, 12 Jun 2023 21:07:00 +0200 Subject: [PATCH] Annotation -> Multiple Annotation on function --- .../peeratcode/parser/java/Annotation.java | 2 ++ .../peeratcode/parser/java/Class.java | 10 +++++--- .../peeratcode/parser/java/Function.java | 23 +++++++++++++++++-- .../peeratcode/parser/java/JavaParser.java | 2 +- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/Annotation.java b/src/be/jeffcheasey88/peeratcode/parser/java/Annotation.java index 6a82f2d..a167856 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/Annotation.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/Annotation.java @@ -20,6 +20,8 @@ public class Annotation extends JavaElement{ Matcher matcher = PATTERN.matcher(content); matcher.lookingAt(); + System.out.println("parseAnnotation("+content.length()+") "+content); + this.type = matcher.group(2); this.param = matcher.group(3); diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/Class.java b/src/be/jeffcheasey88/peeratcode/parser/java/Class.java index ec02b1f..9369538 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/Class.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/Class.java @@ -8,6 +8,7 @@ import java.util.function.BiFunction; 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; public class Class extends JavaElement{ @@ -52,12 +53,15 @@ public class Class extends JavaElement{ this.childs = new ArrayList<>(); + CleanerPool tmp = new CleanerPool(new Cleaner("GENERIC_PARENTHESIS", '(', ')')); + content = matcher.group(3); Pattern empty = Pattern.compile("^\\s*$"); while(!(empty.matcher(content).matches())){ - int quotes = indexOf(content,";"); - int braces = indexOf(content,"\\{"); - int equals = indexOf(content,"="); + String zip = tmp.clean(content); + int quotes = indexOf(zip,";"); + int braces = indexOf(zip,"\\{"); + int equals = indexOf(zip,"="); if((quotes < braces && quotes < equals) || (equals < braces)){ Variable variable = new Variable(); int index = variable.parse(content, global, local); diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/Function.java b/src/be/jeffcheasey88/peeratcode/parser/java/Function.java index 1a666ae..3d3acb0 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/Function.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/Function.java @@ -13,6 +13,7 @@ import be.jeffcheasey88.peeratcode.parser.java.operations.OperationContainer; public class Function extends OperationContainer{ private static Pattern PATTERN = Pattern.compile("^(\\s*([^(]*)\\(([^)]*)\\)\\s*([^{]*)\\{)(.*)$"); + private static Pattern ANNOTATION_PATTERN = Pattern.compile("^(\\s*(@\\s*[^\\s]+\\s*\\^GENERIC_PARENTHESIS\\d+\\s+))"); private List annotations; private int modifier; @@ -30,8 +31,22 @@ public class Function extends OperationContainer{ public int parse(String content, CleanerPool global, CleanerPool local) throws Exception{ local = new CleanerPool(new Cleaner("GENERIC_PARENTHESIS", '(', ')')); + content = local.clean(content); + + int annotationOffset = 0; + + Matcher matcher; + while((matcher = ANNOTATION_PATTERN.matcher(content)).lookingAt()){ + String annot = matcher.group(1); + annotationOffset+=local.unzip(annot, (s,p) -> s).length(); + content = content.substring(annot.length()); + Annotation annotation = new Annotation(); + annotation.parse(matcher.group(2), global, local); + this.annotations.add(annotation); + } + content = local.unzipOne(local.clean(content), (s,p) -> s); - Matcher matcher = PATTERN.matcher(content); + matcher = PATTERN.matcher(content); matcher.matches(); attribute(matcher.group(2)); @@ -47,7 +62,7 @@ public class Function extends OperationContainer{ super.parse(local.clean(unzip), global, local); - return local.unzip(matcher.group(1), (s,p) -> s).length()+local.unzip(unzip, ((s,p) -> s)).length()+1; + return annotationOffset+local.unzip(matcher.group(1), (s,p) -> s).length()+local.unzip(unzip, ((s,p) -> s)).length()+1; } private static Pattern UNZIP_STICK = Pattern.compile("\\s+(?[<|(|\\[|\"|'])"); @@ -67,6 +82,8 @@ public class Function extends OperationContainer{ unzip = UNZIP_MAJ.matcher(unzip).replaceAll("> ${e}"); unzip = UNZIP_ARRAY.matcher(unzip).replaceAll("] ${e}"); + System.out.println("split space on "+unzip); + Iterator values = new ArrayIterator<>(unzip.split("\\s+")); String value = null; int modifier; @@ -74,7 +91,9 @@ public class Function extends OperationContainer{ Annotation annotation = new Annotation(); annotation.parse(value, null, generic); this.annotations.add(annotation); + System.out.println("parse annotation "+value); } + System.out.println("out in("+values.hasNext()+" -> "+value.charAt(0)+") "+value); if((modifier = JavaParser.getModifier(value)) > 0){ do{ this.modifier+=modifier; diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java index c53a672..5e8999c 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java @@ -17,7 +17,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\\routes\\PuzzleResponse.java"); BufferedReader reader = new BufferedReader(new FileReader(file)); JavaParser parser = new JavaParser();