Change unique char for CleanerPool

This commit is contained in:
jeffcheasey88 2023-05-10 08:15:18 +02:00
parent 57132f320a
commit 5e3208c262
4 changed files with 35 additions and 9 deletions

View file

@ -61,7 +61,7 @@ public class Class{
}
}
return matcher.group(1).length();
return cleaner.unzip(matcher.group(1), ((s,p) -> s)).length();
}
private int indexOf(String value, String target){

View file

@ -49,10 +49,10 @@ public class CleanerPool{
public List<String> constants;
public Cleaner(String pattern, char open, char close){
this.pattern = "$"+pattern;
this.pattern = "^"+pattern;
this.open = open;
this.close = close;
this.rPattern = Pattern.compile("^(.*)(\\$"+pattern+"\\d+)(.*)$");
this.rPattern = Pattern.compile("^(.*)(\\^"+pattern+"\\d+)(.*)$");
this.constants = new ArrayList<>();
}

View file

@ -1,11 +1,13 @@
package be.jeffcheasey88.peeratcode.parser.java;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import be.jeffcheasey88.peeratcode.parser.java.CleanerPool.Cleaner;
@ -22,11 +24,33 @@ public class JavaParser{
parser.show();
}
public static void main(String[] args) throws Exception {
File dir = new File("C:\\Users\\jeffc\\eclipse-workspace\\");
public static void mainee(String[] args) throws Exception {
File dir = new File("");
show(dir);
}
public static void main(String[] args) throws Exception{
String variable = "Collection collection = new ArrayList<String>() {\r\n"
+ " { add(\"1\");\r\n"
+ " add(\"2\");\r\n"
+ " add(\"3\");\r\n"
+ " }\r\n"
+ " };";
String clazz = "package test; public class Test{ "+variable+" }";
BufferedWriter writer = new BufferedWriter(new FileWriter(new File("/home/tmp.txt")));
writer.write(clazz);
writer.flush();
writer.close();
BufferedReader reader = new BufferedReader(new FileReader(new File("/home/tmp.txt")));
JavaParser parser = new JavaParser(reader);
parser.parse();
System.out.println("SHOW-----------------");
parser.show();
}
private static void show(File dir) throws Exception{
if(dir.isFile()){
if(!dir.getName().endsWith(".java")) return;
@ -80,7 +104,9 @@ public class JavaParser{
}
this.clazz = new Class();
index = this.clazz.parse(content, new CleanerPool(new Cleaner("CONSTANT_STRING",'"','"')));
index = this.clazz.parse(content, new CleanerPool(
new Cleaner("CONSTANT_STRING",'"','"'),
new Cleaner("CONSTANT_CHAR",'\'','\'')));
content = content.substring(index);
}

View file

@ -93,7 +93,7 @@ public class Variable {
private String generiqueTypes(String content, CleanerPool cleaner){
System.out.println("generic "+content);
String unzip = cleaner.unzip(content, (value, pattern) -> {
return (pattern.equals("$GENERIC_FUNCTION")) ? null : value.replaceAll("\\s+", "");
return (pattern.equals("^GENERIC_FUNCTION")) ? null : value.replaceAll("\\s+", "");
});
System.out.println("unzip "+unzip);
unzip = UNZIP_STICK.matcher(unzip).replaceAll("${e}");
@ -128,7 +128,7 @@ public class Variable {
public void show(int tab){
String start = "";
for(int i = 0; i < tab; i++) start+="\t";
System.out.println(start+Modifier.toString(modifier)+" "+type+" "+name+(value == null ? ";":"="+value+";"));
System.out.println(start+Modifier.toString(modifier)+" "+type+" "+name+(value == null ? ";":" = "+value+";"));
}
public static class Value extends Variable{