forked from JavaTX/JavaCompilerCore
Tests added
This commit is contained in:
parent
07303ffa71
commit
df1c19e60d
@ -267,19 +267,19 @@ public class StatementGenerator {
|
||||
//TODO
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
//TODO Felix_K
|
||||
private Statement convert(Java8Parser.PreIncrementExpressionContext stmt) {
|
||||
return new PreIncExpr(convert(stmt.unaryExpression()),stmt.getStart());
|
||||
}
|
||||
|
||||
//TODO Felix_K
|
||||
private Statement convert(Java8Parser.PreDecrementExpressionContext stmt) {
|
||||
return new PreDecExpr(convert(stmt.unaryExpression()),stmt.getStart());
|
||||
}
|
||||
|
||||
//TODO Felix_K
|
||||
private Statement convert(Java8Parser.PostIncrementExpressionContext stmt) {
|
||||
return new PostIncExpr(convert(stmt.postfixExpression()));
|
||||
}
|
||||
|
||||
//TODO Felix_K
|
||||
private Statement convert(Java8Parser.PostDecrementExpressionContext stmt) {
|
||||
return new PostDecExpr(convert(stmt.postfixExpression()));
|
||||
}
|
||||
@ -295,49 +295,45 @@ public class StatementGenerator {
|
||||
else if (leftSide instanceof LocalVar)return new AssignToLocal((LocalVar) leftSide);
|
||||
else throw new NotImplementedException();
|
||||
}
|
||||
|
||||
//TODO Felix_K
|
||||
private Statement convert(Java8Parser.IfThenStatementContext stmt){
|
||||
Expression expr = convert(stmt.expression());
|
||||
Statement thenBlock = convert(stmt.statement());
|
||||
Statement elseBlock = new EmptyStmt(stmt.getStart());
|
||||
return new IfStmt(TypePlaceholder.fresh(stmt.getStart()),expr,thenBlock,elseBlock,stmt.getStart());
|
||||
}
|
||||
|
||||
//TODO Felix_K
|
||||
private Statement convert(Java8Parser.IfThenElseStatementContext stmt){
|
||||
Expression expr = convert(stmt.expression());
|
||||
Statement thenBlock = convert(stmt.statementNoShortIf());
|
||||
Statement elseBlock = convert(stmt.statement());
|
||||
return new IfStmt(TypePlaceholder.fresh(stmt.getStart()),expr,thenBlock,elseBlock,stmt.getStart());
|
||||
}
|
||||
|
||||
//TODO Felix_K
|
||||
private Statement convert(Java8Parser.IfThenElseStatementNoShortIfContext stmt){
|
||||
Expression expr = convert(stmt.expression());
|
||||
Statement thenBlock = convert(stmt.statementNoShortIf().get(0));
|
||||
Statement elseBlock = convert(stmt.statementNoShortIf().get(1));
|
||||
return new IfStmt(TypePlaceholder.fresh(stmt.getStart()),expr,thenBlock,elseBlock,stmt.getStart());
|
||||
}
|
||||
|
||||
//TODO Felix_K
|
||||
private Statement convert(Java8Parser.AssertStatementContext stmt)
|
||||
{
|
||||
/*
|
||||
if (stmt.expression().size()<2)
|
||||
{
|
||||
Expression expr = convert(stmt.expression(0));
|
||||
return new AssertStmt(expr,stmt.getStart());
|
||||
List<Expression> exprList= new ArrayList<Expression>();
|
||||
for (int i =0; i<stmt.expression().size();i++){
|
||||
exprList.add(convert(stmt.expression(i)));
|
||||
}
|
||||
else {
|
||||
Expression expr1 = convert(stmt.expression(0));
|
||||
Expression expr2 = convert(stmt.expression(1));
|
||||
return new AssertStmt(expr1,expr2,stmt.getStart());
|
||||
}
|
||||
*/
|
||||
//TODO: Check Felix_K
|
||||
throw new NotImplementedException();
|
||||
return new AssertStmt(TypePlaceholder.fresh(stmt.getStart()),exprList,stmt.getStart());
|
||||
}
|
||||
|
||||
//TODO Felix_K
|
||||
private Statement convert(Java8Parser.SwitchStatementContext stmt){
|
||||
//TODO Felix K
|
||||
throw new NotImplementedException();
|
||||
Expression expr = convert(stmt.expression());
|
||||
List<Statement> statementList = new ArrayList<Statement>();
|
||||
statementList.add( convert(stmt.switchBlock()));
|
||||
statementList.add(new BreakStmt(TypePlaceholder.fresh(stmt.getStart()),"",stmt.getStart()));
|
||||
Block block = new Block(statementList, stmt.getStart());
|
||||
return new SwitchStmt(TypePlaceholder.fresh(stmt.getStart()),expr,block,stmt.getStart());
|
||||
|
||||
}
|
||||
|
||||
private Statement convert(Java8Parser.SwitchBlockContext stmt){
|
||||
@ -355,7 +351,7 @@ public class StatementGenerator {
|
||||
Statement block = convert(stmt.statement());
|
||||
return new WhileStmt(expr, block,stmt.getStart());
|
||||
}
|
||||
|
||||
//TODO Felix_K
|
||||
private Statement convert(Java8Parser.WhileStatementNoShortIfContext stmt){
|
||||
Expression expr = convert(stmt.expression());
|
||||
Statement block = convert(stmt.statementNoShortIf());
|
||||
@ -383,7 +379,7 @@ public class StatementGenerator {
|
||||
return convert(stmt.enhancedForStatementNoShortIf());
|
||||
}else throw new NotImplementedException();
|
||||
}
|
||||
|
||||
//TODO Felix_K
|
||||
private Statement convert(Java8Parser.BasicForStatementContext stmt){
|
||||
List<Statement> stateList = new ArrayList<>();
|
||||
List<Statement> whileList = new ArrayList<>();
|
||||
@ -402,7 +398,7 @@ public class StatementGenerator {
|
||||
whileList.add(new WhileStmt(expr,forBlock,stmt.getStart()));
|
||||
return new Block(whileList,stmt.getStart());
|
||||
}
|
||||
|
||||
//TODO Felix_K
|
||||
private Statement convert(Java8Parser.BasicForStatementNoShortIfContext stmt){
|
||||
List<Statement> stateList = new ArrayList<>();
|
||||
List<Statement> whileList = new ArrayList<>();
|
||||
@ -429,7 +425,7 @@ public class StatementGenerator {
|
||||
return convert(stmt.localVariableDeclaration());
|
||||
}else throw new NotImplementedException();
|
||||
}
|
||||
|
||||
//TODO Felix_K
|
||||
private List<Statement> convert(Java8Parser.LocalVariableDeclarationContext declaration) {
|
||||
List<Statement> ret = new ArrayList<>();
|
||||
if(declaration.variableModifier() != null && declaration.variableModifier().size() > 0){
|
||||
@ -499,7 +495,7 @@ public class StatementGenerator {
|
||||
//TODO
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
//TODO Felix_K
|
||||
private Statement convert(Java8Parser.BreakStatementContext stmt){
|
||||
if (stmt.Identifier()==null)
|
||||
{
|
||||
@ -508,7 +504,7 @@ public class StatementGenerator {
|
||||
}
|
||||
return new BreakStmt(TypePlaceholder.fresh(stmt.getStart()),stmt.Identifier().getText(),stmt.getStart());
|
||||
}
|
||||
|
||||
//TODO Felix_K
|
||||
private Statement convert(Java8Parser.ContinueStatementContext stmt){
|
||||
if (stmt.Identifier()==null){
|
||||
String indentifier = "";
|
||||
|
@ -4,13 +4,15 @@ import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Felix_K on 21.09.2017.
|
||||
*/
|
||||
public class AssertStmt extends Statement
|
||||
{
|
||||
final Expression expr;
|
||||
public AssertStmt(RefTypeOrTPHOrWildcardOrGeneric type, Expression expr, Token offset){
|
||||
final List<Expression> expr;
|
||||
public AssertStmt(RefTypeOrTPHOrWildcardOrGeneric type, List<Expression> expr, Token offset){
|
||||
super(type, offset);
|
||||
this.expr=expr;
|
||||
}
|
||||
|
23
src/de/dhbwstuttgart/syntaxtree/statement/SwitchStmt.java
Normal file
23
src/de/dhbwstuttgart/syntaxtree/statement/SwitchStmt.java
Normal file
@ -0,0 +1,23 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
/**
|
||||
* Created by Felix_K on 23.09.2017.
|
||||
*/
|
||||
public class SwitchStmt extends Statement
|
||||
{
|
||||
final Expression expr;
|
||||
final Block switchBlock;
|
||||
public SwitchStmt(RefTypeOrTPHOrWildcardOrGeneric type,Expression expr, Block block, Token offset){
|
||||
super(type,offset);
|
||||
this.expr=expr;
|
||||
this.switchBlock=block;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(StatementVisitor visitor) {
|
||||
}
|
||||
}
|
7
test/parser/AssertTest.jav
Normal file
7
test/parser/AssertTest.jav
Normal file
@ -0,0 +1,7 @@
|
||||
class AssertTest
|
||||
{
|
||||
void assertMethod()
|
||||
{
|
||||
assert true;
|
||||
}
|
||||
}
|
10
test/parser/PrePostOperationTest.jav
Normal file
10
test/parser/PrePostOperationTest.jav
Normal file
@ -0,0 +1,10 @@
|
||||
public class TestClass
|
||||
{
|
||||
void testMethod()
|
||||
{
|
||||
++i;
|
||||
i++;
|
||||
--i;
|
||||
i--;
|
||||
}
|
||||
}
|
11
test/parser/SwitchTest.jav
Normal file
11
test/parser/SwitchTest.jav
Normal file
@ -0,0 +1,11 @@
|
||||
public class SwitchTest
|
||||
{
|
||||
void testMethod()
|
||||
{
|
||||
switch(i)
|
||||
{
|
||||
case i:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user