Skip to content

Commit 9ca72ac

Browse files
committed
fix CreatingASTVisitor
1 parent be978f2 commit 9ca72ac

8 files changed

Lines changed: 71 additions & 23 deletions

File tree

key.core/src/main/java/de/uka/ilkd/key/java/ast/declaration/Modifier.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
import java.util.List;
77

88
import de.uka.ilkd.key.java.ast.*;
9-
import de.uka.ilkd.key.java.ast.expression.operator.BinaryOperator;
109
import de.uka.ilkd.key.java.visitor.Visitor;
11-
1210
import de.uka.ilkd.key.rule.MatchConditions;
13-
import org.jspecify.annotations.Nullable;
11+
1412
import org.key_project.logic.SyntaxElement;
1513

1614
import org.jspecify.annotations.NullMarked;
15+
import org.jspecify.annotations.Nullable;
1716

1817
/**
1918
*
@@ -56,7 +55,7 @@ public void visit(Visitor v) {
5655
@Override
5756
public @Nullable MatchConditions match(SourceData source, MatchConditions matchCond) {
5857
final ProgramElement src = source.getSource();
59-
if(src instanceof Modifier other) {
58+
if (src instanceof Modifier other) {
6059
if (this.keyword.equals(other.getKind())) {
6160
return super.match(source, matchCond);
6261
}

key.core/src/main/java/de/uka/ilkd/key/java/ast/expression/Assignment.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@
1313
import de.uka.ilkd.key.java.ast.SourceData;
1414
import de.uka.ilkd.key.java.ast.abstraction.KeYJavaType;
1515
import de.uka.ilkd.key.java.ast.expression.literal.BooleanLiteral;
16-
import de.uka.ilkd.key.java.ast.expression.operator.LogicFunctionalOperator;
1716
import de.uka.ilkd.key.java.ast.reference.ExecutionContext;
1817
import de.uka.ilkd.key.java.visitor.Visitor;
19-
2018
import de.uka.ilkd.key.rule.MatchConditions;
21-
import org.jspecify.annotations.Nullable;
19+
2220
import org.key_project.util.ExtList;
2321
import org.key_project.util.collection.ImmutableArray;
2422

2523
import org.jspecify.annotations.NullMarked;
24+
import org.jspecify.annotations.Nullable;
2625

2726
import static de.uka.ilkd.key.java.ast.expression.Assignment.AssignmentKind.COPY;
2827

@@ -32,6 +31,11 @@
3231
*/
3332
@NullMarked
3433
public final class Assignment extends Operator implements ExpressionStatement {
34+
public Assignment(AssignmentKind kind, ExtList changeList) {
35+
super(changeList);
36+
this.kind = kind;
37+
}
38+
3539
@Override
3640
public void visit(Visitor v) {
3741
v.performActionOnAssignment(this);
@@ -109,7 +113,7 @@ public boolean isLeftAssociative() {
109113
@Override
110114
public @Nullable MatchConditions match(SourceData source, MatchConditions matchCond) {
111115
final ProgramElement src = source.getSource();
112-
if(src instanceof Assignment other) {
116+
if (src instanceof Assignment other) {
113117
if (getKind().equals(other.getKind())) {
114118
return super.match(source, matchCond);
115119
}

key.core/src/main/java/de/uka/ilkd/key/java/ast/expression/operator/BinaryOperator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import de.uka.ilkd.key.java.ast.expression.Operator;
1818
import de.uka.ilkd.key.java.ast.reference.ExecutionContext;
1919
import de.uka.ilkd.key.java.visitor.Visitor;
20-
2120
import de.uka.ilkd.key.rule.MatchConditions;
21+
2222
import org.key_project.util.ExtList;
2323
import org.key_project.util.collection.ImmutableArray;
2424

@@ -79,8 +79,8 @@ public KeYJavaType getKeYJavaType(Services javaServ, ExecutionContext ec) {
7979

8080
@Override
8181
public MatchConditions match(SourceData source, MatchConditions matchCond) {
82-
final ProgramElement src = source.getSource(); // [ left, right ]
83-
if(src instanceof BinaryOperator other) {
82+
final ProgramElement src = source.getSource();
83+
if (src instanceof BinaryOperator other) {
8484
if (this.kind.equals(other.getKind())) {
8585
return super.match(source, matchCond);
8686
}

key.core/src/main/java/de/uka/ilkd/key/java/ast/expression/operator/BinaryOperatorKind.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* This file is part of KeY - https://key-project.org
2+
* KeY is licensed under the GNU General Public License Version 2
3+
* SPDX-License-Identifier: GPL-2.0-only */
14
package de.uka.ilkd.key.java.ast.expression.operator;
25

36
/**

key.core/src/main/java/de/uka/ilkd/key/java/ast/expression/operator/LogicFunctionalOperator.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
import de.uka.ilkd.key.java.ast.reference.ExecutionContext;
1919
import de.uka.ilkd.key.java.visitor.Visitor;
2020
import de.uka.ilkd.key.pp.PrettyPrinter;
21-
2221
import de.uka.ilkd.key.rule.MatchConditions;
23-
import org.jspecify.annotations.Nullable;
22+
23+
import org.key_project.util.ExtList;
2424
import org.key_project.util.collection.ImmutableArray;
2525

26+
import org.jspecify.annotations.Nullable;
27+
2628
import static de.uka.ilkd.key.pp.PrettyPrinter.*;
2729

2830
/**
@@ -49,6 +51,11 @@ public LogicFunctionalOperator(PositionInfo pi, List<Comment> c, LogicFunction f
4951
this.function = fn;
5052
}
5153

54+
public LogicFunctionalOperator(LogicFunction function, ExtList changeList) {
55+
super(changeList);
56+
this.function = function;
57+
}
58+
5259

5360
public enum LogicFunction {
5461
Intersect(2, 1, PrimitiveType.JAVA_LOCSET, AsFunction("\\intersect")),
@@ -109,7 +116,7 @@ public KeYJavaType getKeYJavaType(Services javaServ, ExecutionContext ec) {
109116
@Override
110117
public @Nullable MatchConditions match(SourceData source, MatchConditions matchCond) {
111118
final ProgramElement src = source.getSource();
112-
if(src instanceof LogicFunctionalOperator other) {
119+
if (src instanceof LogicFunctionalOperator other) {
113120
if (getFunction().equals(other.getFunction())) {
114121
return super.match(source, matchCond);
115122
}

key.core/src/main/java/de/uka/ilkd/key/java/ast/expression/operator/UnaryOperator.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import de.uka.ilkd.key.java.ast.reference.ExecutionContext;
1717
import de.uka.ilkd.key.java.visitor.Visitor;
1818
import de.uka.ilkd.key.rule.MatchConditions;
19+
import org.key_project.util.ExtList;
1920
import org.key_project.util.collection.ImmutableArray;
2021

2122
import java.util.List;
@@ -39,6 +40,16 @@ public UnaryOperator(PositionInfo pi, List<Comment> c, UnaryOperatorKind op, Exp
3940
this.kind = op;
4041
}
4142

43+
public UnaryOperator(ExtList changeList) {
44+
super(changeList);
45+
kind = changeList.get(UnaryOperatorKind.class);
46+
}
47+
48+
public UnaryOperator(UnaryOperatorKind kind, ExtList changeList) {
49+
super(changeList);
50+
this.kind = kind;
51+
}
52+
4253
public UnaryOperatorKind getKind() {
4354
return kind;
4455
}
@@ -77,10 +88,8 @@ public KeYJavaType getKeYJavaType(Services javaServ, ExecutionContext ec) {
7788
try {
7889
return switch (kind) {
7990
case POST_DECREMENT, POST_INCREMENT,
80-
PRE_DECREMENT, PRE_INCREMENT ->
81-
tc.getKeYJavaType((Expression) getChildAt(0), ec);
82-
default ->
83-
tc.getPromotedType(tc.getKeYJavaType((Expression) getChildAt(0), ec));
91+
PRE_DECREMENT, PRE_INCREMENT -> tc.getKeYJavaType((Expression) getChildAt(0), ec);
92+
default -> tc.getPromotedType(tc.getKeYJavaType((Expression) getChildAt(0), ec));
8493
};
8594
} catch (Exception e) {
8695
throw new RuntimeException("Type promotion failed (see below). Operator was " + this,

key.core/src/main/java/de/uka/ilkd/key/java/ast/expression/operator/UnaryOperatorKind.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* This file is part of KeY - https://key-project.org
2+
* KeY is licensed under the GNU General Public License Version 2
3+
* SPDX-License-Identifier: GPL-2.0-only */
14
package de.uka.ilkd.key.java.ast.expression.operator;
25

36
import de.uka.ilkd.key.java.ast.expression.Operator;

key.core/src/main/java/de/uka/ilkd/key/java/visitor/CreatingASTVisitor.java

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -964,22 +964,45 @@ ProgramElement createNewElement(ExtList changeList) {
964964

965965
@Override
966966
public void performActionOnBinaryOperator(BinaryOperator x) {
967-
super.performActionOnBinaryOperator(x);
967+
DefaultAction def = new DefaultAction(x) {
968+
@Override
969+
ProgramElement createNewElement(ExtList changeList) {
970+
return new BinaryOperator(x.getKind(), changeList);
971+
}
972+
};
973+
def.doAction(x);
968974
}
969975

970976
@Override
971977
public void performActionOnUnaryOperator(UnaryOperator x) {
972-
super.performActionOnUnaryOperator(x);
978+
DefaultAction def = new DefaultAction(x) {
979+
@Override
980+
ProgramElement createNewElement(ExtList changeList) {
981+
return new UnaryOperator(x.kind, changeList);
982+
}
983+
};
984+
def.doAction(x);
973985
}
974986

975987
@Override
976988
public void performActionOnLogicFunctionalOperator(LogicFunctionalOperator x) {
977-
super.performActionOnLogicFunctionalOperator(x);
978-
}
989+
DefaultAction def = new DefaultAction(x) {
990+
@Override
991+
ProgramElement createNewElement(ExtList changeList) {
992+
return new LogicFunctionalOperator(x.getFunction(), changeList);
993+
}
994+
};
995+
def.doAction(x); }
979996

980997
@Override
981998
public void performActionOnAssignment(Assignment x) {
982-
super.performActionOnAssignment(x);
999+
DefaultAction def = new DefaultAction(x) {
1000+
@Override
1001+
ProgramElement createNewElement(ExtList changeList) {
1002+
return new Assignment(x.getKind(), changeList);
1003+
}
1004+
};
1005+
def.doAction(x);
9831006
}
9841007

9851008
@Override

0 commit comments

Comments
 (0)