diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/Class.java b/src/be/jeffcheasey88/peeratcode/parser/java/Class.java index b2ca569..3c1ed8e 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/Class.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/Class.java @@ -2,6 +2,7 @@ package be.jeffcheasey88.peeratcode.parser.java; import java.lang.reflect.Modifier; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.function.BiFunction; import java.util.regex.Matcher; @@ -13,22 +14,41 @@ public class Class extends JavaElement{ private static Pattern PATTERN = Pattern.compile("^(\\s*([^\\{]*)\\{(.*)\\})\\s*$"); + private List annotations; + private int modifier; private String name; private List childs; - public Class(){} + public Class(){ + this.annotations = new ArrayList<>(); + } public int parse(String content, CleanerPool global, CleanerPool local) throws Exception{ Matcher matcher = PATTERN.matcher(content); matcher.matches(); - String[] split = matcher.group(2).split("\\s+"); - for(int i = 0; i < split.length-1; i++){ - this.modifier+=JavaParser.getModifier(split[i]); + Iterator values = new ArrayIterator<>(matcher.group(2).split("\\s+")); + String value = null; + int modifier; + while(values.hasNext() && ((value = values.next()).charAt(0) == '@')){ + Annotation annotation = new Annotation(); + annotation.parse(value, global, local); + this.annotations.add(annotation); + } + if((modifier = JavaParser.getModifier(value)) > 0){ + do{ + this.modifier+=modifier; + }while(values.hasNext() && (modifier = JavaParser.getModifier(value = values.next())) > 0); + } + + String type = value; //class interface enum + this.name = values.next(); + + if(values.hasNext()){ + //extends implements } - this.name = split[split.length-1]; this.childs = new ArrayList<>(); @@ -100,6 +120,8 @@ public class Class extends JavaElement{ @Override public void build(ArrayBuffer buffer, int tab) throws Exception{ + for(Annotation annotation : this.annotations) annotation.build(buffer, tab); + super.build(buffer, tab); buffer.append((s) -> s+=Modifier.toString(modifier)+" "+this.name+"{"); buffer.add(""); diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/Import.java b/src/be/jeffcheasey88/peeratcode/parser/java/Import.java index 177f191..2847723 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/Import.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/Import.java @@ -5,7 +5,7 @@ import java.util.regex.Pattern; public class Import { - private static Pattern PATTERN = Pattern.compile("^\\s*(import\\s+([^;]*);)"); + private static Pattern PATTERN = Pattern.compile("^(\\s*import\\s+([^;]*);)"); public static boolean isImport(String content){ return PATTERN.matcher(content).lookingAt(); diff --git a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java index 3058fae..c53a672 100644 --- a/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java +++ b/src/be/jeffcheasey88/peeratcode/parser/java/JavaParser.java @@ -24,6 +24,11 @@ public class JavaParser{ parser.parse(reader); System.out.println("build-----------------"); parser.build(new BufferedWriter(new FileWriter(new File("/home/buildClazzFromParser.txt")))); + + reader = new BufferedReader(new FileReader(new File("/home/buildClazzFromParser.txt"))); + String line; + while((line = reader.readLine()) != null) System.out.println(line); + reader.close(); } public static void mainee(String[] args) throws Exception { @@ -90,8 +95,9 @@ public class JavaParser{ line = cleaner.clean(line); index = line.indexOf("//"); if(index >= 0) line = line.substring(0, index); - content+=line; + content+=line+" "; } + System.out.println(content); this.pack = new Package(); index = this.pack.parse(content);