diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/Annotation.java b/src/be/jeffcheasey88/peeratcode/parser/java/Annotation.java index 7ab225b..6a82f2d 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/Annotation.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/Annotation.java @@ -26,11 +26,14 @@ public class Annotation extends JavaElement{ return matcher.group(1).length(); } + public String getType(){ + return this.type; + } + @Override public void build(ArrayBuffer buffer, int tab) throws Exception { super.build(buffer, tab); buffer.append((s) -> s+="@"+type+(param == null ? "":param)); - buffer.add(""); } @Override diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/Class.java b/src/be/jeffcheasey88/peeratcode/parser/java/Class.java index 3c1ed8e..ec02b1f 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/Class.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/Class.java @@ -120,7 +120,10 @@ public class Class extends JavaElement{ @Override public void build(ArrayBuffer buffer, int tab) throws Exception{ - for(Annotation annotation : this.annotations) annotation.build(buffer, tab); + for(Annotation annotation : this.annotations){ + annotation.build(buffer, tab); + buffer.add(""); + } super.build(buffer, tab); buffer.append((s) -> s+=Modifier.toString(modifier)+" "+this.name+"{"); diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/Function.java b/src/be/jeffcheasey88/peeratcode/parser/java/Function.java index fa99106..1a666ae 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/Function.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/Function.java @@ -29,6 +29,8 @@ 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.unzipOne(local.clean(content), (s,p) -> s); Matcher matcher = PATTERN.matcher(content); matcher.matches(); @@ -36,17 +38,16 @@ public class Function extends OperationContainer{ parameters(matcher.group(3)+";", global, local); this.exceptions = matcher.group(4).trim(); - local = new CleanerPool( - new Cleaner("GENERIC_FUNCTION", '{', '}'), - new Cleaner("GENERIC_PARENTHESIS", '(', ')')); + local = local.group(new CleanerPool(new Cleaner("GENERIC_FUNCTION", '{', '}'))); + + String zip = local.clean("{"+matcher.group(5)); String body = local.unzipOne(zip, (s,p) -> s); String unzip = body.substring(1, body.indexOf('}')); super.parse(local.clean(unzip), global, local); - - return matcher.group(1).length()+local.unzip(unzip, ((s,p) -> s)).length()+1; + return 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+(?[<|(|\\[|\"|'])"); @@ -104,17 +105,28 @@ public class Function extends OperationContainer{ @Override public void build(ArrayBuffer buffer, int tab) throws Exception{ - for(Annotation annotation : this.annotations) annotation.build(buffer, tab); + for(Annotation annotation : this.annotations){ + annotation.build(buffer, tab); + buffer.add(""); + } - String param = ""; - for(Variable v : this.parameters) param+=","+v.getType()+" "+v.getName()+""; - if(!param.isEmpty()) param = param.substring(1); - - final String paramMod = param; boolean empty = getChilds().size() == 0; super.build(buffer, tab); - buffer.append((s) -> s+=Modifier.toString(modifier)+" "+(constructor ? "" : returnType+" ")+name+"("+paramMod+") "+exceptions+"{"+((empty ? "}":""))); + buffer.append((s) -> s+=Modifier.toString(modifier)+" "+(constructor ? "" : returnType+" ")+name+"("); + boolean first = true; + for(Variable variable : this.parameters){ + for(Annotation annotation : variable.getAnnotations()){ + annotation.build(buffer, 0); + buffer.append((s) -> s+=" "); + } + if(first) first = false; + else{ + buffer.append((s) -> s+=","); + } + buffer.append((s) -> s+=variable.getType()+" "+variable.getName()); + } + buffer.append((s) -> s+=") "+exceptions+"{"+((empty ? "}":""))); buffer.add(""); if(empty) return; diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/Variable.java b/src/be/jeffcheasey88/peeratcode/parser/java/Variable.java index d4bd464..b1a18be 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/Variable.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/Variable.java @@ -14,14 +14,19 @@ public class Variable extends JavaElement{ private static Pattern PATTERN = Pattern.compile("^(\\s*)(.*)$"); + private List annotations; + private int modifier; private String name; private String type; private Variable value; //Change into operation or JavaElement - public Variable(){} + public Variable(){ + this.annotations = new ArrayList<>(); + } public Variable(int modifier, String type){ + this(); this.modifier = modifier; this.type = type; } @@ -57,7 +62,7 @@ public class Variable extends JavaElement{ return offset+local.unzipOne(body, (s,p) -> (p.equals("^GENERIC_TYPE") || p.equals("^GENERIC_ARRAY")) ? s : null).length(); } - private void assigment(String content, CleanerPool cleaner){ + private void assigment(String content, CleanerPool cleaner) throws Exception{ Iterator values = onlyDefine(content, cleaner); if(!values.hasNext()) return; values.next(); @@ -67,13 +72,26 @@ public class Variable extends JavaElement{ this.value = new Value(spacesValue); } - private Iterator onlyDefine(String content, CleanerPool cleaner){ + private Iterator onlyDefine(String content, CleanerPool cleaner) throws Exception{ content = generiqueTypes(content, cleaner); - Iterator values = new ArrayIterator<>(content.split("\\s+")); + + CleanerPool tmp = new CleanerPool(new Cleaner("GENERIC_PARENTHESIS",'(',')')); + content = tmp.clean(content); + + String[] array = content.split("\\s+"); +// for(int i = 0; i < array.length; i++) array[i] = tmp.unzip(array[i], (s,p) -> s); + Iterator values = new ArrayIterator<>(array); String value = null; int modifier; - while(values.hasNext() && (modifier = JavaParser.getModifier(value = values.next())) > 0){ - this.modifier+=modifier; + while(values.hasNext() && ((value = values.next()).charAt(0) == '@')){ + Annotation annotation = new Annotation(); + annotation.parse(value, cleaner, tmp); + this.annotations.add(annotation); + } + if((modifier = JavaParser.getModifier(value)) > 0){ + do{ + this.modifier+=modifier; + }while(values.hasNext() && (modifier = JavaParser.getModifier(value = values.next())) > 0); } if(this.type == null){ this.type = value; @@ -126,10 +144,17 @@ public class Variable extends JavaElement{ return this.value; } + public List getAnnotations(){ + return this.annotations; + } @Override public void build(ArrayBuffer buffer, int tab) throws Exception{ super.build(buffer, tab); + for(Annotation annotation : this.annotations){ + annotation.build(buffer, 0); + buffer.append((s) -> s+=" "); + } buffer.append((s) -> s+=Modifier.toString(modifier)+(modifier > 0 ? " ":"")+type+" "+name+(value == null ? ";":" = "+value+";")); buffer.add(""); }