Operation -> Continue
This commit is contained in:
parent
89fd0553a2
commit
eba6a051fd
3 changed files with 78 additions and 3 deletions
|
@ -0,0 +1,47 @@
|
||||||
|
package be.jeffcheasey88.peeratcode.parser.java.operations;
|
||||||
|
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.java.CleanerPool;
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.java.JavaElement;
|
||||||
|
|
||||||
|
public class LoopAffectOperation extends JavaElement{
|
||||||
|
|
||||||
|
private Pattern pattern;
|
||||||
|
|
||||||
|
public LoopAffectOperation(Pattern pattern){
|
||||||
|
this.pattern = pattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int parse(String content, CleanerPool global, CleanerPool local) throws Exception{
|
||||||
|
Matcher matcher = this.pattern.matcher(content);
|
||||||
|
matcher.matches();
|
||||||
|
|
||||||
|
return matcher.group(1).length();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void show(int tab){
|
||||||
|
String start = "";
|
||||||
|
for(int i = 0; i < tab; i++) start+="\t";
|
||||||
|
System.out.println(start+"loop affect??;");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ContinueOperation extends LoopAffectOperation{
|
||||||
|
|
||||||
|
private static Pattern PATTERN = Pattern.compile("^(\\s*continue\\s*;).*$");
|
||||||
|
|
||||||
|
public ContinueOperation(){
|
||||||
|
super(PATTERN);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void show(int tab){
|
||||||
|
String start = "";
|
||||||
|
for(int i = 0; i < tab; i++) start+="\t";
|
||||||
|
System.out.println(start+"continue;");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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.ContinueOperation;
|
||||||
|
|
||||||
public class OperationFactory{
|
public class OperationFactory{
|
||||||
|
|
||||||
|
@ -33,6 +34,8 @@ public class OperationFactory{
|
||||||
this.patterns.put(Pattern.compile("^\\s*else\\s*.*$"), ElseOperation.class);
|
this.patterns.put(Pattern.compile("^\\s*else\\s*.*$"), ElseOperation.class);
|
||||||
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*[^\\^\\s]+\\^GENERIC_PARENTHESIS\\d+;.*$"), MethodCallOperation.class);
|
this.patterns.put(Pattern.compile("^\\s*[^\\^\\s]+\\^GENERIC_PARENTHESIS\\d+;.*$"), MethodCallOperation.class);
|
||||||
|
|
||||||
this.patterns.put(Pattern.compile("^\\s*[^\\s]+\\s+[^\\s]+\\s*=\\s*[^;]+;.*$"), Variable.class);
|
this.patterns.put(Pattern.compile("^\\s*[^\\s]+\\s+[^\\s]+\\s*=\\s*[^;]+;.*$"), Variable.class);
|
||||||
|
@ -50,7 +53,7 @@ public class OperationFactory{
|
||||||
* if OK
|
* if OK
|
||||||
* switch case
|
* switch case
|
||||||
* return OK
|
* return OK
|
||||||
* continue
|
* continue OK
|
||||||
* break
|
* break
|
||||||
* try catch finally
|
* try catch finally
|
||||||
* throw
|
* throw
|
||||||
|
|
|
@ -10,9 +10,12 @@ import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.TestInstance;
|
import org.junit.jupiter.api.TestInstance;
|
||||||
import org.junit.jupiter.api.TestInstance.Lifecycle;
|
import org.junit.jupiter.api.TestInstance.Lifecycle;
|
||||||
|
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.operations.DoOperation;
|
import be.jeffcheasey88.peeratcode.parser.java.operations.ConditionalOperation.ForOperation;
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.operations.MethodCallOperation;
|
|
||||||
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.LoopAffectOperation.ContinueOperation;
|
||||||
|
import be.jeffcheasey88.peeratcode.parser.java.operations.MethodCallOperation;
|
||||||
|
import kotlin.coroutines.Continuation;
|
||||||
|
|
||||||
@TestInstance(Lifecycle.PER_CLASS)
|
@TestInstance(Lifecycle.PER_CLASS)
|
||||||
class OperationTest{
|
class OperationTest{
|
||||||
|
@ -90,4 +93,26 @@ class OperationTest{
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void continueOperation(){
|
||||||
|
try {
|
||||||
|
JavaParser parser = parse("package be.jeffcheasey88.peeratcode.parser.java; class Test{ void function(){ for(int i = 0; i < 1; i++) continue; } }");
|
||||||
|
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(ContinueOperation.class, f.getChilds().get(0).getClass());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue