Operation -> Break
This commit is contained in:
parent
eba6a051fd
commit
6f8a1b4ceb
3 changed files with 42 additions and 2 deletions
|
@ -44,4 +44,20 @@ public class LoopAffectOperation extends JavaElement{
|
||||||
System.out.println(start+"continue;");
|
System.out.println(start+"continue;");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class BreakOperation extends LoopAffectOperation{
|
||||||
|
|
||||||
|
private static Pattern PATTERN = Pattern.compile("^(\\s*break\\s*;).*$");
|
||||||
|
|
||||||
|
public BreakOperation(){
|
||||||
|
super(PATTERN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void show(int tab){
|
||||||
|
String start = "";
|
||||||
|
for(int i = 0; i < tab; i++) start+="\t";
|
||||||
|
System.out.println(start+"break;");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import be.jeffcheasey88.peeratcode.parser.java.Variable;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.operations.ConditionalOperation.ForOperation;
|
import be.jeffcheasey88.peeratcode.parser.java.operations.ConditionalOperation.ForOperation;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.operations.ConditionalOperation.IfOperation;
|
import be.jeffcheasey88.peeratcode.parser.java.operations.ConditionalOperation.IfOperation;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.operations.ConditionalOperation.WhileOperation;
|
import be.jeffcheasey88.peeratcode.parser.java.operations.ConditionalOperation.WhileOperation;
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.java.operations.LoopAffectOperation.BreakOperation;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.operations.LoopAffectOperation.ContinueOperation;
|
import be.jeffcheasey88.peeratcode.parser.java.operations.LoopAffectOperation.ContinueOperation;
|
||||||
|
|
||||||
public class OperationFactory{
|
public class OperationFactory{
|
||||||
|
@ -35,6 +36,7 @@ public class OperationFactory{
|
||||||
this.patterns.put(Pattern.compile("^\\s*do\\s*\\^GENERIC_FUNCTION\\d+.*$"), DoOperation.class);
|
this.patterns.put(Pattern.compile("^\\s*do\\s*\\^GENERIC_FUNCTION\\d+.*$"), DoOperation.class);
|
||||||
|
|
||||||
this.patterns.put(Pattern.compile("^\\s*continue\\s*;.*$"), ContinueOperation.class);
|
this.patterns.put(Pattern.compile("^\\s*continue\\s*;.*$"), ContinueOperation.class);
|
||||||
|
this.patterns.put(Pattern.compile("^\\s*break\\s*;.*$"), BreakOperation.class);
|
||||||
|
|
||||||
this.patterns.put(Pattern.compile("^\\s*[^\\^\\s]+\\^GENERIC_PARENTHESIS\\d+;.*$"), MethodCallOperation.class);
|
this.patterns.put(Pattern.compile("^\\s*[^\\^\\s]+\\^GENERIC_PARENTHESIS\\d+;.*$"), MethodCallOperation.class);
|
||||||
|
|
||||||
|
@ -54,7 +56,7 @@ public class OperationFactory{
|
||||||
* switch case
|
* switch case
|
||||||
* return OK
|
* return OK
|
||||||
* continue OK
|
* continue OK
|
||||||
* break
|
* break OK
|
||||||
* try catch finally
|
* try catch finally
|
||||||
* throw
|
* throw
|
||||||
* else OK
|
* else OK
|
||||||
|
|
|
@ -13,9 +13,9 @@ import org.junit.jupiter.api.TestInstance.Lifecycle;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.operations.ConditionalOperation.ForOperation;
|
import be.jeffcheasey88.peeratcode.parser.java.operations.ConditionalOperation.ForOperation;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.operations.ConditionalOperation.WhileOperation;
|
import be.jeffcheasey88.peeratcode.parser.java.operations.ConditionalOperation.WhileOperation;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.operations.DoOperation;
|
import be.jeffcheasey88.peeratcode.parser.java.operations.DoOperation;
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.java.operations.LoopAffectOperation.BreakOperation;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.operations.LoopAffectOperation.ContinueOperation;
|
import be.jeffcheasey88.peeratcode.parser.java.operations.LoopAffectOperation.ContinueOperation;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.operations.MethodCallOperation;
|
import be.jeffcheasey88.peeratcode.parser.java.operations.MethodCallOperation;
|
||||||
import kotlin.coroutines.Continuation;
|
|
||||||
|
|
||||||
@TestInstance(Lifecycle.PER_CLASS)
|
@TestInstance(Lifecycle.PER_CLASS)
|
||||||
class OperationTest{
|
class OperationTest{
|
||||||
|
@ -115,4 +115,26 @@ class OperationTest{
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void breakOperation(){
|
||||||
|
try {
|
||||||
|
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();
|
||||||
|
|
||||||
|
clazz.show(0);
|
||||||
|
|
||||||
|
assertEquals(1, clazz.getChilds().size());
|
||||||
|
Function function = (Function) clazz.getChilds().get(0);
|
||||||
|
assertEquals(1, function.getChilds().size());
|
||||||
|
|
||||||
|
assertEquals(ForOperation.class, function.getChilds().get(0).getClass());
|
||||||
|
ForOperation f = (ForOperation)function.getChilds().get(0);
|
||||||
|
assertEquals(1, f.getChilds().size());
|
||||||
|
assertEquals(BreakOperation.class, f.getChilds().get(0).getClass());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue