All Case for declaring vars
This commit is contained in:
parent
b0da444be1
commit
38f22e48b0
2 changed files with 24 additions and 6 deletions
|
@ -41,18 +41,16 @@ public class Class{
|
||||||
int equals = indexOf(content,"=");
|
int equals = indexOf(content,"=");
|
||||||
if(quotes < braces && quotes < equals){
|
if(quotes < braces && quotes < equals){
|
||||||
boolean quote = false;
|
boolean quote = false;
|
||||||
Variable last = null;
|
Variable variable = null;
|
||||||
do {
|
do {
|
||||||
Variable variable = (last == null) ? new Variable() : new Variable(last.getModifier(), last.getType());
|
variable = (variable == null) ? new Variable() : new Variable(variable.getModifier(), variable.getType());
|
||||||
int index = variable.parse(content, cleaner);
|
int index = variable.parse(content, cleaner);
|
||||||
this.vars.add(variable);
|
this.vars.add(variable);
|
||||||
content = content.substring(index);
|
content = content.substring(index);
|
||||||
quote = content.startsWith(",");
|
quote = content.startsWith(",");
|
||||||
if(quote) {
|
if(quote) content = content.substring(1);
|
||||||
content = content.substring(1);
|
|
||||||
last = variable;
|
|
||||||
}
|
|
||||||
}while(quote);
|
}while(quote);
|
||||||
|
content = content.substring(1);
|
||||||
}else if(equals < braces){
|
}else if(equals < braces){
|
||||||
//variable with value
|
//variable with value
|
||||||
boolean quote = false;
|
boolean quote = false;
|
||||||
|
|
|
@ -167,4 +167,24 @@ class VariableTest{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void case9(){
|
||||||
|
try {
|
||||||
|
Class clazz = new Class();
|
||||||
|
clazz.parse(cleaner.clean("public class Test{ int i ,j,k,l; } "), cleaner);
|
||||||
|
|
||||||
|
List<Variable> vars = clazz.getVariables();
|
||||||
|
assertEquals(vars.size(), 4);
|
||||||
|
for(int i = 0; i < 3; i++){
|
||||||
|
Variable v = vars.get(i);
|
||||||
|
assertEquals(0, v.getModifier());
|
||||||
|
assertEquals("int", v.getType());
|
||||||
|
assertEquals((char)('i'+i), v.getName().charAt(0));
|
||||||
|
assertNull(v.getValue());
|
||||||
|
}
|
||||||
|
}catch(Exception e){
|
||||||
|
fail(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue