Compare commits
2 commits
6909ca513c
...
97aa0ac391
Author | SHA1 | Date | |
---|---|---|---|
97aa0ac391 | |||
0159f9c5fc |
18 changed files with 253 additions and 146 deletions
BIN
Treasure.jar
BIN
Treasure.jar
Binary file not shown.
28
src/be/jeffcheasey88/peeratcode/parser/java/ArrayBuffer.java
Normal file
28
src/be/jeffcheasey88/peeratcode/parser/java/ArrayBuffer.java
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
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>{
|
||||||
|
@ -8,7 +9,9 @@ public class ArrayIterator<E> implements Iterator<E>{
|
||||||
private int index;
|
private int index;
|
||||||
|
|
||||||
public ArrayIterator(E[] elements){
|
public ArrayIterator(E[] elements){
|
||||||
this.elements = elements;
|
E[] copy = (E[]) Array.newInstance(elements.getClass().getComponentType(), elements.length);
|
||||||
|
System.arraycopy(elements, 0, copy, 0, elements.length);
|
||||||
|
this.elements = copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
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;
|
||||||
|
@ -98,15 +99,20 @@ public class Class extends JavaElement{
|
||||||
// return this.vars;
|
// return this.vars;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
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)+" "+this.name+"{");
|
buffer.append((s) -> s+=Modifier.toString(modifier)+" "+this.name+"{");
|
||||||
for(JavaElement jElement : this.childs){
|
buffer.add("");
|
||||||
jElement.show(tab+1);
|
|
||||||
System.out.println();
|
for(JavaElement child : this.childs){
|
||||||
|
child.build(buffer, tab+1);
|
||||||
|
buffer.add("");
|
||||||
}
|
}
|
||||||
System.out.println(start+"}");
|
|
||||||
|
super.build(buffer, tab);
|
||||||
|
buffer.append((s) -> s+="}");
|
||||||
|
buffer.add("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -93,15 +93,23 @@ public class Function extends OperationContainer{
|
||||||
}while(quote);
|
}while(quote);
|
||||||
}
|
}
|
||||||
|
|
||||||
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";
|
|
||||||
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);
|
||||||
System.out.println(start+Modifier.toString(modifier)+" "+(constructor ? "" : returnType+" ")+name+"("+param+") "+exceptions+"{");
|
super.build(buffer, tab);
|
||||||
for(JavaElement child : getChilds()) child.show(tab+1);
|
|
||||||
System.out.println(start+"}");
|
final String paramMod = param;
|
||||||
|
|
||||||
|
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("");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,10 @@ 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);
|
||||||
|
|
||||||
//Only for development
|
public void build(ArrayBuffer<String> buffer, int tab) throws Exception {
|
||||||
public abstract void show(int tab);
|
String spacement = "";
|
||||||
|
for(int i = 0; i < tab; i++) spacement+="\t";
|
||||||
|
final String modifier = spacement;
|
||||||
|
buffer.append((s) -> s+=modifier);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ 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;
|
||||||
|
@ -19,10 +20,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(reader);
|
JavaParser parser = new JavaParser();
|
||||||
parser.parse();
|
parser.parse(reader);
|
||||||
System.out.println("SHOW-----------------");
|
System.out.println("build-----------------");
|
||||||
parser.show();
|
parser.build(new BufferedWriter(new FileWriter(new File("/home/buildClazzFromParser.txt"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void mainee(String[] args) throws Exception {
|
public static void mainee(String[] args) throws Exception {
|
||||||
|
@ -41,10 +42,9 @@ 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(reader);
|
JavaParser parser = new JavaParser();
|
||||||
parser.parse();
|
parser.parse(reader);
|
||||||
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(reader);
|
JavaParser parser = new JavaParser();
|
||||||
parser.parse();
|
parser.parse(reader);
|
||||||
|
|
||||||
Class clazz = parser.getClazz();
|
Class clazz = parser.getClazz();
|
||||||
System.out.println(clazz.getName());
|
System.out.println(clazz.getName());
|
||||||
|
@ -72,17 +72,15 @@ public class JavaParser{
|
||||||
private List<Import> imports;
|
private List<Import> imports;
|
||||||
private Class clazz;
|
private Class clazz;
|
||||||
|
|
||||||
private BufferedReader reader;
|
private CleanerPool cleaner;
|
||||||
|
|
||||||
public JavaParser(BufferedReader reader){
|
public JavaParser(){}
|
||||||
this.reader = reader;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void parse() throws Exception{
|
public void parse(BufferedReader reader) throws Exception{
|
||||||
String content = "";
|
String content = "";
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
CleanerPool cleaner = new CleanerPool(
|
cleaner = new CleanerPool(
|
||||||
new Cleaner("CONSTANT_STRING",'"','"'),
|
new Cleaner("CONSTANT_STRING",'"','"'),
|
||||||
new Cleaner("CONSTANT_CHAR",'\'','\''));
|
new Cleaner("CONSTANT_CHAR",'\'','\''));
|
||||||
|
|
||||||
|
@ -131,14 +129,28 @@ public class JavaParser{
|
||||||
return this.clazz;
|
return this.clazz;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void show(){
|
public void build(BufferedWriter writer) throws Exception{
|
||||||
System.out.println("package "+this.pack.getName()+";");
|
writer.write("package "+this.pack.getName()+";\n");
|
||||||
System.out.println();
|
writer.write("\n");
|
||||||
for(Import i : this.imports) System.out.println("import "+i.getName()+";");
|
for(Import element : this.imports) writer.write("import "+element.getName()+";\n");
|
||||||
System.out.println();
|
writer.write("\n");
|
||||||
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;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
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;
|
||||||
|
@ -126,10 +127,12 @@ public class Variable extends JavaElement{
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void show(int tab){
|
|
||||||
String start = "";
|
@Override
|
||||||
for(int i = 0; i < tab; i++) start+="\t";
|
public void build(ArrayBuffer<String> buffer, int tab) throws Exception{
|
||||||
System.out.println(start+Modifier.toString(modifier)+(modifier > 0 ? " ":"")+type+" "+name+(value == null ? ";":" = "+value+";"));
|
super.build(buffer, tab);
|
||||||
|
buffer.append((s) -> s+=Modifier.toString(modifier)+(modifier > 0 ? " ":"")+type+" "+name+(value == null ? ";":" = "+value+";"));
|
||||||
|
buffer.add("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -188,16 +191,21 @@ public class Variable extends JavaElement{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void show(int tab){
|
public void build(ArrayBuffer<String> buffer, int tab) throws Exception {
|
||||||
String start = "";
|
String spacement = "";
|
||||||
for(int i = 0; i < tab; i++) start+="\t";
|
for(int i = 0; i < tab; i++) spacement+="\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);
|
||||||
System.out.println(start+Modifier.toString(getModifier())+" "+getType()+" "+vars+";");
|
String varMod = vars;
|
||||||
|
buffer.append((s) -> s+=sMod+Modifier.toString(getModifier())+" "+getType()+" "+varMod+";");
|
||||||
|
buffer.add("");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,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.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,10 +30,10 @@ public class AssigmentOperation extends JavaElement{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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+=variable+" = "+value+";");
|
||||||
System.out.println(start+variable+" = "+value+";");
|
buffer.add("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
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,12 +59,28 @@ public class ConditionalOperation extends OperationContainer{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void show(int tab) {
|
public void build(ArrayBuffer<String> buffer, int tab) throws Exception{
|
||||||
String start = "";
|
boolean empty = getChilds().size() == 0;
|
||||||
for(int i = 0; i < tab; i++) start+="\t";
|
if(empty){
|
||||||
System.out.println(start+"Condition??"+condition+"{");
|
buffer.append((s) -> s+=";");
|
||||||
for(JavaElement child : getChilds()) child.show(tab+1);
|
buffer.add("");
|
||||||
System.out.println(start+"}");
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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{
|
||||||
|
@ -73,13 +91,15 @@ public class ConditionalOperation extends OperationContainer{
|
||||||
super(PATTERN);
|
super(PATTERN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void show(int tab) {
|
public void build(ArrayBuffer<String> buffer, int tab) throws Exception{
|
||||||
String start = "";
|
String spacement = "";
|
||||||
for(int i = 0; i < tab; i++) start+="\t";
|
for(int i = 0; i < tab; i++) spacement+="\t";
|
||||||
System.out.println(start+"if"+super.condition+"{");
|
final String modSpace = spacement;
|
||||||
for(JavaElement child : getChilds()) child.show(tab+1);
|
buffer.append((s) -> s+=modSpace+"if"+super.condition);
|
||||||
System.out.println(start+"}");
|
|
||||||
|
super.build(buffer, tab);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,12 +112,13 @@ public class ConditionalOperation extends OperationContainer{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void show(int tab) {
|
public void build(ArrayBuffer<String> buffer, int tab) throws Exception{
|
||||||
String start = "";
|
String spacement = "";
|
||||||
for(int i = 0; i < tab; i++) start+="\t";
|
for(int i = 0; i < tab; i++) spacement+="\t";
|
||||||
System.out.println(start+"for"+super.condition+"{");
|
final String modSpace = spacement;
|
||||||
for(JavaElement child : getChilds()) child.show(tab+1);
|
buffer.append((s) -> s+=modSpace+"for"+super.condition);
|
||||||
System.out.println(start+"}");
|
|
||||||
|
super.build(buffer, tab);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,12 +131,13 @@ public class ConditionalOperation extends OperationContainer{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void show(int tab) {
|
public void build(ArrayBuffer<String> buffer, int tab) throws Exception{
|
||||||
String start = "";
|
String spacement = "";
|
||||||
for(int i = 0; i < tab; i++) start+="\t";
|
for(int i = 0; i < tab; i++) spacement+="\t";
|
||||||
System.out.println(start+"while"+super.condition+"{");
|
final String modSpace = spacement;
|
||||||
for(JavaElement child : getChilds()) child.show(tab+1);
|
buffer.append((s) -> s+=modSpace+"while"+super.condition);
|
||||||
System.out.println(start+"}");
|
|
||||||
|
super.build(buffer, tab);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
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;
|
||||||
|
|
||||||
|
@ -36,12 +38,16 @@ public class DoOperation extends OperationContainer{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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+="do{");
|
||||||
System.out.println(start+"do{");
|
buffer.add("");
|
||||||
for(JavaElement child : getChilds()) child.show(tab+1);
|
|
||||||
System.out.println(start+"}");
|
for(JavaElement child : getChilds()) child.build(buffer, tab+1);
|
||||||
|
|
||||||
|
super.build(buffer, tab);
|
||||||
|
buffer.append((s) -> s+="}");
|
||||||
|
buffer.add("");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
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;
|
||||||
|
|
||||||
|
@ -41,12 +43,23 @@ public class ElseOperation extends OperationContainer{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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+="else ");
|
||||||
System.out.println(start+"else{");
|
|
||||||
for(JavaElement child : getChilds()) child.show(tab+1);
|
boolean oneOperation = getChilds().size() == 1;
|
||||||
System.out.println(start+"}");
|
if(oneOperation){
|
||||||
|
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("");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
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;
|
||||||
|
|
||||||
|
@ -24,12 +26,6 @@ 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){
|
||||||
|
@ -51,11 +47,12 @@ public class LoopAffectOperation extends JavaElement{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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+="continue;");
|
||||||
System.out.println(start+"continue;");
|
buffer.add("");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class BreakOperation extends LoopAffectOperation{
|
public static class BreakOperation extends LoopAffectOperation{
|
||||||
|
@ -67,10 +64,10 @@ public class LoopAffectOperation extends JavaElement{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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+="break;");
|
||||||
System.out.println(start+"break;");
|
buffer.add("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
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,10 +35,10 @@ public class MethodCallOperation extends JavaElement{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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+=value+";");
|
||||||
System.out.println(start+value+";");
|
buffer.add("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
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,18 +39,19 @@ public class ReturnOperation extends JavaElement{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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";
|
|
||||||
if(value != null){
|
if(value != null){
|
||||||
System.out.println("return");
|
buffer.append((s) -> s+="return ");
|
||||||
value.show(tab+1);
|
value.build(buffer, 0);
|
||||||
System.out.println(";");
|
buffer.add("");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
System.out.println(start+"return "+toChange+";");
|
buffer.append((s) -> s+="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){
|
||||||
if(search.apply(this)) return (E)this;
|
if(search.apply(this)) return (E)this;
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
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,12 +40,16 @@ public class SynchronizedOperation extends OperationContainer{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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+="synchronized"+this.include+"{");
|
||||||
System.out.println(start+"synchronized"+this.include+"{");
|
buffer.add("");
|
||||||
for(JavaElement child : getChilds()) child.show(tab+1);
|
|
||||||
System.out.println(start+"}");
|
for(JavaElement child : getChilds()) child.build(buffer, tab+1);
|
||||||
|
|
||||||
|
super.build(buffer, tab);
|
||||||
|
buffer.append((s) -> s+="}");
|
||||||
|
buffer.add("");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -32,8 +32,8 @@ class OperationTest{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
JavaParser parser = new JavaParser(reader);
|
JavaParser parser = new JavaParser();
|
||||||
parser.parse();
|
parser.parse(reader);
|
||||||
return parser;
|
return parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,8 +43,6 @@ 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());
|
||||||
|
@ -60,8 +58,6 @@ 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());
|
||||||
|
@ -77,8 +73,6 @@ 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());
|
||||||
|
@ -101,8 +95,6 @@ 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());
|
||||||
|
@ -123,8 +115,6 @@ 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());
|
||||||
|
@ -145,8 +135,6 @@ 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());
|
||||||
|
|
|
@ -31,8 +31,8 @@ class SearchTest{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
JavaParser parser = new JavaParser(reader);
|
JavaParser parser = new JavaParser();
|
||||||
parser.parse();
|
parser.parse(reader);
|
||||||
return parser;
|
return parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue