Fix Cleaner when modifier return null case

This commit is contained in:
jeffcheasey88 2023-05-30 19:31:57 +02:00
parent b800b88fb4
commit 800ad9a4e9
2 changed files with 17 additions and 5 deletions

View file

@ -34,6 +34,8 @@ public class CleanerPool{
if(matcher.matches()){
String key = matcher.group(2);
String zip = cleaner.getConstant(key);
String modified = modifier.apply(zip, cleaner.getPattern());
if(modified == null) continue;
map.put(key, cleaner.open+zip+cleaner.close);
tmp = matcher.group(1)+cleaner.open+zip+cleaner.close+matcher.group(3);
edited = true;
@ -57,7 +59,7 @@ public class CleanerPool{
String key = matcher.group(2);
String zip = cleaner.getConstant(key);
String modified = modifier.apply(zip, cleaner.getPattern());
if(modified == null) modified = zip;
if(modified == null) continue;
value = matcher.group(1)+cleaner.open+modified+cleaner.close+matcher.group(3);
edited = true;
}

View file

@ -42,9 +42,9 @@ public class OperationFactory{
* variable OK
* assignation OK
* exec method OK
* for
* for OK
* do while
* while
* while OK
* if OK
* switch case
* return OK
@ -70,8 +70,9 @@ public class OperationFactory{
new Cleaner("GENERIC_ARRAY",'[',']'),
new Cleaner("GENERIC_TYPE_",'<','>'));
content = generic.clean(content);
generiqueTypes(content, generic);
content = generiqueTypes(content, generic);
System.out.println("look for "+content);
for(Entry<Pattern, Class<? extends JavaElement>> entries : this.patterns.entrySet()){
if(entries.getKey().matcher(content).matches()) return entries.getValue().newInstance();
}
@ -86,16 +87,25 @@ public class OperationFactory{
private static Pattern UNZIP_EQUALS_RIGHT = Pattern.compile("=(?<e>[^=\\s])");
private String generiqueTypes(String content, CleanerPool cleaner){
System.out.println("base on "+content);
String unzip = cleaner.unzip(content, (value, pattern) -> {
System.out.println("unzip pattern "+pattern);
if(pattern.equals("^GENERIC_FUNCTION")) return null;
if(pattern.equals("^GENERIC_PARENTHESIS")) return value.replace("\\s+", " ");
if(pattern.equals("^GENERIC_PARENTHESIS")) return null;
System.out.println("let pass "+pattern);
return value.replaceAll("\\s+", "");
});
System.out.println("generiqueTypes on "+unzip);
unzip = UNZIP_STICK.matcher(unzip).replaceAll("${e}");
System.out.println("g => "+unzip);
unzip = UNZIP_MAJ.matcher(unzip).replaceAll("> ${e}");
System.out.println("g => "+unzip);
unzip = UNZIP_ARRAY.matcher(unzip).replaceAll("] ${e}");
System.out.println("g => "+unzip);
unzip = UNZIP_EQUALS_LEFT.matcher(unzip).replaceAll("${e} =");
System.out.println("g => "+unzip);
unzip = UNZIP_EQUALS_RIGHT.matcher(unzip).replaceAll("= ${e}");
System.out.println("g => "+unzip);
return unzip;
}
}