Fix multiple equals & Take Case when value has spaces
This commit is contained in:
parent
e6ad2822eb
commit
8941eac25c
5 changed files with 45 additions and 11 deletions
|
@ -74,7 +74,12 @@ public class CleanerPool{
|
|||
for(int i = 0; i < value.length(); i++){
|
||||
char c = value.charAt(i);
|
||||
if(c == open){
|
||||
i+=cutOpenable(value.substring(i+1), constants, pattern, open, close);
|
||||
int cut = cutOpenable(value.substring(i+1), constants, pattern, open, close);
|
||||
if(cut < 0){
|
||||
builder.append(c);
|
||||
continue;
|
||||
}
|
||||
i+=cut;
|
||||
builder.append(pattern+(constants.size()-1));
|
||||
}else{
|
||||
builder.append(c);
|
||||
|
@ -89,17 +94,22 @@ public class CleanerPool{
|
|||
for(;i < value.length(); i++){
|
||||
char c = value.charAt(i);
|
||||
if(c == close){
|
||||
break;
|
||||
constants.add(builder.toString());
|
||||
return i+1;
|
||||
}else if(c == open){
|
||||
i+=cutOpenable(value.substring(i+1), constants, pattern, open, close);
|
||||
int cut = cutOpenable(value.substring(i+1), constants, pattern, open, close);
|
||||
if(cut < 0){
|
||||
builder.append(c);
|
||||
continue;
|
||||
}
|
||||
i+=cut;
|
||||
builder.append(pattern+(constants.size()-1));
|
||||
}else{
|
||||
builder.append(c);
|
||||
}
|
||||
}
|
||||
|
||||
constants.add(builder.toString());
|
||||
return i+1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ public class JavaParser {
|
|||
}
|
||||
|
||||
this.clazz = new Class();
|
||||
index = this.clazz.parse(content, new CleanerPool());
|
||||
index = this.clazz.parse(content, new CleanerPool(new Cleaner("CONSTANT_STRING",'"','"')));
|
||||
content = content.substring(index);
|
||||
}
|
||||
|
||||
|
@ -95,5 +95,5 @@ public class JavaParser {
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -63,8 +63,9 @@ public class Variable {
|
|||
System.out.println("ah");
|
||||
values.next();
|
||||
if(!values.hasNext()) return;
|
||||
this.value = new Value(values.next());
|
||||
System.out.println("VALUE IS "+value);
|
||||
String spacesValue = values.next();
|
||||
while(values.hasNext()) spacesValue+=" "+values.next();
|
||||
this.value = new Value(spacesValue);
|
||||
}
|
||||
|
||||
private Iterator<String> onlyDefine(String content, CleanerPool cleaner){
|
||||
|
@ -91,8 +92,8 @@ public class Variable {
|
|||
unzip(content, (s) -> s.replaceAll("\\s+", "")).
|
||||
replaceAll(">(?<varname>[^>\\d,;])", "> ${varname}").
|
||||
replaceAll("](?<varname>[^\\[\\d,;])", "] ${varname}").
|
||||
replaceAll("(?<varname>[^\\s=])=","${varname} =").
|
||||
replaceAll("=(?<varname>[^\\s=])"," = ${varname}");
|
||||
replaceAll("(?<varname>[^=\\s])=","${varname} =").
|
||||
replaceAll("=(?<varname>[^=\\s])","= ${varname}");
|
||||
}
|
||||
|
||||
private int indexOf(String value, String target){
|
||||
|
|
|
@ -3,6 +3,7 @@ package be.jeffcheasey88.peeratcode.parser.java;
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -16,4 +17,11 @@ public class CleanerTest {
|
|||
String result = cleaner.clean("Test0< List< Map< Test1, List< Test2 >, Test3>> > ");
|
||||
assertEquals("Test0$TEST3 ", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
void sameOpenClose(){
|
||||
CleanerPool cleaner = new CleanerPool(new Cleaner("STRINGS",'"','"'));
|
||||
String result = cleaner.clean("Pattern.compile(\"^\\s*(import\\s+([^;]*);).*$\");");
|
||||
assertEquals("Pattern.compile($STRINGS0);", result);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -187,4 +187,19 @@ class VariableTest{
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void case10(){
|
||||
try {
|
||||
Variable variable = new Variable();
|
||||
variable.parse(cleaner.clean(" boolean i = j << 3==0 ; "), cleaner);
|
||||
|
||||
assertEquals(0, variable.getModifier());
|
||||
assertEquals("boolean", variable.getType());
|
||||
assertEquals("i", variable.getName());
|
||||
assertEquals("j << 3 == 0", ((Value)variable.getValue()).value());
|
||||
}catch(Exception e){
|
||||
fail(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue