diff --git a/resources/bytecode/javFiles/Op1.jav b/resources/bytecode/javFiles/Op1.jav index 800f58b8..426569dc 100644 --- a/resources/bytecode/javFiles/Op1.jav +++ b/resources/bytecode/javFiles/Op1.jav @@ -1,11 +1,9 @@ -public class Op1{ - public Op1() { - - Runnable lam = () -> { - String test = ""; - String b = "b"; - test = b; - System.out.println(test);}; - //lam.run(); +import java.lang.Boolean; + +public class Op1 { + public m() { + var b = false; + var c = !b; + return c; } } \ No newline at end of file diff --git a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java index 26c9728c..7bdb0489 100644 --- a/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java +++ b/src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java @@ -996,6 +996,9 @@ public class StatementGenerator { ret = new UnaryExpr(UnaryExpr.Operation.PREDECREMENT, expr, TypePlaceholder.fresh(op), op); ret.setStatement(); return ret; + } else if (op.getText().equals("!")) { + ret = new UnaryExpr(UnaryExpr.Operation.NOT, expr, TypePlaceholder.fresh(op), op); + return ret; } else { throw new NotImplementedException(); } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index f4df7a50..4cf55ce9 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -245,6 +245,9 @@ public class TYPEStmt implements StatementVisitor { constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), number, PairOperator.SMALLERNEQDOT, loc(unaryExpr.getOffset()))); // The type of the postfix increment expression is the type of the variable constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), unaryExpr.getType(), PairOperator.EQUALSDOT, loc(unaryExpr.getOffset()))); + } else if (unaryExpr.operation == UnaryExpr.Operation.NOT) { + constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), unaryExpr.getType(), PairOperator.EQUALSDOT, loc(unaryExpr.getOffset()))); + constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), new RefType(ASTFactory.createClass(java.lang.Boolean.class).getClassName(), new NullToken()), PairOperator.EQUALSDOT, loc(unaryExpr.getOffset()))); } else { throw new NotImplementedException(); } diff --git a/src/test/java/TestComplete.java b/src/test/java/TestComplete.java index 06a99ca7..671e9529 100644 --- a/src/test/java/TestComplete.java +++ b/src/test/java/TestComplete.java @@ -837,6 +837,14 @@ public class TestComplete { assertEquals(clazz.getSuperclass().getDeclaredField("x").get(instance), 3); } + @Test + public void testOperators() throws Exception { + var classFiles = generateClassFiles(new ByteArrayClassLoader(), "Op1.jav"); + var clazz = classFiles.get("Op1"); + var instance = clazz.getDeclaredConstructor().newInstance(); + assertEquals(clazz.getDeclaredMethod("m").invoke(instance), true); + } + @Ignore("Not implemented") @Test public void testStringConcat() throws Exception {