Annotation -> Multiple Annotation on function
This commit is contained in:
parent
af3481fd4d
commit
6975d6dad0
4 changed files with 31 additions and 6 deletions
|
@ -20,6 +20,8 @@ public class Annotation extends JavaElement{
|
||||||
Matcher matcher = PATTERN.matcher(content);
|
Matcher matcher = PATTERN.matcher(content);
|
||||||
matcher.lookingAt();
|
matcher.lookingAt();
|
||||||
|
|
||||||
|
System.out.println("parseAnnotation("+content.length()+") "+content);
|
||||||
|
|
||||||
this.type = matcher.group(2);
|
this.type = matcher.group(2);
|
||||||
this.param = matcher.group(3);
|
this.param = matcher.group(3);
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import java.util.function.BiFunction;
|
||||||
import java.util.regex.Matcher;
|
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.Variable.MultipleDeclaratedVariable;
|
import be.jeffcheasey88.peeratcode.parser.java.Variable.MultipleDeclaratedVariable;
|
||||||
|
|
||||||
public class Class extends JavaElement{
|
public class Class extends JavaElement{
|
||||||
|
@ -52,12 +53,15 @@ public class Class extends JavaElement{
|
||||||
|
|
||||||
this.childs = new ArrayList<>();
|
this.childs = new ArrayList<>();
|
||||||
|
|
||||||
|
CleanerPool tmp = new CleanerPool(new Cleaner("GENERIC_PARENTHESIS", '(', ')'));
|
||||||
|
|
||||||
content = matcher.group(3);
|
content = matcher.group(3);
|
||||||
Pattern empty = Pattern.compile("^\\s*$");
|
Pattern empty = Pattern.compile("^\\s*$");
|
||||||
while(!(empty.matcher(content).matches())){
|
while(!(empty.matcher(content).matches())){
|
||||||
int quotes = indexOf(content,";");
|
String zip = tmp.clean(content);
|
||||||
int braces = indexOf(content,"\\{");
|
int quotes = indexOf(zip,";");
|
||||||
int equals = indexOf(content,"=");
|
int braces = indexOf(zip,"\\{");
|
||||||
|
int equals = indexOf(zip,"=");
|
||||||
if((quotes < braces && quotes < equals) || (equals < braces)){
|
if((quotes < braces && quotes < equals) || (equals < braces)){
|
||||||
Variable variable = new Variable();
|
Variable variable = new Variable();
|
||||||
int index = variable.parse(content, global, local);
|
int index = variable.parse(content, global, local);
|
||||||
|
|
|
@ -13,6 +13,7 @@ import be.jeffcheasey88.peeratcode.parser.java.operations.OperationContainer;
|
||||||
public class Function extends OperationContainer{
|
public class Function extends OperationContainer{
|
||||||
|
|
||||||
private static Pattern PATTERN = Pattern.compile("^(\\s*([^(]*)\\(([^)]*)\\)\\s*([^{]*)\\{)(.*)$");
|
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 List<Annotation> annotations;
|
||||||
private int modifier;
|
private int modifier;
|
||||||
|
@ -30,8 +31,22 @@ public class Function extends OperationContainer{
|
||||||
|
|
||||||
public int parse(String content, CleanerPool global, CleanerPool local) throws Exception{
|
public int parse(String content, CleanerPool global, CleanerPool local) throws Exception{
|
||||||
local = new CleanerPool(new Cleaner("GENERIC_PARENTHESIS", '(', ')'));
|
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);
|
content = local.unzipOne(local.clean(content), (s,p) -> s);
|
||||||
Matcher matcher = PATTERN.matcher(content);
|
matcher = PATTERN.matcher(content);
|
||||||
matcher.matches();
|
matcher.matches();
|
||||||
|
|
||||||
attribute(matcher.group(2));
|
attribute(matcher.group(2));
|
||||||
|
@ -47,7 +62,7 @@ public class Function extends OperationContainer{
|
||||||
|
|
||||||
super.parse(local.clean(unzip), global, local);
|
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>[<|(|\\[|\"|'])");
|
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_MAJ.matcher(unzip).replaceAll("> ${e}");
|
||||||
unzip = UNZIP_ARRAY.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+"));
|
Iterator<String> values = new ArrayIterator<>(unzip.split("\\s+"));
|
||||||
String value = null;
|
String value = null;
|
||||||
int modifier;
|
int modifier;
|
||||||
|
@ -74,7 +91,9 @@ public class Function extends OperationContainer{
|
||||||
Annotation annotation = new Annotation();
|
Annotation annotation = new Annotation();
|
||||||
annotation.parse(value, null, generic);
|
annotation.parse(value, null, generic);
|
||||||
this.annotations.add(annotation);
|
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){
|
if((modifier = JavaParser.getModifier(value)) > 0){
|
||||||
do{
|
do{
|
||||||
this.modifier+=modifier;
|
this.modifier+=modifier;
|
||||||
|
|
|
@ -17,7 +17,7 @@ import be.jeffcheasey88.peeratcode.parser.java.CleanerPool.Cleaner;
|
||||||
public class JavaParser{
|
public class JavaParser{
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
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));
|
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||||
|
|
||||||
JavaParser parser = new JavaParser();
|
JavaParser parser = new JavaParser();
|
||||||
|
|
Loading…
Add table
Reference in a new issue