Skip to content

Commit 6c808a3

Browse files
authored
Applying Java 17 refactorings (#3252)
Applies refactorings after the switch to Java 17 for after #3241. Including: * Transform immutable data classes to Java records * Rewrite `instanceof` and casts to Pattern expressions * Use `.toList()` instead of `.collect(Collectors.toList)` * Use Text Block Literals (`""" ... """`) on large strings instead of concatenation cascades.
2 parents 899ae9a + 26c0d78 commit 6c808a3

494 files changed

Lines changed: 2647 additions & 4339 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ plugins {
2121
// id "com.github.ben-manes.versions" version "0.39.0"
2222

2323
// Code formatting
24-
id "com.diffplug.spotless" version "6.16.0"
24+
id "com.diffplug.spotless" version "6.20.0"
2525
}
2626

2727
// Configure this project for use inside IntelliJ:
@@ -335,7 +335,10 @@ subprojects {
335335
toggleOffOn()
336336

337337
removeUnusedImports()
338-
eclipse().configFile("$rootDir/scripts/tools/checkstyle/keyCodeStyle.xml")
338+
/* At the moment, we have to ensure that version 4.22 of the eclipse formatter is run, since newer versions
339+
* of the formatter crash in SymbolicExecutionTreeBuilder (seems to be a but in the formatter)!
340+
*/
341+
eclipse("4.22").configFile("$rootDir/scripts/tools/checkstyle/keyCodeStyle.xml")
339342
trimTrailingWhitespace() // not sure how to set this in the xml file ...
340343
//googleJavaFormat().aosp().reflowLongStrings()
341344

key.core.proof_references/src/main/java/de/uka/ilkd/key/proof_references/analyst/ClassAxiomAndInvariantProofReferencesAnalyst.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@ public LinkedHashSet<IProofReference<?>> computeReferences(Node node, Services s
6565
}
6666
}
6767
}
68-
if (found instanceof PartialInvAxiom) {
68+
if (found instanceof PartialInvAxiom axiom) {
6969
// Invariant was applied
70-
PartialInvAxiom axiom = (PartialInvAxiom) found;
7170
DefaultProofReference<ClassInvariant> reference =
7271
new DefaultProofReference<>(IProofReference.USE_INVARIANT,
7372
node, axiom.getInv());

key.core.proof_references/src/main/java/de/uka/ilkd/key/proof_references/analyst/ContractProofReferencesAnalyst.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ public class ContractProofReferencesAnalyst implements IProofReferencesAnalyst {
2323
*/
2424
@Override
2525
public LinkedHashSet<IProofReference<?>> computeReferences(Node node, Services services) {
26-
if (node.getAppliedRuleApp() instanceof AbstractContractRuleApp) {
27-
AbstractContractRuleApp contractRuleApp =
28-
(AbstractContractRuleApp) node.getAppliedRuleApp();
26+
if (node.getAppliedRuleApp() instanceof AbstractContractRuleApp contractRuleApp) {
2927
DefaultProofReference<Contract> reference = new DefaultProofReference<>(
3028
IProofReference.USE_CONTRACT, node, contractRuleApp.getInstantiation());
3129
LinkedHashSet<IProofReference<?>> result = new LinkedHashSet<>();

key.core.proof_references/src/main/java/de/uka/ilkd/key/proof_references/analyst/MethodBodyExpandProofReferencesAnalyst.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ public class MethodBodyExpandProofReferencesAnalyst implements IProofReferencesA
2626
public LinkedHashSet<IProofReference<?>> computeReferences(Node node, Services services) {
2727
if (node.getAppliedRuleApp() != null && node.getNodeInfo() != null) {
2828
NodeInfo info = node.getNodeInfo();
29-
if (info.getActiveStatement() instanceof MethodBodyStatement) {
30-
MethodBodyStatement mbs = (MethodBodyStatement) info.getActiveStatement();
29+
if (info.getActiveStatement() instanceof MethodBodyStatement mbs) {
3130
IProgramMethod pm = mbs.getProgramMethod(services);
3231
DefaultProofReference<IProgramMethod> reference =
3332
new DefaultProofReference<>(IProofReference.INLINE_METHOD, node,

key.core.proof_references/src/main/java/de/uka/ilkd/key/proof_references/analyst/MethodCallProofReferencesAnalyst.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ public LinkedHashSet<IProofReference<?>> computeReferences(Node node, Services s
5555
new LinkedHashSet<>();
5656
result.add(reference);
5757
return result;
58-
} else if (info.getActiveStatement() instanceof Assignment) {
59-
Assignment assignment = (Assignment) info.getActiveStatement();
58+
} else if (info.getActiveStatement() instanceof Assignment assignment) {
6059
ExecutionContext context = extractContext(node, services);
6160
LinkedHashSet<IProofReference<?>> result =
6261
new LinkedHashSet<>();
@@ -110,7 +109,7 @@ protected IProofReference<IProgramMethod> createReference(Node node, Services se
110109
IProgramMethod pm = mr.method(services, refPrefixType, context);
111110
return new DefaultProofReference<>(IProofReference.CALL_METHOD, node, pm);
112111
} else {
113-
if (!(node.getAppliedRuleApp() instanceof PosTacletApp)) {
112+
if (!(node.getAppliedRuleApp() instanceof PosTacletApp app)) {
114113
throw new IllegalArgumentException("PosTacletApp expected.");
115114
}
116115
if (!"staticMethodCallStaticWithAssignmentViaTypereference"
@@ -119,7 +118,6 @@ protected IProofReference<IProgramMethod> createReference(Node node, Services se
119118
"Rule \"staticMethodCallStaticWithAssignmentViaTypereference\" expected, but is \""
120119
+ MiscTools.getRuleName(node) + "\".");
121120
}
122-
PosTacletApp app = (PosTacletApp) node.getAppliedRuleApp();
123121
SchemaVariable methodSV = app.instantiations().lookupVar(new Name("#mn"));
124122
SchemaVariable typeSV = app.instantiations().lookupVar(new Name("#t"));
125123
SchemaVariable argsSV = app.instantiations().lookupVar(new Name("#elist"));

key.core.proof_references/src/main/java/de/uka/ilkd/key/proof_references/analyst/ProgramVariableReferencesAnalyst.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ protected void listReferences(Node node, ProgramElement pe, ProgramVariable arra
7070
(ProgramVariable) pe);
7171
ProofReferenceUtil.merge(toFill, reference);
7272
}
73-
} else if (pe instanceof FieldReference) {
74-
FieldReference fr = (FieldReference) pe;
73+
} else if (pe instanceof FieldReference fr) {
7574
ReferencePrefix ref = fr.getReferencePrefix();
7675
if (ref != null) {
7776
listReferences(node, ref, arrayLength, toFill, includeExpressionContainer);
@@ -82,8 +81,7 @@ protected void listReferences(Node node, ProgramElement pe, ProgramVariable arra
8281
new DefaultProofReference<>(IProofReference.ACCESS, node, pv);
8382
ProofReferenceUtil.merge(toFill, reference);
8483
}
85-
} else if (includeExpressionContainer && pe instanceof ExpressionContainer) {
86-
ExpressionContainer ec = (ExpressionContainer) pe;
84+
} else if (includeExpressionContainer && pe instanceof ExpressionContainer ec) {
8785
for (int i = ec.getChildCount() - 1; i >= 0; i--) {
8886
ProgramElement element = ec.getChildAt(i);
8987
listReferences(node, element, arrayLength, toFill, includeExpressionContainer);

key.core.proof_references/src/main/java/de/uka/ilkd/key/proof_references/reference/DefaultProofReference.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ public Proof getSource() {
9595
*/
9696
@Override
9797
public boolean equals(Object obj) {
98-
if (obj instanceof IProofReference<?>) {
99-
IProofReference<?> other = (IProofReference<?>) obj;
98+
if (obj instanceof IProofReference<?> other) {
10099
return Objects.equals(getKind(), other.getKind())
101100
&& Objects.equals(getSource(), other.getSource())
102101
&& Objects.equals(getTarget(), other.getTarget());

key.core.proof_references/src/main/java/de/uka/ilkd/key/proof_references/reference/IProofReference.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
* @author Martin Hentschel
2525
* @see ProofReferenceUtil
26-
* @see IProofReferencesAnalyst.
26+
* @see IProofReferencesAnalyst
2727
*/
2828
public interface IProofReference<T> {
2929
/**

key.core.proof_references/src/test/java/de/uka/ilkd/key/proof_references/testcase/AbstractProofReferenceTestCase.java

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,10 @@ protected void assertReferences(LinkedHashSet<IProofReference<?>> current,
235235
int i = 0;
236236
for (IProofReference<?> currentReference : current) {
237237
ExpectedProofReferences expectedReference = expected[i];
238-
assertEquals(expectedReference.getKind(), currentReference.getKind());
239-
if (expectedReference.getTarget() != null) {
238+
assertEquals(expectedReference.kind(), currentReference.getKind());
239+
if (expectedReference.target() != null) {
240240
assertNotNull(currentReference.getTarget());
241-
assertEquals(expectedReference.getTarget(),
241+
assertEquals(expectedReference.target(),
242242
currentReference.getTarget().toString());
243243
} else {
244244
assertNull(currentReference.getTarget());
@@ -250,48 +250,40 @@ protected void assertReferences(LinkedHashSet<IProofReference<?>> current,
250250
/**
251251
* Defines the values of an expected proof reference.
252252
*
253+
* @param kind The expected kind.
254+
* @param target The expected target.
253255
* @author Martin Hentschel
254256
*/
255-
protected static class ExpectedProofReferences {
256-
/**
257-
* The expected kind.
258-
*/
259-
private final String kind;
260-
261-
/**
262-
* The expected target.
263-
*/
264-
private final String target;
265-
257+
protected record ExpectedProofReferences(String kind, String target) {
266258
/**
267259
* Constructor.
268260
*
269-
* @param kind The expected kind.
261+
* @param kind The expected kind.
270262
* @param target The expected target.
271263
*/
272-
public ExpectedProofReferences(String kind, String target) {
273-
this.kind = kind;
274-
this.target = target;
264+
public ExpectedProofReferences {
275265
}
276266

277-
/**
278-
* Returns the expected kind.
279-
*
280-
* @return The expected kind.
281-
*/
282-
public String getKind() {
283-
return kind;
284-
}
267+
/**
268+
* Returns the expected kind.
269+
*
270+
* @return The expected kind.
271+
*/
272+
@Override
273+
public String kind() {
274+
return kind;
275+
}
285276

286-
/**
287-
* Returns the expected target.
288-
*
289-
* @return The expected target.
290-
*/
291-
public String getTarget() {
292-
return target;
277+
/**
278+
* Returns the expected target.
279+
*
280+
* @return The expected target.
281+
*/
282+
@Override
283+
public String target() {
284+
return target;
285+
}
293286
}
294-
}
295287

296288
/**
297289
* Does some test steps with a {@link Proof}.

key.core.symbolic_execution/src/main/java/de/uka/ilkd/key/proof/TermProgramVariableCollectorKeepUpdatesForBreakpointconditions.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ public void visit(Term t) {
3434

3535
private void addVarsToKeep() {
3636
for (IBreakpoint breakpoint : breakpointStopCondition.getBreakpoints()) {
37-
if (breakpoint instanceof AbstractConditionalBreakpoint) {
38-
AbstractConditionalBreakpoint conditionalBreakpoint =
39-
(AbstractConditionalBreakpoint) breakpoint;
37+
if (breakpoint instanceof AbstractConditionalBreakpoint conditionalBreakpoint) {
4038
if (conditionalBreakpoint.getToKeep() != null) {
4139
for (LocationVariable sub : conditionalBreakpoint.getToKeep()) {
4240
if (sub instanceof LocationVariable) {

0 commit comments

Comments
 (0)