forked from JavaTX/JavaCompilerCore
Extended instanceOfTest
This commit is contained in:
parent
951d741d90
commit
bad5d26969
@ -22,6 +22,21 @@ Instanceof(){
|
||||
};
|
||||
}
|
||||
|
||||
void checkInstanceOfWithGuardedPattern(){
|
||||
TPH obj;
|
||||
obj = test;
|
||||
TPH flag;
|
||||
if(obj instanceof s op s.length Signature: [TPH]() op 5)
|
||||
{
|
||||
flag = s.contains Signature: [TPH, TPH](jdk);
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
java.lang.Boolean equals(java.lang.Object o){
|
||||
return o instanceof other op x op other.x op y op other.y;
|
||||
}
|
||||
|
||||
Instanceof(){
|
||||
super(());
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import java.lang.Integer;
|
||||
import java.lang.Double;
|
||||
import java.lang.String;
|
||||
import java.lang.Object;
|
||||
|
||||
public class Instanceof{
|
||||
void checkInstanceof() {
|
||||
@ -16,4 +17,20 @@ public class Instanceof{
|
||||
return "Kein Double";
|
||||
}
|
||||
}
|
||||
|
||||
void checkInstanceOfWithGuardedPattern(){
|
||||
var obj = "test";
|
||||
var flag;
|
||||
if (obj instanceof String s && s.length() > 5) {
|
||||
flag = s.contains("jdk");
|
||||
}
|
||||
}
|
||||
|
||||
record Point(int x, int y){ }
|
||||
|
||||
boolean equals(Object o) {
|
||||
return (o instanceof Point other)
|
||||
&& x == other.x
|
||||
&& y == other.y;
|
||||
}
|
||||
}
|
@ -91,6 +91,7 @@ import de.dhbwstuttgart.parser.antlr.Java17Parser.TypePatternContext;
|
||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.WhileloopContext;
|
||||
import de.dhbwstuttgart.parser.antlr.Java17Parser.YieldstmtContext;
|
||||
import de.dhbwstuttgart.parser.scope.GenericsRegistry;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||
@ -100,6 +101,7 @@ import de.dhbwstuttgart.syntaxtree.statement.AssignLeftSide;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.AssignToField;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.BoolExpression;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Break;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.CastExpr;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.DoStmt;
|
||||
@ -799,7 +801,11 @@ public class StatementGenerator {
|
||||
}
|
||||
|
||||
private Expression convert(Java17Parser.AndexpressionContext expression) {
|
||||
if (expression.expression().size() != 2) {
|
||||
throw new NotImplementedException();
|
||||
} else {
|
||||
return new BoolExpression(BoolExpression.Operator.AND, new RefType(new JavaClassName("java.lang.Boolean"), expression.getStart()), convert(expression.expression(0)), convert(expression.expression(1)), expression.getStart());
|
||||
}
|
||||
}
|
||||
|
||||
private Statement convert(AssignexpressionContext expr) {
|
||||
|
@ -5,6 +5,7 @@ import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class AbstractASTWalker implements ASTVisitor {
|
||||
@Override
|
||||
@ -168,6 +169,7 @@ public abstract class AbstractASTWalker implements ASTVisitor {
|
||||
@Override
|
||||
public void visit(IfStmt ifStmt) {
|
||||
ifStmt.then_block.accept(this);
|
||||
if (!Objects.isNull(ifStmt.else_block))
|
||||
ifStmt.else_block.accept(this);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user