Compare commits

..

No commits in common. "97aa0ac39196b58e68b082cb4036e8297f17023d" and "6909ca513c5ee2aaf202e2094dddec7e7718d268" have entirely different histories.

18 changed files with 145 additions and 252 deletions

Binary file not shown.

View file

@ -1,28 +0,0 @@
package be.jeffcheasey88.peeratcode.parser.java;
import java.lang.reflect.Array;
import java.util.Iterator;
public class ArrayBuffer<E>{
private E[] elements;
public ArrayBuffer(java.lang.Class<?> type){
this.elements = (E[]) Array.newInstance(type, 0);
}
public void add(E e){
E[] copy = (E[]) Array.newInstance(e.getClass(), this.elements.length+1);
System.arraycopy(elements, 0, copy, 0, elements.length);
copy[elements.length] = e;
this.elements = copy;
}
public void append(java.util.function.Function<E, E> modifier){
this.elements[elements.length-1] = modifier.apply(this.elements[elements.length-1]);
}
public Iterator<E> iterator(){
return new ArrayIterator<E>(elements);
}
}

View file

@ -1,6 +1,5 @@
package be.jeffcheasey88.peeratcode.parser.java; package be.jeffcheasey88.peeratcode.parser.java;
import java.lang.reflect.Array;
import java.util.Iterator; import java.util.Iterator;
public class ArrayIterator<E> implements Iterator<E>{ public class ArrayIterator<E> implements Iterator<E>{
@ -9,11 +8,9 @@ public class ArrayIterator<E> implements Iterator<E>{
private int index; private int index;
public ArrayIterator(E[] elements){ public ArrayIterator(E[] elements){
E[] copy = (E[]) Array.newInstance(elements.getClass().getComponentType(), elements.length); this.elements = elements;
System.arraycopy(elements, 0, copy, 0, elements.length);
this.elements = copy;
} }
@Override @Override
public boolean hasNext(){ public boolean hasNext(){
return index < elements.length; return index < elements.length;

View file

@ -1,6 +1,5 @@
package be.jeffcheasey88.peeratcode.parser.java; package be.jeffcheasey88.peeratcode.parser.java;
import java.io.BufferedWriter;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -99,22 +98,17 @@ public class Class extends JavaElement{
// return this.vars; // return this.vars;
// } // }
@Override public void show(int tab){
public void build(ArrayBuffer<String> buffer, int tab) throws Exception{ String start = "";
super.build(buffer, tab); for(int i = 0; i < tab; i++) start+="\t";
buffer.append((s) -> s+=Modifier.toString(modifier)+" "+this.name+"{"); System.out.println(start+Modifier.toString(modifier)+" "+this.name+"{");
buffer.add(""); for(JavaElement jElement : this.childs){
jElement.show(tab+1);
for(JavaElement child : this.childs){ System.out.println();
child.build(buffer, tab+1);
buffer.add("");
} }
System.out.println(start+"}");
super.build(buffer, tab);
buffer.append((s) -> s+="}");
buffer.add("");
} }
@Override @Override
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> search, java.util.function.Function<List<JavaElement>, Boolean> deep, List<JavaElement> trace){ public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> search, java.util.function.Function<List<JavaElement>, Boolean> deep, List<JavaElement> trace){
if(search.apply(this)) return (E)this; if(search.apply(this)) return (E)this;

View file

@ -93,23 +93,15 @@ public class Function extends OperationContainer{
}while(quote); }while(quote);
} }
@Override public void show(int tab){
public void build(ArrayBuffer<String> buffer, int tab) throws Exception{ String start = "";
for(int i = 0; i < tab; i++) start+="\t";
String param = ""; String param = "";
for(Variable v : this.parameters) param+=","+v.getType()+" "+v.getName()+""; for(Variable v : this.parameters) param+=","+v.getType()+" "+v.getName()+"";
if(!param.isEmpty()) param = param.substring(1); if(!param.isEmpty()) param = param.substring(1);
super.build(buffer, tab); System.out.println(start+Modifier.toString(modifier)+" "+(constructor ? "" : returnType+" ")+name+"("+param+") "+exceptions+"{");
for(JavaElement child : getChilds()) child.show(tab+1);
final String paramMod = param; System.out.println(start+"}");
buffer.append((s) -> s+=Modifier.toString(modifier)+" "+(constructor ? "" : returnType+" ")+name+"("+paramMod+") "+exceptions+"{");
buffer.add("");
for(JavaElement child : getChilds()) child.build(buffer, tab+1);
super.build(buffer, tab);
buffer.append((s) -> s+="}");
buffer.add("");
} }
} }

View file

@ -11,10 +11,6 @@ public abstract class JavaElement {
public abstract <E extends JavaElement> E find(Function<JavaElement, Boolean> search, Function<List<JavaElement>, Boolean> deep, List<JavaElement> trace); public abstract <E extends JavaElement> E find(Function<JavaElement, Boolean> search, Function<List<JavaElement>, Boolean> deep, List<JavaElement> trace);
public abstract <E extends JavaElement> E find(BiFunction<JavaElement, List<JavaElement>, Boolean> search, List<JavaElement> trace); public abstract <E extends JavaElement> E find(BiFunction<JavaElement, List<JavaElement>, Boolean> search, List<JavaElement> trace);
public void build(ArrayBuffer<String> buffer, int tab) throws Exception { //Only for development
String spacement = ""; public abstract void show(int tab);
for(int i = 0; i < tab; i++) spacement+="\t";
final String modifier = spacement;
buffer.append((s) -> s+=modifier);
}
} }

View file

@ -7,7 +7,6 @@ import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Function; import java.util.function.Function;
@ -20,10 +19,10 @@ public class JavaParser{
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\\parser\\java\\Class.java");
BufferedReader reader = new BufferedReader(new FileReader(file)); BufferedReader reader = new BufferedReader(new FileReader(file));
JavaParser parser = new JavaParser(); JavaParser parser = new JavaParser(reader);
parser.parse(reader); parser.parse();
System.out.println("build-----------------"); System.out.println("SHOW-----------------");
parser.build(new BufferedWriter(new FileWriter(new File("/home/buildClazzFromParser.txt")))); parser.show();
} }
public static void mainee(String[] args) throws Exception { public static void mainee(String[] args) throws Exception {
@ -42,9 +41,10 @@ public class JavaParser{
BufferedReader reader = new BufferedReader(new FileReader(new File("/home/tmp.txt"))); BufferedReader reader = new BufferedReader(new FileReader(new File("/home/tmp.txt")));
JavaParser parser = new JavaParser(); JavaParser parser = new JavaParser(reader);
parser.parse(reader); parser.parse();
System.out.println("SHOW-----------------"); System.out.println("SHOW-----------------");
parser.show();
} }
private static void show(File dir) throws Exception{ private static void show(File dir) throws Exception{
@ -54,8 +54,8 @@ public class JavaParser{
BufferedReader reader = new BufferedReader(new FileReader(dir)); BufferedReader reader = new BufferedReader(new FileReader(dir));
try { try {
JavaParser parser = new JavaParser(); JavaParser parser = new JavaParser(reader);
parser.parse(reader); parser.parse();
Class clazz = parser.getClazz(); Class clazz = parser.getClazz();
System.out.println(clazz.getName()); System.out.println(clazz.getName());
@ -72,15 +72,17 @@ public class JavaParser{
private List<Import> imports; private List<Import> imports;
private Class clazz; private Class clazz;
private CleanerPool cleaner; private BufferedReader reader;
public JavaParser(){} public JavaParser(BufferedReader reader){
this.reader = reader;
}
public void parse(BufferedReader reader) throws Exception{ public void parse() throws Exception{
String content = ""; String content = "";
int index; int index;
cleaner = new CleanerPool( CleanerPool cleaner = new CleanerPool(
new Cleaner("CONSTANT_STRING",'"','"'), new Cleaner("CONSTANT_STRING",'"','"'),
new Cleaner("CONSTANT_CHAR",'\'','\'')); new Cleaner("CONSTANT_CHAR",'\'','\''));
@ -129,28 +131,14 @@ public class JavaParser{
return this.clazz; return this.clazz;
} }
public void build(BufferedWriter writer) throws Exception{ public void show(){
writer.write("package "+this.pack.getName()+";\n"); System.out.println("package "+this.pack.getName()+";");
writer.write("\n"); System.out.println();
for(Import element : this.imports) writer.write("import "+element.getName()+";\n"); for(Import i : this.imports) System.out.println("import "+i.getName()+";");
writer.write("\n"); System.out.println();
this.clazz.show(0);
ArrayBuffer<String> buffer = new ArrayBuffer<String>(String.class);
buffer.add("");
this.clazz.build(buffer, 0);
Iterator<String> lines = buffer.iterator();
while(lines.hasNext()){
String line = lines.next();
line = this.cleaner.unzip(line, (s,p) -> s);
writer.write(line+"\n");
}
writer.flush();
writer.close();
} }
public static int getModifier(String modifier){ public static int getModifier(String modifier){
switch(modifier){ switch(modifier){
case "public": return Modifier.PUBLIC; case "public": return Modifier.PUBLIC;

View file

@ -1,6 +1,5 @@
package be.jeffcheasey88.peeratcode.parser.java; package be.jeffcheasey88.peeratcode.parser.java;
import java.io.BufferedWriter;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
@ -127,12 +126,10 @@ public class Variable extends JavaElement{
return this.value; return this.value;
} }
public void show(int tab){
@Override String start = "";
public void build(ArrayBuffer<String> buffer, int tab) throws Exception{ for(int i = 0; i < tab; i++) start+="\t";
super.build(buffer, tab); System.out.println(start+Modifier.toString(modifier)+(modifier > 0 ? " ":"")+type+" "+name+(value == null ? ";":" = "+value+";"));
buffer.append((s) -> s+=Modifier.toString(modifier)+(modifier > 0 ? " ":"")+type+" "+name+(value == null ? ";":" = "+value+";"));
buffer.add("");
} }
@Override @Override
@ -191,21 +188,16 @@ public class Variable extends JavaElement{
} }
@Override @Override
public void build(ArrayBuffer<String> buffer, int tab) throws Exception { public void show(int tab){
String spacement = ""; String start = "";
for(int i = 0; i < tab; i++) spacement+="\t"; for(int i = 0; i < tab; i++) start+="\t";
final String sMod = spacement;
String vars = ""; String vars = "";
for(int i = 0; i < this.names.size(); i++){ for(int i = 0; i < this.names.size(); i++){
Variable value = this.values.get(i); Variable value = this.values.get(i);
vars+=","+this.names.get(i)+((value == null) ? "" : " = "+value); vars+=","+this.names.get(i)+((value == null) ? "" : " = "+value);
} }
vars = vars.substring(1); vars = vars.substring(1);
String varMod = vars; System.out.println(start+Modifier.toString(getModifier())+" "+getType()+" "+vars+";");
buffer.append((s) -> s+=sMod+Modifier.toString(getModifier())+" "+getType()+" "+varMod+";");
buffer.add("");
} }
} }
} }

View file

@ -5,7 +5,6 @@ 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.ArrayBuffer;
import be.jeffcheasey88.peeratcode.parser.java.CleanerPool; import be.jeffcheasey88.peeratcode.parser.java.CleanerPool;
import be.jeffcheasey88.peeratcode.parser.java.JavaElement; import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
@ -28,12 +27,12 @@ public class AssigmentOperation extends JavaElement{
return matcher.group(1).length(); return matcher.group(1).length();
} }
@Override @Override
public void build(ArrayBuffer<String> buffer, int tab) throws Exception{ public void show(int tab){
super.build(buffer, tab); String start = "";
buffer.append((s) -> s+=variable+" = "+value+";"); for(int i = 0; i < tab; i++) start+="\t";
buffer.add(""); System.out.println(start+variable+" = "+value+";");
} }
@Override @Override

View file

@ -1,10 +1,8 @@
package be.jeffcheasey88.peeratcode.parser.java.operations; package be.jeffcheasey88.peeratcode.parser.java.operations;
import java.io.BufferedWriter;
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.ArrayBuffer;
import be.jeffcheasey88.peeratcode.parser.java.CleanerPool; import be.jeffcheasey88.peeratcode.parser.java.CleanerPool;
import be.jeffcheasey88.peeratcode.parser.java.JavaElement; import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
@ -57,30 +55,14 @@ public class ConditionalOperation extends OperationContainer{
return index+bodysize; return index+bodysize;
} }
@Override @Override
public void build(ArrayBuffer<String> buffer, int tab) throws Exception{ public void show(int tab) {
boolean empty = getChilds().size() == 0; String start = "";
if(empty){ for(int i = 0; i < tab; i++) start+="\t";
buffer.append((s) -> s+=";"); System.out.println(start+"Condition??"+condition+"{");
buffer.add(""); for(JavaElement child : getChilds()) child.show(tab+1);
return; System.out.println(start+"}");
}
boolean oneChild = getChilds().size() == 1;
if(oneChild) buffer.append((s) -> s+=" ");
else{
buffer.append((s) -> s+="{");
buffer.add("");
}
for(JavaElement child : getChilds()) child.build(buffer, oneChild ? 0 : tab+1);
if(!oneChild){
super.build(buffer, tab);
buffer.append((s) -> s+="}");
buffer.add("");
}
} }
public static class IfOperation extends ConditionalOperation{ public static class IfOperation extends ConditionalOperation{
@ -90,16 +72,14 @@ public class ConditionalOperation extends OperationContainer{
public IfOperation(){ public IfOperation(){
super(PATTERN); super(PATTERN);
} }
@Override @Override
public void build(ArrayBuffer<String> buffer, int tab) throws Exception{ public void show(int tab) {
String spacement = ""; String start = "";
for(int i = 0; i < tab; i++) spacement+="\t"; for(int i = 0; i < tab; i++) start+="\t";
final String modSpace = spacement; System.out.println(start+"if"+super.condition+"{");
buffer.append((s) -> s+=modSpace+"if"+super.condition); for(JavaElement child : getChilds()) child.show(tab+1);
System.out.println(start+"}");
super.build(buffer, tab);
} }
} }
@ -112,13 +92,12 @@ public class ConditionalOperation extends OperationContainer{
} }
@Override @Override
public void build(ArrayBuffer<String> buffer, int tab) throws Exception{ public void show(int tab) {
String spacement = ""; String start = "";
for(int i = 0; i < tab; i++) spacement+="\t"; for(int i = 0; i < tab; i++) start+="\t";
final String modSpace = spacement; System.out.println(start+"for"+super.condition+"{");
buffer.append((s) -> s+=modSpace+"for"+super.condition); for(JavaElement child : getChilds()) child.show(tab+1);
System.out.println(start+"}");
super.build(buffer, tab);
} }
} }
@ -131,13 +110,12 @@ public class ConditionalOperation extends OperationContainer{
} }
@Override @Override
public void build(ArrayBuffer<String> buffer, int tab) throws Exception{ public void show(int tab) {
String spacement = ""; String start = "";
for(int i = 0; i < tab; i++) spacement+="\t"; for(int i = 0; i < tab; i++) start+="\t";
final String modSpace = spacement; System.out.println(start+"while"+super.condition+"{");
buffer.append((s) -> s+=modSpace+"while"+super.condition); for(JavaElement child : getChilds()) child.show(tab+1);
System.out.println(start+"}");
super.build(buffer, tab);
} }
} }
} }

View file

@ -1,10 +1,8 @@
package be.jeffcheasey88.peeratcode.parser.java.operations; package be.jeffcheasey88.peeratcode.parser.java.operations;
import java.io.BufferedWriter;
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.ArrayBuffer;
import be.jeffcheasey88.peeratcode.parser.java.CleanerPool; import be.jeffcheasey88.peeratcode.parser.java.CleanerPool;
import be.jeffcheasey88.peeratcode.parser.java.JavaElement; import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
@ -38,16 +36,12 @@ public class DoOperation extends OperationContainer{
} }
@Override @Override
public void build(ArrayBuffer<String> buffer, int tab) throws Exception{ public void show(int tab) {
super.build(buffer, tab); String start = "";
buffer.append((s) -> s+="do{"); for(int i = 0; i < tab; i++) start+="\t";
buffer.add(""); System.out.println(start+"do{");
for(JavaElement child : getChilds()) child.show(tab+1);
for(JavaElement child : getChilds()) child.build(buffer, tab+1); System.out.println(start+"}");
super.build(buffer, tab);
buffer.append((s) -> s+="}");
buffer.add("");
} }
} }

View file

@ -1,10 +1,8 @@
package be.jeffcheasey88.peeratcode.parser.java.operations; package be.jeffcheasey88.peeratcode.parser.java.operations;
import java.io.BufferedWriter;
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.ArrayBuffer;
import be.jeffcheasey88.peeratcode.parser.java.CleanerPool; import be.jeffcheasey88.peeratcode.parser.java.CleanerPool;
import be.jeffcheasey88.peeratcode.parser.java.JavaElement; import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
@ -43,24 +41,13 @@ public class ElseOperation extends OperationContainer{
} }
@Override @Override
public void build(ArrayBuffer<String> buffer, int tab) throws Exception{ public void show(int tab) {
super.build(buffer, tab); String start = "";
buffer.append((s) -> s+="else "); for(int i = 0; i < tab; i++) start+="\t";
System.out.println(start+"else{");
boolean oneOperation = getChilds().size() == 1; for(JavaElement child : getChilds()) child.show(tab+1);
if(oneOperation){ System.out.println(start+"}");
getChilds().get(0).build(buffer, 0);
return;
}
buffer.append((s) -> s+="{");
buffer.add("");
for(JavaElement child : getChilds()) child.build(buffer, tab+1);
super.build(buffer, tab);
buffer.append((s) -> s+="}");
buffer.add("");
} }
} }

View file

@ -1,12 +1,10 @@
package be.jeffcheasey88.peeratcode.parser.java.operations; package be.jeffcheasey88.peeratcode.parser.java.operations;
import java.io.BufferedWriter;
import java.util.List; import java.util.List;
import java.util.function.BiFunction; 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.ArrayBuffer;
import be.jeffcheasey88.peeratcode.parser.java.CleanerPool; import be.jeffcheasey88.peeratcode.parser.java.CleanerPool;
import be.jeffcheasey88.peeratcode.parser.java.JavaElement; import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
@ -26,6 +24,12 @@ public class LoopAffectOperation extends JavaElement{
return matcher.group(1).length(); return matcher.group(1).length();
} }
@Override
public void show(int tab){
String start = "";
for(int i = 0; i < tab; i++) start+="\t";
System.out.println(start+"loop affect??;");
}
@Override @Override
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> search, java.util.function.Function<List<JavaElement>, Boolean> deep, List<JavaElement> trace){ public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> search, java.util.function.Function<List<JavaElement>, Boolean> deep, List<JavaElement> trace){
@ -47,12 +51,11 @@ public class LoopAffectOperation extends JavaElement{
} }
@Override @Override
public void build(ArrayBuffer<String> buffer, int tab) throws Exception { public void show(int tab){
super.build(buffer, tab); String start = "";
buffer.append((s) -> s+="continue;"); for(int i = 0; i < tab; i++) start+="\t";
buffer.add(""); System.out.println(start+"continue;");
} }
} }
public static class BreakOperation extends LoopAffectOperation{ public static class BreakOperation extends LoopAffectOperation{
@ -64,10 +67,10 @@ public class LoopAffectOperation extends JavaElement{
} }
@Override @Override
public void build(ArrayBuffer<String> buffer, int tab) throws Exception { public void show(int tab){
super.build(buffer, tab); String start = "";
buffer.append((s) -> s+="break;"); for(int i = 0; i < tab; i++) start+="\t";
buffer.add(""); System.out.println(start+"break;");
} }
} }
} }

View file

@ -1,12 +1,10 @@
package be.jeffcheasey88.peeratcode.parser.java.operations; package be.jeffcheasey88.peeratcode.parser.java.operations;
import java.io.BufferedWriter;
import java.util.List; import java.util.List;
import java.util.function.BiFunction; 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.ArrayBuffer;
import be.jeffcheasey88.peeratcode.parser.java.CleanerPool; import be.jeffcheasey88.peeratcode.parser.java.CleanerPool;
import be.jeffcheasey88.peeratcode.parser.java.JavaElement; import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
@ -33,14 +31,14 @@ public class MethodCallOperation extends JavaElement{
public String getValue(){ public String getValue(){
return this.value; return this.value;
} }
@Override
public void build(ArrayBuffer<String> buffer, int tab) throws Exception{
super.build(buffer, tab);
buffer.append((s) -> s+=value+";");
buffer.add("");
}
@Override
public void show(int tab){
String start = "";
for(int i = 0; i < tab; i++) start+="\t";
System.out.println(start+value+";");
}
@Override @Override
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> search, java.util.function.Function<List<JavaElement>, Boolean> deep, List<JavaElement> trace){ public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> search, java.util.function.Function<List<JavaElement>, Boolean> deep, List<JavaElement> trace){
return search.apply(this) ? (E)this : null; return search.apply(this) ? (E)this : null;

View file

@ -1,12 +1,10 @@
package be.jeffcheasey88.peeratcode.parser.java.operations; package be.jeffcheasey88.peeratcode.parser.java.operations;
import java.io.BufferedWriter;
import java.util.List; import java.util.List;
import java.util.function.BiFunction; 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.ArrayBuffer;
import be.jeffcheasey88.peeratcode.parser.java.CleanerPool; import be.jeffcheasey88.peeratcode.parser.java.CleanerPool;
import be.jeffcheasey88.peeratcode.parser.java.JavaElement; import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
@ -37,20 +35,19 @@ public class ReturnOperation extends JavaElement{
return matcher.group(1).length(); return matcher.group(1).length();
} }
@Override @Override
public void build(ArrayBuffer<String> buffer, int tab) throws Exception{ public void show(int tab){
super.build(buffer, tab); String start = "";
for(int i = 0; i < tab; i++) start+="\t";
if(value != null){ if(value != null){
buffer.append((s) -> s+="return "); System.out.println("return");
value.build(buffer, 0); value.show(tab+1);
buffer.add(""); System.out.println(";");
return; return;
} }
buffer.append((s) -> s+="return "+toChange+";"); System.out.println(start+"return "+toChange+";");
buffer.add("");
} }
@Override @Override
public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> search, java.util.function.Function<List<JavaElement>, Boolean> deep, List<JavaElement> trace){ public <E extends JavaElement> E find(java.util.function.Function<JavaElement, Boolean> search, java.util.function.Function<List<JavaElement>, Boolean> deep, List<JavaElement> trace){

View file

@ -1,10 +1,8 @@
package be.jeffcheasey88.peeratcode.parser.java.operations; package be.jeffcheasey88.peeratcode.parser.java.operations;
import java.io.BufferedWriter;
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.ArrayBuffer;
import be.jeffcheasey88.peeratcode.parser.java.CleanerPool; import be.jeffcheasey88.peeratcode.parser.java.CleanerPool;
import be.jeffcheasey88.peeratcode.parser.java.JavaElement; import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
@ -29,7 +27,7 @@ public class SynchronizedOperation extends OperationContainer{
matcher.matches(); matcher.matches();
content = matcher.group(1); content = matcher.group(1);
index += content.length(); index += content.length();
content = local.unzipOne(content, (s,p) -> s); content = local.unzipOne(content, (s,p) -> s);
content = content.substring(1, content.length()-1); content = content.substring(1, content.length()-1);
@ -38,18 +36,14 @@ public class SynchronizedOperation extends OperationContainer{
return index; return index;
} }
@Override @Override
public void build(ArrayBuffer<String> buffer, int tab) throws Exception{ public void show(int tab){
super.build(buffer, tab); String start = "";
buffer.append((s) -> s+="synchronized"+this.include+"{"); for(int i = 0; i < tab; i++) start+="\t";
buffer.add(""); System.out.println(start+"synchronized"+this.include+"{");
for(JavaElement child : getChilds()) child.show(tab+1);
for(JavaElement child : getChilds()) child.build(buffer, tab+1); System.out.println(start+"}");
super.build(buffer, tab);
buffer.append((s) -> s+="}");
buffer.add("");
} }
} }

View file

@ -32,8 +32,8 @@ class OperationTest{
} }
}; };
JavaParser parser = new JavaParser(); JavaParser parser = new JavaParser(reader);
parser.parse(reader); parser.parse();
return parser; return parser;
} }
@ -43,6 +43,8 @@ class OperationTest{
JavaParser parser = parse("package be.jeffcheasey88.peeratcode.parser.java; class Test{ void function(){ int i = 0; if(i == 0) { return i; } return i; } }"); JavaParser parser = parse("package be.jeffcheasey88.peeratcode.parser.java; class Test{ void function(){ int i = 0; if(i == 0) { return i; } return i; } }");
Class clazz = parser.getClazz(); Class clazz = parser.getClazz();
clazz.show(0);
assertEquals(1, clazz.getChilds().size()); assertEquals(1, clazz.getChilds().size());
Function function = (Function) clazz.getChilds().get(0); Function function = (Function) clazz.getChilds().get(0);
assertEquals(3, function.getChilds().size()); assertEquals(3, function.getChilds().size());
@ -58,6 +60,8 @@ class OperationTest{
JavaParser parser = parse("package be.jeffcheasey88.peeratcode.parser.java; class Test{ void function(){ int i = 0; if(i == 0); return i; } }"); JavaParser parser = parse("package be.jeffcheasey88.peeratcode.parser.java; class Test{ void function(){ int i = 0; if(i == 0); return i; } }");
Class clazz = parser.getClazz(); Class clazz = parser.getClazz();
clazz.show(0);
assertEquals(1, clazz.getChilds().size()); assertEquals(1, clazz.getChilds().size());
Function function = (Function) clazz.getChilds().get(0); Function function = (Function) clazz.getChilds().get(0);
assertEquals(3, function.getChilds().size()); assertEquals(3, function.getChilds().size());
@ -73,6 +77,8 @@ class OperationTest{
JavaParser parser = parse("package be.jeffcheasey88.peeratcode.parser.java; class Test{ void function(){ int i = 0; do{ System.out.println(\"Hello\"); }while(i == 0); return i; } }"); JavaParser parser = parse("package be.jeffcheasey88.peeratcode.parser.java; class Test{ void function(){ int i = 0; do{ System.out.println(\"Hello\"); }while(i == 0); return i; } }");
Class clazz = parser.getClazz(); Class clazz = parser.getClazz();
clazz.show(0);
assertEquals(1, clazz.getChilds().size()); assertEquals(1, clazz.getChilds().size());
Function function = (Function) clazz.getChilds().get(0); Function function = (Function) clazz.getChilds().get(0);
assertEquals(4, function.getChilds().size()); assertEquals(4, function.getChilds().size());
@ -95,6 +101,8 @@ class OperationTest{
JavaParser parser = parse("package be.jeffcheasey88.peeratcode.parser.java; class Test{ void function(){ for(int i = 0; i < 1; i++) continue; } }"); JavaParser parser = parse("package be.jeffcheasey88.peeratcode.parser.java; class Test{ void function(){ for(int i = 0; i < 1; i++) continue; } }");
Class clazz = parser.getClazz(); Class clazz = parser.getClazz();
clazz.show(0);
assertEquals(1, clazz.getChilds().size()); assertEquals(1, clazz.getChilds().size());
Function function = (Function) clazz.getChilds().get(0); Function function = (Function) clazz.getChilds().get(0);
assertEquals(1, function.getChilds().size()); assertEquals(1, function.getChilds().size());
@ -115,6 +123,8 @@ class OperationTest{
JavaParser parser = parse("package be.jeffcheasey88.peeratcode.parser.java; class Test{ void function(){ for(int i = 0; i < 1; i++) break ; } }"); JavaParser parser = parse("package be.jeffcheasey88.peeratcode.parser.java; class Test{ void function(){ for(int i = 0; i < 1; i++) break ; } }");
Class clazz = parser.getClazz(); Class clazz = parser.getClazz();
clazz.show(0);
assertEquals(1, clazz.getChilds().size()); assertEquals(1, clazz.getChilds().size());
Function function = (Function) clazz.getChilds().get(0); Function function = (Function) clazz.getChilds().get(0);
assertEquals(1, function.getChilds().size()); assertEquals(1, function.getChilds().size());
@ -135,6 +145,8 @@ class OperationTest{
JavaParser parser = parse("package be.jeffcheasey88.peeratcode.parser.java; class Test{ void function(){ synchronized(this) { this.none(); } } }"); JavaParser parser = parse("package be.jeffcheasey88.peeratcode.parser.java; class Test{ void function(){ synchronized(this) { this.none(); } } }");
Class clazz = parser.getClazz(); Class clazz = parser.getClazz();
clazz.show(0);
assertEquals(1, clazz.getChilds().size()); assertEquals(1, clazz.getChilds().size());
Function function = (Function) clazz.getChilds().get(0); Function function = (Function) clazz.getChilds().get(0);
assertEquals(1, function.getChilds().size()); assertEquals(1, function.getChilds().size());

View file

@ -31,8 +31,8 @@ class SearchTest{
} }
}; };
JavaParser parser = new JavaParser(); JavaParser parser = new JavaParser(reader);
parser.parse(reader); parser.parse();
return parser; return parser;
} }