Annotation -> Multiple Annotation on function

This commit is contained in:
jeffcheasey88 2023-06-12 21:07:00 +02:00
parent af3481fd4d
commit 6975d6dad0
4 changed files with 31 additions and 6 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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<Annotation> 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+(?<e>[<|(|\\[|\"|'])");
@ -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<String> 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;

View file

@ -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();